Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5522392

Browse files
authored
Merge branch 'main' into main
2 parents 28db2cc + 1e930ed commit 5522392

37 files changed

+5092
-4644
lines changed

.eslint-doc-generatorrc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = {
33
configEmoji: [
44
['browser', '🔍'],
55
['internal', '🔐'],
6-
['react', '⚛️']
6+
['react', '⚛️'],
77
],
88
ruleDocSectionInclude: ['Rule Details', 'Version'],
9-
};
9+
}

.eslintrc.js

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

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ npm install --save-dev eslint eslint-plugin-github
88

99
## Setup
1010

11+
### Legacy Configuration (`.eslintrc`)
12+
1113
Add `github` to your list of plugins in your ESLint config.
1214

1315
JSON ESLint config example:
@@ -28,6 +30,36 @@ JSON ESLint config example:
2830
}
2931
```
3032

33+
### Flat Configuration (`eslint-config.js`)
34+
35+
Import the `eslint-plugin-github`, and extend any of the configurations using `getFlatConfigs()` as needed like so:
36+
37+
```js
38+
import github from 'eslint-plugin-github'
39+
40+
export default [
41+
github.getFlatConfigs().browser,
42+
github.getFlatConfigs().recommended,
43+
github.getFlatConfigs().react,
44+
...github.getFlatConfigs().typescript,
45+
{
46+
files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
47+
ignores: ['eslint.config.mjs'],
48+
rules: {
49+
'github/array-foreach': 'error',
50+
'github/async-preventdefault': 'warn',
51+
'github/no-then': 'error',
52+
'github/no-blur': 'error',
53+
},
54+
},
55+
]
56+
```
57+
58+
> [!NOTE]
59+
> If you configured the `filenames/match-regex` rule, please note we have adapted the match regex rule into `eslint-plugin-github` as the original `eslint-filenames-plugin` is no longer maintained and needed an ESLint v9 update. Please update the name to `github/filenames-match-regex` and keep the same configuration. For e.g.:
60+
>
61+
> `'github/filenames-match-regex': ['error', '^[a-z0-9-]+(.[a-z0-9-]+)?$']`
62+
3163
The available configs are:
3264

3365
- `internal`
@@ -93,6 +125,7 @@ This config will be interpreted in the following way:
93125
| [async-currenttarget](docs/rules/async-currenttarget.md) | disallow `event.currentTarget` calls inside of async functions | 🔍 | | |
94126
| [async-preventdefault](docs/rules/async-preventdefault.md) | disallow `event.preventDefault` calls inside of async functions | 🔍 | | |
95127
| [authenticity-token](docs/rules/authenticity-token.md) | disallow usage of CSRF tokens in JavaScript | 🔐 | | |
128+
| [filenames-match-regex](docs/rules/filenames-match-regex.md) | ensure filenames match a regex naming convention | | | |
96129
| [get-attribute](docs/rules/get-attribute.md) | disallow wrong usage of attribute names | 🔍 | 🔧 | |
97130
| [js-class-name](docs/rules/js-class-name.md) | enforce a naming convention for js- prefixed classes | 🔐 | | |
98131
| [no-blur](docs/rules/no-blur.md) | disallow usage of `Element.prototype.blur()` | 🔍 | | |

docs/rules/filenames-match-regex.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Ensure filenames match a regex naming convention (`github/filenames-match-regex`)
2+
3+
<!-- end auto-generated rule header -->
4+
5+
## Rule Details
6+
7+
Rule to ensure that filenames match a convention, with a default of camelCase for ESLint v9+.
8+
9+
👎 Examples of **incorrect** filename for this default rule:
10+
11+
`file-name.js`
12+
13+
👍 Examples of **correct** code for this rule:
14+
15+
`fileName.js`
16+
17+
## Options
18+
19+
regex - Regex to match the filename structure. Defaults to camelCase.
20+
21+
22+
```json
23+
{
24+
"filenames-match-regex": [
25+
"error",
26+
"^[a-z0-9-]+(.[a-z0-9-]+)?$"
27+
]
28+
}
29+
```
30+
31+
## Version
32+
33+
4.3.2

eslint.config.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const globals = require('globals')
2+
const eslintPlugin = require('eslint-plugin-eslint-plugin')
3+
const importPlugin = require('eslint-plugin-import')
4+
const i18nTextPlugin = require('eslint-plugin-i18n-text')
5+
const recommendedGitHub = require('./lib/configs/flat/recommended')
6+
const {fixupPluginRules} = require('@eslint/compat')
7+
8+
module.exports = [
9+
recommendedGitHub,
10+
eslintPlugin.configs['flat/all'],
11+
{
12+
ignores: ['test-examples/**'],
13+
},
14+
{
15+
languageOptions: {
16+
ecmaVersion: 13,
17+
globals: {
18+
...globals.es6,
19+
...globals.node,
20+
},
21+
},
22+
plugins: {
23+
eslintPlugin,
24+
importPlugin,
25+
'i18n-text': fixupPluginRules(i18nTextPlugin),
26+
},
27+
rules: {
28+
'importPlugin/extensions': 'off',
29+
'importPlugin/no-commonjs': 'off',
30+
'github/filenames-match-regex': 'off',
31+
'i18n-text/no-en': 'off',
32+
'eslint-plugin/prefer-placeholders': 'off',
33+
'eslint-plugin/test-case-shorthand-strings': 'off',
34+
'eslint-plugin/require-meta-docs-url': 'off',
35+
},
36+
},
37+
]

lib/configs/flat/browser.js

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

lib/configs/flat/internal.js

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

lib/configs/flat/react.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const github = require('../../plugin')
2+
const jsxA11yPlugin = require('eslint-plugin-jsx-a11y')
3+
const {fixupPluginRules} = require('@eslint/compat')
4+
5+
module.exports = {
6+
...jsxA11yPlugin.flatConfigs.recommended,
7+
languageOptions: {
8+
sourceType: 'module',
9+
parserOptions: {
10+
ecmaFeatures: {
11+
jsx: true,
12+
},
13+
},
14+
},
15+
plugins: {github: fixupPluginRules(github), jsxA11yPlugin},
16+
rules: {
17+
'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
18+
'github/a11y-aria-label-is-well-formatted': 'error',
19+
'github/a11y-no-visually-hidden-interactive-element': 'error',
20+
'github/a11y-no-title-attribute': 'error',
21+
'github/a11y-svg-has-accessible-name': 'error',
22+
'github/a11y-role-supports-aria-props': 'error',
23+
'jsxA11yPlugin/no-aria-hidden-on-focusable': 'error',
24+
'jsxA11yPlugin/no-autofocus': 'off',
25+
'jsxA11yPlugin/anchor-ambiguous-text': [
26+
'error',
27+
{
28+
words: ['this', 'more', 'read here', 'read more'],
29+
},
30+
],
31+
'jsxA11yPlugin/no-interactive-element-to-noninteractive-role': [
32+
'error',
33+
{
34+
tr: ['none', 'presentation'],
35+
td: ['cell'], // TODO: Remove once https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/pull/937#issuecomment-1638128318 is addressed.
36+
canvas: ['img'],
37+
},
38+
],
39+
'jsxA11yPlugin/no-redundant-roles': [
40+
'error',
41+
{
42+
nav: ['navigation'], // default in eslint-plugin-jsx-a11y
43+
tbody: ['rowgroup'],
44+
thead: ['rowgroup'],
45+
},
46+
],
47+
},
48+
}

0 commit comments

Comments
 (0)