From 759b1ed88a0ec02071354a046a4375d25cf2e21a Mon Sep 17 00:00:00 2001 From: Lei Chen Date: Fri, 19 Apr 2024 11:48:45 +0800 Subject: [PATCH 01/10] ci: eslint v9 test --- .github/workflows/ci.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9f1649c..4c88ea7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,6 +35,19 @@ jobs: - run: npm run lint - run: npm run test + eslint9_test: + name: Test eslint-plugin-wxml with eslint9 + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: {node-version: '${{ env.NODE_VERSION }}'} + - run: npm install + - run: npm install eslint@9 + - run: npm run lint + - run: npm run test + eslint8_test: name: Test eslint-plugin-wxml with eslint8 runs-on: ubuntu-latest From 3230d6155202d798262f0e4d1fd00bae45395212 Mon Sep 17 00:00:00 2001 From: iChenLei Date: Fri, 19 Apr 2024 15:23:16 +0800 Subject: [PATCH 02/10] fix: eslint9 compat --- .eslintrc.js | 2 +- eslint.config.mjs | 17 +++++++++++++++++ lib/rules/report-interpolation-error.js | 4 +++- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 eslint.config.mjs diff --git a/.eslintrc.js b/.eslintrc.js index 8a92fed..e13bdd7 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,5 +1,5 @@ module.exports = { - extends: ['eslint:recommended', 'plugin:node/recommended', 'plugin:eslint-plugin/recommended'], + extends: ['eslint:recommended', 'plugin:eslint-plugin/recommended'], env: { es6: true } diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..080ed81 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,17 @@ +import js from "@eslint/js"; + +export default [ + { + ...js.configs.recommended, + files: ["lib/**/*.js"], + ignores: ["website/**", "tools/**"] + }, + { + languageOptions: { + globals: { + module: "readonly", + require: "readonly", + } + } + } +]; \ No newline at end of file diff --git a/lib/rules/report-interpolation-error.js b/lib/rules/report-interpolation-error.js index 8cc507d..8b9956e 100644 --- a/lib/rules/report-interpolation-error.js +++ b/lib/rules/report-interpolation-error.js @@ -23,8 +23,8 @@ module.exports = { return; } try { - // eslint-disable-next-line node/no-extraneous-require espreeParser = require("espree"); + // eslint-disable-next-line no-unused-vars } catch (_) { // ... } @@ -38,11 +38,13 @@ module.exports = { espreeParser.parse(`({${node.value}})`, { ecmaVersion: espreeParser.latestEcmaVersion, }); + // eslint-disable-next-line no-unused-vars } catch (_) { try { espreeParser.parse(`(${node.value})`, { ecmaVersion: espreeParser.latestEcmaVersion, }); + // eslint-disable-next-line no-unused-vars } catch (_) { context.report({ node, From d7cdb515c51fb3f9194f7757c257d88d99e41711 Mon Sep 17 00:00:00 2001 From: iChenLei Date: Fri, 19 Apr 2024 15:28:26 +0800 Subject: [PATCH 03/10] fix: raw eslint config --- .eslintrc.js | 2 +- eslint.config.mjs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index e13bdd7..8a92fed 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,5 +1,5 @@ module.exports = { - extends: ['eslint:recommended', 'plugin:eslint-plugin/recommended'], + extends: ['eslint:recommended', 'plugin:node/recommended', 'plugin:eslint-plugin/recommended'], env: { es6: true } diff --git a/eslint.config.mjs b/eslint.config.mjs index 080ed81..7de11e5 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -14,4 +14,4 @@ export default [ } } } -]; \ No newline at end of file +]; From 1c03fa4b576b7ffe69d05496370e10737ca1f67e Mon Sep 17 00:00:00 2001 From: iChenLei Date: Fri, 19 Apr 2024 15:33:58 +0800 Subject: [PATCH 04/10] chore: fix --- .eslintignore | 1 + .eslintrc.js | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.eslintignore b/.eslintignore index 02596a7..ed6f7c4 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,3 @@ website/ tools/ +eslint.config.mjs diff --git a/.eslintrc.js b/.eslintrc.js index 8a92fed..13f6db1 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -2,5 +2,8 @@ module.exports = { extends: ['eslint:recommended', 'plugin:node/recommended', 'plugin:eslint-plugin/recommended'], env: { es6: true + }, + rules: { + "node/no-extraneous-require": "off" } } From eefae583fa854be5518eb789b321d892cd594fe9 Mon Sep 17 00:00:00 2001 From: iChenLei Date: Fri, 19 Apr 2024 16:40:08 +0800 Subject: [PATCH 05/10] fix: add eslint9 compatiable rule tester --- tests/rule-tester-compat.js | 12 ++++++++++++ tests/rules/colon-style-event-binding.js | 6 ++---- tests/rules/empty-tag-self-closing.js | 6 ++---- tests/rules/event-binding-style.js | 6 ++---- tests/rules/forbid-attributes.js | 6 ++---- tests/rules/forbid-tags.js | 6 ++---- tests/rules/max-depth.js | 6 ++---- tests/rules/max-len.js | 6 ++---- tests/rules/max-lines.js | 6 ++---- tests/rules/no-const-and-let-in-wxs.js | 6 ++---- tests/rules/no-dot-this-in-wx-key.js | 6 ++---- tests/rules/no-duplicate-attributes.js | 6 ++---- tests/rules/no-dynamic-wx-key.js | 6 ++---- tests/rules/no-inconsistent-tagname.js | 6 ++---- tests/rules/no-index-in-wx-key.js | 6 ++---- tests/rules/no-inline-wxs.js | 6 ++---- tests/rules/no-unexpected-string-bool.js | 6 ++---- tests/rules/no-unnecessary-block.js | 6 ++---- tests/rules/no-vue-directive.js | 6 ++---- tests/rules/no-wx-for-with-wx-else.js | 6 ++---- tests/rules/no-wx-for-with-wx-if.js | 6 ++---- tests/rules/no-wx-if-string.js | 6 ++---- tests/rules/omit-bool-attributes.js | 6 ++---- tests/rules/quotes.js | 6 ++---- tests/rules/report-interpolation-error.js | 6 ++---- tests/rules/report-wxml-syntax-error.js | 6 ++---- tests/rules/report-wxs-syntax-error.js | 6 ++---- tests/rules/required-attributes.js | 6 ++---- tests/rules/required-root-tag.js | 6 ++---- tests/rules/required-tags.js | 6 ++---- tests/rules/wx-key.js | 6 ++---- tests/rules/wxs-module-prop.js | 6 ++---- tests/rules/wxs-must-be-top-level.js | 6 +----- 33 files changed, 75 insertions(+), 129 deletions(-) create mode 100644 tests/rule-tester-compat.js diff --git a/tests/rule-tester-compat.js b/tests/rule-tester-compat.js new file mode 100644 index 0000000..6334495 --- /dev/null +++ b/tests/rule-tester-compat.js @@ -0,0 +1,12 @@ +const eslint = require("eslint"); +const semver = require("semver"); + +const ruleTester = semver.gte(eslint.Linter.version, '9.0.0-0') ? + new eslint.RuleTester({ + languageOptions: { + parser: require("@wxml/parser"), + }, + }) : + new eslint.RuleTester({ parser: require.resolve("@wxml/parser") }); + +module.exports.RuleTester = ruleTester; \ No newline at end of file diff --git a/tests/rules/colon-style-event-binding.js b/tests/rules/colon-style-event-binding.js index 1650a7b..b781e33 100644 --- a/tests/rules/colon-style-event-binding.js +++ b/tests/rules/colon-style-event-binding.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/colon-style-event-binding"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("colon-style-event-binding", rule, { valid: [ diff --git a/tests/rules/empty-tag-self-closing.js b/tests/rules/empty-tag-self-closing.js index 2a2b23c..9bc65d8 100644 --- a/tests/rules/empty-tag-self-closing.js +++ b/tests/rules/empty-tag-self-closing.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/empty-tag-self-closing"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("empty-tag-self-closing", rule, { valid: [ diff --git a/tests/rules/event-binding-style.js b/tests/rules/event-binding-style.js index e50a67c..20d65a8 100644 --- a/tests/rules/event-binding-style.js +++ b/tests/rules/event-binding-style.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/event-binding-style"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("event-binding-style", rule, { valid: [ diff --git a/tests/rules/forbid-attributes.js b/tests/rules/forbid-attributes.js index ff6d735..d9f2743 100644 --- a/tests/rules/forbid-attributes.js +++ b/tests/rules/forbid-attributes.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/forbid-attributes"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("forbid-attributes", rule, { valid: [ diff --git a/tests/rules/forbid-tags.js b/tests/rules/forbid-tags.js index 2b6e13e..0a82be9 100644 --- a/tests/rules/forbid-tags.js +++ b/tests/rules/forbid-tags.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/forbid-tags"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("forbid-tags", rule, { valid: [ diff --git a/tests/rules/max-depth.js b/tests/rules/max-depth.js index 688e1a7..4629e5b 100644 --- a/tests/rules/max-depth.js +++ b/tests/rules/max-depth.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/max-depth"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("max-depth", rule, { valid: [ diff --git a/tests/rules/max-len.js b/tests/rules/max-len.js index ed19544..37b8f30 100644 --- a/tests/rules/max-len.js +++ b/tests/rules/max-len.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/max-len"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("max-len", rule, { valid: [ diff --git a/tests/rules/max-lines.js b/tests/rules/max-lines.js index 2368130..a0b9d01 100644 --- a/tests/rules/max-lines.js +++ b/tests/rules/max-lines.js @@ -1,11 +1,9 @@ const fs = require("fs"); const path = require("path"); -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/max-lines"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + function readFixureFiles(filename) { if (filename) { diff --git a/tests/rules/no-const-and-let-in-wxs.js b/tests/rules/no-const-and-let-in-wxs.js index 1e752d0..226c11f 100644 --- a/tests/rules/no-const-and-let-in-wxs.js +++ b/tests/rules/no-const-and-let-in-wxs.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-const-and-let-in-wxs"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("no-const-and-let-in-wxs", rule, { valid: [ diff --git a/tests/rules/no-dot-this-in-wx-key.js b/tests/rules/no-dot-this-in-wx-key.js index 8f2165e..fa01f18 100644 --- a/tests/rules/no-dot-this-in-wx-key.js +++ b/tests/rules/no-dot-this-in-wx-key.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-dot-this-in-wx-key"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("no-dot-this-in-wx-key", rule, { valid: [ diff --git a/tests/rules/no-duplicate-attributes.js b/tests/rules/no-duplicate-attributes.js index a2d2435..bc6ed38 100644 --- a/tests/rules/no-duplicate-attributes.js +++ b/tests/rules/no-duplicate-attributes.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-duplicate-attributes"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("no-duplicate-attributes", rule, { valid: [ diff --git a/tests/rules/no-dynamic-wx-key.js b/tests/rules/no-dynamic-wx-key.js index 674e69e..4afb429 100644 --- a/tests/rules/no-dynamic-wx-key.js +++ b/tests/rules/no-dynamic-wx-key.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-dynamic-wx-key"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("no-dynamic-wx-key", rule, { valid: [ diff --git a/tests/rules/no-inconsistent-tagname.js b/tests/rules/no-inconsistent-tagname.js index d3d7cdb..e7c0870 100644 --- a/tests/rules/no-inconsistent-tagname.js +++ b/tests/rules/no-inconsistent-tagname.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-inconsistent-tagname"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("no-inconsistent-tagname", rule, { valid: [ diff --git a/tests/rules/no-index-in-wx-key.js b/tests/rules/no-index-in-wx-key.js index 4c31925..c58d4f6 100644 --- a/tests/rules/no-index-in-wx-key.js +++ b/tests/rules/no-index-in-wx-key.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-index-in-wx-key"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("no-index-in-wx-key", rule, { valid: [ diff --git a/tests/rules/no-inline-wxs.js b/tests/rules/no-inline-wxs.js index e4b7e52..8e47d1b 100644 --- a/tests/rules/no-inline-wxs.js +++ b/tests/rules/no-inline-wxs.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-inline-wxs"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("no-inline-wxs", rule, { valid: [ diff --git a/tests/rules/no-unexpected-string-bool.js b/tests/rules/no-unexpected-string-bool.js index 5345f1a..ff871a3 100644 --- a/tests/rules/no-unexpected-string-bool.js +++ b/tests/rules/no-unexpected-string-bool.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-unexpected-string-bool"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("no-unexpected-string-bool", rule, { valid: [ diff --git a/tests/rules/no-unnecessary-block.js b/tests/rules/no-unnecessary-block.js index 2b6e58e..7d9ae2f 100644 --- a/tests/rules/no-unnecessary-block.js +++ b/tests/rules/no-unnecessary-block.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-unnecessary-block"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("no-unnecessary-block", rule, { valid: [ diff --git a/tests/rules/no-vue-directive.js b/tests/rules/no-vue-directive.js index 8ab6128..1a9ac22 100644 --- a/tests/rules/no-vue-directive.js +++ b/tests/rules/no-vue-directive.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-vue-directive"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("no-vue-directive", rule, { valid: [ diff --git a/tests/rules/no-wx-for-with-wx-else.js b/tests/rules/no-wx-for-with-wx-else.js index 4fe4a93..092f998 100644 --- a/tests/rules/no-wx-for-with-wx-else.js +++ b/tests/rules/no-wx-for-with-wx-else.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-wx-for-with-wx-else"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("no-wx-for-with-wx-else", rule, { valid: [ diff --git a/tests/rules/no-wx-for-with-wx-if.js b/tests/rules/no-wx-for-with-wx-if.js index 0f8bb6e..7c70ddb 100644 --- a/tests/rules/no-wx-for-with-wx-if.js +++ b/tests/rules/no-wx-for-with-wx-if.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-wx-for-with-wx-if"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("no-wx-for-with-wx-if", rule, { valid: [ diff --git a/tests/rules/no-wx-if-string.js b/tests/rules/no-wx-if-string.js index 9241972..d10c59f 100644 --- a/tests/rules/no-wx-if-string.js +++ b/tests/rules/no-wx-if-string.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-wx-if-string"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("no-wx-if-string", rule, { valid: [ diff --git a/tests/rules/omit-bool-attributes.js b/tests/rules/omit-bool-attributes.js index 6731d09..1633461 100644 --- a/tests/rules/omit-bool-attributes.js +++ b/tests/rules/omit-bool-attributes.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/omit-bool-attributes"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("omit-bool-attributes", rule, { valid: [ diff --git a/tests/rules/quotes.js b/tests/rules/quotes.js index 2d23e32..97b0d2e 100644 --- a/tests/rules/quotes.js +++ b/tests/rules/quotes.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/quotes"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("quotes", rule, { valid: [ diff --git a/tests/rules/report-interpolation-error.js b/tests/rules/report-interpolation-error.js index 58906f9..71d1690 100644 --- a/tests/rules/report-interpolation-error.js +++ b/tests/rules/report-interpolation-error.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/report-interpolation-error"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("report-interpolation-error", rule, { valid: [ diff --git a/tests/rules/report-wxml-syntax-error.js b/tests/rules/report-wxml-syntax-error.js index 5b613ca..6722a7a 100644 --- a/tests/rules/report-wxml-syntax-error.js +++ b/tests/rules/report-wxml-syntax-error.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/report-wxml-syntax-error"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("report-wxml-syntax-error", rule, { valid: [ diff --git a/tests/rules/report-wxs-syntax-error.js b/tests/rules/report-wxs-syntax-error.js index 0200b67..4d58115 100644 --- a/tests/rules/report-wxs-syntax-error.js +++ b/tests/rules/report-wxs-syntax-error.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/report-wxs-syntax-error"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("report-wxs-syntax-error", rule, { valid: [ diff --git a/tests/rules/required-attributes.js b/tests/rules/required-attributes.js index 743dc04..fb23ba5 100644 --- a/tests/rules/required-attributes.js +++ b/tests/rules/required-attributes.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/required-attributes"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("required-attributes", rule, { valid: [ diff --git a/tests/rules/required-root-tag.js b/tests/rules/required-root-tag.js index 7e73599..3624215 100644 --- a/tests/rules/required-root-tag.js +++ b/tests/rules/required-root-tag.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/required-root-tag"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("required-root-tag", rule, { valid: [ diff --git a/tests/rules/required-tags.js b/tests/rules/required-tags.js index 42701f0..1b2aab7 100644 --- a/tests/rules/required-tags.js +++ b/tests/rules/required-tags.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/required-tags"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("required-tags", rule, { valid: [ diff --git a/tests/rules/wx-key.js b/tests/rules/wx-key.js index e9a5226..3377e02 100644 --- a/tests/rules/wx-key.js +++ b/tests/rules/wx-key.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/wx-key"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("wx-key", rule, { valid: [ diff --git a/tests/rules/wxs-module-prop.js b/tests/rules/wxs-module-prop.js index 8e92cc7..d5043a4 100644 --- a/tests/rules/wxs-module-prop.js +++ b/tests/rules/wxs-module-prop.js @@ -1,9 +1,7 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/wxs-module-prop"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); + tester.run("wxs-module-prop", rule, { valid: [ diff --git a/tests/rules/wxs-must-be-top-level.js b/tests/rules/wxs-must-be-top-level.js index 4576fe5..a20cfb8 100644 --- a/tests/rules/wxs-must-be-top-level.js +++ b/tests/rules/wxs-must-be-top-level.js @@ -1,10 +1,6 @@ -const RuleTester = require("eslint").RuleTester; +const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/wxs-must-be-top-level"); -const tester = new RuleTester({ - parser: require.resolve("@wxml/parser"), -}); - tester.run("wxs-must-be-top-level", rule, { valid: [ { From d493a0b5908f9414e3e4f1d0c53257409f819d61 Mon Sep 17 00:00:00 2001 From: iChenLei Date: Fri, 19 Apr 2024 16:44:57 +0800 Subject: [PATCH 06/10] fix: add semver --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c88ea7..e25f080 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,6 +45,7 @@ jobs: with: {node-version: '${{ env.NODE_VERSION }}'} - run: npm install - run: npm install eslint@9 + - run: npm install semver - run: npm run lint - run: npm run test @@ -58,6 +59,7 @@ jobs: with: {node-version: '${{ env.NODE_VERSION }}'} - run: npm install - run: npm install eslint@8 + - run: npm install semver - run: npm run lint - run: npm run test From 091474efdec606e22161111442d5a3bdeb388b0f Mon Sep 17 00:00:00 2001 From: iChenLei Date: Fri, 19 Apr 2024 17:02:40 +0800 Subject: [PATCH 07/10] fix: Stricter RuleTester validations --- lib/rules/no-unexpected-string-bool.js | 4 ++++ lib/rules/omit-bool-attributes.js | 6 +++++- lib/rules/report-interpolation-error.js | 6 +++--- tests/rule-tester-compat.js | 16 ++++++++-------- tests/rules/colon-style-event-binding.js | 2 -- tests/rules/empty-tag-self-closing.js | 2 -- tests/rules/event-binding-style.js | 2 -- tests/rules/forbid-attributes.js | 2 -- tests/rules/forbid-tags.js | 2 -- tests/rules/max-depth.js | 2 -- tests/rules/max-len.js | 2 -- tests/rules/max-lines.js | 2 -- tests/rules/no-const-and-let-in-wxs.js | 2 -- tests/rules/no-dot-this-in-wx-key.js | 2 -- tests/rules/no-duplicate-attributes.js | 2 -- tests/rules/no-dynamic-wx-key.js | 2 -- tests/rules/no-inconsistent-tagname.js | 2 -- tests/rules/no-index-in-wx-key.js | 2 -- tests/rules/no-inline-wxs.js | 2 -- tests/rules/no-unexpected-string-bool.js | 2 -- tests/rules/no-unnecessary-block.js | 2 -- tests/rules/no-vue-directive.js | 2 -- tests/rules/no-wx-for-with-wx-else.js | 2 -- tests/rules/no-wx-for-with-wx-if.js | 2 -- tests/rules/no-wx-if-string.js | 2 -- tests/rules/omit-bool-attributes.js | 2 -- tests/rules/quotes.js | 2 -- tests/rules/report-interpolation-error.js | 2 -- tests/rules/report-wxml-syntax-error.js | 2 -- tests/rules/report-wxs-syntax-error.js | 2 -- tests/rules/required-attributes.js | 2 -- tests/rules/required-root-tag.js | 2 -- tests/rules/required-tags.js | 2 -- tests/rules/wx-key.js | 2 -- tests/rules/wxs-module-prop.js | 2 -- 35 files changed, 20 insertions(+), 74 deletions(-) diff --git a/lib/rules/no-unexpected-string-bool.js b/lib/rules/no-unexpected-string-bool.js index d1c815f..8d8fa78 100644 --- a/lib/rules/no-unexpected-string-bool.js +++ b/lib/rules/no-unexpected-string-bool.js @@ -24,6 +24,10 @@ module.exports = { if (node.value === "true" || node.value === "false") { context.report({ node, + data: { + true: "true", + false: "false", + }, messageId: node.value === "true" ? "trueString" : "falseString", }); } diff --git a/lib/rules/omit-bool-attributes.js b/lib/rules/omit-bool-attributes.js index 93d91ce..bcf445e 100644 --- a/lib/rules/omit-bool-attributes.js +++ b/lib/rules/omit-bool-attributes.js @@ -24,7 +24,11 @@ module.exports = { context.report({ node, messageId: "omitWarn", - data: { attrKey: node.key }, + data: { + attrKey: node.key, + true: "true", + false: "false", + }, }); } } diff --git a/lib/rules/report-interpolation-error.js b/lib/rules/report-interpolation-error.js index 8b9956e..fe58f75 100644 --- a/lib/rules/report-interpolation-error.js +++ b/lib/rules/report-interpolation-error.js @@ -24,7 +24,7 @@ module.exports = { } try { espreeParser = require("espree"); - // eslint-disable-next-line no-unused-vars + // eslint-disable-next-line no-unused-vars } catch (_) { // ... } @@ -38,13 +38,13 @@ module.exports = { espreeParser.parse(`({${node.value}})`, { ecmaVersion: espreeParser.latestEcmaVersion, }); - // eslint-disable-next-line no-unused-vars + // eslint-disable-next-line no-unused-vars } catch (_) { try { espreeParser.parse(`(${node.value})`, { ecmaVersion: espreeParser.latestEcmaVersion, }); - // eslint-disable-next-line no-unused-vars + // eslint-disable-next-line no-unused-vars } catch (_) { context.report({ node, diff --git a/tests/rule-tester-compat.js b/tests/rule-tester-compat.js index 6334495..dcb251b 100644 --- a/tests/rule-tester-compat.js +++ b/tests/rule-tester-compat.js @@ -1,12 +1,12 @@ const eslint = require("eslint"); const semver = require("semver"); -const ruleTester = semver.gte(eslint.Linter.version, '9.0.0-0') ? - new eslint.RuleTester({ - languageOptions: { - parser: require("@wxml/parser"), - }, - }) : - new eslint.RuleTester({ parser: require.resolve("@wxml/parser") }); +const ruleTester = semver.gte(eslint.Linter.version, "9.0.0-0") + ? new eslint.RuleTester({ + languageOptions: { + parser: require("@wxml/parser"), + }, + }) + : new eslint.RuleTester({ parser: require.resolve("@wxml/parser") }); -module.exports.RuleTester = ruleTester; \ No newline at end of file +module.exports.RuleTester = ruleTester; diff --git a/tests/rules/colon-style-event-binding.js b/tests/rules/colon-style-event-binding.js index b781e33..0f94c40 100644 --- a/tests/rules/colon-style-event-binding.js +++ b/tests/rules/colon-style-event-binding.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/colon-style-event-binding"); - - tester.run("colon-style-event-binding", rule, { valid: [ { diff --git a/tests/rules/empty-tag-self-closing.js b/tests/rules/empty-tag-self-closing.js index 9bc65d8..26a213f 100644 --- a/tests/rules/empty-tag-self-closing.js +++ b/tests/rules/empty-tag-self-closing.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/empty-tag-self-closing"); - - tester.run("empty-tag-self-closing", rule, { valid: [ { diff --git a/tests/rules/event-binding-style.js b/tests/rules/event-binding-style.js index 20d65a8..492d90b 100644 --- a/tests/rules/event-binding-style.js +++ b/tests/rules/event-binding-style.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/event-binding-style"); - - tester.run("event-binding-style", rule, { valid: [ { diff --git a/tests/rules/forbid-attributes.js b/tests/rules/forbid-attributes.js index d9f2743..e480aef 100644 --- a/tests/rules/forbid-attributes.js +++ b/tests/rules/forbid-attributes.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/forbid-attributes"); - - tester.run("forbid-attributes", rule, { valid: [ { diff --git a/tests/rules/forbid-tags.js b/tests/rules/forbid-tags.js index 0a82be9..50391d4 100644 --- a/tests/rules/forbid-tags.js +++ b/tests/rules/forbid-tags.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/forbid-tags"); - - tester.run("forbid-tags", rule, { valid: [ { diff --git a/tests/rules/max-depth.js b/tests/rules/max-depth.js index 4629e5b..8e423a6 100644 --- a/tests/rules/max-depth.js +++ b/tests/rules/max-depth.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/max-depth"); - - tester.run("max-depth", rule, { valid: [ { diff --git a/tests/rules/max-len.js b/tests/rules/max-len.js index 37b8f30..98c8734 100644 --- a/tests/rules/max-len.js +++ b/tests/rules/max-len.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/max-len"); - - tester.run("max-len", rule, { valid: [ { diff --git a/tests/rules/max-lines.js b/tests/rules/max-lines.js index a0b9d01..82c5da8 100644 --- a/tests/rules/max-lines.js +++ b/tests/rules/max-lines.js @@ -3,8 +3,6 @@ const path = require("path"); const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/max-lines"); - - function readFixureFiles(filename) { if (filename) { return fs.readFileSync( diff --git a/tests/rules/no-const-and-let-in-wxs.js b/tests/rules/no-const-and-let-in-wxs.js index 226c11f..afd60d5 100644 --- a/tests/rules/no-const-and-let-in-wxs.js +++ b/tests/rules/no-const-and-let-in-wxs.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-const-and-let-in-wxs"); - - tester.run("no-const-and-let-in-wxs", rule, { valid: [ { diff --git a/tests/rules/no-dot-this-in-wx-key.js b/tests/rules/no-dot-this-in-wx-key.js index fa01f18..cd59647 100644 --- a/tests/rules/no-dot-this-in-wx-key.js +++ b/tests/rules/no-dot-this-in-wx-key.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-dot-this-in-wx-key"); - - tester.run("no-dot-this-in-wx-key", rule, { valid: [ { diff --git a/tests/rules/no-duplicate-attributes.js b/tests/rules/no-duplicate-attributes.js index bc6ed38..02dd905 100644 --- a/tests/rules/no-duplicate-attributes.js +++ b/tests/rules/no-duplicate-attributes.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-duplicate-attributes"); - - tester.run("no-duplicate-attributes", rule, { valid: [ { diff --git a/tests/rules/no-dynamic-wx-key.js b/tests/rules/no-dynamic-wx-key.js index 4afb429..15079d9 100644 --- a/tests/rules/no-dynamic-wx-key.js +++ b/tests/rules/no-dynamic-wx-key.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-dynamic-wx-key"); - - tester.run("no-dynamic-wx-key", rule, { valid: [ { diff --git a/tests/rules/no-inconsistent-tagname.js b/tests/rules/no-inconsistent-tagname.js index e7c0870..e87323e 100644 --- a/tests/rules/no-inconsistent-tagname.js +++ b/tests/rules/no-inconsistent-tagname.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-inconsistent-tagname"); - - tester.run("no-inconsistent-tagname", rule, { valid: [ { diff --git a/tests/rules/no-index-in-wx-key.js b/tests/rules/no-index-in-wx-key.js index c58d4f6..7e95420 100644 --- a/tests/rules/no-index-in-wx-key.js +++ b/tests/rules/no-index-in-wx-key.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-index-in-wx-key"); - - tester.run("no-index-in-wx-key", rule, { valid: [ { diff --git a/tests/rules/no-inline-wxs.js b/tests/rules/no-inline-wxs.js index 8e47d1b..9ad920a 100644 --- a/tests/rules/no-inline-wxs.js +++ b/tests/rules/no-inline-wxs.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-inline-wxs"); - - tester.run("no-inline-wxs", rule, { valid: [ { diff --git a/tests/rules/no-unexpected-string-bool.js b/tests/rules/no-unexpected-string-bool.js index ff871a3..1965273 100644 --- a/tests/rules/no-unexpected-string-bool.js +++ b/tests/rules/no-unexpected-string-bool.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-unexpected-string-bool"); - - tester.run("no-unexpected-string-bool", rule, { valid: [ { diff --git a/tests/rules/no-unnecessary-block.js b/tests/rules/no-unnecessary-block.js index 7d9ae2f..ab09d71 100644 --- a/tests/rules/no-unnecessary-block.js +++ b/tests/rules/no-unnecessary-block.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-unnecessary-block"); - - tester.run("no-unnecessary-block", rule, { valid: [ { diff --git a/tests/rules/no-vue-directive.js b/tests/rules/no-vue-directive.js index 1a9ac22..18edd6d 100644 --- a/tests/rules/no-vue-directive.js +++ b/tests/rules/no-vue-directive.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-vue-directive"); - - tester.run("no-vue-directive", rule, { valid: [ { diff --git a/tests/rules/no-wx-for-with-wx-else.js b/tests/rules/no-wx-for-with-wx-else.js index 092f998..85999b4 100644 --- a/tests/rules/no-wx-for-with-wx-else.js +++ b/tests/rules/no-wx-for-with-wx-else.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-wx-for-with-wx-else"); - - tester.run("no-wx-for-with-wx-else", rule, { valid: [ { diff --git a/tests/rules/no-wx-for-with-wx-if.js b/tests/rules/no-wx-for-with-wx-if.js index 7c70ddb..424771e 100644 --- a/tests/rules/no-wx-for-with-wx-if.js +++ b/tests/rules/no-wx-for-with-wx-if.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-wx-for-with-wx-if"); - - tester.run("no-wx-for-with-wx-if", rule, { valid: [ { diff --git a/tests/rules/no-wx-if-string.js b/tests/rules/no-wx-if-string.js index d10c59f..a17df82 100644 --- a/tests/rules/no-wx-if-string.js +++ b/tests/rules/no-wx-if-string.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/no-wx-if-string"); - - tester.run("no-wx-if-string", rule, { valid: [ { diff --git a/tests/rules/omit-bool-attributes.js b/tests/rules/omit-bool-attributes.js index 1633461..b7b7aaf 100644 --- a/tests/rules/omit-bool-attributes.js +++ b/tests/rules/omit-bool-attributes.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/omit-bool-attributes"); - - tester.run("omit-bool-attributes", rule, { valid: [ { diff --git a/tests/rules/quotes.js b/tests/rules/quotes.js index 97b0d2e..113d390 100644 --- a/tests/rules/quotes.js +++ b/tests/rules/quotes.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/quotes"); - - tester.run("quotes", rule, { valid: [ { diff --git a/tests/rules/report-interpolation-error.js b/tests/rules/report-interpolation-error.js index 71d1690..3c12cfc 100644 --- a/tests/rules/report-interpolation-error.js +++ b/tests/rules/report-interpolation-error.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/report-interpolation-error"); - - tester.run("report-interpolation-error", rule, { valid: [ { diff --git a/tests/rules/report-wxml-syntax-error.js b/tests/rules/report-wxml-syntax-error.js index 6722a7a..cb957fd 100644 --- a/tests/rules/report-wxml-syntax-error.js +++ b/tests/rules/report-wxml-syntax-error.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/report-wxml-syntax-error"); - - tester.run("report-wxml-syntax-error", rule, { valid: [ { diff --git a/tests/rules/report-wxs-syntax-error.js b/tests/rules/report-wxs-syntax-error.js index 4d58115..4323694 100644 --- a/tests/rules/report-wxs-syntax-error.js +++ b/tests/rules/report-wxs-syntax-error.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/report-wxs-syntax-error"); - - tester.run("report-wxs-syntax-error", rule, { valid: [ { diff --git a/tests/rules/required-attributes.js b/tests/rules/required-attributes.js index fb23ba5..bc3b6ea 100644 --- a/tests/rules/required-attributes.js +++ b/tests/rules/required-attributes.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/required-attributes"); - - tester.run("required-attributes", rule, { valid: [ { diff --git a/tests/rules/required-root-tag.js b/tests/rules/required-root-tag.js index 3624215..554f89a 100644 --- a/tests/rules/required-root-tag.js +++ b/tests/rules/required-root-tag.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/required-root-tag"); - - tester.run("required-root-tag", rule, { valid: [ { diff --git a/tests/rules/required-tags.js b/tests/rules/required-tags.js index 1b2aab7..55b3bc1 100644 --- a/tests/rules/required-tags.js +++ b/tests/rules/required-tags.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/required-tags"); - - tester.run("required-tags", rule, { valid: [ { diff --git a/tests/rules/wx-key.js b/tests/rules/wx-key.js index 3377e02..9780830 100644 --- a/tests/rules/wx-key.js +++ b/tests/rules/wx-key.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/wx-key"); - - tester.run("wx-key", rule, { valid: [ { diff --git a/tests/rules/wxs-module-prop.js b/tests/rules/wxs-module-prop.js index d5043a4..b19ccbb 100644 --- a/tests/rules/wxs-module-prop.js +++ b/tests/rules/wxs-module-prop.js @@ -1,8 +1,6 @@ const tester = require("../rule-tester-compat").RuleTester; const rule = require("../../lib/rules/wxs-module-prop"); - - tester.run("wxs-module-prop", rule, { valid: [ { From 3e1a3499c44a29738237edf5883249ae8ea21d39 Mon Sep 17 00:00:00 2001 From: iChenLei Date: Fri, 19 Apr 2024 17:07:54 +0800 Subject: [PATCH 08/10] fix: error message --- lib/rules/no-unexpected-string-bool.js | 4 ++-- lib/rules/omit-bool-attributes.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/rules/no-unexpected-string-bool.js b/lib/rules/no-unexpected-string-bool.js index 8d8fa78..ef6e87d 100644 --- a/lib/rules/no-unexpected-string-bool.js +++ b/lib/rules/no-unexpected-string-bool.js @@ -10,8 +10,8 @@ module.exports = { fixable: null, messages: { trueString: - "don't use true string as value, omitted it or use {{true}} instead", - falseString: "don't use false string as value, use {{false}} instead", + "don't use true string as value, omitted it or use {{{{true}}}} instead", + falseString: "don't use false string as value, use {{{{false}}}} instead", }, schema: [], }, diff --git a/lib/rules/omit-bool-attributes.js b/lib/rules/omit-bool-attributes.js index bcf445e..9e2077e 100644 --- a/lib/rules/omit-bool-attributes.js +++ b/lib/rules/omit-bool-attributes.js @@ -10,7 +10,7 @@ module.exports = { fixable: null, messages: { omitWarn: - "please omit {{true}}, it means convert to ", + "please omit {{{{true}}}}, it means convert to ", }, schema: [], }, From b7339ecc7927a5bbe685f957ce25da07696f8c79 Mon Sep 17 00:00:00 2001 From: iChenLei Date: Fri, 19 Apr 2024 17:13:49 +0800 Subject: [PATCH 09/10] fix: false val with brackets --- lib/rules/no-unexpected-string-bool.js | 8 ++++---- lib/rules/omit-bool-attributes.js | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/rules/no-unexpected-string-bool.js b/lib/rules/no-unexpected-string-bool.js index ef6e87d..6b8fcec 100644 --- a/lib/rules/no-unexpected-string-bool.js +++ b/lib/rules/no-unexpected-string-bool.js @@ -10,8 +10,8 @@ module.exports = { fixable: null, messages: { trueString: - "don't use true string as value, omitted it or use {{{{true}}}} instead", - falseString: "don't use false string as value, use {{{{false}}}} instead", + "don't use true string as value, omitted it or use {{true}} instead", + falseString: "don't use false string as value, use {{false}} instead", }, schema: [], }, @@ -25,8 +25,8 @@ module.exports = { context.report({ node, data: { - true: "true", - false: "false", + true: "{{true}}", + false: "{{false}}", }, messageId: node.value === "true" ? "trueString" : "falseString", }); diff --git a/lib/rules/omit-bool-attributes.js b/lib/rules/omit-bool-attributes.js index 9e2077e..aafc2e8 100644 --- a/lib/rules/omit-bool-attributes.js +++ b/lib/rules/omit-bool-attributes.js @@ -10,7 +10,7 @@ module.exports = { fixable: null, messages: { omitWarn: - "please omit {{{{true}}}}, it means convert to ", + "please omit {{true}}, it means convert to ", }, schema: [], }, @@ -26,8 +26,8 @@ module.exports = { messageId: "omitWarn", data: { attrKey: node.key, - true: "true", - false: "false", + true: "{{true}}", + false: "{{false}}", }, }); } From ccafa9eada04e9896262323120d66ce8d95c2aee Mon Sep 17 00:00:00 2001 From: iChenLei Date: Fri, 19 Apr 2024 17:20:56 +0800 Subject: [PATCH 10/10] fix: eslint9 strict ruletester --- tests/rules/no-unexpected-string-bool.js | 30 +++++++++++++++++++++--- tests/rules/omit-bool-attributes.js | 8 +++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/tests/rules/no-unexpected-string-bool.js b/tests/rules/no-unexpected-string-bool.js index 1965273..d4165a4 100644 --- a/tests/rules/no-unexpected-string-bool.js +++ b/tests/rules/no-unexpected-string-bool.js @@ -20,17 +20,41 @@ tester.run("no-unexpected-string-bool", rule, { { filename: "test.wxml", code: ``, - errors: [{ messageId: "trueString" }], + errors: [ + { + messageId: "trueString", + data: { + true: "{{true}}", + false: "{{false}}", + }, + }, + ], }, { filename: "test.wxml", code: ``, - errors: [{ messageId: "falseString" }], + errors: [ + { + messageId: "falseString", + data: { + true: "{{true}}", + false: "{{false}}", + }, + }, + ], }, { filename: "test.wxml", code: ``, - errors: [{ messageId: "falseString" }], + errors: [ + { + messageId: "falseString", + data: { + true: "{{true}}", + false: "{{false}}", + }, + }, + ], }, ], }); diff --git a/tests/rules/omit-bool-attributes.js b/tests/rules/omit-bool-attributes.js index b7b7aaf..2046273 100644 --- a/tests/rules/omit-bool-attributes.js +++ b/tests/rules/omit-bool-attributes.js @@ -33,6 +33,8 @@ tester.run("omit-bool-attributes", rule, { messageId: "omitWarn", data: { attrKey: "autoplay", + true: "{{true}}", + false: "{{false}}", }, }, ], @@ -45,6 +47,8 @@ tester.run("omit-bool-attributes", rule, { messageId: "omitWarn", data: { attrKey: "autoplay", + true: "{{true}}", + false: "{{false}}", }, }, ], @@ -57,6 +61,8 @@ tester.run("omit-bool-attributes", rule, { messageId: "omitWarn", data: { attrKey: "autoplay", + true: "{{true}}", + false: "{{false}}", }, }, ], @@ -69,6 +75,8 @@ tester.run("omit-bool-attributes", rule, { messageId: "omitWarn", data: { attrKey: "autoplay", + true: "{{true}}", + false: "{{false}}", }, }, ],