Skip to content

Commit 2b9166b

Browse files
[-] Technical - Upgrade ESLint rules (#262)
1 parent 5ecdc8a commit 2b9166b

29 files changed

+592
-630
lines changed

.eslint-bin/js-list.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

.eslint-bin/lint-registered-files.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

.eslint-bin/pre-commit-hook.js

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,43 @@
1-
const fs = require('fs');
2-
const _ = require('lodash');
1+
const { spawn } = require('child_process');
32
const simpleGit = require('simple-git')(`${__dirname}/..`);
4-
let filesListValid = require('./js-list.json')
5-
let filesListChanged = [];
63

7-
function addCommitedFilesToEslint(callback) {
4+
let listFilesModified = [];
5+
6+
function getFilesModified(callback) {
87
simpleGit.status((error, status) => {
98
if (error) {
9+
// eslint-disable-next-line no-console
1010
console.error(error);
1111
process.exit(-1);
1212
}
1313

14-
jsFilesListChanged = status.files
15-
.map(file => (file.path.includes(' -> ')
16-
? file.path.substring(file.path.indexOf(' -> ') + 4) : file.path))
17-
.filter(file => file.endsWith('.js'));
18-
19-
const addedFiles = _.difference(filesListChanged, filesListValid);
20-
21-
filesListValid = _.uniq(filesListValid.concat(filesListChanged).sort());
22-
23-
if (addedFiles.length !== 0) {
24-
fs.writeFileSync(`${__dirname}/js-list.json`, `${JSON.stringify(filesListValid, null, 2)}\n`);
25-
console.log(`[ESLint] Adding some files for CI validation:\n${addedFiles.join('\n')}`);
26-
}
14+
listFilesModified = status.files
15+
.map((file) => file.path)
16+
.filter((file) => file.endsWith('.js'));
2717

2818
callback();
2919
});
3020
}
3121

3222
function runEslint(callback) {
33-
if (filesListChanged.length === 0) {
23+
if (listFilesModified.length === 0) {
3424
return callback(0);
3525
}
3626

37-
console.log(`[ESLint] Validating changed files:\n${filesListChanged.join('\n')}`);
27+
// eslint-disable-next-line no-console
28+
console.log(`[ESLint] Validating changed files:\n${listFilesModified.join('\n')}`);
3829
const eslintPath = `${__dirname}/../node_modules/.bin/eslint`;
39-
const spawn = require('child_process').spawn;
40-
const cmd = spawn(eslintPath, filesListChanged, { stdio: 'inherit', shell: true });
30+
const cmd = spawn(eslintPath, listFilesModified, { stdio: 'inherit', shell: true });
4131

42-
cmd.on('exit', function (code) {
43-
callback(code);
44-
});
32+
return cmd.on('exit', (code) => callback(code));
4533
}
4634

47-
addCommitedFilesToEslint((error) => {
35+
getFilesModified((error) => {
4836
if (error) {
37+
// eslint-disable-next-line no-console
4938
console.error(error);
5039
process.exit(-2);
5140
}
5241

53-
simpleGit.add(`${__dirname}/js-list.json`, (error) => {
54-
if (error) {
55-
console.error(error);
56-
process.exit(-3);
57-
}
58-
59-
runEslint((code) => process.exit(code));
60-
})
42+
runEslint((code) => process.exit(code));
6143
});

.eslintrc.js

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
root: true,
3-
'extends': [
3+
extends: [
44
'airbnb-base',
55
'plugin:jest/all'
66
],
@@ -9,26 +9,10 @@ module.exports = {
99
node: true,
1010
},
1111
rules: {
12+
'implicit-arrow-linebreak': 0,
1213
'jest/no-hooks': 0,
13-
'no-console': 0,
1414
'no-param-reassign': 0,
1515
'no-underscore-dangle': 0,
16-
'prefer-destructuring': [
17-
'error',
18-
{
19-
VariableDeclarator: {
20-
array: false,
21-
object: true,
22-
},
23-
AssignmentExpression: {
24-
array: false,
25-
object: false,
26-
},
27-
},
28-
{
29-
enforceForRenamedProperties: false,
30-
},
31-
],
3216
'import/no-extraneous-dependencies': [
3317
'error',
3418
{

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ before_install:
1414
- docker ps
1515

1616
script:
17-
- yarn lint:ci
17+
- yarn lint
1818
- yarn test

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
## [Unreleased]
44
### Changed
55
- Technical - Rename `.env.example` file.
6+
- Technical - Upgrade ESLint rules.
7+
- Technical - Ensure that all files follow the ESLint rules.
68

79
## RELEASE 5.4.0 - 2019-11-29
810
### Added

package.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@
3939
"babel-preset-env": "7.0.0-beta.3",
4040
"babel-register": "7.0.0-beta.3",
4141
"dotenv": "6.2.0",
42-
"eslint": "5.16.0",
43-
"eslint-config-airbnb": "16.1.0",
44-
"eslint-plugin-import": "2.17.2",
42+
"eslint": "6.7.2",
43+
"eslint-config-airbnb-base": "14.0.0",
44+
"eslint-plugin-import": "2.18.2",
4545
"eslint-plugin-jest": "23.0.4",
46-
"eslint-plugin-jsx-a11y": "6.0.2",
47-
"eslint-plugin-react": "7.5.1",
4846
"jest": "24.9.0",
4947
"mongoose": "5.5.9",
5048
"mongoose-fixture-loader": "1.0.2",
@@ -55,8 +53,7 @@
5553
"scripts": {
5654
"build": "./node_modules/babel-cli/bin/babel.js src --out-dir dist && echo '\n\\033[0;34m[+] \\033[0;32mBuild done\\033[0m'",
5755
"build:watch": "onchange 'src/**/*.js' -i -- yarn build",
58-
"lint": "./node_modules/eslint/bin/eslint.js test src",
59-
"lint:ci": "node ./.eslint-bin/lint-registered-files.js",
56+
"lint": "./node_modules/eslint/bin/eslint.js .eslint-bin scripts src test",
6057
"pre-commit": "node ./.eslint-bin/pre-commit-hook.js",
6158
"readme:update-coverage": "yarn test:coverage && node ./scripts/update-coverage.js",
6259
"release": "yarn build && node ./scripts/release.js",
@@ -66,4 +63,4 @@
6663
"pre-commit": [
6764
"pre-commit"
6865
]
69-
}
66+
}

0 commit comments

Comments
 (0)