@bonniernews/eslint-config 2.0.4 → 3.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
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.0.0
4
+
5
+ - Updated all dependencies to latest versions:
6
+ - `@bonniernews/eslint-plugin-typescript-rules` to ^1.0.2
7
+ - `@stylistic/eslint-plugin` to ^5.6.1
8
+ - `@typescript-eslint/eslint-plugin` to ^8.51.0
9
+ - `@typescript-eslint/parser` to ^8.51.0
10
+ - `eslint-plugin-chai-friendly` to ^1.1.0
11
+ - `eslint-plugin-import` to ^2.32.0
12
+ - `eslint-plugin-n` to ^17.23.1
13
+ - `eslint-plugin-react` to ^7.37.5
14
+ - `globals` to ^17.0.0
15
+ - `chai` to ^6.2.2 (dev)
16
+ - `eslint` to ^9.39.2 (dev)
17
+ - `mocha` to ^11.7.5 (dev)
18
+ - `typescript` to ^5.9.3 (dev)
19
+ - Converted package to ESM (`"type": "module"`); all configs use `import`/`export default`.
20
+ - Converted test setup to ESM (`test/helpers/setup.mjs`) for `chai` v6 compatibility; updated `.mocharc.json` accordingly.
21
+
22
+ **Breaking change:** This package is now published as an ES Module. CommonJS projects must switch from `require` to `await import`. See [README](./README.md#migrating-from-2x-to-3x).
23
+
24
+ **Dependency updates impact:**
25
+ - **@stylistic/eslint-plugin (v3 → v5)**: The major version updates were for packaging changes (removing sub-packages), not rule behavior. This package only uses the `@stylistic/no-extra-semi` rule, which has not changed behavior.
26
+ - **@typescript-eslint (8.22 → 8.51)**: Minor version bump with bug fixes and new optional rules. No changes to currently configured rules.
27
+ - **globals (v15 → v17)**: Minor version bump adding more global variable definitions. Existing globals unchanged.
28
+ - **Other plugins**: Bug fixes and minor improvements with no user-facing impact.
29
+
3
30
  ## 2.0.2
4
31
 
5
32
  - Fixed bad docs.
package/README.md CHANGED
@@ -7,6 +7,8 @@ and the appropriate setup will be used by looking at the projects `package.json`
7
7
 
8
8
  For Node versions that support it (version 16 and above), the `es2022` environment will also be activated. Otherwise `es2021` will be used.
9
9
 
10
+ > **Note:** As of version 3.X, this package is published as an ES Module. See the [usage examples](#usage) for how to use it in both ESM and CommonJS projects.
11
+
10
12
  ## Table of contents
11
13
 
12
14
  - [@bonniernews/eslint-config](#bonniernewseslint-config)
@@ -20,6 +22,7 @@ For Node versions that support it (version 16 and above), the `es2022` environme
20
22
  - [Typed react configuration](#typed-react-configuration)
21
23
  - [Global ignores](#global-ignores)
22
24
  - [Globals](#globals)
25
+ - [Migrating from 2.X to 3.X](#migrating-from-2x-to-3x)
23
26
  - [Migrating from 1.X to 2.X](#migrating-from-1x-to-2x)
24
27
  - [Running eslint](#running-eslint)
25
28
  - [Usage in an existing project](#usage-in-an-existing-project)
@@ -41,72 +44,80 @@ npm install --save-dev eslint @bonniernews/eslint-config
41
44
 
42
45
  Configures all rules, js, ts, tsx, jsx and test rules.
43
46
 
44
- To activate the config, you need to add the following to your `eslint.config.js`-file:
47
+ **ESM** - for projects with `"type": "module"` in `package.json`:
45
48
 
46
49
  ```javascript
47
- "use strict";
50
+ // eslint.config.js
51
+ import config from "@bonniernews/eslint-config";
48
52
 
49
- module.exports = require("@bonniernews/eslint-config");
53
+ export default config;
50
54
  ```
51
55
 
52
- ### JavaScript configuration
56
+ **CommonJS** - for projects without `"type": "module"`:
53
57
 
54
- To activate the config, you need to add the following to your `eslint.config.js`-file:
58
+ ```javascript
59
+ // eslint.config.js
60
+ const { default: config } = await import("@bonniernews/eslint-config");
61
+
62
+ module.exports = config;
63
+ ```
64
+
65
+ ### JavaScript configuration
55
66
 
56
67
  ```javascript
57
- "use strict";
68
+ // eslint.config.js
69
+ import config from "@bonniernews/eslint-config/js";
58
70
 
59
- module.exports = require("@bonniernews/eslint-config/js");
71
+ export default [ config ];
60
72
  ```
61
73
 
62
74
  ### TypeScript configuration
63
75
 
64
- To activate the config, you need to add the following to your `eslint.config.js`-file:
65
-
66
76
  ```javascript
67
- "use strict";
77
+ // eslint.config.js
78
+ import config from "@bonniernews/eslint-config/ts";
68
79
 
69
- module.exports = require("@bonniernews/eslint-config/ts");
80
+ export default [ config ];
70
81
  ```
71
82
 
72
83
  ### React configuration
73
84
 
74
- To activate the config, you need to add the following to your `eslint.config.js`-file:
75
-
76
85
  ```javascript
77
- "use strict";
86
+ // eslint.config.js
87
+ import config from "@bonniernews/eslint-config/jsx";
78
88
 
79
- module.exports = require("@bonniernews/eslint-config/jsx");
89
+ export default [ config ];
80
90
  ```
81
91
 
82
92
  ### Test configuration
83
93
 
84
94
  Adds useful plugins and globals for testing with mocha-cakes-2 + chai.
85
95
 
86
- To activate the config, you need to add the following to your `eslint.config.js`-file (for js):
96
+ For JavaScript tests:
87
97
 
88
98
  ```javascript
89
- "use strict";
99
+ // eslint.config.js
100
+ import config from "@bonniernews/eslint-config/test-js";
90
101
 
91
- module.exports = require("@bonniernews/eslint-config/test-js");
102
+ export default [ config ];
92
103
  ```
93
104
 
94
- or the following (for ts):
105
+ For TypeScript tests:
95
106
 
96
107
  ```javascript
97
- "use strict";
108
+ // eslint.config.js
109
+ import config from "@bonniernews/eslint-config/test-ts";
98
110
 
99
- module.exports = require("@bonniernews/eslint-config/test-ts");
111
+ export default [ config ];
100
112
  ```
101
113
 
102
114
  ### Typed react configuration
103
115
 
104
- To activate the config, you need to add the following to your `eslint.config.js`-file:
105
-
106
116
  ```javascript
107
- "use strict";
117
+ // eslint.config.js
118
+ import config from "@bonniernews/eslint-config/tsx";
108
119
 
109
- module.exports = require("@bonniernews/eslint-config/tsx");
120
+ export default [ config ];
110
121
  ```
111
122
 
112
123
  ### Global ignores
@@ -114,13 +125,13 @@ module.exports = require("@bonniernews/eslint-config/tsx");
114
125
  To activate this config (in addition to other config(s), using it alone makes no sense), add the following:
115
126
 
116
127
  ```javascript
117
- "use strict";
118
-
119
- const ignores = require("@bonniernews/eslint-config/ignores");
128
+ // eslint.config.js
129
+ import ignores from "@bonniernews/eslint-config/ignores";
120
130
 
121
- module.exports = [
131
+ export default [
122
132
  ...allYourGoodConfigs,
123
- ignores
133
+ ignores,
134
+ // your additional config
124
135
  ];
125
136
  ```
126
137
 
@@ -128,15 +139,50 @@ module.exports = [
128
139
 
129
140
  Globals for browsers, etc. that may be needed.
130
141
 
142
+ ```javascript
143
+ // eslint.config.js
144
+ import globals from "@bonniernews/eslint-config/globals";
145
+
146
+ export default [
147
+ ...allYourGoodConfigs,
148
+ { files: [ "assets/scripts/**/*.js" ], languageOptions: { globals: globals.browser } },
149
+ ];
150
+ ```
151
+
152
+ ## Migrating from 2.X to 3.X
153
+
154
+ Version 3.X is published as an ES Module (ESM).
155
+
156
+ ### For ESM projects using `import`
157
+
158
+ If your project has `"type": "module"` in `package.json`, and you're already using `import`, then you don't have to make any changes.
159
+
160
+ ### For CommonJS projects using `require`
161
+
162
+ If your project does not have `"type": "module"`, you need to use dynamic `import()` to import an ESM module, which is an asynchronous function:
163
+
164
+ **Before (2.X):**
165
+
131
166
  ```javascript
132
167
  "use strict";
133
168
 
134
- const globals = require("@bonniernews/eslint-config/globals");
169
+ const config = require("@bonniernews/eslint-config");
135
170
 
136
171
  module.exports = [
137
- ...allYourGoodConfigs,
138
- { files: [ "assets/scripts" ], languageOptions: { globals: globals.browser } }
139
- ];
172
+ ...config,
173
+ { ignores: [ "dist/**" ] },
174
+ ]
175
+ ```
176
+
177
+ **After (3.X):**
178
+
179
+ ```javascript
180
+ const { default: config } = await import("@bonniernews/eslint-config");
181
+
182
+ module.exports = [
183
+ ...config,
184
+ { ignores: [ "dist/**" ] },
185
+ ]
140
186
  ```
141
187
 
142
188
  ## Migrating from 1.X to 2.X
@@ -185,7 +231,7 @@ npx eslint .
185
231
  - Remove any 'eslint-disable-line no-unused-expressions' directives added because of chai assertions, they are not
186
232
  needed anymore (`eslint-plugin-chai-friendly` is used in test).
187
233
  - Remove any globals and special rules related to `mocha-cakes-2` in your test configuration, they already exist
188
- in the `@bonniernews/eslint-config/test` and `@bonniernews/eslint-config/all` configs.
234
+ in the `@bonniernews/eslint-config/test-js` and `@bonniernews/eslint-config/test-ts` configs.
189
235
 
190
236
  Once you complete the steps above run the following:
191
237
 
@@ -198,7 +244,7 @@ npx eslint . --fix
198
244
  If you want to use _Prettier_, run it before eslint. ESLint should be the final judge, i.e. run:
199
245
 
200
246
  ```sh
201
- npx prettier --save .
247
+ npx prettier --write .
202
248
  npx eslint . --fix
203
249
  ```
204
250
 
package/base-config.js CHANGED
@@ -1,30 +1,38 @@
1
- "use strict";
1
+ import eslintPluginTypescriptRules from "@bonniernews/eslint-plugin-typescript-rules";
2
+ import eslintPluginImport from "eslint-plugin-import";
3
+ import eslintPluginN from "eslint-plugin-n";
4
+ import fs from "fs";
5
+ import { createRequire } from "module";
6
+ import path from "path";
2
7
 
3
- const path = require("path");
4
- const fs = require("fs");
5
- const getRules = require("./rules");
6
- const globals = require("./globals");
8
+ import globals from "./globals.js";
9
+ import getRules from "./rules.js";
7
10
 
8
- const eslintPluginN = require("eslint-plugin-n");
9
- const eslintPluginImport = require("eslint-plugin-import");
10
- const eslintPluginTypescriptRules = require("@bonniernews/eslint-plugin-typescript-rules");
11
+ const require = createRequire(import.meta.url);
11
12
 
12
- function findPackageJson(startDir) {
13
- let dir = path.resolve(startDir || process.cwd());
13
+ function findPackageJson() {
14
+ let dir = process.cwd();
15
+ const root = path.parse(dir).root;
14
16
 
15
- do {
17
+ while (dir !== root) {
16
18
  const pkgfile = path.join(dir, "package.json");
17
19
 
18
- if (!fs.existsSync(pkgfile)) {
19
- dir = path.join(dir, "..");
20
- continue;
20
+ if (fs.existsSync(pkgfile)) {
21
+ return pkgfile;
21
22
  }
22
- return pkgfile;
23
- } while (dir !== path.resolve(dir, "..") && !fs.existsSync(path.resolve(dir, ".git")));
23
+
24
+ if (fs.existsSync(path.join(dir, ".git"))) {
25
+ break;
26
+ }
27
+
28
+ dir = path.join(dir, "..");
29
+ }
30
+
24
31
  return null;
25
32
  }
26
33
 
27
- const isModuleProject = require(findPackageJson(fs.realpathSync(process.cwd()))).type === "module";
34
+ // eslint-disable-next-line import/no-dynamic-require
35
+ const isModuleProject = require(findPackageJson()).type === "module";
28
36
  const hasES2022Support = parseInt(process.versions.node.split(".").shift(), 10) >= 16;
29
37
 
30
38
  const moduleConfig = {
@@ -57,4 +65,4 @@ const baseConfig = {
57
65
  rules: getRules(isModuleProject),
58
66
  };
59
67
 
60
- module.exports = baseConfig;
68
+ export default baseConfig;
package/globals.js CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";
1
+ import globals from "globals";
2
2
 
3
- module.exports = require("globals");
3
+ export default globals;
package/ignores.js CHANGED
@@ -1,5 +1,4 @@
1
- "use strict";
2
- module.exports = {
1
+ export default {
3
2
  ignores: [
4
3
  "tmp/",
5
4
  "public/",
package/index.js CHANGED
@@ -1,14 +1,12 @@
1
- "use strict";
1
+ import baseConfig from "./base-config.js";
2
+ import ignoresConfig from "./ignores.js";
3
+ import jsxConfig from "./jsx.js";
4
+ import testJsConfig from "./test-js.js";
5
+ import testTsConfig from "./test-ts.js";
6
+ import tsConfig from "./ts.js";
7
+ import tsxConfig from "./tsx.js";
2
8
 
3
- const baseConfig = require("./base-config");
4
- const jsxConfig = require("./jsx");
5
- const tsConfig = require("./ts");
6
- const tsxConfig = require("./tsx");
7
- const testJsConfig = require("./test-js");
8
- const testTsConfig = require("./test-ts");
9
- const ignoresConfig = require("./ignores");
10
-
11
- module.exports = [
9
+ export default [
12
10
  baseConfig,
13
11
  jsxConfig,
14
12
  tsConfig,
package/js.js CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";
1
+ import baseConfig from "./base-config.js";
2
2
 
3
- module.exports = require("./base-config");
3
+ export default baseConfig;
package/jsx.js CHANGED
@@ -1,10 +1,9 @@
1
- "use strict";
1
+ import reactPlugin from "eslint-plugin-react";
2
2
 
3
- const reactPlugin = require("eslint-plugin-react");
4
- const reactRules = require("./react-rules");
5
- const baseConfig = require("./base-config");
3
+ import baseConfig from "./base-config.js";
4
+ import reactRules from "./react-rules.js";
6
5
 
7
- module.exports = {
6
+ export default {
8
7
  ...baseConfig,
9
8
  files: [ "**/*.jsx" ],
10
9
  languageOptions: {
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@bonniernews/eslint-config",
3
- "version": "2.0.4",
3
+ "version": "3.0.0",
4
4
  "description": "ESLint config",
5
+ "type": "module",
5
6
  "main": "index.js",
6
7
  "scripts": {
7
- "test": "mocha && eslint ."
8
+ "test-esm": "mocha",
9
+ "test-cjs": "cd test/commonjs && mocha",
10
+ "test": "npm run test-esm && npm run test-cjs && eslint ."
8
11
  },
9
12
  "repository": {
10
13
  "type": "git",
@@ -20,11 +23,12 @@
20
23
  ],
21
24
  "contributors": [],
22
25
  "devDependencies": {
23
- "chai": "^4.3.10",
24
- "eslint": "^9.19.0",
25
- "mocha": "^11.3.0",
26
+ "chai": "^6.2.2",
27
+ "eslint": "^9.39.2",
28
+ "mocha": "^11.7.5",
26
29
  "mocha-cakes-2": "^3.3.0",
27
- "typescript": "^5.7.3"
30
+ "preact": "^10.29.0",
31
+ "typescript": "^5.9.3"
28
32
  },
29
33
  "peerDependencies": {
30
34
  "eslint": ">=9.19.0",
@@ -40,16 +44,16 @@
40
44
  },
41
45
  "license": "MIT",
42
46
  "dependencies": {
43
- "@bonniernews/eslint-plugin-typescript-rules": "^1.0.0",
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",
47
+ "@bonniernews/eslint-plugin-typescript-rules": "^1.0.2",
48
+ "@stylistic/eslint-plugin": "^5.6.1",
49
+ "@typescript-eslint/eslint-plugin": "^8.51.0",
50
+ "@typescript-eslint/parser": "^8.51.0",
51
+ "eslint-plugin-chai-friendly": "^1.1.0",
52
+ "eslint-plugin-import": "^2.32.0",
53
+ "eslint-plugin-n": "^17.23.1",
50
54
  "eslint-plugin-no-only-tests": "^3.3.0",
51
- "eslint-plugin-react": "^7.37.4",
52
- "globals": "^15.15.0"
55
+ "eslint-plugin-react": "^7.37.5",
56
+ "globals": "^17.0.0"
53
57
  },
54
58
  "files": [
55
59
  "index.js",
package/react-rules.js CHANGED
@@ -1,5 +1,3 @@
1
- "use strict";
2
-
3
1
  const eslintReactRecommendedRules = {
4
2
  "react/display-name": 2,
5
3
  "react/jsx-key": 2,
@@ -24,7 +22,7 @@ const eslintReactRecommendedRules = {
24
22
  "react/require-render-return": 2,
25
23
  };
26
24
 
27
- module.exports = {
25
+ export default {
28
26
  ...eslintReactRecommendedRules,
29
27
  "react/prop-types": 0,
30
28
  "react/jsx-first-prop-new-line": [ 2, "multiline" ],
package/rules.js CHANGED
@@ -1,5 +1,3 @@
1
- "use strict";
2
-
3
1
  const eslintRecommendedRules = {
4
2
  "constructor-super": "error",
5
3
  "for-direction": "error",
@@ -229,7 +227,7 @@ const importRules = {
229
227
  "import/newline-after-import": "error",
230
228
  };
231
229
 
232
- module.exports = function getRules(isModuleProject) {
230
+ export default function getRules(isModuleProject) {
233
231
  return {
234
232
  ...eslintRecommendedRules,
235
233
  ...nodeRecommendedRules,
@@ -284,4 +282,4 @@ module.exports = function getRules(isModuleProject) {
284
282
  "object-curly-newline": [ "error", { multiline: true } ],
285
283
  "object-property-newline": [ "error", { allowAllPropertiesOnSameLine: true } ],
286
284
  };
287
- };
285
+ }
package/test-base.js CHANGED
@@ -1,8 +1,7 @@
1
- "use strict";
1
+ import chaiFriendly from "eslint-plugin-chai-friendly";
2
+ import noOnlyTests from "eslint-plugin-no-only-tests";
2
3
 
3
- const noOnlyTests = require("eslint-plugin-no-only-tests");
4
- const chaiFriendly = require("eslint-plugin-chai-friendly");
5
- const globals = require("./globals");
4
+ import globals from "./globals.js";
6
5
 
7
6
  const mochaCakes2Globals = {
8
7
  And: "readonly",
@@ -40,7 +39,7 @@ const mochaCakes2Rules = {
40
39
  ],
41
40
  };
42
41
 
43
- module.exports = {
42
+ export default {
44
43
  languageOptions: { globals: { ...mochaCakes2Globals } },
45
44
  files: [ "**/test/**/*.js", "**/test/**/*.ts" ],
46
45
  plugins: {
package/test-js.js CHANGED
@@ -1,9 +1,7 @@
1
- "use strict";
1
+ import baseConfig from "./base-config.js";
2
+ import testBase from "./test-base.js";
2
3
 
3
- const baseConfig = require("./base-config");
4
- const testBase = require("./test-base");
5
-
6
- module.exports = {
4
+ export default {
7
5
  ...baseConfig,
8
6
  ...testBase,
9
7
  rules: {
package/test-ts.js CHANGED
@@ -1,9 +1,7 @@
1
- "use strict";
1
+ import testBase from "./test-base.js";
2
+ import tsConfig from "./ts.js";
2
3
 
3
- const tsConfig = require("./ts");
4
- const testBase = require("./test-base");
5
-
6
- module.exports = {
4
+ export default {
7
5
  ...tsConfig,
8
6
  ...testBase,
9
7
  languageOptions: {
package/ts.js CHANGED
@@ -1,11 +1,12 @@
1
- "use strict";
1
+ import bnTypescriptRules from "@bonniernews/eslint-plugin-typescript-rules";
2
+ import stylistic from "@stylistic/eslint-plugin";
3
+ // eslint-disable-next-line import/no-unresolved
4
+ import typeScriptPlugin from "@typescript-eslint/eslint-plugin";
5
+ // eslint-disable-next-line import/no-unresolved
6
+ import typeScriptParser from "@typescript-eslint/parser";
2
7
 
3
- const baseConfig = require("./base-config");
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");
8
+ import baseConfig from "./base-config.js";
9
+ import typescriptRules from "./typescript-rules.js";
9
10
 
10
11
  const typescriptBase = {
11
12
  plugins: {
@@ -23,4 +24,4 @@ const typescriptBase = {
23
24
  settings: { "import/resolver": { node: { extensions: [ ".ts", ".js" ] } } },
24
25
  };
25
26
 
26
- module.exports = typescriptBase;
27
+ export default typescriptBase;
package/tsx.js CHANGED
@@ -1,10 +1,9 @@
1
- "use strict";
1
+ import reactPlugin from "eslint-plugin-react";
2
2
 
3
- const typescriptBase = require("./ts");
4
- const reactPlugin = require("eslint-plugin-react");
5
- const reactRules = require("./react-rules");
3
+ import reactRules from "./react-rules.js";
4
+ import typescriptBase from "./ts.js";
6
5
 
7
- module.exports = {
6
+ export default {
8
7
  ...typescriptBase,
9
8
  plugins: { ...typescriptBase.plugins, react: reactPlugin },
10
9
  files: [ "**/*.tsx" ],
@@ -1,5 +1,3 @@
1
- "use strict";
2
-
3
1
  const typescriptEslintRecommended = {
4
2
  "@typescript-eslint/adjacent-overload-signatures": "error",
5
3
  "@typescript-eslint/ban-ts-comment": "error",
@@ -55,7 +53,7 @@ const eslitRecommendedTs = {
55
53
 
56
54
  const importRules = { "import/named": "off" };
57
55
 
58
- module.exports = {
56
+ export default {
59
57
  ...typescriptEslintRecommended,
60
58
  ...eslitRecommendedTs,
61
59
  ...importRules,