Skip to content

Commit 83f30cd

Browse files
[-] Technical - Upgrade ESLint rules (#341)
1 parent d8d93ed commit 83f30cd

27 files changed

+375
-383
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ let listFilesModified = [];
66
function getFilesModified(callback) {
77
simpleGit.status((error, status) => {
88
if (error) {
9+
// eslint-disable-next-line no-console
910
console.error(error);
1011
process.exit(-1);
1112
}
1213

1314
listFilesModified = status.files
14-
.map(file => file.path)
15-
.filter(file => file.endsWith('.js'));
15+
.map((file) => file.path)
16+
.filter((file) => file.endsWith('.js'));
1617

1718
callback();
1819
});
@@ -23,18 +24,20 @@ function runEslint(callback) {
2324
return callback(0);
2425
}
2526

27+
// eslint-disable-next-line no-console
2628
console.log(`[ESLint] Validating changed files:\n${listFilesModified.join('\n')}`);
2729
const eslintPath = `${__dirname}/../node_modules/.bin/eslint`;
2830
const cmd = spawn(eslintPath, listFilesModified, { stdio: 'inherit', shell: true });
2931

30-
return cmd.on('exit', code => callback(code));
32+
return cmd.on('exit', (code) => callback(code));
3133
}
3234

3335
getFilesModified((error) => {
3436
if (error) {
37+
// eslint-disable-next-line no-console
3538
console.error(error);
3639
process.exit(-2);
3740
}
3841

39-
runEslint(code => process.exit(code));
42+
runEslint((code) => process.exit(code));
4043
});

.eslintrc.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,8 @@ module.exports = {
99
node: true,
1010
},
1111
rules: {
12-
'no-console': 0,
12+
'implicit-arrow-linebreak': 0,
1313
'no-param-reassign': 0,
14-
'prefer-destructuring': [
15-
'error',
16-
{
17-
VariableDeclarator: {
18-
array: false,
19-
object: true,
20-
},
21-
AssignmentExpression: {
22-
array: false,
23-
object: false,
24-
},
25-
},
26-
{
27-
enforceForRenamedProperties: false,
28-
},
29-
],
3014
'import/no-extraneous-dependencies': [
3115
'error',
3216
{

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Change Log
22

33
## [Unreleased]
4+
### Changed
5+
- Technical - Upgrade ESLint rules.
6+
- Technical - Ensure that all files follow the ESLint rules.
47

58
## RELEASE 5.4.0 - 2019-11-29
69
### Added

package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,10 @@
3838
"babel-preset-env": "7.0.0-beta.3",
3939
"babel-register": "7.0.0-beta.3",
4040
"dotenv": "6.2.0",
41-
"eslint": "5.16.0",
42-
"eslint-config-airbnb": "16.1.0",
43-
"eslint-plugin-import": "2.8.0",
41+
"eslint": "6.7.1",
42+
"eslint-config-airbnb-base": "14.0.0",
43+
"eslint-plugin-import": "2.18.2",
4444
"eslint-plugin-jest": "23.0.4",
45-
"eslint-plugin-jsx-a11y": "6.0.2",
46-
"eslint-plugin-react": "7.5.1",
4745
"jest": "24.9.0",
4846
"mysql2": "1.6.5",
4947
"onchange": "6.0.0",
@@ -66,4 +64,4 @@
6664
"pre-commit": [
6765
"pre-commit"
6866
]
69-
}
67+
}

src/adapters/sequelize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ module.exports = (model, opts) => {
8080
idField = 'forestCompositePrimary';
8181
}
8282

83-
_.remove(fields, field =>
83+
_.remove(fields, (field) =>
8484
_.includes(fieldNamesToExclude, field.columnName) && !field.primaryKey);
8585

8686
return {

src/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ exports.init = function init(opts) {
9292
_.each(connection.models, (model) => {
9393
if (detectAllModels) {
9494
models[model.name] = model;
95-
} else if (!_.isEmpty(opts.includedModels) &&
96-
_.includes(opts.includedModels, model.name)) {
95+
} else if (!_.isEmpty(opts.includedModels)
96+
&& _.includes(opts.includedModels, model.name)) {
9797
models[model.name] = model;
98-
} else if (!_.isEmpty(opts.excludedModels) &&
99-
!_.includes(opts.excludedModels, model.name)) {
98+
} else if (!_.isEmpty(opts.excludedModels)
99+
&& !_.includes(opts.excludedModels, model.name)) {
100100
models[model.name] = model;
101101
}
102102
});
@@ -147,7 +147,7 @@ exports.init = function init(opts) {
147147
},
148148
getCustomerByUserField: (customerModel, customerField, userField) => {
149149
if (!customerModel) {
150-
return new P(resolve => resolve());
150+
return new P((resolve) => resolve());
151151
}
152152

153153
const query = {};
@@ -189,7 +189,7 @@ exports.init = function init(opts) {
189189
getUser: (userModel, userId) => {
190190
if (userId) {
191191
return orm.findRecord(userModel, userId)
192-
.then(user => user.toJSON());
192+
.then((user) => user.toJSON());
193193
}
194194

195195
return P.resolve();

src/services/apimap-field-builder.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ function ApimapFieldBuilder(model, column, options) {
126126
schema.isRequired = true;
127127
}
128128

129-
const canHaveDynamicDefaultValue = ['Date', 'Dateonly'].indexOf(schema.type) !== -1 ||
130-
column.type instanceof DataTypes.UUID;
131-
const isDefaultValueFunction = (typeof column.defaultValue) === 'function' ||
132-
(canHaveDynamicDefaultValue && (typeof column.defaultValue) === 'object');
129+
const canHaveDynamicDefaultValue = ['Date', 'Dateonly'].indexOf(schema.type) !== -1
130+
|| column.type instanceof DataTypes.UUID;
131+
const isDefaultValueFunction = (typeof column.defaultValue) === 'function'
132+
|| (canHaveDynamicDefaultValue && (typeof column.defaultValue) === 'object');
133133

134134
if (!_.isNull(column.defaultValue) && !_.isUndefined(column.defaultValue)) {
135135
// NOTICE: Prevent sequelize.Sequelize.NOW to be defined as the default value as the client

src/services/apimap-field-type-detector.js

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,47 @@ function ApimapFieldTypeDetector(column, options) {
22
const DataTypes = options.sequelize;
33

44
this.perform = () => {
5-
if (column.type instanceof DataTypes.STRING ||
6-
column.type instanceof DataTypes.TEXT ||
7-
column.type instanceof DataTypes.UUID ||
8-
column.type instanceof DataTypes.UUIDV1 ||
9-
column.type instanceof DataTypes.UUIDV4 ||
10-
(DataTypes.CITEXT && column.type instanceof DataTypes.CITEXT) ||
11-
column.type === 'citext') { // TODO: Remove 'citext' once Sequelize 4 has been unsupported.
5+
if (column.type instanceof DataTypes.STRING
6+
|| column.type instanceof DataTypes.TEXT
7+
|| column.type instanceof DataTypes.UUID
8+
|| column.type instanceof DataTypes.UUIDV1
9+
|| column.type instanceof DataTypes.UUIDV4
10+
|| (DataTypes.CITEXT && column.type instanceof DataTypes.CITEXT)
11+
|| column.type === 'citext') { // TODO: Remove 'citext' once Sequelize 4 has been unsupported.
1212
return 'String';
13-
} else if (column.type instanceof DataTypes.ENUM) {
13+
}
14+
if (column.type instanceof DataTypes.ENUM) {
1415
return 'Enum';
15-
} else if (column.type instanceof DataTypes.BOOLEAN) {
16+
}
17+
if (column.type instanceof DataTypes.BOOLEAN) {
1618
return 'Boolean';
17-
} else if (column.type instanceof DataTypes.DATEONLY) {
19+
}
20+
if (column.type instanceof DataTypes.DATEONLY) {
1821
return 'Dateonly';
19-
} else if (column.type instanceof DataTypes.DATE) {
22+
}
23+
if (column.type instanceof DataTypes.DATE) {
2024
return 'Date';
21-
} else if (column.type instanceof DataTypes.INTEGER ||
22-
column.type instanceof DataTypes.FLOAT ||
23-
column.type instanceof DataTypes['DOUBLE PRECISION'] ||
24-
column.type instanceof DataTypes.BIGINT ||
25-
column.type instanceof DataTypes.DECIMAL) {
25+
}
26+
if (column.type instanceof DataTypes.INTEGER
27+
|| column.type instanceof DataTypes.FLOAT
28+
|| column.type instanceof DataTypes['DOUBLE PRECISION']
29+
|| column.type instanceof DataTypes.BIGINT
30+
|| column.type instanceof DataTypes.DECIMAL) {
2631
return 'Number';
27-
} else if (column.type instanceof DataTypes.JSONB ||
28-
column.type instanceof DataTypes.JSON) {
32+
}
33+
if (column.type instanceof DataTypes.JSONB
34+
|| column.type instanceof DataTypes.JSON) {
2935
return 'Json';
30-
} else if (column.type instanceof DataTypes.TIME) {
36+
}
37+
if (column.type instanceof DataTypes.TIME) {
3138
return 'Time';
32-
} else if (column.type instanceof DataTypes.GEOMETRY &&
33-
column.type.type === 'POINT') {
39+
}
40+
if (column.type instanceof DataTypes.GEOMETRY
41+
&& column.type.type === 'POINT') {
3442
return 'Point';
43+
}
3544
// NOTICE: Detect Array types (Array(String), Array(Integer), ...)
36-
} else if (column.type.type) {
45+
if (column.type.type) {
3746
return [new ApimapFieldTypeDetector({ type: column.type.type }, options).perform()];
3847
}
3948
return null;

src/services/filters-parser.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { BaseFiltersParser, BaseOperatorDateParser, Schemas } from 'forest-express';
2-
import { getReferenceField } from '../utils/query';
32
import Operators from '../utils/operators';
43
import { NoMatchingOperatorError } from './errors';
54

5+
const { getReferenceField } = require('../utils/query');
6+
67
function FiltersParser(modelSchema, timezone, options) {
78
this.OPERATORS = new Operators(options);
89
this.operatorDateParser = new BaseOperatorDateParser({ operators: this.OPERATORS, timezone });
910

10-
this.perform = async filtersString =>
11+
this.perform = async (filtersString) =>
1112
BaseFiltersParser.perform(filtersString, this.formatAggregation, this.formatCondition);
1213

1314
this.formatAggregation = async (aggregator, formatedConditions) => {
@@ -170,7 +171,7 @@ function FiltersParser(modelSchema, timezone, options) {
170171
return currentPreviousInterval;
171172
};
172173

173-
this.getAssociations = async filtersString => BaseFiltersParser.getAssociations(filtersString);
174+
this.getAssociations = async (filtersString) => BaseFiltersParser.getAssociations(filtersString);
174175
}
175176

176177
module.exports = FiltersParser;

src/services/has-many-associator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function HasManyAssociator(model, association, opts, params, data) {
55
this.perform = function perform() {
66
return orm.findRecord(model, params.recordId)
77
.then((record) => {
8-
const associatedIds = _.map(data.data, value => value.id);
8+
const associatedIds = _.map(data.data, (value) => value.id);
99

1010
// NOTICE: Deactivate validation to prevent potential issues with custom model validations.
1111
// In this case, the full record attributes are missing which may raise an

0 commit comments

Comments
 (0)