-
Notifications
You must be signed in to change notification settings - Fork 1
Code improvments with lint checks by XO and ESLint rules
Since commit ci(sca): static code analysis and linting PhytoJS code was linted by XO, then commit refactor(xo): cleaner tests brings also styled tests.
the xo configuration can break builds if there are style errors in not ignored source files; to get the build broken when there are such kind of errors you should use one of this:
npm run clean:prepare:cover
npm run clean:prepare:test:xo
npm run test:xo
please note that style errors does't break your tests; that is:
npm test
could complete successfully even if there are style errors still present.
Continuous integration Builds (configured in .travis.yml
) run - npm run clean:prepare:cover
, therefore they break if there are unfulfilled rules that mark error
The pluggable linting utility for JavaScript is ESLint
In PhytoJS we use XO that is the ESLint wrapper with lots of goodies included. Enforces strict and readable code. Never discuss code style on a pull request again! No decision-making. No .eslintrc or .jshintrc to manage. It just works!
More about xo.
-
npm install --save-dev xo
this was automatically installed when you clone phytojs and install dependencies by$ npm i
because of the presence inpackage.json
of:
"devDependencies": {
...
"xo": "^0.24.0"
...
-
To get
XO: Fix all auto-fixable problems
command in vscode I've installed Sam Verschueren's vscode extension with identifier:samverschueren.linter-xo
vscode-linter-xo sources repository. Please note that alternatives are available if you works with different IDE or Editor , for esample linter-xo for atom.io and even for vscode they could be alternatives such ase https://marketplace.visualstudio.com/items?itemName=bryan-chen.linter-xo-2 but but these are not options thta have adopted in my case ( ...since now). -
Accordining to my preferences I've changed hyper-sensitive rules to be
warning
insted oferror
; see xo settings section included in./package.json
-
Accordining to my preferences I've changed vscode workspace dettings located at
.vscode/settings.json
xo settings section included in ./package.json
"xo": {
"ignores": [
"esm",
"umd",
"docs",
"samples",
"script"
],
"rules": {
"unicorn/filename-case": 1,
"no-use-extend-native/no-use-extend-native": 1,
"camelcase": 1,
"import/extensions": 1,
"import/first": 1
}
}
vscode workspace dettings located at .vscode/settings.json
{
// The number of spaces a tab is equal to. This setting is overridden
// based on the file contents when `editor.detectIndentation` is true.
"editor.tabSize": 2,
// Insert spaces when pressing Tab. This setting is overriden
// based on the file contents when `editor.detectIndentation` is true.
"editor.insertSpaces": false,
// When opening a file, `editor.tabSize` and `editor.insertSpaces`
// will be detected based on the file contents. Set to false to keep
// the values you've explicitly set, above.
"editor.detectIndentation": false,
// "eslint.enable": false,
"xo.enable": true,
"xo.format.enable": true,
"xo.options": {
"semicolon": true
}
}
Plese open an issue if something is not clear to you or you would like to propose improvements