Skip to content

Commit 24f4da6

Browse files
committed
feat: export flat configs, use esmodules everywhere.
BREAKING
1 parent 7d02b5f commit 24f4da6

File tree

10 files changed

+54
-62
lines changed

10 files changed

+54
-62
lines changed

index.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@
22
* @license MIT
33
* @author Martin Giger
44
*/
5-
"use strict";
5+
import fromMap from "./rules/from-map";
6+
import noUnnecessaryThisArg from "./rules/no-unnecessary-this-arg";
7+
import preferArrayFrom from "./rules/prefer-array-from";
8+
import avoidReverse from "./rules/avoid-reverse";
9+
import preferFlatMap from "./rules/prefer-flat-map";
10+
import preferFlat from "./rules/prefer-flat";
611

7-
module.exports = {
12+
const index = {
813
rules: {
9-
"from-map": require("./rules/from-map"),
10-
"no-unnecessary-this-arg": require("./rules/no-unnecessary-this-arg"),
11-
"prefer-array-from": require("./rules/prefer-array-from"),
12-
"avoid-reverse": require("./rules/avoid-reverse"),
13-
"prefer-flat-map": require("./rules/prefer-flat-map"),
14-
"prefer-flat": require("./rules/prefer-flat")
14+
"from-map": fromMap,
15+
"no-unnecessary-this-arg": noUnnecessaryThisArg,
16+
"prefer-array-from": preferArrayFrom,
17+
"avoid-reverse": avoidReverse,
18+
"prefer-flat-map": preferFlatMap,
19+
"prefer-flat": preferFlat,
1520
},
1621
configs: {
1722
recommended: {
18-
parserOptions: {
19-
ecmaVersion: 2015
20-
},
21-
plugins: [ 'array-func' ],
23+
plugins: { "array-func": index },
2224
rules: {
2325
"array-func/from-map": "error",
2426
"array-func/no-unnecessary-this-arg": "error",
@@ -27,15 +29,17 @@ module.exports = {
2729
}
2830
},
2931
all: {
30-
parserOptions: {
31-
ecmaVersion: 2018
32-
},
33-
plugins: [ 'array-func' ],
32+
plugins: { "array-func": index },
3433
rules: {
34+
"array-func/from-map": "error",
35+
"array-func/no-unnecessary-this-arg": "error",
36+
"array-func/prefer-array-from": "error",
37+
"array-func/avoid-reverse": "error",
3538
"array-func/prefer-flat-map": "error",
3639
"array-func/prefer-flat": "error"
37-
},
38-
extends: [ 'plugin:array-func/recommended' ]
40+
}
3941
}
4042
}
4143
};
44+
45+
export default index;

lib/helpers/call-expression.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
* @author Martin Giger
33
* @license MIT
44
*/
5-
"use strict";
6-
7-
const {
5+
import {
86
MEMBER_EXPRESSION,
97
IDENTIFIER
10-
} = require("../type");
8+
} from "../type";
119

1210
// Helper functions for call expression nodes.
1311

14-
exports.isMethod = (node, name) => "callee" in node && node.callee.type === MEMBER_EXPRESSION && node.callee.property.name === name;
12+
export const isMethod = (node, name) => "callee" in node && node.callee.type === MEMBER_EXPRESSION && node.callee.property.name === name;
1513

16-
exports.isOnObject = (node, name) => "object" in node.callee && node.callee.object.type === IDENTIFIER && node.callee.object.name === name;
14+
export const isOnObject = (node, name) => "object" in node.callee && node.callee.object.type === IDENTIFIER && node.callee.object.name === name;

lib/type.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
* @author Martin Giger
33
* @license MIT
44
*/
5-
"use strict";
65

7-
exports.MEMBER_EXPRESSION = "MemberExpression";
8-
exports.ARROW_FUNCTION_EXPRESSION = "ArrowFunctionExpression";
9-
exports.IDENTIFIER = "Identifier";
6+
export const MEMBER_EXPRESSION = "MemberExpression";
7+
export const ARROW_FUNCTION_EXPRESSION = "ArrowFunctionExpression";
8+
export const IDENTIFIER = "Identifier";

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"typescript": "^5.2.2"
2424
},
2525
"peerDependencies": {
26-
"eslint": ">=8.40.0"
26+
"eslint": ">=8.51.0"
2727
},
2828
"keywords": [
2929
"eslint",
@@ -53,5 +53,6 @@
5353
},
5454
"publishConfig": {
5555
"provenance": true
56-
}
56+
},
57+
"type": "module"
5758
}

