Skip to content

Commit

Permalink
feat!: support ESLint 9
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisIsManta committed Jun 22, 2024
1 parent da8e793 commit 2dfc622
Show file tree
Hide file tree
Showing 7 changed files with 226 additions and 253 deletions.
42 changes: 35 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ npm install --save-dev eslint-plugin-local

## Usage

The JavaScript file named _.eslint-plugin-local.js_ or _.eslint-plugin-local/index.js_ or use _.cjs_ file extension must be created at the root of your repository, which the file has the content of an [ESLint plugin](https://eslint.org/docs/latest/extend/plugins). For example:
The JavaScript file named _eslint.local.js_ or _eslint-plugin-local.js_ or _.eslint-plugin-local/index.js_ must be created at the root of your repository, which the file has the content of an [ESLint plugin](https://eslint.org/docs/latest/extend/plugins). The extension _.cjs_ can be used in place of _.js_ in case ES module is not supported. For example:

```js
module.exports = {
Expand Down Expand Up @@ -39,13 +39,41 @@ module.exports = {
}
```

Then apply the plugin to your _.eslintrc_ file:
Then add the plugin to your _eslint.config.js_ file:

```yml
plugins:
- local
rules:
- local/sample: error
```js
const local = require('eslint-plugin-local')

module.exports = [{
plugins: {
local
},
rules: {
'local/sample': 'error'
}
}]
```

Additionally, this package provides `eslint-plugin-local test` command out of the box, which it scans for `tests: { valid: [], invalid: [] }` field in each rule and runs [`RuleTester`](https://eslint.org/docs/latest/extend/custom-rules#rule-unit-tests) internally.

To make it easy to debug your test cases, wrap one or more test objects inside the global `only()` function. Given the example below, **only the first test case and every invalid case** will be run.

```js
module.exports = {
rules: {
sample: {
tests: {
valid: [
only({
code: 'var foo = 1',
}),
{
code: 'var foo = 2',
}
],
invalid: only([...]),
}
}
}
}
```
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ function findRulePath(workPath) {

const item = fs.readdirSync(workPath, { withFileTypes: true })
.find(item =>
item.isFile() && /^\.eslint-plugin-local\.c?js$/.test(item.name) ||
item.isFile() && (
/^\.eslint.local\.c?js$/.test(item.name) ||
/^\.eslint-plugin-local\.c?js$/.test(item.name)
) ||
item.isDirectory() && item.name === '.eslint-plugin-local'
)

Expand Down
4 changes: 4 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ afterEach(() => {
jest.resetModules()

for (const item of [
'.eslint.local.js',
'.eslint.local.cjs',
'.eslint-plugin-local.js',
'.eslint-plugin-local.cjs',
'.eslint-plugin-local',
Expand Down Expand Up @@ -46,6 +48,8 @@ it('exports meta', () => {
})

it.each([
['.eslint.local.js'],
['.eslint.local.cjs'],
['.eslint-plugin-local.js'],
['.eslint-plugin-local.cjs'],
])('exports "%s"', (item) => {
Expand Down
Loading

0 comments on commit 2dfc622

Please sign in to comment.