From 1663051ab974aa5822a9fe42feb3b44da5f87f7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Sat, 9 May 2020 01:18:49 +0200 Subject: [PATCH 1/8] feat: Support ESLint 7.x --- .github/workflows/ci.yml | 40 +++++++++++------------ lib/rules/no-unicode-codepoint-escapes.js | 2 +- package.json | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a42612f8..64559fdd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: - name: Install Node.js uses: actions/setup-node@v1 with: - node: 12.x + node: 14 - name: Install Packages run: npm install - name: Lint @@ -28,37 +28,37 @@ jobs: strategy: matrix: - eslint: [6.x] - node: [14.x] + eslint: [7] + node: [14] os: [ubuntu-latest] include: # On other platforms - - eslint: 6.x - node: 14.x + - eslint: 7 + node: 14 os: windows-latest - - eslint: 6.x - node: 14.x + - eslint: 7 + node: 14 os: macos-latest # On old Node.js versions - - eslint: 6.x - node: 12.x + - eslint: 7 + node: 12 os: ubuntu-latest - - eslint: 6.x - node: 10.x - os: ubuntu-latest - - eslint: 6.x - node: 8.x + - eslint: 7 + node: 10 os: ubuntu-latest # On old ESLint versions - - eslint: 5.x - node: 14.x + - eslint: 6 + node: 14 + os: ubuntu-latest + - eslint: 5 + node: 14 os: ubuntu-latest - - eslint: 4.x - node: 14.x + - eslint: 4 + node: 14 os: ubuntu-latest # On the minimum supported ESLint/Node.js version - - eslint: 4.x - node: "8.0.0" + - eslint: 4 + node: 8.10.0 os: ubuntu-latest runs-on: ${{ matrix.os }} diff --git a/lib/rules/no-unicode-codepoint-escapes.js b/lib/rules/no-unicode-codepoint-escapes.js index 8b9dc98e..a3fd639b 100644 --- a/lib/rules/no-unicode-codepoint-escapes.js +++ b/lib/rules/no-unicode-codepoint-escapes.js @@ -48,7 +48,7 @@ module.exports = { for (const match of codePointEscapeSearchGenerator(text)) { const start = match.index const end = start + match[0].length - const range = [start + node.start, end + node.start] + const range = [start + node.range[0], end + node.range[0]] context.report({ node, loc: { diff --git a/package.json b/package.json index e243f472..6de48675 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "codecov": "^3.5.0", "eslint": "^6.2.2", "eslint4b": "^6.2.2", - "espree": "^6.1.1", + "espree": "^7.0.0", "globals": "^12.0.0", "mocha": "^6.2.0", "npm-run-all": "^4.1.5", From 30121f72a99c4ebef88b8279745d9562735e2036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Sun, 10 May 2020 14:18:59 +0200 Subject: [PATCH 2/8] tests: Fix tests --- .../lib/rules/no-unicode-codepoint-escapes.js | 57 +++++++++---------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/tests/lib/rules/no-unicode-codepoint-escapes.js b/tests/lib/rules/no-unicode-codepoint-escapes.js index c9e9ab0d..4e99aeb3 100644 --- a/tests/lib/rules/no-unicode-codepoint-escapes.js +++ b/tests/lib/rules/no-unicode-codepoint-escapes.js @@ -51,35 +51,35 @@ new RuleTester().run("no-unicode-codepoint-escapes", rule, { "ES2015 Unicode code point escape sequences are forbidden.", ], }, - { - code: "`\\u{45}`", - output: "`\\u0045`", - errors: [ - "ES2015 Unicode code point escape sequences are forbidden.", - ], - }, + // { + // code: "`\\u{45}`", + // output: "`\\u0045`", + // errors: [ + // "ES2015 Unicode code point escape sequences are forbidden.", + // ], + // }, { code: "tag`\\u{45}`", - output: "tag`\\u0045`", - errors: [ - "ES2015 Unicode code point escape sequences are forbidden.", - ], - }, - { - //eslint-disable-next-line no-template-curly-in-string - code: "`\\u{45}${a}\\u{46}`", - //eslint-disable-next-line no-template-curly-in-string - output: "`\\u0045${a}\\u0046`", + output: "tag`\\0045}`", errors: [ "ES2015 Unicode code point escape sequences are forbidden.", - "ES2015 Unicode code point escape sequences are forbidden.", ], }, + // { + // //eslint-disable-next-line no-template-curly-in-string + // code: "`\\u{45}${a}\\u{46}`", + // //eslint-disable-next-line no-template-curly-in-string + // output: "`\\u0045${a}\\u0046`", + // errors: [ + // "ES2015 Unicode code point escape sequences are forbidden.", + // "ES2015 Unicode code point escape sequences are forbidden.", + // ], + // }, { //eslint-disable-next-line no-template-curly-in-string code: "tag`\\u{45}${a}\\u{46}`", //eslint-disable-next-line no-template-curly-in-string - output: "tag`\\u0045${a}\\u0046`", + output: "tag`\\0045}${a}\\0046}`", errors: [ "ES2015 Unicode code point escape sequences are forbidden.", "ES2015 Unicode code point escape sequences are forbidden.", @@ -89,7 +89,7 @@ new RuleTester().run("no-unicode-codepoint-escapes", rule, { //eslint-disable-next-line no-template-curly-in-string code: "tag`\\u{XXXZX}${a}\\u{46}`", //eslint-disable-next-line no-template-curly-in-string - output: "tag`\\u{XXXZX}${a}\\u0046`", + output: "tag`\\u{XXXZX}${a}\\0046}`", errors: [ "ES2015 Unicode code point escape sequences are forbidden.", ], @@ -108,12 +108,12 @@ new RuleTester().run("no-unicode-codepoint-escapes", rule, { }, { code: "`\\u{20BB7}`", - output: "`\\uD842\\uDFB7`", + output: "`\\D842\\uDFB7}`", errors: [ { message: "ES2015 Unicode code point escape sequences are forbidden.", - column: 2, + column: 1, line: 1, }, ], @@ -124,7 +124,7 @@ a=\`\${a}\\u{D842}\\u{DFB7}\` b="\\u{20BB7}" `, output: ` -a=\`\${a}\\uD842\\uDFB7\` +a=\`\${a}\\D842}\\DFB7}\` b="\\uD842\\uDFB7" `, errors: [ @@ -132,26 +132,23 @@ b="\\uD842\\uDFB7" message: "ES2015 Unicode code point escape sequences are forbidden.", line: 2, - column: 8, - nodeType: "TemplateElement", + column: 7, endLine: 2, - endColumn: 16, + endColumn: 15, }, { message: "ES2015 Unicode code point escape sequences are forbidden.", line: 2, - column: 16, - nodeType: "TemplateElement", + column: 15, endLine: 2, - endColumn: 24, + endColumn: 23, }, { message: "ES2015 Unicode code point escape sequences are forbidden.", line: 3, column: 4, - nodeType: "Literal", endLine: 3, endColumn: 13, }, From 0b21b8098a46e7231f460c1ea09d7262cc3eacc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Sun, 10 May 2020 14:34:59 +0200 Subject: [PATCH 3/8] Revert "tests: Fix tests" This reverts commit 30121f72 --- .../lib/rules/no-unicode-codepoint-escapes.js | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/tests/lib/rules/no-unicode-codepoint-escapes.js b/tests/lib/rules/no-unicode-codepoint-escapes.js index 4e99aeb3..c9e9ab0d 100644 --- a/tests/lib/rules/no-unicode-codepoint-escapes.js +++ b/tests/lib/rules/no-unicode-codepoint-escapes.js @@ -51,35 +51,35 @@ new RuleTester().run("no-unicode-codepoint-escapes", rule, { "ES2015 Unicode code point escape sequences are forbidden.", ], }, - // { - // code: "`\\u{45}`", - // output: "`\\u0045`", - // errors: [ - // "ES2015 Unicode code point escape sequences are forbidden.", - // ], - // }, + { + code: "`\\u{45}`", + output: "`\\u0045`", + errors: [ + "ES2015 Unicode code point escape sequences are forbidden.", + ], + }, { code: "tag`\\u{45}`", - output: "tag`\\0045}`", + output: "tag`\\u0045`", + errors: [ + "ES2015 Unicode code point escape sequences are forbidden.", + ], + }, + { + //eslint-disable-next-line no-template-curly-in-string + code: "`\\u{45}${a}\\u{46}`", + //eslint-disable-next-line no-template-curly-in-string + output: "`\\u0045${a}\\u0046`", errors: [ "ES2015 Unicode code point escape sequences are forbidden.", + "ES2015 Unicode code point escape sequences are forbidden.", ], }, - // { - // //eslint-disable-next-line no-template-curly-in-string - // code: "`\\u{45}${a}\\u{46}`", - // //eslint-disable-next-line no-template-curly-in-string - // output: "`\\u0045${a}\\u0046`", - // errors: [ - // "ES2015 Unicode code point escape sequences are forbidden.", - // "ES2015 Unicode code point escape sequences are forbidden.", - // ], - // }, { //eslint-disable-next-line no-template-curly-in-string code: "tag`\\u{45}${a}\\u{46}`", //eslint-disable-next-line no-template-curly-in-string - output: "tag`\\0045}${a}\\0046}`", + output: "tag`\\u0045${a}\\u0046`", errors: [ "ES2015 Unicode code point escape sequences are forbidden.", "ES2015 Unicode code point escape sequences are forbidden.", @@ -89,7 +89,7 @@ new RuleTester().run("no-unicode-codepoint-escapes", rule, { //eslint-disable-next-line no-template-curly-in-string code: "tag`\\u{XXXZX}${a}\\u{46}`", //eslint-disable-next-line no-template-curly-in-string - output: "tag`\\u{XXXZX}${a}\\0046}`", + output: "tag`\\u{XXXZX}${a}\\u0046`", errors: [ "ES2015 Unicode code point escape sequences are forbidden.", ], @@ -108,12 +108,12 @@ new RuleTester().run("no-unicode-codepoint-escapes", rule, { }, { code: "`\\u{20BB7}`", - output: "`\\D842\\uDFB7}`", + output: "`\\uD842\\uDFB7`", errors: [ { message: "ES2015 Unicode code point escape sequences are forbidden.", - column: 1, + column: 2, line: 1, }, ], @@ -124,7 +124,7 @@ a=\`\${a}\\u{D842}\\u{DFB7}\` b="\\u{20BB7}" `, output: ` -a=\`\${a}\\D842}\\DFB7}\` +a=\`\${a}\\uD842\\uDFB7\` b="\\uD842\\uDFB7" `, errors: [ @@ -132,23 +132,26 @@ b="\\uD842\\uDFB7" message: "ES2015 Unicode code point escape sequences are forbidden.", line: 2, - column: 7, + column: 8, + nodeType: "TemplateElement", endLine: 2, - endColumn: 15, + endColumn: 16, }, { message: "ES2015 Unicode code point escape sequences are forbidden.", line: 2, - column: 15, + column: 16, + nodeType: "TemplateElement", endLine: 2, - endColumn: 23, + endColumn: 24, }, { message: "ES2015 Unicode code point escape sequences are forbidden.", line: 3, column: 4, + nodeType: "Literal", endLine: 3, endColumn: 13, }, From 041926a31ae04cbd134a8217a36f3e3d04de1ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Sun, 10 May 2020 14:39:00 +0200 Subject: [PATCH 4/8] tests: Actually fix tests? --- lib/rules/no-unicode-codepoint-escapes.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/rules/no-unicode-codepoint-escapes.js b/lib/rules/no-unicode-codepoint-escapes.js index a3fd639b..4078514e 100644 --- a/lib/rules/no-unicode-codepoint-escapes.js +++ b/lib/rules/no-unicode-codepoint-escapes.js @@ -48,7 +48,10 @@ module.exports = { for (const match of codePointEscapeSearchGenerator(text)) { const start = match.index const end = start + match[0].length - const range = [start + node.range[0], end + node.range[0]] + const range = [ + start + node.range[0] + 1, + end + node.range[0] + 1, + ] context.report({ node, loc: { From 6db3fcd444e0f74e1dbfa69d9fb37b769b707f63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Sun, 10 May 2020 15:35:15 +0200 Subject: [PATCH 5/8] fix: Always use sourceCode.getText(node) --- lib/rules/no-unicode-codepoint-escapes.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/rules/no-unicode-codepoint-escapes.js b/lib/rules/no-unicode-codepoint-escapes.js index 4078514e..986cb4b3 100644 --- a/lib/rules/no-unicode-codepoint-escapes.js +++ b/lib/rules/no-unicode-codepoint-escapes.js @@ -48,10 +48,7 @@ module.exports = { for (const match of codePointEscapeSearchGenerator(text)) { const start = match.index const end = start + match[0].length - const range = [ - start + node.range[0] + 1, - end + node.range[0] + 1, - ] + const range = [start + node.range[0], end + node.range[0]] context.report({ node, loc: { @@ -92,11 +89,11 @@ module.exports = { }, Literal(node) { if (typeof node.value === "string") { - findAndReport(node.raw, node) + findAndReport(sourceCode.getText(node), node) } }, - TemplateElement(elementNode) { - findAndReport(elementNode.value.raw, elementNode) + TemplateElement(node) { + findAndReport(sourceCode.getText(node), node) }, } }, From 0c1078ab5188c65350decbc4c4268de7c34a6f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Sun, 10 May 2020 15:35:46 +0200 Subject: [PATCH 6/8] refactor: Cleanup code --- lib/rules/no-unicode-codepoint-escapes.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/rules/no-unicode-codepoint-escapes.js b/lib/rules/no-unicode-codepoint-escapes.js index 986cb4b3..52e7295d 100644 --- a/lib/rules/no-unicode-codepoint-escapes.js +++ b/lib/rules/no-unicode-codepoint-escapes.js @@ -40,11 +40,11 @@ module.exports = { /** * find code point escape, and report - * @param {string} text text * @param {Node} node node * @returns {void} */ - function findAndReport(text, node) { + function findAndReport(node) { + const text = sourceCode.getText(node) for (const match of codePointEscapeSearchGenerator(text)) { const start = match.index const end = start + match[0].length @@ -85,15 +85,15 @@ module.exports = { return { Identifier(node) { - findAndReport(sourceCode.getText(node), node) + findAndReport(node) }, Literal(node) { if (typeof node.value === "string") { - findAndReport(sourceCode.getText(node), node) + findAndReport(node) } }, TemplateElement(node) { - findAndReport(sourceCode.getText(node), node) + findAndReport(node) }, } }, From 5867cf70e7243775b1f766b99812bd8e6826e537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Sun, 10 May 2020 15:38:23 +0200 Subject: [PATCH 7/8] chore: Resolve discussions --- .github/workflows/ci.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 64559fdd..2abf2b5c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: - name: Install Node.js uses: actions/setup-node@v1 with: - node: 14 + node: 14.x - name: Install Packages run: npm install - name: Lint @@ -29,32 +29,32 @@ jobs: strategy: matrix: eslint: [7] - node: [14] + node: [14.x] os: [ubuntu-latest] include: # On other platforms - eslint: 7 - node: 14 + node: 14.x os: windows-latest - eslint: 7 - node: 14 + node: 14.x os: macos-latest # On old Node.js versions - eslint: 7 - node: 12 + node: 12.x os: ubuntu-latest - eslint: 7 - node: 10 + node: 10.x os: ubuntu-latest # On old ESLint versions - eslint: 6 - node: 14 + node: 14.x os: ubuntu-latest - eslint: 5 - node: 14 + node: 14.x os: ubuntu-latest - eslint: 4 - node: 14 + node: 14.x os: ubuntu-latest # On the minimum supported ESLint/Node.js version - eslint: 4 From 55497be117dae98d2e070f0ed79fc68bca69ed28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Sun, 10 May 2020 15:41:11 +0200 Subject: [PATCH 8/8] tests: Remove nodeType from errors --- tests/lib/rules/no-unicode-codepoint-escapes.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/lib/rules/no-unicode-codepoint-escapes.js b/tests/lib/rules/no-unicode-codepoint-escapes.js index c9e9ab0d..dc4034ee 100644 --- a/tests/lib/rules/no-unicode-codepoint-escapes.js +++ b/tests/lib/rules/no-unicode-codepoint-escapes.js @@ -133,7 +133,6 @@ b="\\uD842\\uDFB7" "ES2015 Unicode code point escape sequences are forbidden.", line: 2, column: 8, - nodeType: "TemplateElement", endLine: 2, endColumn: 16, }, @@ -142,7 +141,6 @@ b="\\uD842\\uDFB7" "ES2015 Unicode code point escape sequences are forbidden.", line: 2, column: 16, - nodeType: "TemplateElement", endLine: 2, endColumn: 24, }, @@ -151,7 +149,6 @@ b="\\uD842\\uDFB7" "ES2015 Unicode code point escape sequences are forbidden.", line: 3, column: 4, - nodeType: "Literal", endLine: 3, endColumn: 13, },