From fba5fe27f0be017700f7d8efced278f4f737784a Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Thu, 19 Aug 2021 11:42:24 +0900 Subject: [PATCH 01/14] Add test for ESLint v8 --- .github/workflows/CI.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index a6e32261..d3b5533b 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -29,8 +29,8 @@ jobs: name: Test strategy: matrix: - eslint: [7] - node: [14] + eslint: [7, '^8.0.0-0'] + node: [14, 16] os: [ubuntu-latest] include: # On other platforms From f4aa14fb637be59f0bd21237a4eebf7cfd2fb424 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Thu, 19 Aug 2021 11:44:15 +0900 Subject: [PATCH 02/14] fix --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index d3b5533b..1fe52242 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -29,7 +29,7 @@ jobs: name: Test strategy: matrix: - eslint: [7, '^8.0.0-0'] + eslint: [7, '8.0.0-0'] node: [14, 16] os: [ubuntu-latest] include: From 08d7d78d00146c7a216bc3624366df871c1ece1f Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Thu, 19 Aug 2021 11:47:16 +0900 Subject: [PATCH 03/14] fix --- scripts/ci-install-eslint.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/ci-install-eslint.js b/scripts/ci-install-eslint.js index 7bde2b54..fdae7b05 100644 --- a/scripts/ci-install-eslint.js +++ b/scripts/ci-install-eslint.js @@ -12,7 +12,7 @@ function sh(command) { return new Promise((resolve, reject) => { spawn(command, [], { shell: true, stdio: "inherit" }) .on("error", reject) - .on("exit", exitCode => { + .on("exit", (exitCode) => { if (exitCode) { reject(new Error(`Exit with non-zero ${exitCode}`)) } else { @@ -32,7 +32,7 @@ function sh(command) { await sh(`npm install eslint@${requestedVersionSpec}`) // Install ESLint submodule of the requested version - const installedVersion = require("eslint").CLIEngine.version + const installedVersion = require("eslint/package.json").version cd("test/fixtures/eslint") if (!installedVersion.startsWith("7.")) { await sh(`git checkout v${installedVersion}`) @@ -41,7 +41,7 @@ function sh(command) { await sh("npm install eslint-utils@1.4.0") } await sh("npm install") -})().catch(error => { +})().catch((error) => { console.error(error) process.exitCode = 1 }) From acdf687d90966339d018fd06d0d9a9e249268aca Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Thu, 19 Aug 2021 11:49:13 +0900 Subject: [PATCH 04/14] fix --- scripts/ci-install-eslint.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci-install-eslint.js b/scripts/ci-install-eslint.js index fdae7b05..d4b08564 100644 --- a/scripts/ci-install-eslint.js +++ b/scripts/ci-install-eslint.js @@ -29,7 +29,7 @@ function sh(command) { : `^${requestedVersion}` // Install ESLint of the requested version - await sh(`npm install eslint@${requestedVersionSpec}`) + await sh(`npm install eslint@${requestedVersionSpec} --legacy-peer-deps`) // Install ESLint submodule of the requested version const installedVersion = require("eslint/package.json").version From 6217620a59e05a3f3bd70cacbbb14c025b6c5963 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Thu, 19 Aug 2021 11:51:48 +0900 Subject: [PATCH 05/14] fix --- scripts/ci-install-eslint.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci-install-eslint.js b/scripts/ci-install-eslint.js index d4b08564..724c0ebc 100644 --- a/scripts/ci-install-eslint.js +++ b/scripts/ci-install-eslint.js @@ -40,7 +40,7 @@ function sh(command) { if (installedVersion.startsWith("5.")) { await sh("npm install eslint-utils@1.4.0") } - await sh("npm install") + await sh("npm install --legacy-peer-deps") })().catch((error) => { console.error(error) process.exitCode = 1 From 6f60474aaf32dbfbe88f4825bf941c9b1c8eb842 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Thu, 19 Aug 2021 12:13:09 +0900 Subject: [PATCH 06/14] fix babel --- package.json | 5 +- scripts/update-fixtures-ast.js | 7 +- test/ast.js | 7 +- .../filters-opt-filter-off-babel-old/ast.json | 610 ++++++++++++++++++ .../parser-options.json | 6 + .../requirements.json | 3 + .../source.vue | 3 + .../token-ranges.json | 18 + .../tree.json | 66 ++ .../parser-options.json | 10 +- .../requirements.json | 3 + 11 files changed, 732 insertions(+), 6 deletions(-) create mode 100644 test/fixtures/ast/filters-opt-filter-off-babel-old/ast.json create mode 100644 test/fixtures/ast/filters-opt-filter-off-babel-old/parser-options.json create mode 100644 test/fixtures/ast/filters-opt-filter-off-babel-old/requirements.json create mode 100644 test/fixtures/ast/filters-opt-filter-off-babel-old/source.vue create mode 100644 test/fixtures/ast/filters-opt-filter-off-babel-old/token-ranges.json create mode 100644 test/fixtures/ast/filters-opt-filter-off-babel-old/tree.json create mode 100644 test/fixtures/ast/filters-opt-filter-off-babel/requirements.json diff --git a/package.json b/package.json index 5197b8e0..41a83ea6 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,9 @@ "semver": "^6.3.0" }, "devDependencies": { + "@babel/core": "^7.15.0", + "@babel/eslint-parser": "^7.15.0", + "@babel/plugin-syntax-pipeline-operator": "^7.15.0", "@mysticatea/eslint-plugin": "^13.0.0", "@types/debug": "0.0.30", "@types/eslint": "^7.2.6", @@ -67,7 +70,7 @@ "pretest": "run-s build lint", "test": "npm run -s test:mocha", "test:mocha": "nyc mocha \"test/*.js\" --reporter dot --timeout 60000", - "test:debug": "mocha --inspect --require ts-node/register/transpile-only \"test/*.js\" --reporter dot --timeout 60000", + "test:debug": "mocha --require ts-node/register/transpile-only \"test/*.js\" --reporter dot --timeout 60000", "preupdate-fixtures": "npm run -s build", "update-fixtures": "node scripts/update-fixtures-ast.js && node scripts/update-fixtures-document-fragment.js", "preversion": "npm test", diff --git a/scripts/update-fixtures-ast.js b/scripts/update-fixtures-ast.js index 9e0fa561..2290ba28 100644 --- a/scripts/update-fixtures-ast.js +++ b/scripts/update-fixtures-ast.js @@ -208,8 +208,11 @@ for (const name of TARGETS) { : {} if ( Object.entries(requirements).some(([pkgName, pkgVersion]) => { - const pkg = require(`${pkgName}/package.json`) - return !semver.satisfies(pkg.version, pkgVersion) + const version = + pkgName === "node" + ? process.version + : require(`${pkgName}/package.json`).version + return !semver.satisfies(version, pkgVersion) }) ) { continue diff --git a/test/ast.js b/test/ast.js index 48a9b58a..e5634442 100644 --- a/test/ast.js +++ b/test/ast.js @@ -190,8 +190,11 @@ describe("Template AST", () => { if ( Object.entries(requirements).some(([pkgName, pkgVersion]) => { - const pkg = require(`${pkgName}/package.json`) - return !semver.satisfies(pkg.version, pkgVersion) + const version = + pkgName === "node" + ? process.version + : require(`${pkgName}/package.json`).version + return !semver.satisfies(version, pkgVersion) }) ) { continue diff --git a/test/fixtures/ast/filters-opt-filter-off-babel-old/ast.json b/test/fixtures/ast/filters-opt-filter-off-babel-old/ast.json new file mode 100644 index 00000000..200f957a --- /dev/null +++ b/test/fixtures/ast/filters-opt-filter-off-babel-old/ast.json @@ -0,0 +1,610 @@ +{ + "type": "Program", + "start": 0, + "end": 0, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 0 + } + }, + "range": [ + 0, + 0 + ], + "errors": [], + "comments": [], + "tokens": [], + "sourceType": "module", + "body": [], + "templateBody": { + "type": "VElement", + "range": [ + 0, + 54 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 15, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "name": "div", + "rawName": "div", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 15, + 20 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VExpressionContainer", + "range": [ + 20, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 23, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "range": [ + 23, + 33 + ], + "left": { + "type": "Identifier", + "start": 23, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "foo" + }, + "range": [ + 23, + 26 + ], + "name": "foo", + "_babelType": "Identifier" + }, + "operator": "|>", + "right": { + "type": "Identifier", + "start": 30, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 22 + }, + "identifierName": "bar" + }, + "range": [ + 30, + 33 + ], + "name": "bar", + "_babelType": "Identifier" + }, + "_babelType": "BinaryExpression" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 23, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "foo" + }, + "range": [ + 23, + 26 + ], + "name": "foo", + "_babelType": "Identifier" + }, + "mode": "r" + }, + { + "id": { + "type": "Identifier", + "start": 30, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 22 + }, + "identifierName": "bar" + }, + "range": [ + 30, + 33 + ], + "name": "bar", + "_babelType": "Identifier" + }, + "mode": "r" + } + ] + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 36, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 31 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 42, + 43 + ], + "loc": { + "start": { + "line": 2, + "column": 31 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 43, + 54 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 15, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 19, + 20 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "value": "" + }, + { + "type": "VExpressionStart", + "range": [ + 20, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "value": "{{" + }, + { + "type": "Identifier", + "value": "foo", + "start": 23, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "range": [ + 23, + 26 + ] + }, + { + "type": "Punctuator", + "value": "|>", + "start": 27, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "range": [ + 27, + 29 + ] + }, + { + "type": "Identifier", + "value": "bar", + "start": 30, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "range": [ + 30, + 33 + ] + }, + { + "type": "VExpressionEnd", + "range": [ + 34, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "value": "}}" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 36, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 30 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 41, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 42, + 43 + ], + "loc": { + "start": { + "line": 2, + "column": 31 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 43, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 54, + 55 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/filters-opt-filter-off-babel-old/parser-options.json b/test/fixtures/ast/filters-opt-filter-off-babel-old/parser-options.json new file mode 100644 index 00000000..69efe8d7 --- /dev/null +++ b/test/fixtures/ast/filters-opt-filter-off-babel-old/parser-options.json @@ -0,0 +1,6 @@ +{ + "parser": "babel-eslint", + "vueFeatures": { + "filter": false + } +} diff --git a/test/fixtures/ast/filters-opt-filter-off-babel-old/requirements.json b/test/fixtures/ast/filters-opt-filter-off-babel-old/requirements.json new file mode 100644 index 00000000..a3f8f083 --- /dev/null +++ b/test/fixtures/ast/filters-opt-filter-off-babel-old/requirements.json @@ -0,0 +1,3 @@ +{ + "eslint": "<8" +} \ No newline at end of file diff --git a/test/fixtures/ast/filters-opt-filter-off-babel-old/source.vue b/test/fixtures/ast/filters-opt-filter-off-babel-old/source.vue new file mode 100644 index 00000000..868e8859 --- /dev/null +++ b/test/fixtures/ast/filters-opt-filter-off-babel-old/source.vue @@ -0,0 +1,3 @@ + diff --git a/test/fixtures/ast/filters-opt-filter-off-babel-old/token-ranges.json b/test/fixtures/ast/filters-opt-filter-off-babel-old/token-ranges.json new file mode 100644 index 00000000..68f472a1 --- /dev/null +++ b/test/fixtures/ast/filters-opt-filter-off-babel-old/token-ranges.json @@ -0,0 +1,18 @@ +[ + "", + "\n ", + "", + "{{", + "foo", + "|>", + "bar", + "}}", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/filters-opt-filter-off-babel-old/tree.json b/test/fixtures/ast/filters-opt-filter-off-babel-old/tree.json new file mode 100644 index 00000000..7db3a314 --- /dev/null +++ b/test/fixtures/ast/filters-opt-filter-off-babel-old/tree.json @@ -0,0 +1,66 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/filters-opt-filter-off-babel/parser-options.json b/test/fixtures/ast/filters-opt-filter-off-babel/parser-options.json index 69efe8d7..959a61c7 100644 --- a/test/fixtures/ast/filters-opt-filter-off-babel/parser-options.json +++ b/test/fixtures/ast/filters-opt-filter-off-babel/parser-options.json @@ -1,5 +1,13 @@ { - "parser": "babel-eslint", + "parser": "@babel/eslint-parser", + "requireConfigFile": false, + "babelOptions": { + "plugins": [ + [ + "@babel/plugin-syntax-pipeline-operator", { "proposal": "minimal" } + ] + ] + }, "vueFeatures": { "filter": false } diff --git a/test/fixtures/ast/filters-opt-filter-off-babel/requirements.json b/test/fixtures/ast/filters-opt-filter-off-babel/requirements.json new file mode 100644 index 00000000..599c1280 --- /dev/null +++ b/test/fixtures/ast/filters-opt-filter-off-babel/requirements.json @@ -0,0 +1,3 @@ +{ + "node": ">=12" +} \ No newline at end of file From 46fb4c08720ac56ca113b54db2ffbbb9ad401ab6 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Thu, 19 Aug 2021 12:14:26 +0900 Subject: [PATCH 07/14] fix --- .../ast/filters-opt-filter-off-babel/ast.json | 28 ++++++------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/test/fixtures/ast/filters-opt-filter-off-babel/ast.json b/test/fixtures/ast/filters-opt-filter-off-babel/ast.json index 200f957a..5798c090 100644 --- a/test/fixtures/ast/filters-opt-filter-off-babel/ast.json +++ b/test/fixtures/ast/filters-opt-filter-off-babel/ast.json @@ -16,7 +16,6 @@ 0, 0 ], - "errors": [], "comments": [], "tokens": [], "sourceType": "module", @@ -163,15 +162,13 @@ "end": { "line": 2, "column": 15 - }, - "identifierName": "foo" + } }, "range": [ 23, 26 ], - "name": "foo", - "_babelType": "Identifier" + "name": "foo" }, "operator": "|>", "right": { @@ -186,17 +183,14 @@ "end": { "line": 2, "column": 22 - }, - "identifierName": "bar" + } }, "range": [ 30, 33 ], - "name": "bar", - "_babelType": "Identifier" - }, - "_babelType": "BinaryExpression" + "name": "bar" + } }, "references": [ { @@ -212,15 +206,13 @@ "end": { "line": 2, "column": 15 - }, - "identifierName": "foo" + } }, "range": [ 23, 26 ], - "name": "foo", - "_babelType": "Identifier" + "name": "foo" }, "mode": "r" }, @@ -237,15 +229,13 @@ "end": { "line": 2, "column": 22 - }, - "identifierName": "bar" + } }, "range": [ 30, 33 ], - "name": "bar", - "_babelType": "Identifier" + "name": "bar" }, "mode": "r" } From 4d3309cb1a34470419338d93743de60b3174ca98 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Thu, 19 Aug 2021 12:32:37 +0900 Subject: [PATCH 08/14] fix test --- test/parser-options.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/test/parser-options.js b/test/parser-options.js index b9141ff9..2c7f26eb 100644 --- a/test/parser-options.js +++ b/test/parser-options.js @@ -5,7 +5,6 @@ "use strict" const assert = require("assert") -const { rules } = require("@mysticatea/eslint-plugin") const { parseForESLint } = require("../src") const eslint = require("./fixtures/eslint") const Linter = eslint.Linter @@ -14,10 +13,18 @@ describe("parserOptions", () => { describe("parser", () => { const linter = new Linter() linter.defineParser("vue-eslint-parser", { parseForESLint }) - linter.defineRule( - "vue/valid-template-root", - rules["vue/valid-template-root"] - ) + linter.defineRule("vue/template-test", { + create(context) { + return { + Program(node) { + const element = node.templateBody + if (element != null) { + context.report({ node, message: "test" }) + } + }, + } + }, + }) it("false then skip parsing '