@bonniernews/eslint-config 1.2.0 → 2.0.0-alpha.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
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.0
4
+
5
+ - Breaking change: switch to eslint 8 to eslint 9 and adapt to the new flat file config format.
6
+ - Breaking change: removed `all`, `react`, `test` and `typescript-react` configs. Replaced with the default config (js) and
7
+ just one for typescript `typescript` which includes react and test rules.
8
+
3
9
  ## 1.2.0
4
10
 
5
11
  - Bumped `typescript` to 5.4.3 and `@typescript-eslint` to 7.4.0.
package/README.md CHANGED
@@ -15,71 +15,41 @@ Install `eslint` and `@bonniernews/eslint-config`:
15
15
  npm install --save-dev eslint @bonniernews/eslint-config
16
16
  ```
17
17
 
18
- ### Base configuration
18
+ ## Migrating from 1.X to 2.X
19
19
 
20
- To activate the config, you need to add the following to your `.eslintrc.json`-file:
20
+ 2.X introduces eslint 9 which has a different configuration format. It is recommended to read the [eslint migration guide](https://eslint.org/docs/latest/use/configure/migration-guide).
21
21
 
22
- ```json
23
- {
24
- "root": true,
25
- "extends": [ "@bonniernews" ]
26
- }
27
- ```
22
+ A major change from eslint 8 is that only one `eslint.config.js` file will be used, placing a specific configuration file in a folder will not behave in the same
23
+ way as in 8 where it would inherit the configuration from files from the root folder, and the new recommendation is to just have one `eslint.config.js` at the root
24
+ of the repository.
28
25
 
29
- ### React configuration
26
+ As well as changing the configuration format to adapt to eslint 9, @bonniernews/eslint-config has removed some of the previous configuration options `all`, `test`, `react`
27
+ and `typescript-react` have all been removed. Now there are only two, the base (js only) and `typescript` which is the base with added support for `ts` and `tsx`.
30
28
 
31
- To activate the config, you need to add the following to your `.eslintrc.json`-file:
29
+ ### JavaScript configuration
32
30
 
33
- ```json
34
- {
35
- "root": true,
36
- "extends": [ "@bonniernews/eslint-config/react" ]
37
- }
38
- ```
31
+ This config includes support for `js`, `jsx` and tests written using `mocha-cakes-2` and `chai`.
39
32
 
40
- This will enable the react plugin for `*.jsx`-files.
33
+ To activate the config, you need to add the following to your `eslint.config.js`-file:
41
34
 
42
- ### TypeScript configuration
43
-
44
- To activate the config, you need to add the following to your `.eslintrc.json`-file:
35
+ ```javascript
36
+ "use strict";
45
37
 
46
- ```json
47
- {
48
- "root": true,
49
- "extends": [ "@bonniernews/eslint-config/typescript" ]
50
- }
38
+ module.exports = require("@bonniernews/eslint-config");
51
39
  ```
52
40
 
53
- This will enable the typescript plugin for `*.ts`-files.
41
+ ### TypeScript configuration
54
42
 
55
- ### React with TypeScript configuration
43
+ This config includes support for `js`, `jsx`, `ts`, `tsx` and and tests written using `mocha-cakes-2` and `chai`.
56
44
 
57
45
  To activate the config, you need to add the following to your `.eslintrc.json`-file:
58
46
 
