Skip to content

Continue ESLint upgrade to V9 #326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
10 changes: 10 additions & 0 deletions .changeset/sweet-tables-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'eslint-plugin-primer-react': minor
---

Add support for ESLint v9

- Adds flat config support
- Adds meta information to config object
- Backwards compatibility with v8
- Updates README with usage example for flat config
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

39 changes: 0 additions & 39 deletions .eslintrc.js

This file was deleted.

4 changes: 2 additions & 2 deletions .markdownlint-cli2.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ const options = githubMarkdownOpinions.init({
'no-hard-tabs': false,
'first-line-heading': false,
'no-space-in-emphasis': false,
'blanks-around-fences': false
'blanks-around-fences': false,
})

module.exports = {
config: options,
customRules: ['@github/markdownlint-github'],
outputFormatters: [['markdownlint-cli2-formatter-pretty', {appendLink: true}]]
outputFormatters: [['markdownlint-cli2-formatter-pretty', {appendLink: true}]],
}
54 changes: 37 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,48 @@ ESLint rules for Primer React

## Installation

1. Assuming you already have [ESLint](https://www.npmjs.com/package/eslint) and
[Primer React](https://github.com/primer/react) installed, run:
Assuming you already have [ESLint](https://www.npmjs.com/package/eslint) and [Primer React](https://github.com/primer/react) installed, run:

```shell
npm install --save-dev eslint-plugin-primer-react
```shell
npm install --save-dev eslint-plugin-primer-react

# or
# or

yarn add --dev eslint-plugin-primer-react
```
yarn add --dev eslint-plugin-primer-react
```

2. In your [ESLint configuration file](https://eslint.org/docs/user-guide/configuring/configuration-files), extend the
recommended Primer React ESLint config:
## Setup

```js
{
"extends": [
// ...
"plugin:primer-react/recommended"
]
}
```
### Flat Configuration (`eslint.config.js`)

In your [`eslint.config`](https://eslint.org/docs/user-guide/configuring/configuration-files) file, import `eslint-plugin-primer-react` and extend the recommended configuration using `getFlatConfigs()`:

```js
import pluginPrimerReact from 'eslint-plugin-primer-react'

export default [
pluginPrimerReact.getFlatConfigs().recommended,
{
rules: {
'primer-react/no-system-props': 'error',
// other custom rules...
},
},
]
```

### Legacy Configuration (`.eslintrc.js`)

In your [`.eslintrc`](https://eslint.org/docs/latest/use/configure/configuration-files-deprecated) file, extend the recommended Primer React ESLint config:

```js
{
"extends": [
// ...
"plugin:primer-react/recommended"
]
}
```

## Rules

Expand Down
48 changes: 48 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const eslintJs = require('@eslint/js')
const github = require('eslint-plugin-github')
const globals = require('globals')
const pluginJest = require('eslint-plugin-jest')

module.exports = [
github.getFlatConfigs().recommended,
eslintJs.configs.recommended,
{
languageOptions: {
parserOptions: {
ecmaVersion: 'latest',
},
globals: {
...globals.commonjs,
...globals.node,
},
},
rules: {
'import/no-commonjs': 'off',
'no-shadow': 'off',
'no-unused-vars': [
'error',
{
varsIgnorePattern: '^_',
},
],
},
ignores: ['**/dist/**', '**/node_modules/**'],
},
{
files: ['**/*.test.js'],
languageOptions: {
globals: {
...pluginJest.environments.globals.globals,
},
},
rules: {
'i18n-text/no-en': 'off',
},
},
{
files: ['.markdownlint-cli2.cjs'],
rules: {
'github/filenames-match-regex': 'off',
},
},
]
Loading