rules/avoid-reverse.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
* @license MIT
33
* @author Martin Giger
44
*/
5-
"use strict";
5+
import { isMethod } from "../lib/helpers/call-expression";
66

7-
const { isMethod } = require("../lib/helpers/call-expression"),
8-
9-
REPLACEMENTS = {
10-
reduce: "reduceRight",
11-
reduceRight: "reduce"
12-
};
7+
const REPLACEMENTS = {
8+
reduce: "reduceRight",
9+
reduceRight: "reduce"
10+
};
1311

14-
module.exports = {
12+
export default {
1513
meta: {
1614
docs: {
1715
description: "Prefer methods operating from the right over reversing the array",

rules/from-map.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@
22
* @license MIT
33
* @author Martin Giger
44
*/
5-
"use strict";
5+
import { ARROW_FUNCTION_EXPRESSION } from "../lib/type";
66

7-
const { ARROW_FUNCTION_EXPRESSION } = require("../lib/type"),
8-
ALL_PARAMS = [
9-
{ name: 'item' },
10-
{ name: 'index' }
11-
];
7+
const ALL_PARAMS = [
8+
{ name: 'item' },
9+
{ name: 'index' }
10+
];
1211

1312
function isFunction(node) {
1413
return node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression";
1514
}
1615

17-
module.exports = {
16+
export default {
1817
meta: {
1918
docs: {
2019
description: "Prefer using the mapFn callback of Array.from over an immediate .map() call.",

rules/no-unnecessary-this-arg.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
* @license MIT
33
* @author Martin Giger
44
*/
5-
"use strict";
5+
import {
6+
isMethod,
7+
isOnObject
8+
} from "../lib/helpers/call-expression";
9+
import { ARROW_FUNCTION_EXPRESSION } from "../lib/type";
610

7-
const {
8-
isMethod,
9-
isOnObject
10-
} = require("../lib/helpers/call-expression"),
11-
{ ARROW_FUNCTION_EXPRESSION } = require("../lib/type"),
12-
13-
arrayFunctions = {
11+
const arrayFunctions = {
1412
from: 3
1513
},
1614
// All have param location 2
@@ -72,7 +70,7 @@ const {
7270
});
7371
};
7472

75-
module.exports = {
73+
export default {
7674
meta: {
7775
docs: {
7876
description: "Avoid the this parameter when providing arrow function as callback in array functions.",

rules/prefer-array-from.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
* @license MIT
33
* @author Martin Giger
44
*/
5-
"use strict";
65

76
const firstElement = (array) => {
87
const [ element ] = array;
98
return element;
109
};
1110

12-
module.exports = {
11+
export default {
1312
meta: {
1413
docs: {
1514
description: "Prefer using Array.from over spreading an iterable in an array literal. Using Array.from also preserves the original type of TypedArrays while mapping.",

rules/prefer-flat-map.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
* @license MIT
33
* @author Martin Giger
44
*/
5-
"use strict";
65

7-
module.exports = {
6+
export default {
87
meta: {
98
docs: {
109
description: "Prefer using the flatMap over an immediate .flat() call after a .map().",

rules/prefer-flat.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22
* @license MIT
33
* @author Martin Giger
44
*/
5-
"use strict";
6-
7-
//TODO no works.
85

96
const
107
firstElement = ([ first ]) => first,
118
secondElement = ([
129
, second
1310
]) => second;
1411

15-
module.exports = {
12+
export default {
1613
meta: {
1714
docs: {
1815
description: "Prefer using .flat() over concatenating to flatten an array.",

0 commit comments

Comments
 (0)