59
- ```json
60
- {
61
- "root": true,
62
- "extends": [ "@bonniernews/eslint-config/typescript-react" ]
63
- }
64
- ```
65
-
66
- This will enable the typescript and react plugin for `*.tsx`-files.
47
+ ```javascript
48
+ "use strict";
67
49
 
68
- ### Test configuration
69
-
70
- You can also choose to use the test config, which is adapted to testing using `mocha`, `mocha-cakes-2` and `chai`. To also enable this,
71
- either add a separate test configuration file extending from `"@bonniernews/eslint-config/test"`, or use the `"@bonniernews/eslint-config/all"`
72
- in your root configuration to activate everything together:
73
-
74
- ```json
75
- {
76
- "root": true,
77
- "extends": [ "@bonniernews/eslint-config/all" ]
78
- }
50
+ module.exports = require("@bonniernews/eslint-config/typescript");
79
51
  ```
80
52
 
81
- This will activate the test configuration for all files inside directories named `test` or `tests`.
82
-
83
53
  ### Running eslint
84
54
 
85
55
  Run with:
package/base-config.js ADDED
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ const path = require("path");
4
+ const fs = require("fs");
5
+ const getRules = require("./rules");
6
+ const globals = require("globals");
7
+
8
+ const eslintPluginN = require("eslint-plugin-n");
9
+ const eslintPluginImport = require("eslint-plugin-import");
10
+ const eslintPluginTypescriptRules = require("@bonniernews/eslint-plugin-typescript-rules");
11
+
12
+ // This will take care of potential symlinks
13
+ const appDir = fs.realpathSync(process.cwd());
14
+
15
+ const isModuleProject = require(path.resolve(appDir, "package.json")).type === "module";
16
+ const hasES2022Support = parseInt(process.versions.node.split(".").shift(), 10) >= 16;
17
+
18
+ const moduleConfig = {
19
+ languageOptions: {
20
+ ecmaVersion: hasES2022Support ? 2022 : 2021,
21
+ globals: { ...globals.node },
22
+ sourceType: "module",
23
+ },
24
+ plugins: {
25
+ n: eslintPluginN,
26
+ import: eslintPluginImport,
27
+ "@bonniernews/typescript-rules": eslintPluginTypescriptRules,
28
+ },
29
+ };
30
+
31
+ const commonjsConfig = {
32
+ languageOptions: {
33
+ ecmaVersion: 2021,
34
+ sourceType: "commonjs",
35
+ globals: { ...globals.node },
36
+ },
37
+ plugins: {
38
+ n: eslintPluginN,
39
+ "@bonniernews/typescript-rules": eslintPluginTypescriptRules,
40
+ },
41
+ };
42
+
43
+ const baseConfig = {
44
+ ignores: [
45
+ "tmp/",
46
+ "public/",
47
+ "submodule/**",
48
+ "logs/",
49
+ "docs/",
50
+ ],
51
+ ...(isModuleProject ? moduleConfig : commonjsConfig),
52
+ rules: getRules(isModuleProject),
53
+ };
54
+
55
+ module.exports = baseConfig;
package/index.js CHANGED
@@ -1,44 +1,27 @@
1
1
  "use strict";
2
2
 
3
- const path = require("path");
4
- const fs = require("fs");
5
- const getRules = require("./rules");
3
+ const reactPlugin = require("eslint-plugin-react");
4
+ const reactRules = require("./react-rules");
5
+ const baseConfig = require("./base-config");
6
+ const testConfig = require("./test");
6
7
 
7
- // This will take care of potential symlinks
8
- const appDir = fs.realpathSync(process.cwd());
9
-
10
- const isModuleProject = require(path.resolve(appDir, "package.json")).type === "module";
11
- const hasES2022Support = parseInt(process.versions.node.split(".").shift(), 10) >= 16;
12
-
13
- const moduleConfig = {
14
- parserOptions: {
15
- ecmaVersion: hasES2022Support ? 2022 : 2021,
16
- sourceType: "module",
8
+ module.exports = [
9
+ baseConfig,
10
+ {
11
+ ...baseConfig,
12
+ files: [ "**/*.jsx" ],
13
+ languageOptions: {
14
+ ...baseConfig.languageOptions,
15
+ parserOptions: { ecmaFeatures: { jsx: true } },
16
+ },
17
+ plugins: { ...baseConfig.plugins, react: reactPlugin },
18
+ rules: { ...baseConfig.rules, ...reactRules },
17
19
  },
18
- env: {
19
- node: true,
20
- ...(hasES2022Support ? { es2022: true } : { es6: true }),
20
+ {
21
+ ...baseConfig,
22
+ languageOptions: { ...baseConfig.languageOptions, ...testConfig.languageOptions },
23
+ plugins: { ...baseConfig.plugins, ...testConfig.plugins },
24
+ rules: { ...baseConfig.rules, ...testConfig.rules },
25
+ files: [ "test/**/*.js" ],
21
26
  },
22
- plugins: [ "eslint-plugin-n", "import", "@bonniernews/typescript-rules" ],
23
- };
24
-
25
- const commonjsConfig = {
26
- parserOptions: { ecmaVersion: 2021 },
27
- env: {
28
- node: true,
29
- es6: true,
30
- },
31
- plugins: [ "eslint-plugin-n", "@bonniernews/typescript-rules" ],
32
- };
33
-
34
- module.exports = {
35
- ignorePatterns: [
36
- "tmp/",
37
- "public/",
38
- "submodule/**",
39
- "logs/",
40
- "docs/",
41
- ],
42
- ...(isModuleProject ? moduleConfig : commonjsConfig),
43
- rules: getRules(isModuleProject),
44
- };
27
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bonniernews/eslint-config",
3
- "version": "1.2.0",
3
+ "version": "2.0.0-alpha.0",
4
4
  "description": "ESLint config",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://github.com/BonnierNews/eslint-config"
11
+ "url": "git+https://github.com/BonnierNews/eslint-config.git"
12
12
  },
13
13
  "keywords": [
14
14
  "eslint",
@@ -21,14 +21,14 @@
21
21
  "contributors": [],
22
22
  "devDependencies": {
23
23
  "chai": "^4.3.10",
24
- "eslint": "^8.53.0",
25
- "mocha": "^10.2.0",
24
+ "eslint": "^9.19.0",
25
+ "mocha": "^11.1.0",
26
26
  "mocha-cakes-2": "^3.3.0",
27
- "typescript": "^5.4.3"
27
+ "typescript": "^5.7.3"
28
28
  },
29
29
  "peerDependencies": {
30
- "eslint": ">=8.3.0",
31
- "typescript": ">=5.1.0"
30
+ "eslint": ">=9.19.0",
31
+ "typescript": ">=5.7.3"
32
32
  },
33
33
  "peerDependenciesMeta": {
34
34
  "typescript": {
@@ -36,27 +36,26 @@
36
36
  }
37
37
  },
38
38
  "engines": {
39
- "node": ">=16"
39
+ "node": ">=18"
40
40
  },
41
41
  "license": "MIT",
42
42
  "dependencies": {
43
43
  "@bonniernews/eslint-plugin-typescript-rules": "^0.9.0",
44
- "@typescript-eslint/eslint-plugin": "^7.4.0",
45
- "@typescript-eslint/parser": "^7.4.0",
46
- "eslint-plugin-chai-friendly": "^0.7.2",
47
- "eslint-plugin-import": "^2.29.0",
48
- "eslint-plugin-n": "^16.3.1",
49
- "eslint-plugin-no-only-tests": "^3.1.0",
50
- "eslint-plugin-react": "^7.33.2"
44
+ "@stylistic/eslint-plugin": "^3.1.0",
45
+ "@typescript-eslint/eslint-plugin": "^8.22.0",
46
+ "@typescript-eslint/parser": "^8.22.0",
47
+ "eslint-plugin-chai-friendly": "^1.0.1",
48
+ "eslint-plugin-import": "^2.31.0",
49
+ "eslint-plugin-n": "^17.15.1",
50
+ "eslint-plugin-no-only-tests": "^3.3.0",
51
+ "eslint-plugin-react": "^7.37.4"
51
52
  },
52
53
  "files": [
53
- "all.js",
54
54
  "index.js",
55
+ "base-config.js",
55
56
  "react-rules.js",
56
- "react.js",
57
57
  "rules.js",
58
58
  "test.js",
59
- "typescript-react.js",
60
59
  "typescript-rules.js",
61
60
  "typescript.js",
62
61
  "README.md",
package/test.js CHANGED
@@ -1,5 +1,8 @@
1
1
  "use strict";
2
2
 
3
+ const noOnlyTests = require("eslint-plugin-no-only-tests");
4
+ const chaiFriendly = require("eslint-plugin-chai-friendly");
5
+
3
6
  const mochaCakes2Globals = {
4
7
  And: "readonly",
5
8
  But: "readonly",
@@ -37,9 +40,11 @@ const mochaCakes2Rules = {
37
40
  };
38
41
 
39
42
  module.exports = {
40
- env: { mocha: true },
41
- globals: { ...mochaCakes2Globals },
42
- plugins: [ "no-only-tests", "chai-friendly" ],
43
+ languageOptions: { globals: { ...mochaCakes2Globals } },
44
+ plugins: {
45
+ "no-only-tests": noOnlyTests,
46
+ "chai-friendly": chaiFriendly,
47
+ },
43
48
  rules: {
44
49
  ...mochaCakes2Rules,
45
50
  // no only in tests
@@ -3,7 +3,7 @@
3
3
  const typescriptEslintRecommended = {
4
4
  "@typescript-eslint/adjacent-overload-signatures": "error",
5
5
  "@typescript-eslint/ban-ts-comment": "error",
6
- "@typescript-eslint/ban-types": "error",
6
+ "@typescript-eslint/no-restricted-types": "error",
7
7
  "no-array-constructor": "off",
8
8
  "@typescript-eslint/no-array-constructor": "error",
9
9
  "no-empty-function": "off",
@@ -11,8 +11,7 @@ const typescriptEslintRecommended = {
11
11
  "@typescript-eslint/no-empty-interface": "error",
12
12
  "@typescript-eslint/no-explicit-any": "off",
13
13
  "@typescript-eslint/no-extra-non-null-assertion": "error",
14
- "no-extra-semi": "off",
15
- "@typescript-eslint/no-extra-semi": "error",
14
+ "@stylistic/no-extra-semi": "error",
16
15
  "@typescript-eslint/no-inferrable-types": "error",
17
16
  "no-loss-of-precision": "off",
18
17
  "@typescript-eslint/no-loss-of-precision": "error",
@@ -62,4 +61,5 @@ module.exports = {
62
61
  ...importRules,
63
62
  "@bonniernews/typescript-rules/disallow-abstract-class": "error",
64
63
  "@bonniernews/typescript-rules/disallow-non-es-compatible": "error",
64
+ "@bonniernews/typescript-rules/disallow-class-extends": "error",
65
65
  };
package/typescript.js CHANGED
@@ -2,19 +2,36 @@
2
2
 
3
3
  const baseConfig = require(".");
4
4
  const typescriptRules = require("./typescript-rules");
5
+ const typeScriptPlugin = require("@typescript-eslint/eslint-plugin");
6
+ const typeScriptParser = require("@typescript-eslint/parser");
7
+ const stylistic = require("@stylistic/eslint-plugin");
8
+ const bnTypescriptRules = require("@bonniernews/eslint-plugin-typescript-rules");
9
+ const reactPlugin = require("eslint-plugin-react");
10
+ const reactRules = require("./react-rules");
5
11
 
6
- module.exports = {
7
- ...baseConfig,
8
- overrides: [
9
- {
10
- parser: "@typescript-eslint/parser",
11
- parserOptions: { sourceType: "module" },
12
- settings: { "import/resolver": { node: { extensions: [ ".ts", ".js" ] } } },
13
- plugins: [
14
- "@typescript-eslint",
15
- ],
16
- files: [ "*.ts" ],
17
- rules: typescriptRules,
18
- },
19
- ],
12
+ const typescriptBase = {
13
+ plugins: {
14
+ "@typescript-eslint": typeScriptPlugin,
15
+ "@stylistic": stylistic,
16
+ "@bonniernews/typescript-rules": bnTypescriptRules,
17
+ },
18
+ languageOptions: {
19
+ sourceType: "module",
20
+ parser: typeScriptParser,
21
+ },
22
+ files: [ "**/*.ts" ],
23
+ rules: typescriptRules,
24
+ settings: { "import/resolver": { node: { extensions: [ ".ts", ".js" ] } } },
20
25
  };
26
+
27
+ module.exports = [
28
+ ...baseConfig,
29
+ typescriptBase,
30
+ {
31
+ ...typescriptBase,
32
+ plugins: { ...typescriptBase.plugins, react: reactPlugin },
33
+ files: [ "**/*.tsx" ],
34
+ settings: { "import/resolver": { node: { extensions: [ ".ts", ".js", ".tsx", ".jsx" ] } } },
35
+ rules: { ...typescriptBase.rules, ...reactRules },
36
+ },
37
+ ];
package/all.js DELETED
@@ -1,14 +0,0 @@
1
- "use strict";
2
-
3
- const baseConfig = require(".");
4
- const testConfig = require("./test");
5
-
6
- module.exports = {
7
- ...baseConfig,
8
- overrides: [
9
- {
10
- files: [ "**/test?(s)/**/*" ],
11
- ...testConfig,
12
- },
13
- ],
14
- };
package/react.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- const baseConfig = require(".");
4
- const reactRules = require("./react-rules");
5
-
6
- module.exports = {
7
- ...baseConfig,
8
- overrides: [
9
- {
10
- plugins: [
11
- "react",
12
- ],
13
- parserOptions: { ecmaFeatures: { jsx: true } },
14
- files: [ "*.jsx" ],
15
- rules: reactRules,
16
- },
17
- ],
18
- };
@@ -1,45 +0,0 @@
1
- "use strict";
2
-
3
- const baseConfig = require(".");
4
- const typescriptRules = require("./typescript-rules");
5
- const reactRules = require("./react-rules");
6
- const settings = { "import/resolver": { node: { extensions: [ ".ts", ".js", ".tsx", ".jsx" ] } } };
7
-
8
- module.exports = {
9
- ...baseConfig,
10
- overrides: [
11
- {
12
- parser: "@typescript-eslint/parser",
13
- parserOptions: { sourceType: "module", ecmaFeatures: { jsx: true } },
14
- plugins: [
15
- "react",
16
- "@typescript-eslint",
17
- ],
18
- settings,
19
- files: [ "*.tsx" ],
20
- rules: {
21
- ...typescriptRules,
22
- ...reactRules,
23
- },
24
- },
25
- {
26
- parser: "@typescript-eslint/parser",
27
- parserOptions: { sourceType: "module" },
28
- settings,
29
- plugins: [
30
- "@typescript-eslint",
31
- ],
32
- files: [ "*.ts" ],
33
- rules: typescriptRules,
34
- },
35
- {
36
- plugins: [
37
- "react",
38
- ],
39
- settings,
40
- parserOptions: { ecmaFeatures: { jsx: true } },
41
- files: [ "*.jsx" ],
42
- rules: reactRules,
43
- },
44
- ],
45
- };