Skip to content

Commit ba44074

Browse files
committed
## 1.9.0 - April 2022
* Fixes an issue with remaining source calculation and minified files.
1 parent 01a4ae7 commit ba44074

File tree

7 files changed

+261
-34
lines changed

7 files changed

+261
-34
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# ESLint Plugin Regex Change Log
22

3-
## 1.9.0 - March 2022
3+
## 1.9.0 - April 2022
44

55
* Closes #15, Allowing mixing different error level.
66
* This bug required that the same rule can be defined with different error levels, that is not possible at the moment on eslint. Error level is not available at plugin level (as indicate by ESLint official documentation: "Keep in mind that the error level is not part of context.options, as the error level cannot be known or modified from inside a rule"). So I came up a different approach, which not only **allows to use "the same" rule with different error levels**, but also **allows Mixing custom set of regex rules**, this is useful for creating package/libraries/plugins with your own set of rules and sharing it with others.
7+
* Fixes an issue with remaining source calculation and minified files.
78
* Improves project configuration.
89
* Now uses [`any-eslint-parser`](https://www.npmjs.com/package/any-eslint-parser)
910
* Improves documentation.

lib/rules/invalid-regex-rule.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,21 @@ const { formatReportMessage } = require('../utils/report-utils.js')
55
const { shouldCheck } = require('../utils/check-utils.js')
66

77
function checkRegexInLines(sourceLines, nextLine, nextChar, regex) {
8-
if (nextLine !== -1) {
9-
regex.test('')
10-
let foundDetail = regex.exec(sourceLines[nextLine].slice(nextChar))
11-
if (foundDetail) {
12-
return {
13-
foundColumn: nextChar + foundDetail.index,
14-
nextLine,
15-
nextChar: nextChar + regex.lastIndex
16-
}
8+
regex.test('')
9+
let foundDetail = regex.exec(sourceLines[nextLine].slice(nextChar))
10+
if (foundDetail) {
11+
return {
12+
foundColumn: nextChar + foundDetail.index,
13+
nextLine,
14+
nextChar: nextChar + regex.lastIndex
1715
}
18-
nextLine = sourceLines.findIndex((lin, index) => index > nextLine && (foundDetail = regex.exec(lin)))
19-
if (foundDetail) {
20-
return {
21-
foundColumn: foundDetail.index,
22-
nextLine,
23-
nextChar: regex.lastIndex
24-
}
16+
}
17+
nextLine = sourceLines.findIndex((lin, index) => index > nextLine && (foundDetail = regex.exec(lin)))
18+
if (foundDetail) {
19+
return {
20+
foundColumn: foundDetail.index,
21+
nextLine,
22+
nextChar: regex.lastIndex
2523
}
2624
}
2725
return {
@@ -58,9 +56,9 @@ function checkRegex(source, sourceLines, nextLine, nextChar, rootChar, pattern,
5856
if (source.length !== 0) {
5957
const sourceDetail = checkRegexInSource(source, pattern.regex)
6058
if (sourceDetail.patternIndex !== -1) {
61-
const remainingSourceStart = sourceDetail.patternIndex + 1
59+
const remainingSourceStart = sourceDetail.patternIndex + sourceDetail.$[0].length
6260
const remainingSource = source.slice(remainingSourceStart)
63-
let foundDetail = checkRegexInLines(sourceLines, nextLine, nextChar, pattern.regex)
61+
const foundDetail = checkRegexInLines(sourceLines, nextLine, nextChar, pattern.regex)
6462
if (foundDetail.nextLine !== -1) {
6563
report({
6664
loc: {
@@ -79,16 +77,18 @@ function checkRegex(source, sourceLines, nextLine, nextChar, rootChar, pattern,
7977
pattern, replace, report, originalSource)
8078
}
8179
else {
82-
report({
83-
loc: { start: foundStart(originalSource, sourceDetail.patternIndex + rootChar) },
84-
message: formatReportMessage(
85-
pattern,
86-
from => `Invalid regular expression ${from} found`
87-
),
88-
fix: replace(rootChar, sourceDetail)
89-
})
90-
checkRegex(remainingSource, sourceLines, nextLine + 1, nextChar, rootChar + remainingSourceStart, pattern, replace, report,
91-
originalSource)
80+
if (++nextLine < sourceLines.length) {
81+
report({
82+
loc: { start: foundStart(originalSource, sourceDetail.patternIndex + rootChar) },
83+
message: formatReportMessage(
84+
pattern,
85+
from => `Invalid regular expression ${from} found`
86+
),
87+
fix: replace(rootChar, sourceDetail)
88+
})
89+
checkRegex(remainingSource, sourceLines, nextLine, nextChar, rootChar + remainingSourceStart, pattern, replace, report,
90+
originalSource)
91+
}
9292
}
9393
}
9494
}

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@
6464
],
6565
"scripts": {
6666
"lint": "npm run lint.common && npm run lint.source",
67-
"lint.common": "echo ==== Lint Common ==== && eslint --config .eslintrc-any.json \"**/[\\.a-zA-Z]*.+(js|jsx|ts|tsx|json|yml|xml|sh|txt|md|svg|properties|gradle|java|cpp|c|html|css|groovy)\" \"**/.+(|gitignore|npmignore)\" --no-eslintrc --ignore-pattern \"build\"",
68-
"lint.source": "echo ==== Lint Source Code ==== && eslint --color \"**/*.js\"",
69-
"test.only": "node tests/tests.js && node tests/lib/rules/e2e-tests.js ",
67+
"lint.common": "echo ==== Lint Common ==== && eslint --config .eslintrc-any.json \"**/[\\.a-zA-Z]*.+(js|jsx|ts|tsx|json|yml|xml|sh|txt|md|svg|properties|gradle|java|cpp|c|html|css|groovy)\" \"**/.+(|gitignore|npmignore)\" --no-eslintrc --ignore-pattern \"build\" --ignore-pattern \"tests/lib/rules/case-*.js\"",
68+
"lint.source": "echo ==== Lint Source Code ==== && eslint --color \"**/*.js\" --ignore-pattern \"tests/lib/rules/case-*.js\"",
69+
"test.only": "node tests/tests.js && node tests/lib/rules/e2e-tests.js",
7070
"test": "echo ==== Test With Coverage ==== && mkdir -p build && nyc npm run test.only",
7171
"prepack": "echo ==== Build Package ====",
7272
"check": "npm install && npm run lint && npm test && mkdir -p build && cd build && npm pack ../",
@@ -81,7 +81,7 @@
8181
},
8282
"devDependencies": {
8383
"any-eslint-parser": "^1.0.1",
84-
"eslint": "^8.12.0",
84+
"eslint": "^8.13.0",
8585
"eslint-plugin-base-style-config": "^2.8.1",
8686
"eslint-plugin-import": "^2.25.4",
8787
"jasmine": "^4.0.2",

tests/lib/rules/.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"rules": {
33
"global-require": "off",
44
"no-console": "off",
5-
"no-throw-literal": "off"
5+
"no-throw-literal": "off",
6+
"max-lines": "off"
67
}
78
}

tests/lib/rules/case-001-minified.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/lib/rules/case-002-minified.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)