@pob/eslint-config 56.0.0 → 57.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,29 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [57.0.0](https://github.com/christophehurpeau/eslint-config-pob/compare/v56.1.0...v57.0.0) (2024-08-11)
7
+
8
+ ### ⚠ BREAKING CHANGES
9
+
10
+ * use flat config
11
+
12
+ ### Features
13
+
14
+ * add baseModule ([c1e7cef](https://github.com/christophehurpeau/eslint-config-pob/commit/c1e7cef19d835b3ab0333b4588d1810e09874d53))
15
+ * use flat config ([b0bda47](https://github.com/christophehurpeau/eslint-config-pob/commit/b0bda47976ec40a30679988c603d425f9b75346f))
16
+
17
+ Version bump for dependency: @pob/eslint-plugin
18
+
19
+
20
+ ## [56.1.0](https://github.com/christophehurpeau/eslint-config-pob/compare/v56.0.0...v56.1.0) (2024-07-27)
21
+
22
+ ### Features
23
+
24
+ * pob plugin ([fd99ec8](https://github.com/christophehurpeau/eslint-config-pob/commit/fd99ec8711409b3bc9b960f7eb2e0b2e67984381))
25
+
26
+ Version bump for dependency: @pob/eslint-plugin
27
+
28
+
6
29
  ## [56.0.0](https://github.com/christophehurpeau/eslint-config-pob/compare/v55.3.0...v56.0.0) (2024-05-05)
7
30
 
8
31
 
@@ -505,7 +528,7 @@ Note: no notable changes
505
528
 
506
529
  ### BREAKING CHANGES
507
530
 
508
- * **deps:** requires eslint-plugin-unicorn 34 and enable new rules
531
+ * **deps:** requires eslint-plugin-unicorn 34 and enable new rules
509
532
  * requires new min supported node versions
510
533
 
511
534
 
package/lib/_base.js CHANGED
@@ -1,16 +1,40 @@
1
- "use strict";
1
+ import js from "@eslint/js";
2
+ import pobPlugin from "@pob/eslint-plugin";
3
+ import unicornPluginConfigs from "./plugins/unicorn.js";
4
+ import bestPracticesConfig from "./rules/best-practices.js";
5
+ import codeQualityConfig from "./rules/code-quality.js";
6
+ import devOnlyConfig from "./rules/dev-only.js";
7
+ import errorsConfig from "./rules/errors.js";
8
+ import styleConfig from "./rules/style.js";
2
9
 
3
- module.exports = {
4
- extends: [
5
- "eslint:recommended",
6
- ...[
7
- "./plugins/unicorn",
8
- "./rules/best-practices",
9
- "./rules/code-quality",
10
- "./rules/errors",
11
- "./rules/style",
12
- "./plugins/import/import-base",
13
- "./plugins/import/import-commonjs",
14
- ].map(require.resolve),
15
- ],
16
- };
10
+ export default [
11
+ {
12
+ linterOptions: {
13
+ // todo noInlineConfig: true,
14
+ reportUnusedDisableDirectives: "error",
15
+ },
16
+ plugins: {
17
+ "@pob": pobPlugin,
18
+ },
19
+ },
20
+ {
21
+ ignores: [".yarn", "**/dist/", "**/build/", "**/coverage/"],
22
+ },
23
+ js.configs.recommended,
24
+ pobPlugin.configs.base,
25
+ ...unicornPluginConfigs,
26
+ bestPracticesConfig,
27
+ codeQualityConfig,
28
+ errorsConfig,
29
+ styleConfig,
30
+ devOnlyConfig,
31
+
32
+ // TODO
33
+ // {
34
+ // files: ["*.json"],
35
+ // languageOptions: {
36
+ // parser: jsoncParser,
37
+ // },
38
+ // rules: {},
39
+ // },
40
+ ];
@@ -1,10 +1,14 @@
1
- "use strict";
2
-
3
- module.exports = {
4
- parserOptions: {
1
+ export default {
2
+ languageOptions: {
5
3
  sourceType: "script",
6
4
  },
7
5
  rules: {
8
6
  strict: ["error", "safe"],
7
+
8
+ // https://eslint.org/docs/rules/global-require
9
+ "global-require": "error",
10
+
11
+ // disallow use of new operator with the require function
12
+ "no-new-require": "error",
9
13
  },
10
14
  };
@@ -1,10 +1,28 @@
1
- "use strict";
2
-
3
- module.exports = {
4
- parserOptions: {
1
+ export default {
2
+ languageOptions: {
5
3
  sourceType: "module",
6
4
  },
7
5
  rules: {
8
6
  strict: "off",
7
+
8
+ // replaced by import/no-duplicates
9
+ "no-duplicate-imports": "off",
10
+
11
+ // https://eslint.org/docs/rules/no-restricted-exports
12
+ "no-restricted-exports": [
13
+ "error",
14
+ {
15
+ restrictDefaultExports: {
16
+ direct: false, // permits `export default` declarations
17
+ named: true, // restricts `export { foo as default };` declarations
18
+ defaultFrom: false, // permits `export { default } from 'foo';` declarations
19
+ namedFrom: false, // permits `export { foo as default } from 'foo';` declarations
20
+ namespaceFrom: true, // restricts `export * as default from 'foo';` declarations
21
+ },
22
+ restrictedNamedExports: [
23
+ "then", // this will cause tons of confusion when your module is dynamically `import()`ed, and will break in most node ESM versions
24
+ ],
25
+ },
26
+ ],
9
27
  },
10
28
  };
package/lib/index.js CHANGED
@@ -1,20 +1,74 @@
1
- "use strict";
1
+ import path from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
+ import { FlatCompat } from "@eslint/eslintrc";
4
+ import baseConfigs from "./_base.js";
5
+ import baseCommonjsConfig from "./base/commonjs.js";
6
+ import baseModuleConfig from "./base/module.js";
7
+ import nodePluginCommonjsConfigs from "./node/commonjs.js";
8
+ import nodePluginModuleConfigs from "./node/module.js";
9
+ import importPluginBaseConfigs from "./plugins/import/import-base.js";
10
+ import importPluginCommonjsConfig from "./plugins/import/import-commonjs.js";
11
+ import importPluginModuleConfig from "./plugins/import/import-module.js";
2
12
 
3
- module.exports = {
4
- extends: ["./_base", "./base/commonjs"].map(require.resolve),
13
+ export default (url) => {
14
+ const __filename = fileURLToPath(url);
15
+ const __dirname = path.dirname(__filename);
5
16
 
6
- overrides: [
17
+ const compat = new FlatCompat({
18
+ baseDirectory: __dirname,
19
+ });
20
+
21
+ const nodeCommonjs = [
22
+ ...baseConfigs,
23
+ baseCommonjsConfig,
24
+ ...importPluginBaseConfigs(compat),
25
+ importPluginCommonjsConfig,
26
+ ...nodePluginCommonjsConfigs,
27
+
28
+ {
29
+ files: ["**/*.mjs"],
30
+ ...baseModuleConfig,
31
+ },
32
+ {
33
+ files: ["**/*.mjs"],
34
+ ...importPluginModuleConfig,
35
+ },
36
+ ...nodePluginModuleConfigs.map((config) => ({
37
+ ...config,
38
+ files: ["**/*.mjs"],
39
+ })),
40
+ ];
41
+
42
+ const baseModule = [
43
+ ...baseConfigs,
44
+ baseModuleConfig,
45
+ ...importPluginBaseConfigs(compat),
46
+ importPluginModuleConfig,
7
47
  {
8
- files: ["*.mjs"],
9
- extends: ["./base/module", "./plugins/import/import-module"].map(
10
- require.resolve
11
- ),
48
+ files: ["**/*.cjs"],
49
+ ...baseCommonjsConfig,
12
50
  },
13
51
  {
14
- files: ["*.cjs"],
15
- extends: ["./base/commonjs", "./plugins/import/import-commonjs"].map(
16
- require.resolve
17
- ),
52
+ files: ["**/*.cjs"],
53
+ ...importPluginCommonjsConfig,
54
+ },
55
+ ];
56
+
57
+ const nodeModule = [
58
+ ...baseModule,
59
+ ...nodePluginModuleConfigs,
60
+ ...nodePluginCommonjsConfigs.map((config) => ({
61
+ ...config,
62
+ files: ["**/*.cjs"],
63
+ })),
64
+ ];
65
+
66
+ return {
67
+ compat,
68
+ configs: {
69
+ baseModule,
70
+ nodeModule,
71
+ nodeCommonjs,
18
72
  },
19
- ],
73
+ };
20
74
  };
package/lib/node/_base.js CHANGED
@@ -1,6 +1,4 @@
1
- "use strict";
2
-
3
- exports.overrideRules = {
1
+ export const overrideRules = {
4
2
  // Disable rules already checked by import plugin
5
3
  "n/no-unpublished-require": "off",
6
4
  "n/no-extraneous-require": "off",
@@ -25,19 +23,13 @@ exports.overrideRules = {
25
23
  "no-sync": "off",
26
24
 
27
25
  // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/import/extensions.md
28
- "import/extensions": [
29
- "error",
30
- "ignorePackages",
31
- {
32
- mjs: "always",
33
- cjs: "always",
34
- js: "never",
35
- },
36
- ],
37
- };
38
-
39
- exports.env = {
40
- browser: false,
41
- node: true,
42
- es6: true,
26
+ // "import/extensions": [
27
+ // "error",
28
+ // "ignorePackages",
29
+ // {
30
+ // mjs: "always",
31
+ // cjs: "always",
32
+ // js: "never",
33
+ // },
34
+ // ],
43
35
  };
@@ -1,24 +1,14 @@
1
- "use strict";
2
-
3
- const { env, overrideRules } = require("./_base");
4
-
5
- module.exports = {
6
- plugins: ["n"],
7
- extends: ["plugin:n/recommended-script"],
8
- env,
9
-
10
- parserOptions: {
11
- // https://node.green/#ES2020
12
- // most 2020 features are supported in node 14
13
- // top level await is introduced in 2022
14
- // current ecmaVersion in eslint-plugin-node is 2019
15
- ecmaVersion: 2022,
16
- },
17
-
18
- rules: {
19
- ...overrideRules,
20
- "unicorn/prefer-module": "off",
21
- "n/no-new-require": "error",
22
- "n/no-path-concat": "error",
1
+ import nodePlugin from "eslint-plugin-n";
2
+ import { overrideRules } from "./_base.js";
3
+
4
+ export default [
5
+ nodePlugin.configs["flat/recommended-script"],
6
+ {
7
+ rules: {
8
+ ...overrideRules,
9
+ // "unicorn/prefer-module": "off",
10
+ "n/no-new-require": "error",
11
+ "n/no-path-concat": "error",
12
+ },
23
13
  },
24
- };
14
+ ];
@@ -1,33 +1,24 @@
1
- "use strict";
1
+ import nodePlugin from "eslint-plugin-n";
2
+ import { overrideRules } from "./_base.js";
2
3
 
3
- const { env, overrideRules } = require("./_base");
4
+ export default [
5
+ nodePlugin.configs["flat/recommended-module"],
6
+ {
7
+ rules: {
8
+ ...overrideRules,
9
+ "unicorn/prefer-module": "error",
10
+ "unicorn/import-index": "off",
4
11
 
5
- module.exports = {
6
- plugins: ["n"],
7
- extends: ["plugin:n/recommended-module"],
8
- parserOptions: {
9
- sourceType: "module",
10
- // https://node.green/#ES2020
11
- // most 2020 features are supported in node 14
12
- // top level await is introduced in 2022
13
- // current ecmaVersion in eslint-plugin-node is 2019
14
- ecmaVersion: 2022,
12
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/import/extensions.md
13
+ "import/extensions": [
14
+ "error",
15
+ "ignorePackages",
16
+ {
17
+ mjs: "always",
18
+ cjs: "always",
19
+ js: "always",
20
+ },
21
+ ],
22
+ },
15
23
  },
16
- env,
17
- rules: {
18
- ...overrideRules,
19
- "unicorn/prefer-module": "error",
20
- "unicorn/import-index": "off",
21
-
22
- // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/import/extensions.md
23
- "import/extensions": [
24
- "error",
25
- "ignorePackages",
26
- {
27
- mjs: "always",
28
- cjs: "always",
29
- js: "always",
30
- },
31
- ],
32
- },
33
- };
24
+ ];
@@ -1,99 +1,132 @@
1
- "use strict";
1
+ import { fixupPluginRules } from "@eslint/compat";
2
2
 
3
- module.exports = {
4
- plugins: ["import"],
3
+ function legacyPlugin(compat, name, alias = name) {
4
+ const plugin = compat.plugins(name)[0]?.plugins?.[alias];
5
5
 
6
- settings: {
7
- "import/extensions": [".js", ".mjs"],
8
- "import/core-modules": [],
9
- "import/ignore": ["node_modules"],
6
+ if (!plugin) {
7
+ throw new Error(`Unable to resolve plugin ${name} and/or alias ${alias}`);
8
+ }
9
+
10
+ return fixupPluginRules(plugin);
11
+ }
12
+
13
+ export default (compat) => [
14
+ {
15
+ //
16
+ languageOptions: {
17
+ parserOptions: {
18
+ ecmaVersion: 2022,
19
+ sourceType: "module",
20
+ },
21
+ },
22
+ plugins: {
23
+ import: legacyPlugin(compat, "eslint-plugin-import", "import"),
24
+ },
25
+ settings: {
26
+ "import/parsers": {
27
+ // https://github.com/import-js/eslint-plugin-import/issues/2556#issuecomment-1419518561
28
+ espree: [".js", ".cjs", ".mjs"],
29
+ },
30
+ "import/resolver": {
31
+ node: true,
32
+ },
33
+ },
10
34
  },
35
+ ...compat.config({
36
+ settings: {
37
+ "import/extensions": [".js", ".mjs"],
38
+ "import/ignore": ["node_modules"],
39
+ },
11
40
 
12
- rules: {
13
- // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-unresolved.md
14
- "import/no-unresolved": ["error", { commonjs: true, caseSensitive: true }],
41
+ rules: {
42
+ // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-unresolved.md
43
+ "import/no-unresolved": [
44
+ "error",
45
+ { commonjs: true, caseSensitive: true },
46
+ ],
15
47
 
16
- // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/named.md
17
- "import/named": "error",
48
+ // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/named.md
49
+ "import/named": "error",
18
50
 
19
- // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/export.md
20
- "import/export": "error",
51
+ // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/export.md
52
+ "import/export": "error",
21
53
 
22
- // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-named-as-default.md
23
- "import/no-named-as-default": "error",
54
+ // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-named-as-default.md
55
+ "import/no-named-as-default": "error",
24
56
 
25
- // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-named-as-default-member.md
26
- "import/no-named-as-default-member": "error",
57
+ // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-named-as-default-member.md
58
+ "import/no-named-as-default-member": "error",
27
59
 
28
- // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-deprecated.md
29
- "import/no-deprecated": "off",
60
+ // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-deprecated.md
61
+ "import/no-deprecated": "off",
30
62
 
31
- // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md
32
- "import/no-extraneous-dependencies": "error",
63
+ // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md
64
+ "import/no-extraneous-dependencies": "error",
33
65
 
34
- // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-mutable-exports.md
35
- "import/no-mutable-exports": "error",
66
+ // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-mutable-exports.md
67
+ "import/no-mutable-exports": "error",
36
68
 
37
- // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-amd.md
38
- "import/no-amd": "error",
69
+ // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-amd.md
70
+ "import/no-amd": "error",
39
71
 
40
- // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/first.md
41
- "import/first": "error",
72
+ // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/first.md
73
+ "import/first": "error",
42
74
 
43
- // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-duplicates.md
44
- "import/no-duplicates": "error",
75
+ // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-duplicates.md
76
+ "import/no-duplicates": "error",
45
77
 
46
- // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/newline-after-import.md
47
- "import/newline-after-import": "error",
78
+ // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/newline-after-import.md
79
+ "import/newline-after-import": "error",
48
80
 
49
- // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/prefer-default-export.md
50
- "import/prefer-default-export": "off",
81
+ // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/prefer-default-export.md
82
+ "import/prefer-default-export": "off",
51
83
 
52
- // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-absolute-path.md
53
- "import/no-absolute-path": "error",
84
+ // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-absolute-path.md
85
+ "import/no-absolute-path": "error",
54
86
 
55
- // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-dynamic-require.md
56
- "import/no-dynamic-require": "error",
87
+ // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-dynamic-require.md
88
+ "import/no-dynamic-require": "error",
57
89
 
58
- // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-webpack-loader-syntax.md
59
- "import/no-webpack-loader-syntax": "error",
90
+ // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-webpack-loader-syntax.md
91
+ "import/no-webpack-loader-syntax": "error",
60
92
 
61
- // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-named-default.md
62
- "import/no-named-default": "error",
93
+ // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-named-default.md
94
+ "import/no-named-default": "error",
63
95
 
64
- // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-self-import.md
65
- "import/no-self-import": "error",
96
+ // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-self-import.md
97
+ "import/no-self-import": "error",
66
98
 
67
- // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-cycle.md
68
- "import/no-cycle": ["error", { maxDepth: "∞" }],
99
+ // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-cycle.md
100
+ "import/no-cycle": ["error", { maxDepth: "∞" }],
69
101
 
70
- // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-useless-path-segments.md
71
- "import/no-useless-path-segments": ["error", { commonjs: true }],
102
+ // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-useless-path-segments.md
103
+ "import/no-useless-path-segments": ["error", { commonjs: true }],
72
104
 
73
- // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-import-module-exports.md
74
- "import/no-import-module-exports": "error",
105
+ // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-import-module-exports.md
106
+ "import/no-import-module-exports": "error",
75
107
 
76
- // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-relative-packages.md
77
- "import/no-relative-packages": "error",
108
+ // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-relative-packages.md
109
+ "import/no-relative-packages": "error",
78
110
 
79
- // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-empty-named-blocks.md
80
- "import/no-empty-named-blocks": "error",
111
+ // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-empty-named-blocks.md
112
+ "import/no-empty-named-blocks": "error",
81
113
 
82
- // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md
83
- "import/order": [
84
- "error",
85
- {
86
- groups: [
87
- "builtin",
88
- "external",
89
- "internal",
90
- "parent",
91
- "sibling",
92
- "index",
93
- ],
94
- alphabetize: { order: "asc", caseInsensitive: false },
95
- "newlines-between": "never",
96
- },
97
- ],
98
- },
99
- };
114
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md
115
+ "import/order": [
116
+ "error",
117
+ {
118
+ groups: [
119
+ "builtin",
120
+ "external",
121
+ "internal",
122
+ "parent",
123
+ "sibling",
124
+ "index",
125
+ ],
126
+ alphabetize: { order: "asc", caseInsensitive: false },
127
+ "newlines-between": "never",
128
+ },
129
+ ],
130
+ },
131
+ }),
132
+ ];
@@ -1,6 +1,4 @@
1
- "use strict";
2
-
3
- module.exports = {
1
+ export default {
4
2
  rules: {
5
3
  // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-commonjs.md
6
4
  "import/no-commonjs": "off",
@@ -1,6 +1,4 @@
1
- "use strict";
2
-
3
- module.exports = {
1
+ export default {
4
2
  rules: {
5
3
  // https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-commonjs.md
6
4
  "import/no-commonjs": "error",