@metamask/eslint-config-typescript 10.0.0 → 11.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
@@ -6,22 +6,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [11.0.0]
10
+ ### Added
11
+ - **BREAKING:** Add rules that require type information ([#250](https://github.com/MetaMask/eslint-config/pull/250))
12
+ - This requires setting some parser options. See the README for more details.
13
+ - **BREAKING:** Bump all ESLint dependencies to the latest version ([#252](https://github.com/MetaMask/eslint-config/pull/252))
14
+ - This includes peer dependencies.
15
+ - **BREAKING:** Forbid TypeScript's private modifier in favour of hash names ([#244](https://github.com/MetaMask/eslint-config/pull/244))
16
+
9
17
  ## [10.0.0]
10
18
  ### Changed
11
- - **(BREAKING)** Update ESLint from v7 to v8 ([#233](https://github.com/MetaMask/eslint-config/pull/233))
19
+ - **BREAKING:** Update ESLint from v7 to v8 ([#233](https://github.com/MetaMask/eslint-config/pull/233))
12
20
  - This is breaking because `eslint` is a `peerDependency`.
13
21
  - Four new rules have been added:
14
22
  - [`no-loss-of-precision`](https://eslint.org/docs/latest/rules/no-loss-of-precision)
15
23
  - [`no-nonoctal-decimal-escape`](https://eslint.org/docs/latest/rules/no-nonoctal-decimal-escape)
16
24
  - [`no-unsafe-optional-chaining`](https://eslint.org/docs/latest/rules/no-unsafe-optional-chaining)
17
25
  - [`no-useless-backreference`](https://eslint.org/docs/latest/rules/no-useless-backreference)
18
- - **(BREAKING)** Update `@typescript-eslint` parser and plugin ([#230](https://github.com/MetaMask/eslint-config/pull/230))
26
+ - **BREAKING:** Update `@typescript-eslint` parser and plugin ([#230](https://github.com/MetaMask/eslint-config/pull/230))
19
27
  - This is breaking because these two packages are `peerDependencies`
20
28
  - There are two new rules:
21
29
  - [`@typescript-eslint/no-loss-of-precision`](https://typescript-eslint.io/rules/no-loss-of-precision)
22
30
  - [`@typescript-eslint/no-unnecessary-type-constraint`](https://typescript-eslint.io/rules/no-unnecessary-type-constraint).
23
- - **(BREAKING)** Update minimium Node.js version to v14 ([#225](https://github.com/MetaMask/eslint-config/pull/225))
24
- - **(BREAKING)** Forbid TypeScript interfaces ([#216](https://github.com/MetaMask/eslint-config/pull/216))
31
+ - **BREAKING:** Update minimium Node.js version to v14 ([#225](https://github.com/MetaMask/eslint-config/pull/225))
32
+ - **BREAKING:** Forbid TypeScript interfaces ([#216](https://github.com/MetaMask/eslint-config/pull/216))
25
33
  - Ignore rest siblings for `no-unused-vars` ([#213](https://github.com/MetaMask/eslint-config/pull/213))
26
34
  - This makes the `no-unused-vars` rule more permissive
27
35
 
@@ -32,16 +40,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
32
40
 
33
41
  ## [9.0.0]
34
42
  ### Added
35
- - **BREAKING** Add JSDoc ESLint rules ([#203](https://github.com/MetaMask/eslint-config/pull/203))
43
+ - **BREAKING:** Add JSDoc ESLint rules ([#203](https://github.com/MetaMask/eslint-config/pull/203))
36
44
 
37
45
  ### Changed
38
- - **BREAKING** Disable `no-throw-literal` and enable `@typescript-eslint/no-throw-literal` ([#201](https://github.com/MetaMask/eslint-config/pull/201))
46
+ - **BREAKING:** Disable `no-throw-literal` and enable `@typescript-eslint/no-throw-literal` ([#201](https://github.com/MetaMask/eslint-config/pull/201))
39
47
  - This rule requires type information, which requires [additional project setup](https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/TYPED_LINTING.md).
40
48
  - Note: This change has been undone in v9.0.1. You can ignore this change if you're updating to v9.0.1 or greater.
41
49
 
42
50
  ## [8.0.0]
43
51
  ### Changed
44
- - ***BREAKING*** The peer dependency `@metamask/eslint-config` has been updated from v7 to v8.
52
+ - **BREAKING:** The peer dependency `@metamask/eslint-config` has been updated from v7 to v8.
45
53
 
46
54
  ## [7.0.1]
47
55
  ### Fixed
@@ -51,7 +59,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
51
59
 
52
60
  ## [7.0.0]
53
61
  ### Changed
54
- - **(BREAKING)** Update `@typescript/no-shadow` config ([#168](https://github.com/MetaMask/eslint-config/pull/168))
62
+ - **BREAKING:** Update `@typescript/no-shadow` config ([#168](https://github.com/MetaMask/eslint-config/pull/168))
55
63
  - Use recommended `eslint-plugin-import` rule sets ([#184](https://github.com/MetaMask/eslint-config/pull/184))
56
64
  - This only removed or disabled rules, and is not breaking.
57
65
  - Update install instructions in readme ([#185](https://github.com/MetaMask/eslint-config/pull/185))
@@ -62,9 +70,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
62
70
 
63
71
  ## [6.0.0] - 2021-04-08
64
72
  ### Changed
65
- - **(BREAKING)** Set minimum Node.js version to `^12.0.0` ([#144](https://github.com/MetaMask/eslint-config/pull/144))
66
- - **(BREAKING)** Set ECMAScript version to `es2020`/`11` ([#150](https://github.com/MetaMask/eslint-config/pull/150))
67
- - **(BREAKING)** Enable all rules recommended by the `@typescript-eslint` plugin ([#156](https://github.com/MetaMask/eslint-config/pull/156))
73
+ - **BREAKING:** Set minimum Node.js version to `^12.0.0` ([#144](https://github.com/MetaMask/eslint-config/pull/144))
74
+ - **BREAKING:** Set ECMAScript version to `es2020`/`11` ([#150](https://github.com/MetaMask/eslint-config/pull/150))
75
+ - **BREAKING:** Enable all rules recommended by the `@typescript-eslint` plugin ([#156](https://github.com/MetaMask/eslint-config/pull/156))
68
76
  - This amounted to setting the following core ESLint rules to `error`:
69
77
  - [no-var](https://eslint.org/docs/7.0.0/rules/no-var)
70
78
  - [prefer-const](https://eslint.org/docs/7.0.0/rules/prefer-const)
@@ -76,7 +84,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
76
84
  - To continue extending this config, install this package and update your `.eslintrc.js` `extends` array to include `@metamask/eslint-config-typescript` instead of `@metamask/eslint-config/typescript`.
77
85
  - Update `eslint` and other ESLint peer dependencies ([#151](https://github.com/MetaMask/eslint-config/pull/151))
78
86
 
79
- [Unreleased]: https://github.com/MetaMask/eslint-config/compare/v10.0.0...HEAD
87
+ [Unreleased]: https://github.com/MetaMask/eslint-config/compare/v11.0.0...HEAD
88
+ [11.0.0]: https://github.com/MetaMask/eslint-config/compare/v10.0.0...v11.0.0
80
89
  [10.0.0]: https://github.com/MetaMask/eslint-config/compare/v9.0.1...v10.0.0
81
90
  [9.0.1]: https://github.com/MetaMask/eslint-config/compare/v9.0.0...v9.0.1
82
91
  [9.0.0]: https://github.com/MetaMask/eslint-config/compare/v8.0.0...v9.0.0
package/README.md CHANGED
@@ -6,17 +6,16 @@ MetaMask's [TypeScript](https://www.typescriptlang.org) ESLint configuration.
6
6
 
7
7
  ```bash
8
8
  yarn add --dev \
9
- @metamask/eslint-config@^9.0.0 \
10
- @metamask/eslint-config-typescript@^9.0.1 \
11
- @typescript-eslint/eslint-plugin@^5.33.0 \
12
- @typescript-eslint/parser@^5.33.0 \
13
- eslint@^7.23.0 \
14
- eslint-config-prettier@^8.1.0 \
15
- eslint-plugin-import@^2.22.1 \
16
- eslint-plugin-jsdoc@^39.2.9 \
17
- eslint-plugin-prettier@^3.3.1 \
18
- prettier@^2.2.1
19
-
9
+ @metamask/eslint-config@^11.0.0 \
10
+ @metamask/eslint-config-typescript@^11.0.0 \
11
+ @typescript-eslint/eslint-plugin@^5.42.1 \
12
+ @typescript-eslint/parser@^5.42.1 \
13
+ eslint@^8.27.0 \
14
+ eslint-config-prettier@^8.5.0 \
15
+ eslint-plugin-import@^2.26.0 \
16
+ eslint-plugin-jsdoc@^39.6.2 \
17
+ eslint-plugin-prettier@^4.2.1 \
18
+ prettier@^2.7.1
20
19
  ```
21
20
 
22
21
  The order in which you extend ESLint rules matters.
@@ -41,5 +40,11 @@ module.exports = {
41
40
  extends: ['@metamask/eslint-config-typescript'],
42
41
  },
43
42
  ],
43
+
44
+ // This is required for rules that use type information.
45
+ // See here for more information: https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/TYPED_LINTING.md
46
+ parserOptions: {
47
+ tsconfigRootDir: __dirname,
48
+ },
44
49
  };
45
50
  ```
package/package.json CHANGED
@@ -1,48 +1,50 @@
1
1
  {
2
2
  "name": "@metamask/eslint-config-typescript",
3
- "version": "10.0.0",
3
+ "version": "11.0.0",
4
4
  "description": "Shareable MetaMask ESLint config for TypeScript.",
5
- "main": "src/index.js",
6
- "publishConfig": {
7
- "registry": "https://registry.npmjs.org/",
8
- "access": "public"
9
- },
10
- "files": [
11
- "src/"
12
- ],
13
- "engines": {
14
- "node": ">=14.0.0"
15
- },
16
- "scripts": {
17
- "test": "eslint .",
18
- "publish": "npm publish"
5
+ "homepage": "https://github.com/MetaMask/eslint-config#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/MetaMask/eslint-config/issues"
19
8
  },
20
9
  "repository": {
21
10
  "type": "git",
22
11
  "url": "https://github.com/MetaMask/eslint-config.git"
23
12
  },
24
13
  "license": "MIT",
25
- "bugs": {
26
- "url": "https://github.com/MetaMask/eslint-config/issues"
14
+ "main": "src/index.js",
15
+ "files": [
16
+ "src/"
17
+ ],
18
+ "scripts": {
19
+ "lint:changelog": "auto-changelog validate",
20
+ "publish": "npm publish",
21
+ "test": "eslint ."
27
22
  },
28
- "homepage": "https://github.com/MetaMask/eslint-config#readme",
29
23
  "devDependencies": {
30
- "@metamask/eslint-config": "^10.0.0",
31
- "@typescript-eslint/eslint-plugin": "^5.33.0",
32
- "@typescript-eslint/parser": "^5.33.0",
33
- "eslint": "^8.21.0",
34
- "eslint-config-prettier": "^8.1.0",
24
+ "@metamask/auto-changelog": "^3.0.0",
25
+ "@metamask/eslint-config": "^11.0.0",
26
+ "@typescript-eslint/eslint-plugin": "^5.42.1",
27
+ "@typescript-eslint/parser": "^5.42.1",
28
+ "eslint": "^8.27.0",
29
+ "eslint-config-prettier": "^8.5.0",
35
30
  "eslint-plugin-import": "^2.26.0",
36
- "eslint-plugin-jsdoc": "^39.2.9",
31
+ "eslint-plugin-jsdoc": "^39.6.2",
37
32
  "eslint-plugin-prettier": "^4.2.1",
38
- "prettier": "^2.2.1",
39
- "typescript": "^4.0.7"
33
+ "prettier": "^2.7.1",
34
+ "typescript": "~4.8.4"
40
35
  },
41
36
  "peerDependencies": {
42
- "@metamask/eslint-config": "^10.0.0",
43
- "@typescript-eslint/eslint-plugin": "^5.33.0",
44
- "@typescript-eslint/parser": "^5.33.0",
45
- "eslint": "^8.21.0",
46
- "typescript": "^4.0.7"
37
+ "@metamask/eslint-config": "^11.0.0",
38
+ "@typescript-eslint/eslint-plugin": "^5.42.1",
39
+ "@typescript-eslint/parser": "^5.42.1",
40
+ "eslint": "^8.27.0",
41
+ "typescript": "~4.8.4"
42
+ },
43
+ "engines": {
44
+ "node": ">=14.0.0"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public",
48
+ "registry": "https://registry.npmjs.org/"
47
49
  }
48
50
  }
@@ -0,0 +1,2 @@
1
+ // This file is only used to test the config.
2
+ console.log('Hello, world!');
package/src/index.js CHANGED
@@ -15,12 +15,19 @@ module.exports = {
15
15
  // (not pre-release) here: https://github.com/tc39/ecma262/releases
16
16
  ecmaVersion: 2020,
17
17
  sourceType: 'module',
18
+
19
+ // This enables support for linting rules that require type information. We
20
+ // assume that the project has a `tsconfig.json` file in the directory where
21
+ // ESLint is being run.
22
+ tsconfigRootDir: process.cwd(),
23
+ project: ['./tsconfig.json'],
18
24
  },
19
25
 
20
26
  plugins: ['@typescript-eslint', 'jsdoc'],
21
27
 
22
28
  extends: [
23
29
  'plugin:@typescript-eslint/recommended',
30
+ 'plugin:@typescript-eslint/recommended-requiring-type-checking',
24
31
  'plugin:import/typescript',
25
32
  ],
26
33
 
@@ -58,6 +65,72 @@ module.exports = {
58
65
  },
59
66
  ],
60
67
 
68
+ // Recommended rules that require type information
69
+ '@typescript-eslint/no-unsafe-argument': 'off',
70
+ '@typescript-eslint/no-unsafe-assignment': 'off',
71
+ '@typescript-eslint/no-unsafe-call': 'off',
72
+ '@typescript-eslint/no-unsafe-member-access': 'off',
73
+ '@typescript-eslint/no-unsafe-return': 'off',
74
+
75
+ // Our rules that require type information
76
+ '@typescript-eslint/consistent-type-exports': 'error',
77
+ '@typescript-eslint/naming-convention': [
78
+ 'error',
79
+ {
80
+ selector: 'default',
81
+ format: ['camelCase'],
82
+ leadingUnderscore: 'allow',
83
+ trailingUnderscore: 'forbid',
84
+ },
85
+ {
86
+ selector: 'enumMember',
87
+ format: ['PascalCase'],
88
+ },
89
+ {
90
+ selector: 'interface',
91
+ format: ['PascalCase'],
92
+ custom: {
93
+ regex: '^I[A-Z]',
94
+ match: false,
95
+ },
96
+ },
97
+ {
98
+ selector: 'objectLiteralMethod',
99
+ format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
100
+ },
101
+ {
102
+ selector: 'objectLiteralProperty',
103
+ format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
104
+ },
105
+ {
106
+ selector: 'typeLike',
107
+ format: ['PascalCase'],
108
+ },
109
+ {
110
+ selector: 'variable',
111
+ format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
112
+ leadingUnderscore: 'allow',
113
+ },
114
+ ],
115
+ '@typescript-eslint/no-meaningless-void-operator': 'error',
116
+ '@typescript-eslint/no-unnecessary-boolean-literal-compare': 'error',
117
+ '@typescript-eslint/no-unnecessary-qualifier': 'error',
118
+ '@typescript-eslint/no-unnecessary-type-arguments': 'error',
119
+ '@typescript-eslint/prefer-includes': 'error',
120
+ '@typescript-eslint/prefer-nullish-coalescing': 'error',
121
+ '@typescript-eslint/prefer-readonly': 'error',
122
+ '@typescript-eslint/prefer-reduce-type-parameter': 'error',
123
+ '@typescript-eslint/prefer-string-starts-ends-with': 'error',
124
+ '@typescript-eslint/promise-function-async': 'error',
125
+ '@typescript-eslint/restrict-template-expressions': [
126
+ 'error',
127
+ {
128
+ allowBoolean: true,
129
+ allowNumber: true,
130
+ },
131
+ ],
132
+ '@typescript-eslint/switch-exhaustiveness-check': 'error',
133
+
61
134
  'default-param-last': 'off',
62
135
  '@typescript-eslint/default-param-last': 'error',
63
136
 
@@ -65,7 +138,7 @@ module.exports = {
65
138
  '@typescript-eslint/no-shadow': ['error', { builtinGlobals: true }],
66
139
 
67
140
  'no-throw-literal': 'off',
68
- // '@typescript-eslint/no-throw-literal' is left disabled because it requires type information
141
+ '@typescript-eslint/no-throw-literal': 'error',
69
142
 
70
143
  'no-unused-expressions': 'off',
71
144
  '@typescript-eslint/no-unused-expressions': [
@@ -95,5 +168,15 @@ module.exports = {
95
168
  'jsdoc/require-property-type': 'off',
96
169
  'jsdoc/require-returns-type': 'off',
97
170
  'jsdoc/valid-types': 'off',
171
+
172
+ // Prefer hash names over TypeScript's `private` modifier.
173
+ 'no-restricted-syntax': [
174
+ 'error',
175
+ {
176
+ selector:
177
+ "PropertyDefinition[accessibility='private'], MethodDefinition[accessibility='private'], TSParameterProperty[accessibility='private']",
178
+ message: 'Use a hash name instead.',
179
+ },
180
+ ],
98
181
  },
99
182
  };
@@ -0,0 +1,31 @@
1
+ const { ESLint } = require('eslint');
2
+ const { resolve } = require('path');
3
+
4
+ const config = require('.');
5
+
6
+ describe('index', () => {
7
+ it('is a valid ESLint config', async () => {
8
+ const api = new ESLint({
9
+ baseConfig: config,
10
+ useEslintrc: false,
11
+ overrideConfig: {
12
+ env: {
13
+ node: true,
14
+ },
15
+ parserOptions: {
16
+ tsconfigRootDir: resolve(__dirname, '..'),
17
+ project: 'tsconfig.json',
18
+ },
19
+ },
20
+ });
21
+
22
+ // In order to test rules that require type information, we need to actually
23
+ // compile the file with TypeScript, so rather than using `api.lintText()`,
24
+ // we use `api.lintFiles()` and pass in a file that we know will pass.
25
+ const result = await api.lintFiles(resolve(__dirname, '__test__/dummy.ts'));
26
+
27
+ expect(result[0].messages).toStrictEqual([]);
28
+ expect(result[0].warningCount).toBe(0);
29
+ expect(result[0].errorCount).toBe(0);
30
+ });
31
+ });