Skip to content

Commit 0ab9d62

Browse files
committed
support flat config
1 parent 118479e commit 0ab9d62

25 files changed

Lines changed: 4060 additions & 64 deletions

‎lib/configs/flat/browser.js‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const globals = require('globals')
2+
const github = require('../../plugin')
3+
const importPlugin = require('eslint-plugin-import')
4+
const escompatPlugin = require('eslint-plugin-escompat')
5+
6+
module.exports = {
7+
...escompatPlugin.configs['flat/recommended'],
8+
languageOptions: {
9+
globals: {
10+
...globals.browser,
11+
},
12+
},
13+
plugins: {importPlugin, escompatPlugin, github},
14+
rules: {
15+
'escompatPlugin/no-dynamic-imports': 'off',
16+
'github/async-currenttarget': 'error',
17+
'github/async-preventdefault': 'error',
18+
'github/get-attribute': 'error',
19+
'github/no-blur': 'error',
20+
'github/no-dataset': 'error',
21+
'github/no-innerText': 'error',
22+
'github/no-inner-html': 'error',
23+
'github/unescaped-html-literal': 'error',
24+
'github/no-useless-passive': 'error',
25+
'github/require-passive-events': 'error',
26+
'github/prefer-observers': 'error',
27+
'importPlugin/no-nodejs-modules': 'error',
28+
'no-restricted-syntax': [
29+
'error',
30+
{
31+
selector: "NewExpression[callee.name='URL'][arguments.length=1]",
32+
message: 'Please pass in `window.location.origin` as the 2nd argument to `new URL()`',
33+
},
34+
],
35+
},
36+
}

‎lib/configs/flat/internal.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const github = require('../../plugin')
2+
3+
module.exports = {
4+
plugins: {github},
5+
rules: {
6+
'github/authenticity-token': 'error',
7+
'github/js-class-name': 'error',
8+
'github/no-d-none': 'error',
9+
},
10+
}

‎lib/configs/flat/react.js‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
const github = require('../../plugin')
2+
const jsxA11yPlugin = require('eslint-plugin-jsx-a11y')
3+
4+
module.exports = {
5+
...jsxA11yPlugin.flatConfigs.recommended,
6+
languageOptions: {
7+
sourceType: 'module',
8+
parserOptions: {
9+
ecmaFeatures: {
10+
jsx: true,
11+
},
12+
},
13+
},
14+
plugins: {github, jsxA11yPlugin},
15+
rules: {
16+
'jsxA11yPlugin/role-supports-aria-props': 'off', // Override with github/a11y-role-supports-aria-props until https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/issues/910 is resolved
17+
'github/a11y-aria-label-is-well-formatted': 'error',
18+
'github/a11y-no-visually-hidden-interactive-element': 'error',
19+
'github/a11y-no-title-attribute': 'error',
20+
'github/a11y-svg-has-accessible-name': 'error',
21+
'github/a11y-role-supports-aria-props': 'error',
22+
'jsxA11yPlugin/no-aria-hidden-on-focusable': 'error',
23+
'jsxA11yPlugin/no-autofocus': 'off',
24+
'jsxA11yPlugin/anchor-ambiguous-text': [
25+
'error',
26+
{
27+
words: ['this', 'more', 'read here', 'read more'],
28+
},
29+
],
30+
'jsxA11yPlugin/no-interactive-element-to-noninteractive-role': [
31+
'error',
32+
{
33+
tr: ['none', 'presentation'],
34+
td: ['cell'], // TODO: Remove once https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/pull/937#issuecomment-1638128318 is addressed.
35+
canvas: ['img'],
36+
},
37+
],
38+
// Remove once https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/pull/950 is shipped.
39+
'jsxA11yPlugin/no-noninteractive-element-to-interactive-role': [
40+
'error',
41+
{
42+
ul: ['listbox', 'menu', 'menubar', 'radiogroup', 'tablist', 'tree', 'treegrid'],
43+
ol: ['listbox', 'menu', 'menubar', 'radiogroup', 'tablist', 'tree', 'treegrid'],
44+
li: ['menuitem', 'menuitemradio', 'menuitemcheckbox', 'option', 'row', 'tab', 'treeitem'],
45+
table: ['grid'],
46+
td: ['gridcell'],
47+
fieldset: ['radiogroup', 'presentation'],
48+
},
49+
],
50+
'jsxA11yPlugin/no-redundant-roles': [
51+
'error',
52+
{
53+
nav: ['navigation'], // default in eslint-plugin-jsx-a11y
54+
tbody: ['rowgroup'],
55+
thead: ['rowgroup'],
56+
},
57+
],
58+
},
59+
}

