Skip to content

Commit

Permalink
chore: add test for eslint v9 (#125)
Browse files Browse the repository at this point in the history
* chore: add test for eslint v9

* fix

* fix

* fix

* fix
  • Loading branch information
ota-meshi authored Jan 16, 2024
1 parent 493e7c2 commit ad02846
Show file tree
Hide file tree
Showing 21 changed files with 78 additions and 42 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/NodeCI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16
- name: Install Packages
run: npm i --legacy-peer-deps
run: npm i -f
- name: Build
run: npm run build
- name: Lint
Expand All @@ -35,6 +33,18 @@ jobs:
run: npm i --legacy-peer-deps
- name: Test
run: npm test
test-with-eslint9:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Install Target Packages
run: |+
npm i -D eslint@^9.0.0-0 -f
npx rimraf node_modules
npm install -f
- name: Test
run: npm test
test-with-eslint6:
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"css.validate": false,
"typescript.tsdk": "node_modules/typescript/lib",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.fixAll.stylelint": true
"source.fixAll.eslint": "explicit",
"source.fixAll.stylelint": "explicit"
},
"stylelint.validate": [
"css",
Expand Down
2 changes: 2 additions & 0 deletions lib/configs/recommended.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- ignore
// @ts-ignore -- Backwards compatibility
export = {
plugins: ["node-dependencies"],
overrides: [
Expand Down
2 changes: 2 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const rules = ruleList.reduce(
{} as { [key: string]: RuleModule },
);

// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- ignore
// @ts-ignore -- Backwards compatibility
export = {
meta,
configs,
Expand Down
2 changes: 2 additions & 0 deletions lib/utils/package-json/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// @ts-expect-error -- I don't know how to set the tsconfig...
import { createSyncFn } from "synckit";
// @ts-expect-error -- I don't know how to set the tsconfig...
import type { AbbreviatedMetadata, Options } from "package-json";
type SyncPackageJson = (
packageName: string,
Expand Down
3 changes: 3 additions & 0 deletions lib/utils/package-json/worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// @ts-expect-error -- I don't know how to set the tsconfig...
import type packageJson from "package-json";
// @ts-expect-error -- I don't know how to set the tsconfig...
import type { Options } from "package-json";
// @ts-expect-error -- I don't know how to set the tsconfig...
import { runAsWorker } from "synckit";
// @ts-expect-error -- no types
import tunnel from "tunnel-agent";
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"chai": "^5.0.0",
"env-cmd": "^10.1.0",
"eslint": "^8.0.0",
"eslint-compat-utils": "^0.3.3",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-eslint-plugin": "^5.0.0",
Expand Down
4 changes: 3 additions & 1 deletion tests/lib/eslint-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import path from "path";
import assert from "assert";
import { ESLint } from "eslint";
import { getLegacyESLint } from "eslint-compat-utils/eslint";
import plugin from "../../lib/index";
// eslint-disable-next-line @typescript-eslint/naming-convention -- ignore
const ESLint = getLegacyESLint();

// -----------------------------------------------------------------------------
// Tests
Expand Down
7 changes: 4 additions & 3 deletions tests/lib/rules/absolute-version.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { RuleTester } from "eslint";
import { RuleTester } from "../utils/compat-eslint";
import rule from "../../../lib/rules/absolute-version";

import * as jsoncParser from "jsonc-eslint-parser";
const tester = new RuleTester({
parser: require.resolve("jsonc-eslint-parser"),
parserOptions: {
languageOptions: {
parser: jsoncParser,
ecmaVersion: 2020,
sourceType: "module",
},
Expand Down
7 changes: 4 additions & 3 deletions tests/lib/rules/compat-engines.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { RuleTester } from "eslint";
import { RuleTester } from "../utils/compat-eslint";
import rule from "../../../lib/rules/compat-engines";

import * as jsoncParser from "jsonc-eslint-parser";
const tester = new RuleTester({
parser: require.resolve("jsonc-eslint-parser"),
parserOptions: {
languageOptions: {
parser: jsoncParser,
ecmaVersion: 2020,
sourceType: "module",
},
Expand Down
7 changes: 4 additions & 3 deletions tests/lib/rules/no-deprecated.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { RuleTester } from "eslint";
import { RuleTester } from "../utils/compat-eslint";
import rule from "../../../lib/rules/no-deprecated";

import * as jsoncParser from "jsonc-eslint-parser";
const tester = new RuleTester({
parser: require.resolve("jsonc-eslint-parser"),
parserOptions: {
languageOptions: {
parser: jsoncParser,
ecmaVersion: 2020,
sourceType: "module",
},
Expand Down
7 changes: 4 additions & 3 deletions tests/lib/rules/no-dupe-deps.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { RuleTester } from "eslint";
import { RuleTester } from "../utils/compat-eslint";
import rule from "../../../lib/rules/no-dupe-deps";

import * as jsoncParser from "jsonc-eslint-parser";
const tester = new RuleTester({
parser: require.resolve("jsonc-eslint-parser"),
parserOptions: {
languageOptions: {
parser: jsoncParser,
ecmaVersion: 2020,
sourceType: "module",
},
Expand Down
7 changes: 4 additions & 3 deletions tests/lib/rules/no-restricted-deps.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { RuleTester } from "eslint";
import { RuleTester } from "../utils/compat-eslint";
import rule from "../../../lib/rules/no-restricted-deps";

import * as jsoncParser from "jsonc-eslint-parser";
const tester = new RuleTester({
parser: require.resolve("jsonc-eslint-parser"),
parserOptions: {
languageOptions: {
parser: jsoncParser,
ecmaVersion: 2020,
sourceType: "module",
},
Expand Down
7 changes: 4 additions & 3 deletions tests/lib/rules/prefer-caret-range-version.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { RuleTester } from "eslint";
import { RuleTester } from "../utils/compat-eslint";
import rule from "../../../lib/rules/prefer-caret-range-version";

import * as jsoncParser from "jsonc-eslint-parser";
const tester = new RuleTester({
parser: require.resolve("jsonc-eslint-parser"),
parserOptions: {
languageOptions: {
parser: jsoncParser,
ecmaVersion: 2020,
sourceType: "module",
},
Expand Down
7 changes: 4 additions & 3 deletions tests/lib/rules/prefer-tilde-range-version.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { RuleTester } from "eslint";
import { RuleTester } from "../utils/compat-eslint";
import rule from "../../../lib/rules/prefer-tilde-range-version";

import * as jsoncParser from "jsonc-eslint-parser";
const tester = new RuleTester({
parser: require.resolve("jsonc-eslint-parser"),
parserOptions: {
languageOptions: {
parser: jsoncParser,
ecmaVersion: 2020,
sourceType: "module",
},
Expand Down
7 changes: 4 additions & 3 deletions tests/lib/rules/valid-engines.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { RuleTester } from "eslint";
import { RuleTester } from "../utils/compat-eslint";
import rule from "../../../lib/rules/valid-engines";

import * as jsoncParser from "jsonc-eslint-parser";
const tester = new RuleTester({
parser: require.resolve("jsonc-eslint-parser"),
parserOptions: {
languageOptions: {
parser: jsoncParser,
ecmaVersion: 2020,
sourceType: "module",
},
Expand Down
8 changes: 4 additions & 4 deletions tests/lib/rules/valid-semver.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { RuleTester } from "eslint";
import { RuleTester } from "../utils/compat-eslint";
import rule from "../../../lib/rules/valid-semver";

import * as jsoncParser from "jsonc-eslint-parser";
const tester = new RuleTester({
parser: require.resolve("jsonc-eslint-parser"),
parserOptions: {
languageOptions: {
parser: jsoncParser,
ecmaVersion: 2020,
sourceType: "module",
},
Expand Down
3 changes: 3 additions & 0 deletions tests/lib/utils/compat-eslint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { getRuleTester } from "eslint-compat-utils/rule-tester";
// eslint-disable-next-line @typescript-eslint/naming-convention -- class name
export const RuleTester = getRuleTester();
15 changes: 8 additions & 7 deletions tools/new-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,17 @@ export default createRule("${ruleId}", {
);
fs.writeFileSync(
testFile,
`import { RuleTester } from "eslint"
`import { RuleTester } from "../utils/compat-eslint"
import rule from "../../../lib/rules/${ruleId}"
import * as jsoncParser from "jsonc-eslint-parser";
const tester = new RuleTester({
parser: require.resolve("jsonc-eslint-parser"),
parserOptions: {
ecmaVersion: 2020,
sourceType: "module",
},
})
languageOptions: {
parser: jsoncParser,
ecmaVersion: 2020,
sourceType: "module",
},
});
tester.run("${ruleId}", rule as any, {
valid: [
Expand Down
2 changes: 2 additions & 0 deletions tools/update-rulesets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import fs from "fs";
import { rules } from "./lib/load-rules";

const content = `
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- ignore
// @ts-ignore -- Backwards compatibility
export = {
plugins: ["node-dependencies"],
overrides: [
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"module": "node16",
"lib": ["es2020"],
"allowJs": true,
"checkJs": true,
Expand Down

0 comments on commit ad02846

Please sign in to comment.