Skip to content

Commit 6e45f32

Browse files
author
b-richard
committed
Code style tooling (php and JS)
1 parent 40b016d commit 6e45f32

31 files changed

+2001
-504
lines changed

.editorconfig

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; top-most EditorConfig file
2+
root = true
3+
4+
; Unix-style newlines
5+
[*]
6+
end_of_line = LF
7+
trim_trailing_whitespace = true
8+
indent_style = space
9+
indent_size = 4
10+
charset = utf-8
11+
insert_final_newline = true
12+
13+
[*.php]
14+

.php_cs.dist

+6
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,11 @@ return PhpCsFixer\Config::create()
55
'@PSR1' => true,
66
'@PSR2' => true,
77
'array_syntax' => ['syntax' => 'short'],
8+
'protected_to_private' => false,
89
])
10+
->setFinder(
11+
PhpCsFixer\Finder::create()
12+
->in(__DIR__.'/src')
13+
->append(array(__FILE__))
14+
)
915
;

.prettierrc.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
"printWidth": 120,
3+
"semi": false,
4+
"single-quote": true,
5+
"tabWidth": 4,
6+
"trailing-comma": "all",
7+
}

README.md

+18-6
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,25 @@ Also, if you want to use the asset server finely, you have to add the assets con
127127
`json_manifest_path: '%kernel.project_dir%/public/build/manifest.json'`. In fact the npm command will build asset in memory only, and modify the manifest file to map asset to a new url served by the asset server instead of the main web server.
128128

129129
# code quality
130+
## PHP
131+
The project uses 2 packages to lint and fix the code style of PHP code :You can install phpcs to check your code
132+
* squizlabs/PHP_CodeSniffer to lint and follow PSR1/PSR2 rules.
133+
* friendsofphp/php-cs-fixer to fix the code
134+
135+
Lint with this command `vendor/bin/phpcs src -n --standard=PSR1,PSR2 --report=summary` to get a summary of errors.
136+
Fix with this command `vendor/bin/php-cs-fixer fix src --rules=@PSR1,@PSR2`
137+
138+
## Javascript
139+
For Javascript the following packages has been used:
140+
`npm install prettier`
141+
142+
To lint the code: `node bin-prettier.js assets/js/**`
143+
To fix it: `node bin-prettier.js assets/js/** --write`
130144

131-
You can install phpcs to check your code, for this run `composer require squizlabs/PHP_CodeSniffer`. This project follows
132-
PSR1/PSR2 rules. Run this command `vendor/bin/phpcs src -n --standard=PSR1,PSR2 --report=summary` to get a summary of
133-
errors
145+
## IDE
134146

135-
For PHP you should configure your IDE to follow Symfony code style (or anything else if you prefer) for PHP, and Airbnb or any other check style for Javascript.
136-
You can use `friendsofphp/php-cs-fixer` package to fix your PHP code and `prettier`for Javascript.
137-
We may add those packages to the current stack if it's something requested.
147+
For PHP you should configure your IDE to follow PSR1/PSR2 code style (or anything else if you prefer). For JS you will
148+
have to install [prettier tool](https://prettier.io/docs/en/editors.html).
138149

139150
## todo
140151

@@ -143,3 +154,4 @@ We may add those packages to the current stack if it's something requested.
143154
* ~~add db fixtures at init ! almost 40 books and some reviews (at least 3 for 5 1st books)~~ all sqlite fixtures is converted into the final db model
144155
* customize easyAdminBundle to add author/editor from Book and display those related infos on Book admin page (same for other author/editor entities and serie/reviews)
145156
* manage Entity orphanRemoval / CASCADE onDelete
157+
* find a good way to add a `pre-commit` hook that lint PHP and JS code, and run the PHP / JS tests

assets/js/app.js

-1
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

assets/js/csrf_token.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ export default function getToken(loaderToActivate) {
1818
cache: 'no-cache',
1919
}
2020
fetch(uri, myInit)
21-
// @todo manage http error
22-
.then(res => res.json()).then(res => {
23-
changeMeta(meta, res)
24-
if (loaderToActivate) {
25-
loaderToActivate.isLoading = false
26-
}
27-
resolve(res)
28-
})
21+
// @todo manage http error
22+
.then(res => res.json())
23+
.then(res => {
24+
changeMeta(meta, res)
25+
if (loaderToActivate) {
26+
loaderToActivate.isLoading = false
27+
}
28+
resolve(res)
29+
})
2930
})
3031
}
3132

assets/js/form/App.vue

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
</template>
66

77
<script>
8-
export default {
9-
name: 'app',
10-
}
8+
export default {
9+
name: 'app',
10+
}
1111
</script>
1212

1313
<style>
14-
#app {
15-
font-family: 'Avenir', Helvetica, Arial, sans-serif;
16-
-webkit-font-smoothing: antialiased;
17-
-moz-osx-font-smoothing: grayscale;
18-
text-align: center;
19-
color: #2c3e50;
20-
margin-top: 60px;
21-
}
14+
#app {
15+
font-family: 'Avenir', Helvetica, Arial, sans-serif;
16+
-webkit-font-smoothing: antialiased;
17+
-moz-osx-font-smoothing: grayscale;
18+
text-align: center;
19+
color: #2c3e50;
20+
margin-top: 60px;
21+
}
2222
</style>

assets/js/form/app.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import router from './router'
66
import Quasar from 'quasar-framework'
77
import Vuelidate from 'vuelidate'
88
import VueApollo from 'vue-apollo'
9-
import {apolloProvider} from '../apollo'
9+
import { apolloProvider } from '../apollo'
1010

1111
require('../../../node_modules/quasar-framework/dist/quasar.mat.css')
1212
// not sure that fonts are loaded finely

assets/js/form/components/Book.vue

+9-11
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,19 @@
55
</template>
66

77
<script>
8-
import {
8+
import { QItemMain, QItemTile } from 'quasar-framework'
9+
10+
export default {
11+
name: 'Book',
12+
components: {
913
QItemMain,
1014
QItemTile,
11-
} from 'quasar-framework'
12-
13-
export default {
14-
name: 'Book',
15-
components: {
16-
QItemMain,
17-
QItemTile,
18-
},
19-
props: ['book'],
20-
}
15+
},
16+
props: ['book'],
17+
}
2118
</script>
2219

2320
<!-- Add "scoped" attribute to limit CSS to this component only -->
2421
<style scoped>
22+
2523
</style>

0 commit comments

Comments
 (0)