‎lib/configs/flat/recommended.js‎

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
const globals = require('globals')
2+
const github = require('../../plugin')
3+
const prettierPlugin = require('eslint-plugin-prettier')
4+
const eslintComments = require('eslint-plugin-eslint-comments')
5+
const importPlugin = require('eslint-plugin-import')
6+
const filenames = require('eslint-plugin-filenames')
7+
const i18nTextPlugin = require('eslint-plugin-i18n-text')
8+
const noOnlyTestsPlugin = require('eslint-plugin-no-only-tests')
9+
const {fixupPluginRules} = require('@eslint/compat')
10+
11+
module.exports = {
12+
languageOptions: {
13+
ecmaVersion: 6,
14+
sourceType: 'module',
15+
globals: {
16+
...globals.es6,
17+
},
18+
},
19+
plugins: {
20+
filenames: fixupPluginRules(filenames),
21+
prettierPlugin,
22+
eslintComments,
23+
importPlugin,
24+
i18nTextPlugin: fixupPluginRules(i18nTextPlugin),
25+
noOnlyTestsPlugin,
26+
github,
27+
},
28+
rules: {
29+
'constructor-super': 'error',
30+
'eslintComments/disable-enable-pair': 'off',
31+
'eslintComments/no-aggregating-enable': 'off',
32+
'eslintComments/no-duplicate-disable': 'error',
33+
'eslintComments/no-unlimited-disable': 'error',
34+
'eslintComments/no-unused-disable': 'error',
35+
'eslintComments/no-unused-enable': 'error',
36+
'eslintComments/no-use': ['error', {allow: ['eslint', 'eslint-disable-next-line', 'eslint-env', 'globals']}],
37+
'filenames/match-regex': ['error', '^[a-z0-9-]+(.[a-z0-9-]+)?$'],
38+
'func-style': ['error', 'declaration', {allowArrowFunctions: true}],
39+
'github/array-foreach': 'error',
40+
'github/no-implicit-buggy-globals': 'error',
41+
'github/no-then': 'error',
42+
'github/no-dynamic-script-tag': 'error',
43+
'i18nTextPlugin/no-en': ['error'],
44+
'importPlugin/default': 'error',
45+
'importPlugin/export': 'error',
46+
'importPlugin/extensions': 'error',
47+
'importPlugin/first': 'error',
48+
'importPlugin/named': 'error',
49+
'importPlugin/namespace': 'error',
50+
'importPlugin/no-absolute-path': 'error',
51+
'importPlugin/no-amd': 'error',
52+
'importPlugin/no-anonymous-default-export': [
53+
'error',
54+
{
55+
allowAnonymousClass: false,
56+
allowAnonymousFunction: false,
57+
allowArray: true,
58+
allowArrowFunction: false,
59+
allowLiteral: true,
60+
allowObject: true,
61+
},
62+
],
63+
'importPlugin/no-commonjs': 'error',
64+
'importPlugin/no-deprecated': 'error',
65+
'importPlugin/no-duplicates': 'error',
66+
'importPlugin/no-dynamic-require': 'error',
67+
'importPlugin/no-extraneous-dependencies': [0, {devDependencies: false}],
68+
'importPlugin/no-mutable-exports': 'error',
69+
'importPlugin/no-named-as-default': 'error',
70+
'importPlugin/no-named-as-default-member': 'error',
71+
'importPlugin/no-namespace': 'error',
72+
'importPlugin/no-unresolved': 'error',
73+
'importPlugin/no-webpack-loader-syntax': 'error',
74+
'no-case-declarations': 'error',
75+
'no-class-assign': 'error',
76+
'no-compare-neg-zero': 'error',
77+
'no-cond-assign': 'error',
78+
'no-console': 'error',
79+
'no-const-assign': 'error',
80+
'no-constant-condition': 'error',
81+
'no-control-regex': 'error',
82+
'no-debugger': 'error',
83+
'no-delete-var': 'error',
84+
'no-dupe-args': 'error',
85+
'no-dupe-class-members': 'error',
86+
'no-dupe-keys': 'error',
87+
'no-duplicate-case': 'error',
88+
'no-empty': 'error',
89+
'no-empty-character-class': 'error',
90+
'no-empty-pattern': 'error',
91+
'no-ex-assign': 'error',
92+
'no-extra-boolean-cast': 'error',
93+
'no-fallthrough': 'error',
94+
'no-func-assign': 'error',
95+
'no-global-assign': 'error',
96+
'no-implicit-globals': 'error',
97+
'no-implied-eval': 'error',
98+
'no-inner-declarations': 'error',
99+
'no-invalid-regexp': 'error',
100+
'no-invalid-this': 'error',
101+
'no-irregular-whitespace': 'error',
102+
'no-new-symbol': 'error',
103+
'no-obj-calls': 'error',
104+
'no-octal': 'error',
105+
'noOnlyTestsPlugin/no-only-tests': [
106+
'error',
107+
{
108+
block: ['describe', 'it', 'context', 'test', 'tape', 'fixture', 'serial', 'suite'],
109+
},
110+
],
111+
'no-redeclare': 'error',
112+
'no-regex-spaces': 'error',
113+
'no-return-assign': 'error',
114+
'no-self-assign': 'error',
115+
'no-sequences': ['error'],
116+
'no-shadow': 'error',
117+
'no-sparse-arrays': 'error',
118+
'no-this-before-super': 'error',
119+
'no-throw-literal': 'error',
120+
'no-undef': 'error',
121+
'no-unreachable': 'error',
122+
'no-unsafe-finally': 'error',
123+
'no-unsafe-negation': 'error',
124+
'no-unused-labels': 'error',
125+
'no-unused-vars': 'error',
126+
'no-useless-concat': 'error',
127+
'no-useless-escape': 'error',
128+
'no-var': 'error',
129+
'object-shorthand': ['error', 'always', {avoidQuotes: true}],
130+
'one-var': ['error', 'never'],
131+
'prefer-const': 'error',
132+
'prefer-promise-reject-errors': 'error',
133+
'prefer-rest-params': 'error',
134+
'prefer-spread': 'error',
135+
'prefer-template': 'error',
136+
'prettierPlugin/prettier': 'error',
137+
'require-yield': 'error',
138+
'use-isnan': 'error',
139+
'valid-typeof': 'error',
140+
camelcase: ['error', {properties: 'always'}],
141+
eqeqeq: ['error', 'smart'],
142+
},
143+
settings: {
144+
'importPlugin/resolver': {
145+
node: {
146+
extensions: ['.js', '.ts'],
147+
},
148+
},
149+
},
150+
151+
}

