Skip to content

Commit 1d1126a

Browse files
authored
ESLint: Migrate to flat config format (#10621)
see https://eslint.org/docs/latest/use/configure/migration-guide
1 parent 7526783 commit 1d1126a

File tree

11 files changed

+215
-162
lines changed

11 files changed

+215
-162
lines changed

.eslintignore

-20
This file was deleted.

.eslintrc.js

-132
This file was deleted.

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
packages/**
4343
public/**
4444
tests/**
45-
.eslintrc
45+
eslint.config.mjs
4646
.template-lintrc.js
4747
ember-cli-build.js
4848
package.json

app/services/color-scheme.js

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export default class DesignService extends Service {
4444
*/
4545
watcherTask = restartableTask(async () => {
4646
let mediaQueryList = window.matchMedia('(prefers-color-scheme: dark)');
47-
// eslint-disable-next-line no-constant-condition
4847
while (true) {
4948
let scheme = this.scheme;
5049
if (scheme === 'system') {

app/services/session.js

-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ export default class SessionService extends Service {
144144
});
145145

146146
windowEventWatcherTask = task(async () => {
147-
// eslint-disable-next-line no-constant-condition
148147
while (true) {
149148
let event = await waitForEvent(window, 'message');
150149
if (event.origin !== window.location.origin || !event.data) {
@@ -161,7 +160,6 @@ export default class SessionService extends Service {
161160
});
162161

163162
windowCloseWatcherTask = task(async window => {
164-
// eslint-disable-next-line no-constant-condition
165163
while (true) {
166164
if (window.closed) {
167165
return { closed: true };

docs/ARCHITECTURE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ These files have to do with the frontend:
5050
frontend; served under the root `/` url - (ignored in `.gitignore`)
5151
- `.ember-cli` - Settings for the `ember` command line interface
5252
- `ember-cli-build.js` - Contains the build specification for Broccoli
53-
- `.eslintrc.js` - Defines Javascript coding style guidelines (enforced during CI???)
53+
- `eslint.config.mjs` - Defines Javascript coding style guidelines
5454
- `node_modules/` - npm dependencies - (ignored in `.gitignore`)
5555
- `packages/crates-io-msw` - A mock backend used for testing
5656
- `package.json` - Defines the npm package and its dependencies

eslint.config.mjs

+197
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
import babelParser from '@babel/eslint-parser';
2+
import { FlatCompat } from '@eslint/eslintrc';
3+
import js from '@eslint/js';
4+
import ember from 'eslint-plugin-ember';
5+
import emberConcurrency from 'eslint-plugin-ember-concurrency';
6+
import importHelpers from 'eslint-plugin-import-helpers';
7+
import prettier from 'eslint-plugin-prettier';
8+
import globals from 'globals';
9+
import path from 'node:path';
10+
import { fileURLToPath } from 'node:url';
11+
12+
const __filename = fileURLToPath(import.meta.url);
13+
const __dirname = path.dirname(__filename);
14+
const compat = new FlatCompat({
15+
baseDirectory: __dirname,
16+
recommendedConfig: js.configs.recommended,
17+
allConfig: js.configs.all,
18+
});
19+
20+
export default [
21+
{
22+
ignores: [
23+
'.git/**/*',
24+
'crates/',
25+
'playwright-report/',
26+
'target/',
27+
'test-results/',
28+
'tmp/',
29+
// unconventional js
30+
'blueprints/*/files/',
31+
'vendor/',
32+
// compiled output
33+
'dist/',
34+
'tmp/',
35+
// dependencies
36+
'bower_components/',
37+
'node_modules/',
38+
// misc
39+
'coverage/',
40+
'!**/.*',
41+
// ember-try
42+
'.node_modules.ember-try/',
43+
'bower.json.ember-try',
44+
'package.json.ember-try',
45+
],
46+
},
47+
...compat.extends(
48+
'eslint:recommended',
49+
'plugin:ember/recommended',
50+
'plugin:qunit/recommended',
51+
'plugin:qunit-dom/recommended',
52+
'plugin:unicorn/recommended',
53+
'plugin:prettier/recommended',
54+
),
55+
{
56+
plugins: {
57+
ember,
58+
'ember-concurrency': emberConcurrency,
59+
prettier,
60+
'import-helpers': importHelpers,
61+
},
62+
63+
languageOptions: {
64+
globals: {
65+
...globals.browser,
66+
},
67+
68+
parser: babelParser,
69+
ecmaVersion: 2018,
70+
sourceType: 'module',
71+
72+
parserOptions: {
73+
requireConfigFile: false,
74+
75+
babelOptions: {
76+
plugins: [
77+
[
78+
'@babel/plugin-proposal-decorators',
79+
{
80+
decoratorsBeforeExport: true,
81+
},
82+
],
83+
],
84+
},
85+
},
86+
},
87+
88+
rules: {
89+
// it's fine to use `return` without a value and rely on the implicit `undefined` return value
90+
'getter-return': 'off',
91+
92+
// declaration sort is taken care of by `import-helpers/order-imports`
93+
'sort-imports': ['error', { ignoreDeclarationSort: true, ignoreCase: true }],
94+
95+
'prettier/prettier': 'error',
96+
97+
// disabled because we still use `this.set()` in a few places and it works just fine
98+
'ember/classic-decorator-no-classic-methods': 'off',
99+
// disabled because the alternatives are currently not worth the additional complexity
100+
'ember/no-array-prototype-extensions': 'off',
101+
102+
'ember-concurrency/no-perform-without-catch': 'warn',
103+
'ember-concurrency/require-task-name-suffix': 'error',
104+
105+
// disabled because of false positives in `assert.rejects()` calls
106+
'qunit/require-expect': 'off',
107+
108+
// disabled because of false positives related to ember-concurrency usage
109+
'unicorn/consistent-function-scoping': 'off',
110+
'unicorn/explicit-length-check': ['error', { 'non-zero': 'not-equal' }],
111+
// disabled because it conflicts with Ember.js conventions
112+
'unicorn/no-anonymous-default-export': 'off',
113+
// disabled because of false positives related to `EmberArray`
114+
'unicorn/no-array-for-each': 'off',
115+
// disabled because it is annoying in some cases...
116+
'unicorn/no-await-expression-member': 'off',
117+
// disabled because we need `null` since JSON has no `undefined`
118+
'unicorn/no-null': 'off',
119+
// disabled because this rule conflicts with prettier
120+
'unicorn/no-nested-ternary': 'off',
121+
// disabled because of unfixable false positives
122+
'unicorn/prevent-abbreviations': 'off',
123+
// disabled because we are targeting only browsers at the moment
124+
'unicorn/prefer-global-this': 'off',
125+
// disabled because we don't want to go all-in on ES6 modules for Node.js code yet
126+
'unicorn/prefer-module': 'off',
127+
// disabled because it seems unnecessary
128+
'unicorn/prefer-number-properties': 'off',
129+
// disabled because it seems unnecessary
130+
'unicorn/prefer-reflect-apply': 'off',
131+
// disabled because of false positives related to `EmberArray`
132+
'unicorn/prefer-spread': 'off',
133+
// disabled because it seems unnecessary
134+
'unicorn/prefer-string-raw': 'off',
135+
// disabled because of Sentry issues
136+
'unicorn/prefer-string-replace-all': 'off',
137+
// disabled because switch statements in JS are quite error-prone
138+
'unicorn/prefer-switch': 'off',
139+
// disabled because of false positives
140+
'unicorn/consistent-destructuring': 'off',
141+
'unicorn/filename-case': ['error', { case: 'kebabCase', ignore: ['^-'] }],
142+
143+
'import-helpers/order-imports': [
144+
'error',
145+
{
146+
newlinesBetween: 'always',
147+
groups: [
148+
// Node.js built-in modules
149+
'/^(assert|async_hooks|buffer|child_process|cluster|console|constants|crypto|dgram|dns|domain|events|fs|http|http2|https|inspector|module|net|os|path|perf_hooks|process|punycode|querystring|readline|repl|stream|string_decoder|timers|tls|trace_events|tty|url|util|v8|vm|zli)/',
150+
// Testing modules
151+
['/^(qunit|ember-qunit|@ember/test-helpers|ember-exam|htmlbars-inline-precompile)$/', '/^ember-exam\\//'],
152+
// Ember.js modules
153+
['/^@(ember|ember-data|glimmer)\\//', '/^(ember|ember-data|rsvp)$/', '/^ember-data\\//'],
154+
['module'],
155+
['/^crates-io\\//'],
156+
['parent', 'sibling', 'index'],
157+
],
158+
alphabetize: { order: 'asc', ignoreCase: true },
159+
},
160+
],
161+
},
162+
},
163+
164+
// test files
165+
{
166+
files: ['tests/**/*.js'],
167+
168+
rules: {
169+
'unicorn/consistent-function-scoping': 'off',
170+
'unicorn/prefer-dom-node-dataset': 'off',
171+
},
172+
},
173+
174+
// node files
175+
{
176+
files: [
177+
'eslint.config.mjs',
178+
'**/.template-lintrc.js',
179+
'**/ember-cli-build.js',
180+
'**/testem.js',
181+
'blueprints/*/index.js',
182+
'config/**/*.js',
183+
'lib/*/index.js',
184+
'server/**/*.js',
185+
],
186+
187+
languageOptions: {
188+
globals: {
189+
...Object.fromEntries(Object.entries(globals.browser).map(([key]) => [key, 'off'])),
190+
...globals.node,
191+
},
192+
193+
ecmaVersion: 2018,
194+
sourceType: 'script',
195+
},
196+
},
197+
];

0 commit comments

Comments
 (0)