Skip to content

Commit ddd4fc0

Browse files
Copilotgavinbarron
andauthored
fix(deps)!: update to latest ESLint and @typescript-eslint packages with flat config migration (#32)
* Initial plan * Update to latest ESLint and @typescript-eslint packages with flat config migration Agent-Logs-Url: https://github.com/microsoftgraph/eslint-config-msgraph/sessions/20ea8472-433d-4379-93b0-d656ff00a61b Co-authored-by: gavinbarron <7122716+gavinbarron@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: gavinbarron <7122716+gavinbarron@users.noreply.github.com>
1 parent 4a16cd4 commit ddd4fc0

File tree

4 files changed

+146
-107
lines changed

4 files changed

+146
-107
lines changed

README.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,48 @@ To install the configuration, run the following command:
1111
npm install --save-dev @microsoft/eslint-config-msgraph
1212
```
1313

14+
You will also need to install the peer dependencies:
15+
16+
```bash
17+
npm install --save-dev eslint @eslint/js @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-config-prettier eslint-plugin-prefer-arrow globals prettier
18+
```
19+
1420
### eslint configuration
1521

22+
This package uses [ESLint flat config](https://eslint.org/docs/latest/use/configure/configuration-files) format.
23+
1624
#### non-React projects
1725

1826
If your project does not contain react components, use this configuration.
1927

20-
In your project's eslint config file, add the following entry in your `extends` array:
28+
In your project's `eslint.config.js` file:
2129

2230
```js
23-
extends: ['@microsoft/eslint-config-msgraph/core'],
31+
const msgraphConfig = require('@microsoft/eslint-config-msgraph/core');
32+
33+
module.exports = [
34+
...msgraphConfig,
35+
// add any overrides here
36+
];
2437
```
2538

2639
#### React projects
2740

28-
If your project contains react components, use this configuration instead.
41+
If your project contains react components, also install `eslint-plugin-react`:
42+
43+
```bash
44+
npm install --save-dev eslint-plugin-react
45+
```
2946

30-
In your project's eslint config file, add the following entry in your `extends` array:
47+
In your project's `eslint.config.js` file:
3148

3249
```js
33-
extends: ['@microsoft/eslint-config-msgraph'],
50+
const msgraphConfig = require('@microsoft/eslint-config-msgraph');
51+
52+
module.exports = [
53+
...msgraphConfig,
54+
// add any overrides here
55+
];
3456
```
3557

3658
### Prettier configuration

core.js

Lines changed: 98 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,100 @@
1-
module.exports = {
2-
env: {
3-
browser: true,
4-
es6: true,
5-
node: true
6-
},
7-
extends: [
8-
'eslint:recommended',
9-
'plugin:@typescript-eslint/recommended-type-checked',
10-
'plugin:@typescript-eslint/stylistic-type-checked',
11-
'prettier'
12-
],
13-
parser: '@typescript-eslint/parser',
14-
parserOptions: { project: './tsconfig.json' },
15-
plugins: ['eslint-plugin-prefer-arrow', '@typescript-eslint'],
16-
rules: {
17-
'@typescript-eslint/class-literal-property-style': ['error', 'getters'],
18-
'@typescript-eslint/consistent-generic-constructors': 'error',
19-
'@typescript-eslint/consistent-indexed-object-style': 'warn',
20-
'@typescript-eslint/consistent-type-assertions': 'error',
21-
'@typescript-eslint/dot-notation': 'error',
22-
'@typescript-eslint/explicit-function-return-type': 'off',
23-
'@typescript-eslint/explicit-module-boundary-types': 'off',
24-
'@typescript-eslint/naming-convention': [
25-
'warn',
26-
{
27-
selector: 'variable',
28-
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
29-
leadingUnderscore: 'forbid',
30-
trailingUnderscore: 'forbid'
1+
const tsPlugin = require('@typescript-eslint/eslint-plugin');
2+
const tsParser = require('@typescript-eslint/parser');
3+
const preferArrow = require('eslint-plugin-prefer-arrow');
4+
const prettier = require('eslint-config-prettier');
5+
const js = require('@eslint/js');
6+
const globals = require('globals');
7+
8+
module.exports = [
9+
js.configs.recommended,
10+
...tsPlugin.configs['flat/recommended-type-checked'],
11+
...tsPlugin.configs['flat/stylistic-type-checked'],
12+
prettier,
13+
{
14+
plugins: {
15+
'prefer-arrow': preferArrow
16+
},
17+
languageOptions: {
18+
globals: {
19+
...globals.browser,
20+
...globals.es2015,
21+
...globals.node
3122
},
32-
{
33-
selector: ['property', 'accessor'],
34-
modifiers: ['private'],
35-
format: ['camelCase'],
36-
leadingUnderscore: 'allow'
37-
},
38-
{
39-
selector: ['variable', 'function'],
40-
format: ['camelCase'],
41-
leadingUnderscore: 'allow'
42-
}
43-
],
44-
'@typescript-eslint/no-shadow': [
45-
'error',
46-
{
47-
hoist: 'all'
48-
}
49-
],
50-
'@typescript-eslint/no-unused-expressions': 'error',
51-
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
52-
'@typescript-eslint/prefer-for-of': 'error',
53-
'@typescript-eslint/prefer-function-type': 'error',
54-
'@typescript-eslint/prefer-optional-chain': 'error',
55-
'@typescript-eslint/prefer-readonly': 'error',
56-
'@typescript-eslint/restrict-template-expressions': ['error', { allowBoolean: true, allowNumber: true }],
57-
'@typescript-eslint/unified-signatures': 'error',
58-
'dot-notation': 'off',
59-
eqeqeq: ['error', 'smart'],
60-
'guard-for-in': 'error',
61-
'linebreak-style': 'off',
62-
'max-classes-per-file': ['error', 1],
63-
'new-parens': ['error', 'always'],
64-
'no-bitwise': 'error',
65-
'no-caller': 'error',
66-
'no-console': ['error', { allow: ['warn', 'error'] }],
67-
'no-empty-function': 'off',
68-
'no-eval': 'error',
69-
'no-new-wrappers': 'error',
70-
'no-shadow': 'off',
71-
'no-throw-literal': 'error',
72-
'no-trailing-spaces': 'error',
73-
'no-undef-init': 'error',
74-
'no-unused-expressions': 'off',
75-
'no-var': 'error',
76-
'object-shorthand': 'error',
77-
'one-var': ['error', 'never'],
78-
'prefer-arrow/prefer-arrow-functions': 'error',
79-
'prefer-const': 'error',
80-
radix: 'error',
81-
'spaced-comment': [
82-
'error',
83-
'always',
84-
{
85-
markers: ['/']
86-
}
87-
]
23+
parser: tsParser,
24+
parserOptions: { project: './tsconfig.json' }
25+
},
26+
rules: {
27+
'@typescript-eslint/class-literal-property-style': ['error', 'getters'],
28+
'@typescript-eslint/consistent-generic-constructors': 'error',
29+
'@typescript-eslint/consistent-indexed-object-style': 'warn',
30+
'@typescript-eslint/consistent-type-assertions': 'error',
31+
'@typescript-eslint/dot-notation': 'error',
32+
'@typescript-eslint/explicit-function-return-type': 'off',
33+
'@typescript-eslint/explicit-module-boundary-types': 'off',
34+
'@typescript-eslint/naming-convention': [
35+
'warn',
36+
{
37+
selector: 'variable',
38+
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
39+
leadingUnderscore: 'forbid',
40+
trailingUnderscore: 'forbid'
41+
},
42+
{
43+
selector: ['property', 'accessor'],
44+
modifiers: ['private'],
45+
format: ['camelCase'],
46+
leadingUnderscore: 'allow'
47+
},
48+
{
49+
selector: ['variable', 'function'],
50+
format: ['camelCase'],
51+
leadingUnderscore: 'allow'
52+
}
53+
],
54+
'@typescript-eslint/no-shadow': [
55+
'error',
56+
{
57+
hoist: 'all'
58+
}
59+
],
60+
'@typescript-eslint/no-unused-expressions': 'error',
61+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
62+
'@typescript-eslint/prefer-for-of': 'error',
63+
'@typescript-eslint/prefer-function-type': 'error',
64+
'@typescript-eslint/prefer-optional-chain': 'error',
65+
'@typescript-eslint/prefer-readonly': 'error',
66+
'@typescript-eslint/restrict-template-expressions': ['error', { allowBoolean: true, allowNumber: true }],
67+
'@typescript-eslint/unified-signatures': 'error',
68+
'dot-notation': 'off',
69+
eqeqeq: ['error', 'smart'],
70+
'guard-for-in': 'error',
71+
'linebreak-style': 'off',
72+
'max-classes-per-file': ['error', 1],
73+
'new-parens': ['error', 'always'],
74+
'no-bitwise': 'error',
75+
'no-caller': 'error',
76+
'no-console': ['error', { allow: ['warn', 'error'] }],
77+
'no-empty-function': 'off',
78+
'no-eval': 'error',
79+
'no-new-wrappers': 'error',
80+
'no-shadow': 'off',
81+
'no-throw-literal': 'error',
82+
'no-trailing-spaces': 'error',
83+
'no-undef-init': 'error',
84+
'no-unused-expressions': 'off',
85+
'no-var': 'error',
86+
'object-shorthand': 'error',
87+
'one-var': ['error', 'never'],
88+
'prefer-arrow/prefer-arrow-functions': 'error',
89+
'prefer-const': 'error',
90+
radix: 'error',
91+
'spaced-comment': [
92+
'error',
93+
'always',
94+
{
95+
markers: ['/']
96+
}
97+
]
98+
}
8899
}
89-
};
100+
];

index.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
const reactPlugin = require('eslint-plugin-react');
12
const core = require('./core.js');
2-
core.extends = [...core.extends, 'plugin:react/recommended'];
3-
core.plugins = [...core.plugins, 'react'];
4-
core.rules = {
5-
'react/no-unstable-nested-components': ['warn', { allowAsProps: true }],
6-
...core.rules
7-
};
8-
core.settings = {
9-
react: {
10-
version: 'detect'
3+
4+
module.exports = [
5+
...core,
6+
reactPlugin.configs.flat['recommended'],
7+
{
8+
rules: {
9+
'react/no-unstable-nested-components': ['warn', { allowAsProps: true }]
10+
},
11+
settings: {
12+
react: {
13+
version: 'detect'
14+
}
15+
}
1116
}
12-
};
13-
module.exports = core;
17+
];

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
"author": "Microsoft",
1515
"license": "MIT",
1616
"peerDependencies": {
17-
"@typescript-eslint/eslint-plugin": "^8.0.0-alpha.54",
18-
"@typescript-eslint/parser": "^8.0.0-alpha.54",
19-
"eslint": "^9.7.0",
20-
"eslint-config-prettier": "^10.0.1",
17+
"@eslint/js": "^9.0.0 || ^10.0.0",
18+
"@typescript-eslint/eslint-plugin": "^8.0.0",
19+
"@typescript-eslint/parser": "^8.0.0",
20+
"eslint": "^9.0.0 || ^10.0.0",
21+
"eslint-config-prettier": "^10.0.0",
2122
"eslint-plugin-prefer-arrow": "^1.2.3",
2223
"eslint-plugin-react": "^7.34.1",
24+
"globals": ">=14.0.0",
2325
"prettier": "^3.2.5"
2426
},
2527
"publishConfig": {

0 commit comments

Comments
 (0)