Skip to content

Commit ddc3586

Browse files
committed
feat: support eslint flat config
1 parent 9cd2082 commit ddc3586

File tree

7 files changed

+144
-71
lines changed

7 files changed

+144
-71
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,21 @@ Or
2525
npm install --save-dev eslint-plugin-ember
2626
```
2727

28-
### 2. Modify your `.eslintrc.js`
28+
### 2. Update your config
2929

3030
```js
31-
// .eslintrc.js
31+
// eslint.config.js (flat config)
32+
const eslintPluginEmberRecommended = require('eslint-plugin-ember/configs/recommended');
33+
34+
module.exports = [
35+
...eslintPluginEmberRecommended,
36+
];
37+
```
38+
39+
or
40+
41+
```js
42+
// .eslintrc.js (legacy config)
3243
module.exports = {
3344
plugins: ['ember'],
3445
extends: [

lib/config-legacy/recommended.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const rules = require('../recommended-rules');
2+
const util = require('ember-template-imports/src/util');
3+
4+
module.exports = {
5+
root: true,
6+
7+
parserOptions: {
8+
ecmaVersion: 2020,
9+
sourceType: 'module',
10+
},
11+
12+
env: {
13+
browser: true,
14+
es2020: true,
15+
},
16+
17+
plugins: ['ember'],
18+
19+
rules,
20+
21+
overrides: [
22+
/**
23+
* We don't want to *always* have the preprocessor active,
24+
* it's only relevant on gjs and gts files.
25+
*
26+
* Additionally, we need to declare a global (which is private API)
27+
* so that ESLint doesn't report errors about the variable being undefined.
28+
* While this is true, it's a temporary thing for babel to do further processing
29+
* on -- and isn't relevant to user-land code.
30+
*/
31+
{
32+
files: ['**/*.gjs', '**/*.gts'],
33+
processor: 'ember/<template>',
34+
globals: {
35+
[util.TEMPLATE_TAG_PLACEHOLDER]: 'readonly',
36+
},
37+
},
38+
],
39+
};

lib/config/recommended.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
const rules = require('../recommended-rules');
22
const util = require('ember-template-imports/src/util');
3+
const plugin = require('../index');
34

4-
module.exports = {
5-
root: true,
5+
module.exports = [
6+
{
7+
languageOptions: {
8+
parserOptions: {
9+
ecmaVersion: 2020,
10+
sourceType: 'module',
11+
},
12+
},
613

7-
parserOptions: {
8-
ecmaVersion: 2020,
9-
sourceType: 'module',
10-
},
14+
plugins: { ember: plugin },
1115

12-
env: {
13-
browser: true,
14-
es2020: true,
16+
rules,
1517
},
1618

17-
plugins: ['ember'],
18-
19-
rules,
20-
21-
overrides: [
19+
{
2220
/**
2321
* We don't want to *always* have the preprocessor active,
2422
* it's only relevant on gjs and gts files.
@@ -28,12 +26,12 @@ module.exports = {
2826
* While this is true, it's a temporary thing for babel to do further processing
2927
* on -- and isn't relevant to user-land code.
3028
*/
31-
{
32-
files: ['**/*.gjs', '**/*.gts'],
33-
processor: 'ember/<template>',
29+
files: ['**/*.gjs', '**/*.gts'],
30+
processor: 'ember/<template>',
31+
languageOptions: {
3432
globals: {
3533
[util.TEMPLATE_TAG_PLACEHOLDER]: 'readonly',
3634
},
3735
},
38-
],
39-
};
36+
},
37+
];

lib/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
'use strict';
22

33
const requireIndex = require('requireindex');
4-
4+
const pkg = require("../package.json");
55
const gjs = require('./preprocessors/glimmer');
66

77
module.exports = {
8+
meta: {
9+
name: pkg.name,
10+
version: pkg.version
11+
},
812
rules: requireIndex(`${__dirname}/rules`),
9-
configs: requireIndex(`${__dirname}/config`),
13+
configs: requireIndex(`${__dirname}/config-legacy`),
1014
utils: {
1115
ember: require('./utils/ember'),
1216
},

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
"url": "git+https://github.com/ember-cli/eslint-plugin-ember.git"
2222
},
2323
"license": "MIT",
24-
"exports": "./lib/index.js",
24+
"exports": {
25+
".": "./lib/index.js",
26+
"./configs/*": "./lib/config/*.js"
27+
},
2528
"main": "./lib/index.js",
2629
"directories": {
2730
"test": "test",
@@ -84,7 +87,7 @@
8487
"@babel/plugin-proposal-class-properties": "^7.13.0",
8588
"@babel/plugin-proposal-decorators": "^7.15.8",
8689
"@typescript-eslint/parser": "^5.31.0",
87-
"eslint": "^8.20.0",
90+
"eslint": "^8.55.0",
8891
"eslint-config-prettier": "^8.5.0",
8992
"eslint-doc-generator": "^1.0.0",
9093
"eslint-plugin-eslint-comments": "^3.2.0",

tests/plugin-exports.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const plugin = require('../lib');
44
const ember = require('../lib/utils/ember');
5-
const recommended = require('../lib/config/recommended');
5+
const recommendedLegacy = require('../lib/config-legacy/recommended');
66

77
describe('plugin exports', () => {
88
describe('utils', () => {
@@ -12,8 +12,8 @@ describe('plugin exports', () => {
1212
});
1313

1414
describe('configs', () => {
15-
it('has the right configurations', () => {
16-
expect(plugin.configs).toStrictEqual({ recommended });
15+
it('has the right configurations (legacy)', () => {
16+
expect(plugin.configs).toStrictEqual({ recommended: recommendedLegacy });
1717
});
1818
});
1919
});

yarn.lock

Lines changed: 61 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -499,15 +499,15 @@
499499
dependencies:
500500
eslint-visitor-keys "^3.3.0"
501501

502-
"@eslint-community/regexpp@^4.4.0":
503-
version "4.4.0"
504-
resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.4.0.tgz#3e61c564fcd6b921cb789838631c5ee44df09403"
505-
integrity sha512-A9983Q0LnDGdLPjxyXQ00sbV+K+O+ko2Dr+CZigbHWtX9pNfxlaBkMR8X1CztI73zuEyEBXTVjx7CE+/VSwDiQ==
502+
"@eslint-community/regexpp@^4.6.1":
503+
version "4.10.0"
504+
resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.10.0.tgz#548f6de556857c8bb73bbee70c35dc82a2e74d63"
505+
integrity sha512-Cu96Sd2By9mCNTx2iyKOmq10v22jUVQv0lQnlGNy16oE9589yE+QADPbrMGCkA51cKZSg3Pu/aTJVTGfL/qjUA==
506506

507-
"@eslint/eslintrc@^2.1.0":
508-
version "2.1.0"
509-
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-2.1.0.tgz#82256f164cc9e0b59669efc19d57f8092706841d"
510-
integrity sha512-Lj7DECXqIVCqnqjjHMPna4vn6GJcMgul/wuS0je9OZ9gsL0zzDpKPVtcG1HaDVc+9y+qgXneTeUMbCqXJNpH1A==
507+
"@eslint/eslintrc@^2.1.4":
508+
version "2.1.4"
509+
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-2.1.4.tgz#388a269f0f25c1b6adc317b5a2c55714894c70ad"
510+
integrity sha512-269Z39MS6wVJtsoUl10L60WdkhJVdPG24Q4eZTH3nnF6lpvSShEK3wQjDX9JRWAUPvPh7COouPpU9IrqaZFvtQ==
511511
dependencies:
512512
ajv "^6.12.4"
513513
debug "^4.3.2"
@@ -519,10 +519,10 @@
519519
minimatch "^3.1.2"
520520
strip-json-comments "^3.1.1"
521521

522-
"@eslint/js@8.44.0":
523-
version "8.44.0"
524-
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.44.0.tgz#961a5903c74139390478bdc808bcde3fc45ab7af"
525-
integrity sha512-Ag+9YM4ocKQx9AarydN0KY2j0ErMHNIocPDrVo8zAE44xLTjEtz81OdR68/cydGtk6m6jDb5Za3r2useMzYmSw==
522+
"@eslint/js@8.55.0":
523+
version "8.55.0"
524+
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.55.0.tgz#b721d52060f369aa259cf97392403cb9ce892ec6"
525+
integrity sha512-qQfo2mxH5yVom1kacMtZZJFVdW+E70mqHMJvVg6WTLo+VBuQJ4TojZlfWBjK0ve5BdEeNAVxOsl/nvNMpJOaJA==
526526

527527
"@gar/promisify@^1.0.1":
528528
version "1.1.3"
@@ -591,12 +591,12 @@
591591
resolved "https://registry.yarnpkg.com/@handlebars/parser/-/parser-2.0.0.tgz#5e8b7298f31ff8f7b260e6b7363c7e9ceed7d9c5"
592592
integrity sha512-EP9uEDZv/L5Qh9IWuMUGJRfwhXJ4h1dqKTT4/3+tY0eu7sPis7xh23j61SYUnNF4vqCQvvUXpDo9Bh/+q1zASA==
593593

594-
"@humanwhocodes/config-array@^0.11.10":
595-
version "0.11.10"
596-
resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.10.tgz#5a3ffe32cc9306365fb3fd572596cd602d5e12d2"
597-
integrity sha512-KVVjQmNUepDVGXNuoRRdmmEjruj0KfiGSbS8LVc12LMsWDQzRXJ0qdhN8L8uUigKpfEHRhlaQFY0ib1tnUbNeQ==
594+
"@humanwhocodes/config-array@^0.11.13":
595+
version "0.11.13"
596+
resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.13.tgz#075dc9684f40a531d9b26b0822153c1e832ee297"
597+
integrity sha512-JSBDMiDKSzQVngfRjOdFXgFfklaXI4K9nLF49Auh21lmBWRLIK3+xTErTWD4KU54pb6coM6ESE7Awz/FNU3zgQ==
598598
dependencies:
599-
"@humanwhocodes/object-schema" "^1.2.1"
599+
"@humanwhocodes/object-schema" "^2.0.1"
600600
debug "^4.1.1"
601601
minimatch "^3.0.5"
602602

@@ -605,10 +605,10 @@
605605
resolved "https://registry.yarnpkg.com/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz#af5b2691a22b44be847b0ca81641c5fb6ad0172c"
606606
integrity sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==
607607

608-
"@humanwhocodes/object-schema@^1.2.1":
609-
version "1.2.1"
610-
resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz#b520529ec21d8e5945a1851dfd1c32e94e39ff45"
611-
integrity sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==
608+
"@humanwhocodes/object-schema@^2.0.1":
609+
version "2.0.1"
610+
resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-2.0.1.tgz#e5211452df060fa8522b55c7b3c0c4d1981cb044"
611+
integrity sha512-dvuCeX5fC9dXgJn9t+X5atfmgQAzUOWqS1254Gh0m6i8wKd10ebXkfNKiRK+1GWi/yTvvLDHpoxLr0xxxeslWw==
612612

613613
614614
version "2.2.5"
@@ -1383,6 +1383,11 @@
13831383
"@typescript-eslint/types" "5.60.1"
13841384
eslint-visitor-keys "^3.3.0"
13851385

1386+
"@ungap/structured-clone@^1.2.0":
1387+
version "1.2.0"
1388+
resolved "https://registry.yarnpkg.com/@ungap/structured-clone/-/structured-clone-1.2.0.tgz#756641adb587851b5ccb3e095daf27ae581c8406"
1389+
integrity sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==
1390+
13861391
JSONStream@^1.3.5:
13871392
version "1.3.5"
13881393
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0"
@@ -1460,7 +1465,7 @@ ajv-errors@^1.0.1:
14601465
resolved "https://registry.yarnpkg.com/ajv-errors/-/ajv-errors-1.0.1.tgz#f35986aceb91afadec4102fbd85014950cefa64d"
14611466
integrity sha512-DCRfO/4nQ+89p/RK43i8Ezd41EqdGIU4ld7nGF8OQ14oc/we5rEntLCUa7+jrn3nn83BosfwZA0wb4pon2o8iQ==
14621467

1463-
ajv@^6.10.0, ajv@^6.12.4, ajv@^6.12.6:
1468+
ajv@^6.12.4, ajv@^6.12.6:
14641469
version "6.12.6"
14651470
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4"
14661471
integrity sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==
@@ -3062,10 +3067,10 @@ [email protected], eslint-scope@^5.1.1:
30623067
esrecurse "^4.3.0"
30633068
estraverse "^4.1.1"
30643069

3065-
eslint-scope@^7.2.0:
3066-
version "7.2.0"
3067-
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-7.2.0.tgz#f21ebdafda02352f103634b96dd47d9f81ca117b"
3068-
integrity sha512-DYj5deGlHBfMt15J7rdtyKNq/Nqlv5KfU4iodrQ019XESsRnwXH9KAE0y3cwtUHDo2ob7CypAnCqefh6vioWRw==
3070+
eslint-scope@^7.2.2:
3071+
version "7.2.2"
3072+
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-7.2.2.tgz#deb4f92563390f32006894af62a22dba1c46423f"
3073+
integrity sha512-dOt21O7lTMhDM+X9mB4GX+DZrZtCUJPL/wlcTqxyrx5IvO0IYtILdtrQGQp+8n5S0gwSVmOf9NQrjMOgfQZlIg==
30693074
dependencies:
30703075
esrecurse "^4.3.0"
30713076
estraverse "^5.2.0"
@@ -3099,27 +3104,33 @@ eslint-visitor-keys@^3.3.0, eslint-visitor-keys@^3.4.1:
30993104
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.4.1.tgz#c22c48f48942d08ca824cc526211ae400478a994"
31003105
integrity sha512-pZnmmLwYzf+kWaM/Qgrvpen51upAktaaiI01nsJD/Yr3lMOdNtq0cxkrrg16w64VtisN6okbs7Q8AfGqj4c9fA==
31013106

3102-
eslint@^8.20.0:
3103-
version "8.44.0"
3104-
resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.44.0.tgz#51246e3889b259bbcd1d7d736a0c10add4f0e500"
3105-
integrity sha512-0wpHoUbDUHgNCyvFB5aXLiQVfK9B0at6gUvzy83k4kAsQ/u769TQDX6iKC+aO4upIHO9WSaA3QoXYQDHbNwf1A==
3107+
eslint-visitor-keys@^3.4.3:
3108+
version "3.4.3"
3109+
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz#0cd72fe8550e3c2eae156a96a4dddcd1c8ac5800"
3110+
integrity sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==
3111+
3112+
eslint@^8.55.0:
3113+
version "8.55.0"
3114+
resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.55.0.tgz#078cb7b847d66f2c254ea1794fa395bf8e7e03f8"
3115+
integrity sha512-iyUUAM0PCKj5QpwGfmCAG9XXbZCWsqP/eWAWrG/W0umvjuLRBECwSFdt+rCntju0xEH7teIABPwXpahftIaTdA==
31063116
dependencies:
31073117
"@eslint-community/eslint-utils" "^4.2.0"
3108-
"@eslint-community/regexpp" "^4.4.0"
3109-
"@eslint/eslintrc" "^2.1.0"
3110-
"@eslint/js" "8.44.0"
3111-
"@humanwhocodes/config-array" "^0.11.10"
3118+
"@eslint-community/regexpp" "^4.6.1"
3119+
"@eslint/eslintrc" "^2.1.4"
3120+
"@eslint/js" "8.55.0"
3121+
"@humanwhocodes/config-array" "^0.11.13"
31123122
"@humanwhocodes/module-importer" "^1.0.1"
31133123
"@nodelib/fs.walk" "^1.2.8"
3114-
ajv "^6.10.0"
3124+
"@ungap/structured-clone" "^1.2.0"
3125+
ajv "^6.12.4"
31153126
chalk "^4.0.0"
31163127
cross-spawn "^7.0.2"
31173128
debug "^4.3.2"
31183129
doctrine "^3.0.0"
31193130
escape-string-regexp "^4.0.0"
3120-
eslint-scope "^7.2.0"
3121-
eslint-visitor-keys "^3.4.1"
3122-
espree "^9.6.0"
3131+
eslint-scope "^7.2.2"
3132+
eslint-visitor-keys "^3.4.3"
3133+
espree "^9.6.1"
31233134
esquery "^1.4.2"
31243135
esutils "^2.0.2"
31253136
fast-deep-equal "^3.1.3"
@@ -3129,7 +3140,6 @@ eslint@^8.20.0:
31293140
globals "^13.19.0"
31303141
graphemer "^1.4.0"
31313142
ignore "^5.2.0"
3132-
import-fresh "^3.0.0"
31333143
imurmurhash "^0.1.4"
31343144
is-glob "^4.0.0"
31353145
is-path-inside "^3.0.3"
@@ -3141,7 +3151,6 @@ eslint@^8.20.0:
31413151
natural-compare "^1.4.0"
31423152
optionator "^0.9.3"
31433153
strip-ansi "^6.0.1"
3144-
strip-json-comments "^3.1.0"
31453154
text-table "^0.2.0"
31463155

31473156
espree@^9.6.0:
@@ -3153,6 +3162,15 @@ espree@^9.6.0:
31533162
acorn-jsx "^5.3.2"
31543163
eslint-visitor-keys "^3.4.1"
31553164

3165+
espree@^9.6.1:
3166+
version "9.6.1"
3167+
resolved "https://registry.yarnpkg.com/espree/-/espree-9.6.1.tgz#a2a17b8e434690a5432f2f8018ce71d331a48c6f"
3168+
integrity sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==
3169+
dependencies:
3170+
acorn "^8.9.0"
3171+
acorn-jsx "^5.3.2"
3172+
eslint-visitor-keys "^3.4.1"
3173+
31563174
esprima@^4.0.0, esprima@^4.0.1:
31573175
version "4.0.1"
31583176
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71"
@@ -3852,7 +3870,7 @@ ignore@^5.0.5, ignore@^5.1.1, ignore@^5.2.0, ignore@~5.2.4:
38523870
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.2.4.tgz#a291c0c6178ff1b960befe47fcdec301674a6324"
38533871
integrity sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==
38543872

3855-
import-fresh@^3.0.0, import-fresh@^3.2.1:
3873+
import-fresh@^3.2.1:
38563874
version "3.3.0"
38573875
resolved "https://registry.yarnpkg.com/import-fresh/-/import-fresh-3.3.0.tgz#37162c25fcb9ebaa2e6e53d5b4d88ce17d9e0c2b"
38583876
integrity sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==
@@ -6907,7 +6925,7 @@ [email protected]:
69076925
dependencies:
69086926
lru-cache "^6.0.0"
69096927

6910-
semver@^6.0.0, semver@^6.1.0, semver@^6.3.0:
6928+
semver@^6.0.0, semver@^6.1.0, semver@^6.3.0, semver@^6.3.1:
69116929
version "6.3.1"
69126930
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4"
69136931
integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==
@@ -7280,7 +7298,7 @@ strip-indent@^3.0.0:
72807298
dependencies:
72817299
min-indent "^1.0.0"
72827300

7283-
strip-json-comments@^3.1.0, strip-json-comments@^3.1.1, strip-json-comments@~3.1.1:
7301+
strip-json-comments@^3.1.1, strip-json-comments@~3.1.1:
72847302
version "3.1.1"
72857303
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006"
72867304
integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==

0 commit comments

Comments
 (0)