‎lib/configs/flat/typescript.js‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const { FlatCompat } = require('@eslint/eslintrc')
2+
3+
const compat = new FlatCompat({ resolvePluginsRelativeTo: __dirname })
4+
5+
const typescriptModule = {
6+
...compat.config({
7+
extends: ['plugin:@typescript-eslint/recommended', 'prettier', 'plugin:escompat/typescript-2020'],
8+
plugins: ['@typescript-eslint', 'escompat'],
9+
parser: '@typescript-eslint/parser',
10+
rules: {
11+
camelcase: 'off',
12+
'no-unused-vars': 'off',
13+
'no-shadow': 'off',
14+
'no-invalid-this': 'off',
15+
'@typescript-eslint/no-invalid-this': ['error'],
16+
'@typescript-eslint/no-shadow': ['error'],
17+
'@typescript-eslint/interface-name-prefix': 'off',
18+
'@typescript-eslint/array-type': ['error', {default: 'array-simple'}],
19+
'@typescript-eslint/no-use-before-define': 'off',
20+
'@typescript-eslint/explicit-member-accessibility': 'off',
21+
'@typescript-eslint/explicit-function-return-type': 'off',
22+
'@typescript-eslint/no-non-null-assertion': 'off',
23+
'@typescript-eslint/no-unused-vars': 'error',
24+
'@typescript-eslint/explicit-module-boundary-types': 'off',
25+
},
26+
})
27+
}
28+
// Need to merge to get the appropriate structure for the config
29+
const mergedConfig = {}
30+
31+
Object.values(typescriptModule).forEach(obj => {
32+
Object.assign(mergedConfig, {
33+
languageOptions: { ...mergedConfig.languageOptions, ...obj.languageOptions },
34+
plugins: { ...mergedConfig.plugins, ...obj.plugins },
35+
rules: { ...mergedConfig.rules, ...obj.rules },
36+
files: [...(mergedConfig.files || []), ...(obj.files || [])]
37+
})
38+
})
39+
40+
module.exports = mergedConfig

