Skip to content

Commit

Permalink
chore: readme
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasBa committed Nov 29, 2021
1 parent d7c7423 commit c9eb282
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
eslint-plugin-no-lookahead-lookbehind-regexp
==============================

Lint the use of lookahead and lookbehind regexp expression. The expression is problematic, as compiling it in an unsupported browser will throw an error.

### 1. Install

```bash
npm install --save-dev eslint-plugin-no-lookahead-lookbehind-regexp
```

### 2. Add plugin to your ESlint configuration

#### `.eslintrc.json`

```diff
{
+ "extends": ["plugin:no-lookahead-lookbehind-regexp/recommended"],
+ "env": {
+ "browser": true
+ },
}
```

### 3. Configure Browser Targets

We use [browserslist](https://github.com/browserslist/browserslist) to resolve browser support - **if no browserslist config** is found, then the use of lookahead and lookbehind regexp group will always throw an error!

### `package.json`

```diff
{
+ "browserslist": [
+ "defaults"
+ ]
}
```
1 change: 1 addition & 0 deletions src/rules/noLookaheadLookbehindRegex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const noLookaheadLookbehindRegexp: Rule.RuleModule = {
const { targets, hasConfig } = collectBrowserTargets(context.getFilename(), browsers);
const unsupportedTargets = collectUnsupportedTargets("js-regexp-lookbehind", targets);

// If there are no unsupported targets resolved from the browserlist config, then we can skip this rule
if (!unsupportedTargets.length && hasConfig) return {};

return {
Expand Down

0 comments on commit c9eb282

Please sign in to comment.