From de53d1e0303013cc6caf7ee0a8abc8539727cd2c Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 15 Jan 2024 22:50:32 +0900 Subject: [PATCH] fix(deps): update dependency eslint-compat-utils to ^0.2.0 (#292) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Yosuke Ota --- .changeset/famous-bugs-listen.md | 5 +++ .github/workflows/NodeCI.yml | 13 ++++++ package.json | 2 +- tests/fixtures/indent/vue-sfc-01.vue | 2 +- tests/lib/as-parser.ts | 4 +- tests/lib/auto-rule.ts | 4 +- tests/lib/eslint-plugin.ts | 4 +- tests/lib/rules/array-bracket-newline.ts | 14 ++++-- tests/lib/rules/array-bracket-spacing.ts | 14 ++++-- tests/lib/rules/array-element-newline.ts | 14 ++++-- tests/lib/rules/auto.ts | 26 ++++++++--- tests/lib/rules/comma-dangle.ts | 14 ++++-- tests/lib/rules/comma-style.ts | 14 ++++-- tests/lib/rules/indent.ts | 28 ++++++++---- tests/lib/rules/key-name-casing.ts | 7 +-- tests/lib/rules/key-spacing.ts | 14 ++++-- tests/lib/rules/no-bigint-literals.ts | 14 ++++-- tests/lib/rules/no-binary-expression.ts | 7 +-- tests/lib/rules/no-binary-numeric-literals.ts | 7 +-- tests/lib/rules/no-comments.ts | 14 ++++-- tests/lib/rules/no-dupe-keys.ts | 14 ++++-- .../rules/no-escape-sequence-in-identifier.ts | 7 +-- tests/lib/rules/no-floating-decimal.ts | 7 +-- .../rules/no-hexadecimal-numeric-literals.ts | 7 +-- tests/lib/rules/no-infinity.ts | 7 +-- tests/lib/rules/no-irregular-whitespace.ts | 7 +-- tests/lib/rules/no-multi-str.ts | 16 +++++-- tests/lib/rules/no-nan.ts | 7 +-- tests/lib/rules/no-number-props.ts | 14 ++++-- tests/lib/rules/no-numeric-separators.ts | 14 ++++-- tests/lib/rules/no-octal-escape.ts | 20 +++++++-- tests/lib/rules/no-octal-numeric-literals.ts | 7 +-- tests/lib/rules/no-octal.ts | 17 +++++-- tests/lib/rules/no-parenthesized.ts | 7 +-- tests/lib/rules/no-plus-sign.ts | 7 +-- tests/lib/rules/no-regexp-literals.ts | 14 ++++-- tests/lib/rules/no-sparse-arrays.ts | 14 ++++-- tests/lib/rules/no-template-literals.ts | 14 ++++-- tests/lib/rules/no-undefined-value.ts | 14 ++++-- .../lib/rules/no-unicode-codepoint-escapes.ts | 7 +-- tests/lib/rules/no-useless-escape.ts | 14 ++++-- tests/lib/rules/object-curly-newline.ts | 14 ++++-- tests/lib/rules/object-curly-spacing.ts | 14 ++++-- tests/lib/rules/object-property-newline.ts | 14 ++++-- tests/lib/rules/quote-props.ts | 14 ++++-- tests/lib/rules/quotes.ts | 14 ++++-- tests/lib/rules/sort-array-values.ts | 7 +-- tests/lib/rules/sort-keys.ts | 14 ++++-- tests/lib/rules/space-unary-ops.ts | 14 ++++-- tests/lib/rules/valid-json-number.ts | 14 ++++-- .../vue-custom-block/no-parsing-error.ts | 44 +++++++++++++++---- tests/lib/test-lib/eslint-compat.ts | 6 +++ tools/new-rule.ts | 11 ++--- tsconfig.json | 2 +- 54 files changed, 472 insertions(+), 166 deletions(-) create mode 100644 .changeset/famous-bugs-listen.md create mode 100644 tests/lib/test-lib/eslint-compat.ts diff --git a/.changeset/famous-bugs-listen.md b/.changeset/famous-bugs-listen.md new file mode 100644 index 00000000..14768745 --- /dev/null +++ b/.changeset/famous-bugs-listen.md @@ -0,0 +1,5 @@ +--- +"eslint-plugin-jsonc": minor +--- + +fix(deps): update dependency eslint-compat-utils to ^0.2.0 diff --git a/.github/workflows/NodeCI.yml b/.github/workflows/NodeCI.yml index d9285cb1..64501fe5 100644 --- a/.github/workflows/NodeCI.yml +++ b/.github/workflows/NodeCI.yml @@ -87,6 +87,19 @@ jobs: npm install - name: Test run: npm test + test-with-eslint9: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Use Node.js + uses: actions/setup-node@v4 + - name: Install Target Packages + run: |+ + npm i -D eslint@^9.0.0-0 --legacy-peer-deps + npx rimraf node_modules + npm install --legacy-peer-deps + - name: Test + run: npm test test-with-eslint7: runs-on: ubuntu-latest strategy: diff --git a/package.json b/package.json index 83fe39d3..2a98639b 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "homepage": "https://ota-meshi.github.io/eslint-plugin-jsonc/", "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", - "eslint-compat-utils": "^0.1.2", + "eslint-compat-utils": "^0.2.0", "espree": "^9.6.1", "graphemer": "^1.4.0", "jsonc-eslint-parser": "^2.0.4", diff --git a/tests/fixtures/indent/vue-sfc-01.vue b/tests/fixtures/indent/vue-sfc-01.vue index 874c355d..9d7d3d35 100644 --- a/tests/fixtures/indent/vue-sfc-01.vue +++ b/tests/fixtures/indent/vue-sfc-01.vue @@ -1,4 +1,4 @@ - + { "key": "value" diff --git a/tests/lib/as-parser.ts b/tests/lib/as-parser.ts index 83cfa9bd..a05b1460 100644 --- a/tests/lib/as-parser.ts +++ b/tests/lib/as-parser.ts @@ -1,8 +1,8 @@ import path from "path"; import assert from "assert"; import plugin from "../../lib/index"; -import { getESLint } from "eslint-compat-utils"; -const ESLint = getESLint(); +import { getLegacyESLint } from "eslint-compat-utils/eslint"; +const ESLint = getLegacyESLint(); // ----------------------------------------------------------------------------- // Tests diff --git a/tests/lib/auto-rule.ts b/tests/lib/auto-rule.ts index 0a82b6a3..c61d3463 100644 --- a/tests/lib/auto-rule.ts +++ b/tests/lib/auto-rule.ts @@ -2,8 +2,8 @@ import path from "path"; import fs from "fs"; import assert from "assert"; import plugin from "../../lib/index"; -import { getESLint } from "eslint-compat-utils"; -const ESLint = getESLint(); +import { getLegacyESLint } from "eslint-compat-utils/eslint"; +const ESLint = getLegacyESLint(); // ----------------------------------------------------------------------------- // Tests diff --git a/tests/lib/eslint-plugin.ts b/tests/lib/eslint-plugin.ts index 08dd795b..ebf064ed 100644 --- a/tests/lib/eslint-plugin.ts +++ b/tests/lib/eslint-plugin.ts @@ -1,8 +1,8 @@ import path from "path"; import assert from "assert"; import plugin from "../../lib/index"; -import { getESLint } from "eslint-compat-utils"; -const ESLint = getESLint(); +import { getLegacyESLint } from "eslint-compat-utils/eslint"; +const ESLint = getLegacyESLint(); // ----------------------------------------------------------------------------- // Tests diff --git a/tests/lib/rules/array-bracket-newline.ts b/tests/lib/rules/array-bracket-newline.ts index 0fb03a62..5082b1fc 100644 --- a/tests/lib/rules/array-bracket-newline.ts +++ b/tests/lib/rules/array-bracket-newline.ts @@ -1,8 +1,12 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/array-bracket-newline"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), + languageOptions: { + parser: jsonParser, + }, }); tester.run("array-bracket-newline", rule as any, { @@ -28,13 +32,17 @@ tester.run("array-bracket-newline", rule as any, { filename: "test.vue", code: `[1,\n2][\n1\n]`, output: `[\n1,\n2\n][1]`, - parser: require.resolve("vue-eslint-parser"), errors: [ "A linebreak is required after '['.", "A linebreak is required before ']'.", "There should be no linebreak after '['.", "There should be no linebreak before ']'.", ], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, ], }); diff --git a/tests/lib/rules/array-bracket-spacing.ts b/tests/lib/rules/array-bracket-spacing.ts index bcc6316d..5311e34b 100644 --- a/tests/lib/rules/array-bracket-spacing.ts +++ b/tests/lib/rules/array-bracket-spacing.ts @@ -1,8 +1,12 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/array-bracket-spacing"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), + languageOptions: { + parser: jsonParser, + }, }); tester.run("array-bracket-spacing", rule as any, { @@ -210,13 +214,17 @@ tester.run("array-bracket-spacing", rule as any, { filename: "test.vue", code: `[ 1, 2 ][ 1 ]`, output: `[1, 2][1]`, - parser: require.resolve("vue-eslint-parser"), errors: [ "There should be no space after '['.", "There should be no space before ']'.", "There should be no space after '['.", "There should be no space before ']'.", ], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, { code: "[ ]", diff --git a/tests/lib/rules/array-element-newline.ts b/tests/lib/rules/array-element-newline.ts index 7a166fbf..509644bc 100644 --- a/tests/lib/rules/array-element-newline.ts +++ b/tests/lib/rules/array-element-newline.ts @@ -1,8 +1,12 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/array-element-newline"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), + languageOptions: { + parser: jsonParser, + }, }); tester.run("array-element-newline", rule as any, { @@ -30,13 +34,17 @@ tester.run("array-element-newline", rule as any, { 3][1, 2, 3]`, - parser: require.resolve("vue-eslint-parser"), errors: [ "There should be a linebreak after this element.", "There should be a linebreak after this element.", "There should be a linebreak after this element.", "There should be a linebreak after this element.", ], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, ], }); diff --git a/tests/lib/rules/auto.ts b/tests/lib/rules/auto.ts index b1181cf9..a8a3a97c 100644 --- a/tests/lib/rules/auto.ts +++ b/tests/lib/rules/auto.ts @@ -1,10 +1,12 @@ import path from "path"; -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/auto"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), - parserOptions: { + languageOptions: { + parser: jsonParser, ecmaVersion: 2020, }, }); @@ -21,7 +23,11 @@ tester.run("auto", rule as any, { "foo": "bar" } `, - parser: require.resolve("vue-eslint-parser"), + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, { filename: path.join(ROOT_DIR, "test03", "test.json"), @@ -75,7 +81,6 @@ tester.run("auto", rule as any, { "bar": 2, "foo": 3} `, - parser: require.resolve("vue-eslint-parser"), errors: [ "[jsonc/indent] Expected indentation of 4 spaces but found 0.", "[jsonc/indent] Expected indentation of 0 spaces but found 4.", @@ -99,6 +104,11 @@ tester.run("auto", rule as any, { "[jsonc/no-dupe-keys] Duplicate key 'foo'.", "[jsonc/object-curly-spacing] There should be no space before '}'.", ], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, { filename: path.join(ROOT_DIR, "test02", "sfc.vue"), @@ -114,11 +124,15 @@ tester.run("auto", rule as any, { "foo": "bar" } `, - parser: require.resolve("vue-eslint-parser"), errors: [ "[jsonc/indent] Expected indentation of 4 spaces but found 0.", "[jsonc/indent] Expected indentation of 0 spaces but found 4.", ], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, ], }); diff --git a/tests/lib/rules/comma-dangle.ts b/tests/lib/rules/comma-dangle.ts index 6fe7b7ee..2797e253 100644 --- a/tests/lib/rules/comma-dangle.ts +++ b/tests/lib/rules/comma-dangle.ts @@ -1,8 +1,12 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/comma-dangle"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), + languageOptions: { + parser: jsonParser, + }, }); tester.run("comma-dangle", rule as any, { @@ -23,8 +27,12 @@ tester.run("comma-dangle", rule as any, { filename: "test.vue", code: `{"key": "value",}{"key": "value",}`, output: `{"key": "value"}{"key": "value",}`, - parser: require.resolve("vue-eslint-parser"), errors: ["Unexpected trailing comma."], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, ], }); diff --git a/tests/lib/rules/comma-style.ts b/tests/lib/rules/comma-style.ts index ee884e66..833884e2 100644 --- a/tests/lib/rules/comma-style.ts +++ b/tests/lib/rules/comma-style.ts @@ -1,8 +1,12 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/comma-style"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), + languageOptions: { + parser: jsonParser, + }, }); tester.run("comma-style", rule as any, { @@ -70,8 +74,12 @@ tester.run("comma-style", rule as any, { , "b": 2 } }`, - parser: require.resolve("vue-eslint-parser"), errors: ["',' should be placed last.", "',' should be placed last."], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, ], }); diff --git a/tests/lib/rules/indent.ts b/tests/lib/rules/indent.ts index 67c8f7ea..8f18fcbb 100644 --- a/tests/lib/rules/indent.ts +++ b/tests/lib/rules/indent.ts @@ -1,7 +1,9 @@ import fs from "fs"; import path from "path"; -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; +import type { RuleTester as ESLintRuleTester } from "eslint"; import rule from "../../../lib/rules/indent"; +import * as jsonParser from "jsonc-eslint-parser"; // ------------------------------------------------------------------------------ // Helpers @@ -22,8 +24,8 @@ const FIXTURE_ROOT = path.resolve(__dirname, "../../fixtures/indent/"); * */ function loadPatterns( - additionalValid: RuleTester.ValidTestCase[], - additionalInvalid: RuleTester.InvalidTestCase[], + additionalValid: ESLintRuleTester.ValidTestCase[], + additionalInvalid: ESLintRuleTester.InvalidTestCase[], ) { const valid = fs.readdirSync(FIXTURE_ROOT).map((filename) => { const code0 = fs.readFileSync(path.join(FIXTURE_ROOT, filename), "utf8"); @@ -33,12 +35,18 @@ function loadPatterns( const baseObj = JSON.parse( /^(?:\/\*|)/u.exec(code0)![1], ); - if ("parser" in baseObj) { - baseObj.parser = require.resolve(baseObj.parser); + baseObj.languageOptions ??= {}; + if ("parser" in baseObj.languageOptions) { + // eslint-disable-next-line @typescript-eslint/no-require-imports -- ignore + baseObj.languageOptions.parser = require(baseObj.languageOptions.parser); } - if ("parserOptions" in baseObj && "parser" in baseObj.parserOptions) { - baseObj.parserOptions.parser = require.resolve( - baseObj.parserOptions.parser, + if ( + baseObj.languageOptions.parserOptions && + "parser" in baseObj.languageOptions.parserOptions + ) { + // eslint-disable-next-line @typescript-eslint/no-require-imports -- ignore + baseObj.languageOptions.parserOptions.parser = require( + baseObj.languageOptions.parserOptions.parser, ); } return Object.assign(baseObj, { code, filename }); @@ -104,7 +112,9 @@ function unIndent(strings: TemplateStringsArray) { } const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), + languageOptions: { + parser: jsonParser, + }, }); tester.run( diff --git a/tests/lib/rules/key-name-casing.ts b/tests/lib/rules/key-name-casing.ts index 43915a4b..e9d89ff2 100644 --- a/tests/lib/rules/key-name-casing.ts +++ b/tests/lib/rules/key-name-casing.ts @@ -1,9 +1,10 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/key-name-casing"; +import * as jsonParser from "jsonc-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), - parserOptions: { + languageOptions: { + parser: jsonParser, ecmaVersion: 2020, }, }); diff --git a/tests/lib/rules/key-spacing.ts b/tests/lib/rules/key-spacing.ts index 5b2cbc92..419f0083 100644 --- a/tests/lib/rules/key-spacing.ts +++ b/tests/lib/rules/key-spacing.ts @@ -1,8 +1,12 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/key-spacing"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), + languageOptions: { + parser: jsonParser, + }, }); tester.run("key-spacing", rule as any, { @@ -20,11 +24,15 @@ tester.run("key-spacing", rule as any, { filename: "test.vue", code: `{"key" :"value"}`, output: `{"key": "value"}`, - parser: require.resolve("vue-eslint-parser"), errors: [ "Extra space after key 'key'.", "Missing space before value for key 'key'.", ], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, ], }); diff --git a/tests/lib/rules/no-bigint-literals.ts b/tests/lib/rules/no-bigint-literals.ts index 7072390f..820ab205 100644 --- a/tests/lib/rules/no-bigint-literals.ts +++ b/tests/lib/rules/no-bigint-literals.ts @@ -1,9 +1,11 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-bigint-literals"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), - parserOptions: { + languageOptions: { + parser: jsonParser, ecmaVersion: 2020, }, }); @@ -25,8 +27,12 @@ tester.run("no-bigint-literals", rule as any, { { filename: "test.vue", code: `42n`, - parser: require.resolve("vue-eslint-parser"), errors: ["BigInt literals are not allowed."], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, ], }); diff --git a/tests/lib/rules/no-binary-expression.ts b/tests/lib/rules/no-binary-expression.ts index e9dac2fe..a01bad64 100644 --- a/tests/lib/rules/no-binary-expression.ts +++ b/tests/lib/rules/no-binary-expression.ts @@ -1,9 +1,10 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-binary-expression"; +import * as jsonParser from "jsonc-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), - parserOptions: { + languageOptions: { + parser: jsonParser, ecmaVersion: 2020, }, }); diff --git a/tests/lib/rules/no-binary-numeric-literals.ts b/tests/lib/rules/no-binary-numeric-literals.ts index 9590f256..aa40867d 100644 --- a/tests/lib/rules/no-binary-numeric-literals.ts +++ b/tests/lib/rules/no-binary-numeric-literals.ts @@ -1,9 +1,10 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-binary-numeric-literals"; +import * as jsonParser from "jsonc-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), - parserOptions: { + languageOptions: { + parser: jsonParser, ecmaVersion: 2020, }, }); diff --git a/tests/lib/rules/no-comments.ts b/tests/lib/rules/no-comments.ts index 962232b7..0bc513d1 100644 --- a/tests/lib/rules/no-comments.ts +++ b/tests/lib/rules/no-comments.ts @@ -1,8 +1,12 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-comments"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), + languageOptions: { + parser: jsonParser, + }, }); tester.run("no-comments", rule as any, { @@ -37,8 +41,12 @@ tester.run("no-comments", rule as any, { code: ` // comment "a"`, - parser: require.resolve("vue-eslint-parser"), errors: ["Unexpected comment."], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, ], }); diff --git a/tests/lib/rules/no-dupe-keys.ts b/tests/lib/rules/no-dupe-keys.ts index c29bc63e..3daad013 100644 --- a/tests/lib/rules/no-dupe-keys.ts +++ b/tests/lib/rules/no-dupe-keys.ts @@ -1,8 +1,12 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-dupe-keys"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), + languageOptions: { + parser: jsonParser, + }, }); tester.run("no-dupe-keys", rule as any, { @@ -15,8 +19,12 @@ tester.run("no-dupe-keys", rule as any, { { filename: "test.vue", code: `{"key": "value", "key": "value"}`, - parser: require.resolve("vue-eslint-parser"), errors: ["Duplicate key 'key'."], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, ], }); diff --git a/tests/lib/rules/no-escape-sequence-in-identifier.ts b/tests/lib/rules/no-escape-sequence-in-identifier.ts index 1c938f63..e19357d6 100644 --- a/tests/lib/rules/no-escape-sequence-in-identifier.ts +++ b/tests/lib/rules/no-escape-sequence-in-identifier.ts @@ -1,9 +1,10 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-escape-sequence-in-identifier"; +import * as jsonParser from "jsonc-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), - parserOptions: { + languageOptions: { + parser: jsonParser, ecmaVersion: 2020, }, }); diff --git a/tests/lib/rules/no-floating-decimal.ts b/tests/lib/rules/no-floating-decimal.ts index 2feeb494..d7c20fd2 100644 --- a/tests/lib/rules/no-floating-decimal.ts +++ b/tests/lib/rules/no-floating-decimal.ts @@ -1,9 +1,10 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-floating-decimal"; +import * as jsonParser from "jsonc-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), - parserOptions: { + languageOptions: { + parser: jsonParser, ecmaVersion: 2020, }, }); diff --git a/tests/lib/rules/no-hexadecimal-numeric-literals.ts b/tests/lib/rules/no-hexadecimal-numeric-literals.ts index f2f31cff..a124febb 100644 --- a/tests/lib/rules/no-hexadecimal-numeric-literals.ts +++ b/tests/lib/rules/no-hexadecimal-numeric-literals.ts @@ -1,9 +1,10 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-hexadecimal-numeric-literals"; +import * as jsonParser from "jsonc-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), - parserOptions: { + languageOptions: { + parser: jsonParser, ecmaVersion: 2020, }, }); diff --git a/tests/lib/rules/no-infinity.ts b/tests/lib/rules/no-infinity.ts index 2c6eacfd..5f48e6aa 100644 --- a/tests/lib/rules/no-infinity.ts +++ b/tests/lib/rules/no-infinity.ts @@ -1,9 +1,10 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-infinity"; +import * as jsonParser from "jsonc-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), - parserOptions: { + languageOptions: { + parser: jsonParser, ecmaVersion: 2020, }, }); diff --git a/tests/lib/rules/no-irregular-whitespace.ts b/tests/lib/rules/no-irregular-whitespace.ts index a29ee4fb..53e64843 100644 --- a/tests/lib/rules/no-irregular-whitespace.ts +++ b/tests/lib/rules/no-irregular-whitespace.ts @@ -1,9 +1,10 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-irregular-whitespace"; +import * as jsonParser from "jsonc-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), - parserOptions: { + languageOptions: { + parser: jsonParser, ecmaVersion: 2020, }, }); diff --git a/tests/lib/rules/no-multi-str.ts b/tests/lib/rules/no-multi-str.ts index 46d1e9ea..e39c7a61 100644 --- a/tests/lib/rules/no-multi-str.ts +++ b/tests/lib/rules/no-multi-str.ts @@ -1,8 +1,12 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-multi-str"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), + languageOptions: { + parser: jsonParser, + }, }); tester.run("no-multi-str", rule as any, { @@ -20,8 +24,12 @@ tester.run("no-multi-str", rule as any, { { filename: "test.vue", code: `"Line 1 \\\nLine 2"`, - parser: require.resolve("vue-eslint-parser"), - errors: 1, // FIXME: drop supports eslint6 ["Multiline support is limited to JSON5 only."], + errors: 1, + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), // FIXME: drop supports eslint6 ["Multiline support is limited to JSON5 only."], }, ], }); diff --git a/tests/lib/rules/no-nan.ts b/tests/lib/rules/no-nan.ts index 8821c9f6..fccbbd9b 100644 --- a/tests/lib/rules/no-nan.ts +++ b/tests/lib/rules/no-nan.ts @@ -1,9 +1,10 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-nan"; +import * as jsonParser from "jsonc-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), - parserOptions: { + languageOptions: { + parser: jsonParser, ecmaVersion: 2020, }, }); diff --git a/tests/lib/rules/no-number-props.ts b/tests/lib/rules/no-number-props.ts index 5c3d0476..30c7590d 100644 --- a/tests/lib/rules/no-number-props.ts +++ b/tests/lib/rules/no-number-props.ts @@ -1,8 +1,12 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-number-props"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), + languageOptions: { + parser: jsonParser, + }, }); tester.run("no-number-props", rule as any, { @@ -17,8 +21,12 @@ tester.run("no-number-props", rule as any, { filename: "test.vue", code: `{123: 123}`, output: `{"123": 123}`, - parser: require.resolve("vue-eslint-parser"), errors: ["The number property keys are not allowed."], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, ], }); diff --git a/tests/lib/rules/no-numeric-separators.ts b/tests/lib/rules/no-numeric-separators.ts index cdc56145..26d738f9 100644 --- a/tests/lib/rules/no-numeric-separators.ts +++ b/tests/lib/rules/no-numeric-separators.ts @@ -1,15 +1,17 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-numeric-separators"; import { Linter } from "eslint"; import semver from "semver"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; if (!semver.gte(Linter.version, "7.3.0")) { // @ts-expect-error return; } const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), - parserOptions: { + languageOptions: { ecmaVersion: 2021, + parser: jsonParser, }, }); @@ -35,8 +37,12 @@ tester.run("no-numeric-separators", rule as any, { filename: "test.vue", code: `{"a": 1_23}`, output: `{"a": 123}`, - parser: require.resolve("vue-eslint-parser"), errors: ["Numeric separators are not allowed."], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, ], }); diff --git a/tests/lib/rules/no-octal-escape.ts b/tests/lib/rules/no-octal-escape.ts index 57fe9632..7dd2dafb 100644 --- a/tests/lib/rules/no-octal-escape.ts +++ b/tests/lib/rules/no-octal-escape.ts @@ -1,8 +1,12 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-octal-escape"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), + languageOptions: { + parser: jsonParser, + }, }); tester.run("no-octal-escape", rule as any, { @@ -11,12 +15,22 @@ tester.run("no-octal-escape", rule as any, { { code: '{"BAD": "Copyright \\251"}', errors: ["Don't use octal: '\\251'. Use '\\u....' instead."], + ...({ + languageOptions: { + sourceType: "script", + }, + } as any), }, { filename: "test.vue", code: `{"BAD": "Copyright \\251"}`, - parser: require.resolve("vue-eslint-parser"), errors: ["Don't use octal: '\\251'. Use '\\u....' instead."], + ...({ + languageOptions: { + sourceType: "script", + parser: vueParser, + }, + } as any), }, ], }); diff --git a/tests/lib/rules/no-octal-numeric-literals.ts b/tests/lib/rules/no-octal-numeric-literals.ts index 2411d569..286e4699 100644 --- a/tests/lib/rules/no-octal-numeric-literals.ts +++ b/tests/lib/rules/no-octal-numeric-literals.ts @@ -1,9 +1,10 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-octal-numeric-literals"; +import * as jsonParser from "jsonc-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), - parserOptions: { + languageOptions: { + parser: jsonParser, ecmaVersion: 2020, }, }); diff --git a/tests/lib/rules/no-octal.ts b/tests/lib/rules/no-octal.ts index 5b9331d0..c63c2246 100644 --- a/tests/lib/rules/no-octal.ts +++ b/tests/lib/rules/no-octal.ts @@ -1,9 +1,10 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-octal"; +import * as jsonParser from "jsonc-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), - parserOptions: { + languageOptions: { + parser: jsonParser, ecmaVersion: 2020, }, }); @@ -14,10 +15,20 @@ tester.run("no-octal", rule as any, { { code: `01`, errors: ["Octal literals should not be used."], + ...({ + languageOptions: { + sourceType: "script", + }, + } as any), }, { code: `09`, errors: ["Octal literals should not be used."], + ...({ + languageOptions: { + sourceType: "script", + }, + } as any), }, ], }); diff --git a/tests/lib/rules/no-parenthesized.ts b/tests/lib/rules/no-parenthesized.ts index 9c6d48ff..51ef8856 100644 --- a/tests/lib/rules/no-parenthesized.ts +++ b/tests/lib/rules/no-parenthesized.ts @@ -1,9 +1,10 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-parenthesized"; +import * as jsonParser from "jsonc-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), - parserOptions: { + languageOptions: { + parser: jsonParser, ecmaVersion: 2020, }, }); diff --git a/tests/lib/rules/no-plus-sign.ts b/tests/lib/rules/no-plus-sign.ts index 70de2210..e4c10de4 100644 --- a/tests/lib/rules/no-plus-sign.ts +++ b/tests/lib/rules/no-plus-sign.ts @@ -1,9 +1,10 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-plus-sign"; +import * as jsonParser from "jsonc-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), - parserOptions: { + languageOptions: { + parser: jsonParser, ecmaVersion: 2020, }, }); diff --git a/tests/lib/rules/no-regexp-literals.ts b/tests/lib/rules/no-regexp-literals.ts index eeb71a1c..758a5cae 100644 --- a/tests/lib/rules/no-regexp-literals.ts +++ b/tests/lib/rules/no-regexp-literals.ts @@ -1,8 +1,12 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-regexp-literals"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), + languageOptions: { + parser: jsonParser, + }, }); tester.run("no-regexp-literals", rule as any, { @@ -22,8 +26,12 @@ tester.run("no-regexp-literals", rule as any, { { filename: "test.vue", code: `/reg/`, - parser: require.resolve("vue-eslint-parser"), errors: ["RegExp literals are not allowed."], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, ], }); diff --git a/tests/lib/rules/no-sparse-arrays.ts b/tests/lib/rules/no-sparse-arrays.ts index ab7eb4ac..9fbfca03 100644 --- a/tests/lib/rules/no-sparse-arrays.ts +++ b/tests/lib/rules/no-sparse-arrays.ts @@ -1,8 +1,12 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-sparse-arrays"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), + languageOptions: { + parser: jsonParser, + }, }); tester.run("no-sparse-arrays", rule as any, { @@ -19,8 +23,12 @@ tester.run("no-sparse-arrays", rule as any, { { filename: "test.vue", code: `[,,]`, - parser: require.resolve("vue-eslint-parser"), errors: ["Unexpected comma in middle of array."], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, ], }); diff --git a/tests/lib/rules/no-template-literals.ts b/tests/lib/rules/no-template-literals.ts index 8a87696d..9851b7dd 100644 --- a/tests/lib/rules/no-template-literals.ts +++ b/tests/lib/rules/no-template-literals.ts @@ -1,9 +1,11 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-template-literals"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), - parserOptions: { + languageOptions: { + parser: jsonParser, ecmaVersion: 2020, }, }); @@ -35,8 +37,12 @@ tester.run("no-template-literals", rule as any, { filename: "test.vue", code: `{"foo":\`template\`}`, output: `{"foo":"template"}`, - parser: require.resolve("vue-eslint-parser"), errors: ["The template literals are not allowed."], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, ], }); diff --git a/tests/lib/rules/no-undefined-value.ts b/tests/lib/rules/no-undefined-value.ts index 461b040f..0716bd91 100644 --- a/tests/lib/rules/no-undefined-value.ts +++ b/tests/lib/rules/no-undefined-value.ts @@ -1,8 +1,12 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-undefined-value"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), + languageOptions: { + parser: jsonParser, + }, }); tester.run("no-undefined-value", rule as any, { @@ -37,8 +41,12 @@ tester.run("no-undefined-value", rule as any, { { filename: "test.vue", code: `undefined`, - parser: require.resolve("vue-eslint-parser"), errors: ["`undefined` is not allowed."], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, ], }); diff --git a/tests/lib/rules/no-unicode-codepoint-escapes.ts b/tests/lib/rules/no-unicode-codepoint-escapes.ts index 1fdf42e9..3e808bf0 100644 --- a/tests/lib/rules/no-unicode-codepoint-escapes.ts +++ b/tests/lib/rules/no-unicode-codepoint-escapes.ts @@ -1,9 +1,10 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-unicode-codepoint-escapes"; +import * as jsonParser from "jsonc-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), - parserOptions: { + languageOptions: { + parser: jsonParser, ecmaVersion: 2020, }, }); diff --git a/tests/lib/rules/no-useless-escape.ts b/tests/lib/rules/no-useless-escape.ts index 4387c4a2..2ea8477a 100644 --- a/tests/lib/rules/no-useless-escape.ts +++ b/tests/lib/rules/no-useless-escape.ts @@ -1,8 +1,12 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/no-useless-escape"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), + languageOptions: { + parser: jsonParser, + }, }); tester.run("no-useless-escape", rule as any, { @@ -16,8 +20,12 @@ tester.run("no-useless-escape", rule as any, { { filename: "test.vue", code: `"hol\\a"`, - parser: require.resolve("vue-eslint-parser"), errors: ["Unnecessary escape character: \\a."], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, ], }); diff --git a/tests/lib/rules/object-curly-newline.ts b/tests/lib/rules/object-curly-newline.ts index 9a74da4b..c545713f 100644 --- a/tests/lib/rules/object-curly-newline.ts +++ b/tests/lib/rules/object-curly-newline.ts @@ -1,8 +1,12 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/object-curly-newline"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), + languageOptions: { + parser: jsonParser, + }, }); tester.run("object-curly-newline", rule as any, { @@ -17,8 +21,12 @@ tester.run("object-curly-newline", rule as any, { filename: "test.vue", code: `{\n"key": "value"}`, output: `{"key": "value"}`, - parser: require.resolve("vue-eslint-parser"), errors: ["Unexpected line break after this opening brace."], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, ], }); diff --git a/tests/lib/rules/object-curly-spacing.ts b/tests/lib/rules/object-curly-spacing.ts index a0dd2f53..5132830d 100644 --- a/tests/lib/rules/object-curly-spacing.ts +++ b/tests/lib/rules/object-curly-spacing.ts @@ -1,8 +1,12 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/object-curly-spacing"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), + languageOptions: { + parser: jsonParser, + }, }); tester.run("object-curly-spacing", rule as any, { @@ -72,11 +76,15 @@ tester.run("object-curly-spacing", rule as any, { filename: "test.vue", code: `{ "key": "value" }`, output: `{"key": "value"}`, - parser: require.resolve("vue-eslint-parser"), errors: [ "There should be no space after '{'.", "There should be no space before '}'.", ], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, // always - arraysInObjects { diff --git a/tests/lib/rules/object-property-newline.ts b/tests/lib/rules/object-property-newline.ts index 81a4b0fc..43a7f397 100644 --- a/tests/lib/rules/object-property-newline.ts +++ b/tests/lib/rules/object-property-newline.ts @@ -1,8 +1,12 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/object-property-newline"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), + languageOptions: { + parser: jsonParser, + }, }); tester.run("object-property-newline", rule as any, { @@ -36,8 +40,12 @@ tester.run("object-property-newline", rule as any, { filename: "test.vue", code: `{ "foo": "foo", "bar": "bar" }`, output: `{ "foo": "foo",\n"bar": "bar" }`, - parser: require.resolve("vue-eslint-parser"), errors: ["Object properties must go on a new line."], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, ], }); diff --git a/tests/lib/rules/quote-props.ts b/tests/lib/rules/quote-props.ts index c38589a2..83f2a8be 100644 --- a/tests/lib/rules/quote-props.ts +++ b/tests/lib/rules/quote-props.ts @@ -1,8 +1,12 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/quote-props"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), + languageOptions: { + parser: jsonParser, + }, }); tester.run("quote-props", rule as any, { @@ -17,8 +21,12 @@ tester.run("quote-props", rule as any, { filename: "test.vue", code: `{key: "value"}`, output: `{"key": "value"}`, - parser: require.resolve("vue-eslint-parser"), errors: ["Unquoted property 'key' found."], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, ], }); diff --git a/tests/lib/rules/quotes.ts b/tests/lib/rules/quotes.ts index 5cb9f908..f4abc4f1 100644 --- a/tests/lib/rules/quotes.ts +++ b/tests/lib/rules/quotes.ts @@ -1,8 +1,12 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/quotes"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), + languageOptions: { + parser: jsonParser, + }, }); tester.run("quotes", rule as any, { @@ -31,8 +35,12 @@ tester.run("quotes", rule as any, { filename: "test.vue", code: `['element']`, output: `["element"]`, - parser: require.resolve("vue-eslint-parser"), errors: ["Strings must use doublequote."], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, ], }); diff --git a/tests/lib/rules/sort-array-values.ts b/tests/lib/rules/sort-array-values.ts index 9621b14a..99968787 100644 --- a/tests/lib/rules/sort-array-values.ts +++ b/tests/lib/rules/sort-array-values.ts @@ -1,9 +1,10 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/sort-array-values"; +import * as jsonParser from "jsonc-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), - parserOptions: { + languageOptions: { + parser: jsonParser, ecmaVersion: 2020, }, }); diff --git a/tests/lib/rules/sort-keys.ts b/tests/lib/rules/sort-keys.ts index 9983030a..58ec09c5 100644 --- a/tests/lib/rules/sort-keys.ts +++ b/tests/lib/rules/sort-keys.ts @@ -1,9 +1,13 @@ import fs from "fs"; -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/sort-keys"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), + languageOptions: { + parser: jsonParser, + }, }); const OPTIONS_FOR_PACKAGE_JSON = [ @@ -350,10 +354,14 @@ tester.run("sort-keys", rule as any, { filename: "test.vue", code: `{a:1, A: 2, B:3, b:4}`, output: `{ A: 2,a:1, B:3, b:4}`, - parser: require.resolve("vue-eslint-parser"), errors: [ "Expected object keys to be in ascending order. 'A' should be before 'a'.", ], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, // package.json { diff --git a/tests/lib/rules/space-unary-ops.ts b/tests/lib/rules/space-unary-ops.ts index 20199a1b..3f1aa58a 100644 --- a/tests/lib/rules/space-unary-ops.ts +++ b/tests/lib/rules/space-unary-ops.ts @@ -1,8 +1,12 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/space-unary-ops"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), + languageOptions: { + parser: jsonParser, + }, }); tester.run("space-unary-ops", rule as any, { @@ -42,8 +46,12 @@ tester.run("space-unary-ops", rule as any, { filename: "test.vue", code: `- 1`, output: `-1`, - parser: require.resolve("vue-eslint-parser"), errors: ["Unexpected space after unary operator '-'."], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, ], }); diff --git a/tests/lib/rules/valid-json-number.ts b/tests/lib/rules/valid-json-number.ts index d1187f50..6bd98d61 100644 --- a/tests/lib/rules/valid-json-number.ts +++ b/tests/lib/rules/valid-json-number.ts @@ -1,9 +1,11 @@ -import { RuleTester } from "eslint"; +import { RuleTester } from "../test-lib/eslint-compat"; import rule from "../../../lib/rules/valid-json-number"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), - parserOptions: { + languageOptions: { + parser: jsonParser, ecmaVersion: 2020, }, }); @@ -157,8 +159,12 @@ tester.run("valid-json-number", rule as any, { filename: "test.vue", code: `0x123`, output: `291`, - parser: require.resolve("vue-eslint-parser"), errors: ["Hexadecimal literals are not allowed in JSON."], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, ], }); diff --git a/tests/lib/rules/vue-custom-block/no-parsing-error.ts b/tests/lib/rules/vue-custom-block/no-parsing-error.ts index f34ba36e..7263bce4 100644 --- a/tests/lib/rules/vue-custom-block/no-parsing-error.ts +++ b/tests/lib/rules/vue-custom-block/no-parsing-error.ts @@ -1,9 +1,11 @@ -import { RuleTester } from "eslint"; import rule from "../../../../lib/rules/vue-custom-block/no-parsing-error"; +import { RuleTester } from "../../test-lib/eslint-compat"; +import * as jsonParser from "jsonc-eslint-parser"; +import * as vueParser from "vue-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), - parserOptions: { + languageOptions: { + parser: jsonParser, ecmaVersion: 2020, }, }); @@ -16,19 +18,26 @@ tester.run("vue-custom-block/no-parsing-error", rule as any, { { filename: "test.vue", code: `{"key": "value"}`, - parser: require.resolve("vue-eslint-parser"), + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, { filename: "test.vue", code: `/**/123`, - parser: require.resolve("vue-eslint-parser"), + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, ], invalid: [ { filename: "test.vue", code: `{"key" "value"}`, - parser: require.resolve("vue-eslint-parser"), errors: [ { message: `Unexpected token '"value"'.`, @@ -36,11 +45,15 @@ tester.run("vue-custom-block/no-parsing-error", rule as any, { column: 14, }, ], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, { filename: "test.vue", code: ``, - parser: require.resolve("vue-eslint-parser"), errors: [ { message: "Expected to be an expression, but got empty.", @@ -48,11 +61,15 @@ tester.run("vue-custom-block/no-parsing-error", rule as any, { column: 7, }, ], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, { filename: "test.vue", code: `/**/123`, - parser: require.resolve("vue-eslint-parser"), errors: [ { message: "Unexpected comment.", @@ -60,11 +77,15 @@ tester.run("vue-custom-block/no-parsing-error", rule as any, { column: 7, }, ], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, { filename: "test.vue", code: `/**/123`, - parser: require.resolve("vue-eslint-parser"), errors: [ { message: "Unexpected comment.", @@ -72,6 +93,11 @@ tester.run("vue-custom-block/no-parsing-error", rule as any, { column: 19, }, ], + ...({ + languageOptions: { + parser: vueParser, + }, + } as any), }, ], }); diff --git a/tests/lib/test-lib/eslint-compat.ts b/tests/lib/test-lib/eslint-compat.ts new file mode 100644 index 00000000..85a15a37 --- /dev/null +++ b/tests/lib/test-lib/eslint-compat.ts @@ -0,0 +1,6 @@ +import { getRuleTester } from "eslint-compat-utils/rule-tester"; +import { getLegacyESLint } from "eslint-compat-utils/eslint"; + +export const RuleTester = getRuleTester(); + +export const LegacyESLint = getLegacyESLint(); diff --git a/tools/new-rule.ts b/tools/new-rule.ts index 7bf06bfd..62bd4092 100644 --- a/tools/new-rule.ts +++ b/tools/new-rule.ts @@ -52,14 +52,15 @@ export default createRule("${ruleId}", { ); fs.writeFileSync( testFile, - `import { RuleTester } from "eslint" + `import { RuleTester } from "../test-lib/eslint-compat" import rule from "../../../lib/rules/${ruleId}" +import * as jsonParser from "jsonc-eslint-parser"; const tester = new RuleTester({ - parser: require.resolve("jsonc-eslint-parser"), - parserOptions: { - ecmaVersion: 2020, - }, + languageOptions: { + parser: jsonParser, + ecmaVersion: 2020, + }, }) tester.run("${ruleId}", rule as any, { diff --git a/tsconfig.json b/tsconfig.json index 941a1eea..0815140d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "target": "es2015", - "module": "commonjs", + "module": "node16", "lib": ["es2022"], "allowJs": true, "checkJs": true,