Skip to content

Commit 18f9f27

Browse files
chore: eslint 9 support (#101)
* chore: eslint 9 support * ci: adding eslint9 and 8 tests, downgrading the supported node version to 18 and 19
1 parent 55e2990 commit 18f9f27

31 files changed

+11146
-10249
lines changed

.eslintrc.js

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

.github/workflows/tests.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@ jobs:
1313

1414
strategy:
1515
matrix:
16-
node-version: [12.x, 14.x, 16.x]
16+
node-version: [18.x, 20.x]
17+
eslint-version: [8.x, 9.x]
1718

1819
steps:
1920
- uses: actions/checkout@v2
2021
- name: Use Node.js ${{ matrix.node-version }}
2122
uses: actions/setup-node@v1
2223
with:
2324
node-version: ${{ matrix.node-version }}
24-
- run: npm install
25+
- name: Install ESLint ${{ matrix.eslint-version }}
26+
run: npm install eslint@${{ matrix.eslint-version }}
27+
- run: npm install --force
2528
- run: npm test
2629
env:
2730
CI: true

eslint.config.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = {
2+
"plugins": {
3+
"react": require("eslint-plugin-react"),
4+
"jsx-a11y": require("eslint-plugin-jsx-a11y"),
5+
"import": require("eslint-plugin-import")
6+
},
7+
"rules": {
8+
"func-names": 0,
9+
"global-require": 0,
10+
"prefer-destructuring": 0,
11+
"strict": 0,
12+
// Include rules from airbnb configuration directly here
13+
// Make sure to copy the rules from the airbnb configuration
14+
},
15+
"languageOptions": {
16+
"globals": {
17+
// Define global variables here for your files
18+
"mocha": true
19+
}
20+
}
21+
};
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
const isReactReduxConnect = require('../isReactReduxConnect');
22

3-
const report = function (context, node) {
4-
context.report({
5-
message: 'Connect function should have at least 2 arguments.',
6-
node,
7-
});
8-
};
3+
const create = function (context) {
4+
const report = function (node) {
5+
context.report({
6+
message: 'Connect function should have at least 2 arguments.',
7+
node,
8+
});
9+
};
910

10-
module.exports = function (context) {
1111
return {
1212
CallExpression(node) {
1313
if (isReactReduxConnect(node)) {
1414
if (node.arguments.length < 2) {
15-
report(context, node);
15+
report(node);
1616
}
1717
}
1818
},
1919
};
2020
};
21+
22+
module.exports = {
23+
create,
24+
};

lib/rules/connect-prefer-named-arguments.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,32 @@ const argumentNames = [
77
'options',
88
];
99

10-
const report = function (context, node, i) {
11-
context.report({
12-
message: `Connect function argument #${i} should be named ${argumentNames[i]}`,
13-
node,
14-
});
15-
};
10+
const create = function (context) {
11+
const report = function (node, i) {
12+
context.report({
13+
message: `Connect function argument #${i + 1} should be named ${argumentNames[i]}`,
14+
node,
15+
});
16+
};
1617

17-
module.exports = function (context) {
1818
return {
1919
CallExpression(node) {
2020
if (isReactReduxConnect(node)) {
2121
node.arguments.forEach((argument, i) => {
2222
if (argument.raw && argument.raw !== 'null') {
23-
report(context, node, i);
23+
report(node, i);
2424
} else if (
2525
!argument.raw
2626
&& argumentNames[i]
2727
&& (!argument.name || argument.name !== argumentNames[i])) {
28-
report(context, node, i);
28+
report(node, i);
2929
}
3030
});
3131
}
3232
},
3333
};
3434
};
35+
36+
module.exports = {
37+
create,
38+
};

lib/rules/mapDispatchToProps-prefer-parameters-names.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const check = function (context, params) {
2020
});
2121
};
2222

23-
module.exports = function (context) {
23+
const create = function (context) {
2424
return {
2525
VariableDeclaration(node) {
2626
node.declarations.forEach((decl) => {
@@ -52,3 +52,7 @@ module.exports = function (context) {
5252
},
5353
};
5454
};
55+
56+
module.exports = {
57+
create,
58+
};

lib/rules/mapDispatchToProps-prefer-shorthand.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ const report = function (context, node) {
88
});
99
};
1010

11-
const getParamsString = (params, context) =>
12-
params.map(param => context.getSource(param)).join(',');
11+
const getParamsString = (params, context) => {
12+
const sourceCode = context.sourceCode ?? context.getSourceCode();
13+
return params.map(param => sourceCode.getText(param)).join(',')
14+
}
1315

1416

1517
const propertyCanUseShortHandButDoesnt = (context, prop, dispatchName) => {
1618
const propName = prop.key && prop.key.name;
17-
const sourceCode = context.getSource(prop.value).replace(/(\r\n|\n|\r|\t| |;)/gm, '');
19+
const sourceCodeImpl = context.sourceCode ?? context.getSourceCode();
20+
const sourceCode = sourceCodeImpl.getText(prop.value).replace(/(\r\n|\n|\r|\t| |;)/gm, '');
1821
if (prop.value && prop.value.type === 'ArrowFunctionExpression') {
1922
const fncDef = prop.value;
2023
const paramString = getParamsString(fncDef.params, context);
@@ -42,8 +45,7 @@ const checkReturnNode = function (context, returnNode, dispatchName) {
4245
}
4346
};
4447

45-
46-
module.exports = function (context) {
48+
const create = function (context) {
4749
return {
4850
VariableDeclaration(node) {
4951
node.declarations.forEach((decl) => {
@@ -84,3 +86,7 @@ module.exports = function (context) {
8486
},
8587
};
8688
};
89+
90+
module.exports = {
91+
create,
92+
};

lib/rules/mapDispatchToProps-returns-object.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ const report = function (context, node) {
88
});
99
};
1010

11-
12-
module.exports = function (context) {
11+
const create = function (context) {
1312
return {
1413
VariableDeclaration(node) {
1514
node.declarations.forEach((decl) => {
@@ -50,3 +49,7 @@ module.exports = function (context) {
5049
},
5150
};
5251
};
52+
53+
module.exports = {
54+
create,
55+
};

lib/rules/mapStateToProps-no-store.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const checkFunction = function (context, body, firstParamName) {
4444
}
4545
};
4646

47-
module.exports = function (context) {
47+
const create = function (context) {
4848
return {
4949
VariableDeclaration(node) {
5050
node.declarations.forEach((decl) => {
@@ -78,3 +78,7 @@ module.exports = function (context) {
7878
},
7979
};
8080
};
81+
82+
module.exports = {
83+
create,
84+
};

lib/rules/mapStateToProps-prefer-hoisted.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@ const checkProp = (node, context) => {
2929
}
3030
};
3131

32-
3332
const checkFunction = function (context, body) {
3433
const returnNode = utils.getReturnNode(body);
3534
if (returnNode && returnNode.type === 'ObjectExpression') {
3635
returnNode.properties.forEach(prop => checkProp(prop.value, context));
3736
}
3837
};
3938

40-
module.exports = function (context) {
39+
const create = function (context) {
4140
return {
4241
VariableDeclaration(node) {
4342
node.declarations.forEach((decl) => {
@@ -62,3 +61,7 @@ module.exports = function (context) {
6261
},
6362
};
6463
};
64+
65+
module.exports = {
66+
create,
67+
};

0 commit comments

Comments
 (0)