Skip to content

Commit 8ab85f9

Browse files
ember-cli 6.1, eslint 9, eslint flat config, RFC#1055 (#320)
* ember-cli < 6.1 is too old * Switch to ESLint 9 * fix * afix * fix * ope * Cleanup, update prettier config * ope * Fix lints * Lints * lints * Fix assertions * Use TypeScript 5.6 * Upgrade typescript-eslint * Set project: true * Override ember-cli's tsconfig.json see: ember-cli/ember-cli#10611 and ember-cli/ember-cli#10613 and ember-cli/ember-cli#10612 * Re-lock
1 parent 3a61c29 commit 8ab85f9

12 files changed

Lines changed: 407 additions & 544 deletions

File tree

files/__addonLocation__/.eslintignore

Lines changed: 0 additions & 9 deletions
This file was deleted.

files/__addonLocation__/.eslintrc.cjs

Lines changed: 0 additions & 104 deletions
This file was deleted.
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/**
2+
* Debugging:
3+
* https://eslint.org/docs/latest/use/configure/debug
4+
* ----------------------------------------------------
5+
*
6+
* Print a file's calculated configuration
7+
*
8+
* npx eslint --print-config path/to/file.js
9+
*
10+
* Inspecting the config
11+
*
12+
* npx eslint --inspect-config
13+
*
14+
*/
15+
import babelParser from '@babel/eslint-parser';
16+
import js from '@eslint/js';
17+
import prettier from 'eslint-config-prettier';
18+
import ember from 'eslint-plugin-ember/recommended';
19+
import importPlugin from 'eslint-plugin-import';
20+
import n from 'eslint-plugin-n';
21+
import globals from 'globals';
22+
23+
const esmParserOptions = {
24+
ecmaFeatures: { modules: true },
25+
ecmaVersion: 'latest',
26+
};
27+
28+
export default [
29+
js.configs.recommended,
30+
prettier,
31+
ember.configs.base,
32+
ember.configs.gjs,
33+
/**
34+
* Ignores must be in their own object
35+
* https://eslint.org/docs/latest/use/configure/ignore
36+
*/
37+
{
38+
ignores: ['dist/', 'declarations/', 'node_modules/', 'coverage/', '!**/.*'],
39+
},
40+
/**
41+
* https://eslint.org/docs/latest/use/configure/configuration-files#configuring-linter-options
42+
*/
43+
{
44+
linterOptions: {
45+
reportUnusedDisableDirectives: 'error',
46+
},
47+
},
48+
{
49+
files: ['**/*.js'],
50+
languageOptions: {
51+
parser: babelParser,
52+
},
53+
},
54+
{
55+
files: ['**/*.{js,gjs}'],
56+
languageOptions: {
57+
parserOptions: esmParserOptions,
58+
globals: {
59+
...globals.browser,
60+
},
61+
},
62+
},
63+
{
64+
files: ['src/**/*'],
65+
plugins: {
66+
import: importPlugin,
67+
},
68+
rules: {
69+
// require relative imports use full extensions
70+
'import/extensions': ['error', 'always', { ignorePackages: true }],
71+
},
72+
},
73+
/**
74+
* CJS node files
75+
*/
76+
{
77+
files: [
78+
'**/*.cjs',
79+
'.prettierrc.js',
80+
'.stylelintrc.js',
81+
'.template-lintrc.js',
82+
'addon-main.cjs',
83+
],
84+
plugins: {
85+
n,
86+
},
87+
88+
languageOptions: {
89+
sourceType: 'script',
90+
ecmaVersion: 'latest',
91+
globals: {
92+
...globals.node,
93+
},
94+
},
95+
},
96+
/**
97+
* ESM node files
98+
*/
99+
{
100+
files: ['**/*.mjs'],
101+
plugins: {
102+
n,
103+
},
104+
105+
languageOptions: {
106+
sourceType: 'module',
107+
ecmaVersion: 'latest',
108+
parserOptions: esmParserOptions,
109+
globals: {
110+
...globals.node,
111+
},
112+
},
113+
},
114+
];
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/**
2+
* Debugging:
3+
* https://eslint.org/docs/latest/use/configure/debug
4+
* ----------------------------------------------------
5+
*
6+
* Print a file's calculated configuration
7+
*
8+
* npx eslint --print-config path/to/file.js
9+
*
10+
* Inspecting the config
11+
*
12+
* npx eslint --inspect-config
13+
*
14+
*/
15+
import babelParser from '@babel/eslint-parser';
16+
import js from '@eslint/js';
17+
import prettier from 'eslint-config-prettier';
18+
import ember from 'eslint-plugin-ember/recommended';
19+
import importPlugin from 'eslint-plugin-import';
20+
import n from 'eslint-plugin-n';
21+
import globals from 'globals';
22+
import ts from 'typescript-eslint';
23+
24+
const parserOptions = {
25+
esm: {
26+
js: {
27+
ecmaFeatures: { modules: true },
28+
ecmaVersion: 'latest',
29+
},
30+
ts: {
31+
projectService: true,
32+
project: true,
33+
tsconfigRootDir: import.meta.dirname,
34+
},
35+
},
36+
};
37+
38+
export default ts.config(
39+
js.configs.recommended,
40+
ember.configs.base,
41+
ember.configs.gjs,
42+
ember.configs.gts,
43+
prettier,
44+
/**
45+
* Ignores must be in their own object
46+
* https://eslint.org/docs/latest/use/configure/ignore
47+
*/
48+
{
49+
ignores: ['dist/', 'declarations/', 'node_modules/', 'coverage/', '!**/.*'],
50+
},
51+
/**
52+
* https://eslint.org/docs/latest/use/configure/configuration-files#configuring-linter-options
53+
*/
54+
{
55+
linterOptions: {
56+
reportUnusedDisableDirectives: 'error',
57+
},
58+
},
59+
{
60+
files: ['**/*.js'],
61+
languageOptions: {
62+
parser: babelParser,
63+
},
64+
},
65+
{
66+
files: ['**/*.{js,gjs}'],
67+
languageOptions: {
68+
parserOptions: parserOptions.esm.js,
69+
globals: {
70+
...globals.browser,
71+
},
72+
},
73+
},
74+
{
75+
files: ['**/*.{ts,gts}'],
76+
languageOptions: {
77+
parser: ember.parser,
78+
parserOptions: parserOptions.esm.ts,
79+
},
80+
extends: [...ts.configs.recommendedTypeChecked, ember.configs.gts],
81+
},
82+
{
83+
files: ['src/**/*'],
84+
plugins: {
85+
import: importPlugin,
86+
},
87+
rules: {
88+
// require relative imports use full extensions
89+
'import/extensions': ['error', 'always', { ignorePackages: true }],
90+
},
91+
},
92+
/**
93+
* CJS node files
94+
*/
95+
{
96+
files: [
97+
'**/*.cjs',
98+
'.prettierrc.js',
99+
'.stylelintrc.js',
100+
'.template-lintrc.js',
101+
'addon-main.cjs',
102+
],
103+
plugins: {
104+
n,
105+
},
106+
107+
languageOptions: {
108+
sourceType: 'script',
109+
ecmaVersion: 'latest',
110+
globals: {
111+
...globals.node,
112+
},
113+
},
114+
},
115+
/**
116+
* ESM node files
117+
*/
118+
{
119+
files: ['**/*.mjs'],
120+
plugins: {
121+
n,
122+
},
123+
124+
languageOptions: {
125+
sourceType: 'module',
126+
ecmaVersion: 'latest',
127+
parserOptions: parserOptions.esm.js,
128+
globals: {
129+
...globals.node,
130+
},
131+
},
132+
},
133+
);
Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
{
22
"plugins": [
3-
<% if (typescript) { %> ["@babel/plugin-transform-typescript", { "allExtensions": true, "onlyRemoveTypeImports": true, "allowDeclareFields": true }],
3+
<% if (typescript) { %> [
4+
"@babel/plugin-transform-typescript",
5+
{
6+
"allExtensions": true,
7+
"onlyRemoveTypeImports": true,
8+
"allowDeclareFields": true
9+
}
10+
],
411
<% } %> "@embroider/addon-dev/template-colocation-plugin",
5-
["babel-plugin-ember-template-compilation", {
6-
"targetFormat": "hbs",
7-
"transforms": []
8-
}],
9-
["module:decorator-transforms", { "runtime": { "import": "decorator-transforms/runtime" } }],
12+
[
13+
"babel-plugin-ember-template-compilation",
14+
{
15+
"targetFormat": "hbs",
16+
"transforms": []
17+
}
18+
],
19+
[
20+
"module:decorator-transforms",
21+
{ "runtime": { "import": "decorator-transforms/runtime" } }
22+
]
1023
]
1124
}

0 commit comments

Comments
 (0)