Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
npm install --save-dev eslint eslint-plugin-github
```

`eslint-plugin-github` supports ESLint 9 and 10.

## Setup

### Legacy Configuration (`.eslintrc`)

Legacy `.eslintrc` configuration is supported with ESLint 9. ESLint 10 removes `.eslintrc` support, so use flat config when upgrading to ESLint 10.

Add `github` to your list of plugins in your ESLint config.

JSON ESLint config example:
Expand All @@ -30,6 +34,12 @@ JSON ESLint config example:
}
```

If you extend `plugin:github/react` from a legacy `.eslintrc` config, install the legacy JSX accessibility plugin alongside this package:

```sh
npm install --save-dev eslint-plugin-jsx-a11y
```

### Flat Configuration (`eslint-config.js`)

Import the `eslint-plugin-github`, and extend any of the configurations using `getFlatConfigs()` as needed like so:
Expand Down Expand Up @@ -127,7 +137,7 @@ This config will be interpreted in the following way:
| [async-currenttarget](docs/rules/async-currenttarget.md) | disallow `event.currentTarget` calls inside of async functions | 🔍 | | |
| [async-preventdefault](docs/rules/async-preventdefault.md) | disallow `event.preventDefault` calls inside of async functions | 🔍 | | |
| [authenticity-token](docs/rules/authenticity-token.md) | disallow usage of CSRF tokens in JavaScript | 🔐 | | |
| [filenames-match-regex](docs/rules/filenames-match-regex.md) | require filenames to match a regex naming convention | | | |
| [filenames-match-regex](docs/rules/filenames-match-regex.md) | require filenames to match a regex naming convention | | | |
| [get-attribute](docs/rules/get-attribute.md) | disallow wrong usage of attribute names | 🔍 | 🔧 | |
| [js-class-name](docs/rules/js-class-name.md) | enforce a naming convention for js- prefixed classes | 🔐 | | |
| [no-blur](docs/rules/no-blur.md) | disallow usage of `Element.prototype.blur()` | 🔍 | | |
Expand Down
2 changes: 2 additions & 0 deletions docs/rules/filenames-match-regex.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Require filenames to match a regex naming convention (`github/filenames-match-regex`)

💼 This rule is enabled in the ✅ `recommended` config.

<!-- end auto-generated rule header -->

## Rule Details
Expand Down
4 changes: 2 additions & 2 deletions lib/configs/flat/react.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import github from '../../plugin.js'
import jsxA11yPlugin from 'eslint-plugin-jsx-a11y'
import jsxA11yPlugin, {jsxA11yRecommendedRules} from '../../utils/jsx-a11y.js'
import {fixupPluginRules} from '@eslint/compat'

export default {
...jsxA11yPlugin.flatConfigs.recommended,
languageOptions: {
sourceType: 'module',
parserOptions: {
Expand All @@ -14,6 +13,7 @@ export default {
},
plugins: {github: fixupPluginRules(github), 'jsx-a11y': jsxA11yPlugin},
rules: {
...jsxA11yRecommendedRules,
'jsx-a11y/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
'github/a11y-aria-label-is-well-formatted': 'error',
'github/a11y-no-visually-hidden-interactive-element': 'error',
Expand Down
1 change: 0 additions & 1 deletion lib/configs/flat/typescript.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line import/no-unresolved
import tseslint from 'typescript-eslint'
import escompat from 'eslint-plugin-escompat'

Expand Down
4 changes: 3 additions & 1 deletion lib/configs/react.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {jsxA11yRecommendedRules} from '../utils/jsx-a11y.js'

export default {
parserOptions: {
sourceType: 'module',
Expand All @@ -6,8 +8,8 @@ export default {
},
},
plugins: ['github', 'jsx-a11y'],
extends: ['plugin:jsx-a11y/recommended'],
rules: {
...jsxA11yRecommendedRules,
'jsx-a11y/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
'github/a11y-aria-label-is-well-formatted': 'error',
'github/a11y-no-visually-hidden-interactive-element': 'error',
Expand Down
5 changes: 2 additions & 3 deletions lib/configs/recommended.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
env: {
es6: true,
},
plugins: ['github', 'prettier', 'eslint-comments', 'import', 'filenames', 'i18n-text', 'no-only-tests'],
plugins: ['github', 'prettier', 'eslint-comments', 'import', 'no-only-tests'],
rules: {
'constructor-super': 'error',
'eslint-comments/disable-enable-pair': 'off',
Expand All @@ -18,13 +18,12 @@ export default {
'eslint-comments/no-unused-disable': 'error',
'eslint-comments/no-unused-enable': 'error',
'eslint-comments/no-use': ['error', {allow: ['eslint', 'eslint-disable-next-line', 'eslint-env', 'globals']}],
'filenames/match-regex': ['error', '^[a-z0-9-]+(.[a-z0-9-]+)?$'],
'github/filenames-match-regex': 'error',
'func-style': ['error', 'declaration', {allowArrowFunctions: true}],
'github/array-foreach': 'error',
'github/no-implicit-buggy-globals': 'error',
'github/no-then': 'error',
'github/no-dynamic-script-tag': 'error',
'i18n-text/no-en': ['error'],
'import/default': 'error',
'import/export': 'error',
'import/extensions': 'error',
Expand Down
22 changes: 13 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ const getFlatConfig = () => ({
react: flatReactConfig,
})

export const rules = github.rules
export const configs = {
browser: browserConfig,
internal: internalConfig,
recommended: recommendedConfig,
typescript: typescriptConfig,
react: reactConfig,
}
export const getFlatConfigs = getFlatConfig

export default {
rules: github.rules,
configs: {
browser: browserConfig,
internal: internalConfig,
recommended: recommendedConfig,
typescript: typescriptConfig,
react: reactConfig,
},
getFlatConfigs: getFlatConfig,
rules,
configs,
getFlatConfigs,
}
10 changes: 10 additions & 0 deletions lib/utils/jsx-a11y.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import jsxA11yPlugin from 'eslint-plugin-jsx-a11y'

export const jsxA11yRecommendedRules = Object.fromEntries(
Object.entries(jsxA11yPlugin.configs.recommended.rules).map(([ruleName, ruleConfig]) => [
ruleName.replace(/^jsx-a11y-x\//, 'jsx-a11y/'),
ruleConfig,
]),
)

export default jsxA11yPlugin
Loading