‎lib/index.js‎

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,19 @@
1+
const github = require('./plugin')
2+
13
module.exports = {
2-
rules: {
3-
'a11y-no-visually-hidden-interactive-element': require('./rules/a11y-no-visually-hidden-interactive-element'),
4-
'a11y-no-generic-link-text': require('./rules/a11y-no-generic-link-text'),
5-
'a11y-no-title-attribute': require('./rules/a11y-no-title-attribute'),
6-
'a11y-aria-label-is-well-formatted': require('./rules/a11y-aria-label-is-well-formatted'),
7-
'a11y-role-supports-aria-props': require('./rules/a11y-role-supports-aria-props'),
8-
'a11y-svg-has-accessible-name': require('./rules/a11y-svg-has-accessible-name'),
9-
'array-foreach': require('./rules/array-foreach'),
10-
'async-currenttarget': require('./rules/async-currenttarget'),
11-
'async-preventdefault': require('./rules/async-preventdefault'),
12-
'authenticity-token': require('./rules/authenticity-token'),
13-
'get-attribute': require('./rules/get-attribute'),
14-
'js-class-name': require('./rules/js-class-name'),
15-
'no-blur': require('./rules/no-blur'),
16-
'no-d-none': require('./rules/no-d-none'),
17-
'no-dataset': require('./rules/no-dataset'),
18-
'no-implicit-buggy-globals': require('./rules/no-implicit-buggy-globals'),
19-
'no-inner-html': require('./rules/no-inner-html'),
20-
'no-innerText': require('./rules/no-innerText'),
21-
'no-dynamic-script-tag': require('./rules/no-dynamic-script-tag'),
22-
'no-then': require('./rules/no-then'),
23-
'no-useless-passive': require('./rules/no-useless-passive'),
24-
'prefer-observers': require('./rules/prefer-observers'),
25-
'require-passive-events': require('./rules/require-passive-events'),
26-
'unescaped-html-literal': require('./rules/unescaped-html-literal'),
27-
},
4+
rules: github.rules,
285
configs: {
296
browser: require('./configs/browser'),
307
internal: require('./configs/internal'),
318
recommended: require('./configs/recommended'),
329
typescript: require('./configs/typescript'),
3310
react: require('./configs/react'),
3411
},
12+
flatConfigs: {
13+
browser: require('./configs/flat/browser'),
14+
internal: require('./configs/flat/internal'),
15+
recommended: require('./configs/flat/recommended'),
16+
typescript: require('./configs/flat/typescript'),
17+
react: require('./configs/flat/react'),
18+
}
3519
}

‎lib/plugin.js‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const {name, version} = require('../package.json')
2+
3+
module.exports = {
4+
meta: {name, version},
5+
rules: {
6+
'a11y-no-visually-hidden-interactive-element': require('./rules/a11y-no-visually-hidden-interactive-element'),
7+
'a11y-no-generic-link-text': require('./rules/a11y-no-generic-link-text'),
8+
'a11y-no-title-attribute': require('./rules/a11y-no-title-attribute'),
9+
'a11y-aria-label-is-well-formatted': require('./rules/a11y-aria-label-is-well-formatted'),
10+
'a11y-role-supports-aria-props': require('./rules/a11y-role-supports-aria-props'),
11+
'a11y-svg-has-accessible-name': require('./rules/a11y-svg-has-accessible-name'),
12+
'array-foreach': require('./rules/array-foreach'),
13+
'async-currenttarget': require('./rules/async-currenttarget'),
14+
'async-preventdefault': require('./rules/async-preventdefault'),
15+
'authenticity-token': require('./rules/authenticity-token'),
16+
'get-attribute': require('./rules/get-attribute'),
17+
'js-class-name': require('./rules/js-class-name'),
18+
'no-blur': require('./rules/no-blur'),
19+
'no-d-none': require('./rules/no-d-none'),
20+
'no-dataset': require('./rules/no-dataset'),
21+
'no-implicit-buggy-globals': require('./rules/no-implicit-buggy-globals'),
22+
'no-inner-html': require('./rules/no-inner-html'),
23+
'no-innerText': require('./rules/no-innerText'),
24+
'no-dynamic-script-tag': require('./rules/no-dynamic-script-tag'),
25+
'no-then': require('./rules/no-then'),
26+
'no-useless-passive': require('./rules/no-useless-passive'),
27+
'prefer-observers': require('./rules/prefer-observers'),
28+
'require-passive-events': require('./rules/require-passive-events'),
29+
'unescaped-html-literal': require('./rules/unescaped-html-literal'),
30+
}
31+
}

‎lib/rules/no-implicit-buggy-globals.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ module.exports = {
99
},
1010

1111
create(context) {
12+
const sourceCode = context.sourceCode ?? context.getSourceCode()
1213
return {
13-
Program() {
14-
const scope = context.getScope()
14+
Program(node) {
15+
const scope = sourceCode.getScope(node) ? sourceCode.getScope(node) : context.getScope()
1516

1617
for (const variable of scope.variables) {
1718
if (variable.writeable) {

0 commit comments

Comments
 (0)