Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelpuyol authored Dec 2, 2024
2 parents 28db2cc + 1e930ed commit 5522392
Show file tree
Hide file tree
Showing 37 changed files with 5,092 additions and 4,644 deletions.
4 changes: 2 additions & 2 deletions .eslint-doc-generatorrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
configEmoji: [
['browser', '🔍'],
['internal', '🔐'],
['react', '⚛️']
['react', '⚛️'],
],
ruleDocSectionInclude: ['Rule Details', 'Version'],
};
}
21 changes: 0 additions & 21 deletions .eslintrc.js

This file was deleted.

33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ npm install --save-dev eslint eslint-plugin-github

## Setup

### Legacy Configuration (`.eslintrc`)

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

JSON ESLint config example:
Expand All @@ -28,6 +30,36 @@ JSON ESLint config example:
}
```

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

Import the `eslint-plugin-github`, and extend any of the configurations using `getFlatConfigs()` as needed like so:

```js
import github from 'eslint-plugin-github'

export default [
github.getFlatConfigs().browser,
github.getFlatConfigs().recommended,
github.getFlatConfigs().react,
...github.getFlatConfigs().typescript,
{
files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
ignores: ['eslint.config.mjs'],
rules: {
'github/array-foreach': 'error',
'github/async-preventdefault': 'warn',
'github/no-then': 'error',
'github/no-blur': 'error',
},
},
]
```

> [!NOTE]
> 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.:
>
> `'github/filenames-match-regex': ['error', '^[a-z0-9-]+(.[a-z0-9-]+)?$']`
The available configs are:

- `internal`
Expand Down Expand Up @@ -93,6 +125,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) | ensure filenames 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
33 changes: 33 additions & 0 deletions docs/rules/filenames-match-regex.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Ensure filenames match a regex naming convention (`github/filenames-match-regex`)

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

## Rule Details

Rule to ensure that filenames match a convention, with a default of camelCase for ESLint v9+.

👎 Examples of **incorrect** filename for this default rule:

`file-name.js`

👍 Examples of **correct** code for this rule:

`fileName.js`

## Options

regex - Regex to match the filename structure. Defaults to camelCase.


```json
{
"filenames-match-regex": [
"error",
"^[a-z0-9-]+(.[a-z0-9-]+)?$"
]
}
```

## Version

4.3.2
37 changes: 37 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const globals = require('globals')
const eslintPlugin = require('eslint-plugin-eslint-plugin')
const importPlugin = require('eslint-plugin-import')
const i18nTextPlugin = require('eslint-plugin-i18n-text')
const recommendedGitHub = require('./lib/configs/flat/recommended')
const {fixupPluginRules} = require('@eslint/compat')

module.exports = [
recommendedGitHub,
eslintPlugin.configs['flat/all'],
{
ignores: ['test-examples/**'],
},
{
languageOptions: {
ecmaVersion: 13,
globals: {
...globals.es6,
...globals.node,
},
},
plugins: {
eslintPlugin,
importPlugin,
'i18n-text': fixupPluginRules(i18nTextPlugin),
},
rules: {
'importPlugin/extensions': 'off',
'importPlugin/no-commonjs': 'off',
'github/filenames-match-regex': 'off',
'i18n-text/no-en': 'off',
'eslint-plugin/prefer-placeholders': 'off',
'eslint-plugin/test-case-shorthand-strings': 'off',
'eslint-plugin/require-meta-docs-url': 'off',
},
},
]
37 changes: 37 additions & 0 deletions lib/configs/flat/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const globals = require('globals')
const github = require('../../plugin')
const importPlugin = require('eslint-plugin-import')
const escompatPlugin = require('eslint-plugin-escompat')
const {fixupPluginRules} = require('@eslint/compat')

module.exports = {
...escompatPlugin.configs['flat/recommended'],
languageOptions: {
globals: {
...globals.browser,
},
},
plugins: {importPlugin, escompatPlugin, github: fixupPluginRules(github)},
rules: {
'escompatPlugin/no-dynamic-imports': 'off',
'github/async-currenttarget': 'error',
'github/async-preventdefault': 'error',
'github/get-attribute': 'error',
'github/no-blur': 'error',
'github/no-dataset': 'error',
'github/no-innerText': 'error',
'github/no-inner-html': 'error',
'github/unescaped-html-literal': 'error',
'github/no-useless-passive': 'error',
'github/require-passive-events': 'error',
'github/prefer-observers': 'error',
'importPlugin/no-nodejs-modules': 'error',
'no-restricted-syntax': [
'error',
{
selector: "NewExpression[callee.name='URL'][arguments.length=1]",
message: 'Please pass in `window.location.origin` as the 2nd argument to `new URL()`',
},
],
},
}
11 changes: 11 additions & 0 deletions lib/configs/flat/internal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const github = require('../../plugin')
const {fixupPluginRules} = require('@eslint/compat')

module.exports = {
plugins: {github: fixupPluginRules(github)},
rules: {
'github/authenticity-token': 'error',
'github/js-class-name': 'error',
'github/no-d-none': 'error',
},
}
48 changes: 48 additions & 0 deletions lib/configs/flat/react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const github = require('../../plugin')
const jsxA11yPlugin = require('eslint-plugin-jsx-a11y')
const {fixupPluginRules} = require('@eslint/compat')

module.exports = {
...jsxA11yPlugin.flatConfigs.recommended,
languageOptions: {
sourceType: 'module',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
plugins: {github: fixupPluginRules(github), jsxA11yPlugin},
rules: {
'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
'github/a11y-aria-label-is-well-formatted': 'error',
'github/a11y-no-visually-hidden-interactive-element': 'error',
'github/a11y-no-title-attribute': 'error',
'github/a11y-svg-has-accessible-name': 'error',
'github/a11y-role-supports-aria-props': 'error',
'jsxA11yPlugin/no-aria-hidden-on-focusable': 'error',
'jsxA11yPlugin/no-autofocus': 'off',
'jsxA11yPlugin/anchor-ambiguous-text': [
'error',
{
words: ['this', 'more', 'read here', 'read more'],
},
],
'jsxA11yPlugin/no-interactive-element-to-noninteractive-role': [
'error',
{
tr: ['none', 'presentation'],
td: ['cell'], // TODO: Remove once https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/pull/937#issuecomment-1638128318 is addressed.
canvas: ['img'],
},
],
'jsxA11yPlugin/no-redundant-roles': [
'error',
{
nav: ['navigation'], // default in eslint-plugin-jsx-a11y
tbody: ['rowgroup'],
thead: ['rowgroup'],
},
],
},
}
Loading

0 comments on commit 5522392

Please sign in to comment.