Skip to content

Commit

Permalink
feat: add plugin to prevent use of lookbehind in regexp
Browse files Browse the repository at this point in the history
Not so old versions of Safari do not support it.
  • Loading branch information
targos committed Feb 9, 2024
1 parent e6d5a90 commit 1a5dc32
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
13 changes: 11 additions & 2 deletions base.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
ecmaVersion: '2022',
sourceType: 'module',
},
plugins: ['import'],
plugins: ['import', 'no-lookahead-lookbehind-regexp'],
reportUnusedDisableDirectives: true,
overrides: [
{
Expand Down Expand Up @@ -40,7 +40,7 @@ module.exports = {
],
rules: {
// https://eslint.org/docs/latest/rules/
// Last rules review: v8.55.0
// Last rules review: v8.56.0

// https://github.com/import-js/eslint-plugin-import#rules
// Last rules review: v2.26.0
Expand Down Expand Up @@ -307,5 +307,14 @@ module.exports = {
],
'import/no-named-default': 'error',
//#endregion

//#region No lookbehind plugin (https://github.com/JonasBa/eslint-plugin-no-lookahead-lookbehind-regexp)
'no-lookahead-lookbehind-regexp/no-lookahead-lookbehind-regexp': [
'error',
'no-lookbehind',
'no-negative-lookbehind',
{ browserslist: false },
],
//#endregion
},
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@
"url": "https://github.com/cheminfo/eslint-config/issues"
},
"homepage": "https://github.com/cheminfo/eslint-config#readme",
"dependencies": {},
"peerDependencies": {
"eslint": "^8.56.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsdoc": "^48.0.6",
"eslint-plugin-no-lookahead-lookbehind-regexp": "0.3.0",
"eslint-plugin-unicorn": "^51.0.1"
},
"devDependencies": {
"eslint": "8.56.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-jsdoc": "48.0.6",
"eslint-plugin-no-lookahead-lookbehind-regexp": "0.3.0",
"eslint-plugin-unicorn": "51.0.1",
"prettier": "^3.2.5"
}
Expand Down
2 changes: 2 additions & 0 deletions test/not-ok.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ function A() {
this.x = 1;
}

useIt(/test(?<=text)/)

useIt(['a', 'b', 'c'].reduce((prev, curr) => {
prev[curr] = true;
return prev;
Expand Down
1 change: 1 addition & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ eslint
.sort();
assert.deepStrictEqual(errors, [
'no-console',
'no-lookahead-lookbehind-regexp/no-lookahead-lookbehind-regexp',
'no-redeclare',
'no-unused-vars',
'no-unused-vars',
Expand Down

0 comments on commit 1a5dc32

Please sign in to comment.