Skip to content
Open
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
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict'
module.exports = {
env: {
node: true,
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.nyc_output
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,26 @@ npm install eslint-plugin-optimize-regex --save-dev

**Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `eslint-plugin-optimize-regex` globally.

## Usage
## Usage for Eslint 9 and above

Add the following to your `eslint.config.mjs`

```js
import pluginOptimizeRegex from "eslint-plugin-optimize-regex";

/** @type {import("eslint").Linter.FlatConfig[]} */
export default [pluginOptimizeRegex.configs.recommended];
```

or the following to your `eslint.config.cjs`

```js
const pluginOptimizeRegex = require("eslint-plugin-optimize-regex").default

module.exports = [pluginOptimizeRegex.configs.recommended]
```

## Usage for Eslint 8 and below

Add `optimize-regex` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:

Expand Down Expand Up @@ -61,15 +80,15 @@ If you want the latter particular settings, you can avoid setting `plugins` and

```json
{
"extends": ["optimize-regex/recommended"]
"extends": ["optimize-regex/recommended-legacy"]
}
```

Or without the blacklist:

```json
{
"extends": ["optimize-regex/all"]
"extends": ["optimize-regex/all-legacy"]
}
```

Expand Down
4 changes: 4 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import pluginOptimizeRegex from "./lib/index.js";

/** @type {import("eslint").Linter.FlatConfig[]} */
export default [pluginOptimizeRegex.configs.recommended];
12 changes: 12 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { ESLint, Linter } from "eslint";

declare const plugin: ESLint.Plugin & {
configs: {
recommended: Linter.FlatConfig;
"recommended-legacy": Linter.Config;
all: Linter.FlatConfig;
"all-legacy": Linter.Config;
};
};

export default plugin;
94 changes: 75 additions & 19 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,83 @@
* @author Ezinwa Okpoechi <brainmaestro@outlook.com>
*/

'use strict'

module.exports = {
/**
* @type {import("eslint").ESLint.Plugin}
*/
const plugin = {
meta: {
type: 'problem',
docs: {
description: 'Optimize regex literals',
category: 'Best Practices',
recommended: true,
url: 'https://github.com/BrainMaestro/eslint-plugin-optimize-regex',
},
},
rules: {
'optimize-regex': require('./rules/optimize-regex'),
},

configs: {
recommended: {
plugins: ['optimize-regex'],
rules: {
'optimize-regex/optimize-regex': ['warn', {
'blacklist': ['charClassClassrangesMerge']
}]
}
},
all: {
plugins: ['optimize-regex'],
rules: {
'optimize-regex/optimize-regex': ['warn']
}
}
}
recommended: {},
'recommended-legacy': {},
all: {},
'all-legacy': {},
},
}

/**
* @type {import("eslint").Linter.FlatConfig}
*/
plugin.configs.recommended = {
plugins: {
'optimize-regex': plugin,
},
rules: {
'optimize-regex/optimize-regex': [
'warn',
{
blacklist: ['charClassClassrangesMerge'],
},
],
},
}

/**
* @type {import("eslint").Linter.Config}
*/
plugin.configs['recommended-legacy'] = {
plugins: ['optimize-regex'],
rules: {
'optimize-regex/optimize-regex': [
'warn',
{
blacklist: ['charClassClassrangesMerge'],
},
],
},
}

/**
* @type {import("eslint").Linter.FlatConfig}
*/
plugin.configs.all = {
plugins: {
'optimize-regex': plugin,
},
rules: {
'optimize-regex/optimize-regex': ['warn'],
},
}

/**
* @type {import("eslint").Linter.Config}
*/
plugin.configs['all-legacy'] = {
plugins: ['optimize-regex'],
rules: {
'optimize-regex/optimize-regex': ['warn'],
},
}

module.exports = plugin
module.exports.default = plugin
Loading