Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ESLint v9 (Excluding flat config support) #341

Merged
merged 17 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci-node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
fail-fast: false
matrix:
node: [18, 20]
eslint: ['^8.0.0']
eslint: ['8', '9.0.0-alpha.0']
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -41,15 +41,15 @@ jobs:
node-version: ${{ matrix.node }}
cache: 'pnpm'
- name: Change ESLint version
run: pnpm add -w -D eslint@${{ matrix.eslint }}
run: pnpm add -w -D "eslint@${{ matrix.eslint }}"
- run: pnpm run test

e2e:
strategy:
fail-fast: false
matrix:
node: [18, 20]
eslint: ['^8.0.0']
eslint: ['8', '9.0.0-alpha.0']
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -60,5 +60,5 @@ jobs:
node-version: ${{ matrix.node }}
cache: 'pnpm'
- name: Change ESLint version
run: pnpm add -w -D eslint@${{ matrix.eslint }}
run: pnpm add -w -D "eslint@${{ matrix.eslint }}"
- run: pnpm run e2e
2 changes: 1 addition & 1 deletion e2e-test/global-installation/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test('can print error with eslint-formatter-codeframe', async () => {
// merge stderr to stdout
'2>&1',
],
{ shell: true, stdio: 'pipe', cwd: __dirname },
{ shell: true, stdio: 'pipe', cwd: __dirname, env: { ...process.env, ESLINT_USE_FLAT_CONFIG: 'false' } },
);
const streamWatcher = createStreamWatcher(child.stdout, { debug: true });

Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"yargs": "^17.7.2"
},
"peerDependencies": {
"eslint": ">=8.45.0"
"eslint": ">=8.45.0, 9.0.0-alpha.0"
},
"engines": {
"node": ">=18.0.0"
Expand All @@ -93,5 +93,10 @@
"!src/**/__snapshots__",
"dist",
"static"
]
],
"pnpm": {
"patchedDependencies": {
"@types/eslint@8.44.6": "patches/@types__eslint@8.44.6.patch"
}
}
}
89 changes: 89 additions & 0 deletions patches/@types__eslint@8.44.6.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
diff --git a/index.d.ts b/index.d.ts
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Submit PR to DefinitelyTyped

index 538c0dc1851122fbba808968e02100c9ca5728c4..d16f8776837a844f5e8be9b4053386e53d495ef5 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -842,7 +842,7 @@ export class Linter {

version: string;

- constructor(options?: { cwd?: string | undefined; configType?: "flat" });
+ constructor(options?: { cwd?: string | undefined; configType?: "flat" | "eslintrc" });

verify(
code: SourceCode | string,
diff --git a/use-at-your-own-risk.d.ts b/use-at-your-own-risk.d.ts
index 089a657babec22d7bfa526d10d2950c77af041f3..31c56d1ed865fb11ba484efba01edc6ba7c57da9 100644
--- a/use-at-your-own-risk.d.ts
+++ b/use-at-your-own-risk.d.ts
@@ -1,6 +1,63 @@
+import { ESLint, Linter, Rule } from "eslint";
+
/** @deprecated */
export const builtinRules: Map<string, import("./index.js").Rule.RuleModule>;
/** @deprecated */
+export namespace FlatESLint {
+ interface Options {
+ // File enumeration
+ cwd?: string | undefined;
+ errorOnUnmatchedPattern?: boolean | undefined;
+ globInputPaths?: boolean | undefined;
+ ignore?: boolean | undefined;
+
+ // Linting
+ allowInlineConfig?: boolean | undefined;
+ baseConfig?: Linter.FlatConfig | Linter.FlatConfig[] | undefined;
+ overrideConfig?: Linter.FlatConfig | Linter.FlatConfig[] | undefined;
+ overrideConfigFile?: boolean | string | undefined;
+ reportUnusedDisableDirectives?: Linter.StringSeverity | undefined;
+
+ // Autofix
+ fix?: boolean | ((message: Linter.LintMessage) => boolean) | undefined;
+ fixTypes?: Rule.RuleMetaData['type'][] | undefined;
+
+ // Cache-related
+ cache?: boolean | undefined;
+ cacheLocation?: string | undefined;
+ cacheStrategy?: 'content' | 'metadata' | undefined;
+ }
+}
+/** @deprecated */
+export class FlatESLint {
+ constructor(options?: FlatESLint.Options);
+
+ static get version(): string;
+
+ static outputFixes(results: ESLint.LintResult[]): Promise<void>;
+
+ static getErrorResults(results: ESLint.LintResult[]): ESLint.LintResult[];
+
+ getRulesMetaForResults(results: ESLint.LintResult[]): Record<string, Rule.RuleMetaData>;
+
+ lintFiles(patterns: string | string[]): Promise<ESLint.LintResult[]>;
+
+ lintText(
+ code: string,
+ options?: { filePath?: string | undefined; warnIgnored?: boolean | undefined },
+ ): Promise<ESLint.LintResult[]>;
+
+ loadFormatter(name?: string): Promise<ESLint.Formatter>;
+
+ calculateConfigForFile(filePath: string): Promise<Linter.FlatConfig | undefined>;
+
+ findConfigFile(): Promise<string | undefined>;
+
+ isPathIgnored(filePath: string): Promise<boolean>;
+}
+/** @deprecated */
+export function shouldUseFlatConfig(): Promise<boolean>;
+/** @deprecated */
export class FileEnumerator {
constructor(
params?: {
@@ -17,3 +74,7 @@ export class FileEnumerator {
patternOrPatterns: string | string[],
): IterableIterator<{ config: any; filePath: string; ignored: boolean }>;
}
+export {
+ /** @deprecated */
+ ESLint as LegacyESLint
+};
10 changes: 8 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { fileURLToPath } from 'node:url';
import { Worker } from 'node:worker_threads';
import { wrap } from 'comlink';
import nodeEndpoint from 'comlink/dist/esm/node-adapter.mjs';
import eslintPkg from 'eslint/use-at-your-own-risk';
import isInstalledGlobally from 'is-installed-globally';
import terminalLink from 'terminal-link';
import { warn } from '../cli/log.js';
Expand All @@ -11,6 +12,8 @@ import { translateCLIOptions } from '../config.js';
import { SerializableCore } from '../core-worker.js';
import { lint, selectAction, selectRuleIds, checkResults, NextScene } from '../scene/index.js';

const { shouldUseFlatConfig } = eslintPkg;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is workaround for eslint/eslint#17954.


export type Options = {
argv: string[];
};
Expand All @@ -27,6 +30,10 @@ export async function run(options: Options) {
);
}
const parsedCLIOptions = parseArgv(options.argv);
const usingFlatConfig = await shouldUseFlatConfig();
if (usingFlatConfig) {
throw new Error('Flat Config is not yet supported.'); // TODO: support flat config
}
const config = translateCLIOptions(parsedCLIOptions, 'eslintrc'); // TODO: support flat config

// Directly executing the Core API will hog the main thread and halt the spinner.
Expand Down
8 changes: 4 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ESLint } from 'eslint';
import type { LegacyESLint } from 'eslint/use-at-your-own-risk';
import { cliOptionsDefaults, ParsedCLIOptions } from './cli/parse-argv.js';
import { DeepPartial } from './util/type-check.js';
type ESLintrcESLintOptions = { type: 'eslintrc' } & Pick<
ESLint.Options,
type LegacyESLintOptions = { type: 'eslintrc' } & Pick<
LegacyESLint.Options,
| 'useEslintrc'
| 'overrideConfigFile'
| 'extensions'
Expand All @@ -15,7 +15,7 @@ type ESLintrcESLintOptions = { type: 'eslintrc' } & Pick<
| 'resolvePluginsRelativeTo'
>;

export type ESLintOptions = ESLintrcESLintOptions; // TODO: support flat config
export type ESLintOptions = LegacyESLintOptions; // TODO: support flat config

/** The config of eslint-interactive */
export type Config = {
Expand Down
5 changes: 4 additions & 1 deletion src/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import { dirname, join, relative } from 'node:path';
import { fileURLToPath } from 'node:url';
import dedent from 'dedent';
import { ESLint, Linter } from 'eslint';
import eslintPkg from 'eslint/use-at-your-own-risk';
import { resolve } from 'import-meta-resolve';
import { beforeEach, describe, expect, test, vi } from 'vitest';
import { Core } from './core.js';
import { createIFF } from './test-util/fixtures.js';

const { LegacyESLint } = eslintPkg;

const rootDir = join(dirname(fileURLToPath(import.meta.url)), '..');

// Normalize `message` for the snapshot.
Expand Down Expand Up @@ -181,7 +184,7 @@ describe('Core', () => {
});
test('printSummaryOfResults', async () => {
const results = await core.lint();
vi.spyOn(ESLint.prototype, 'getRulesMetaForResults').mockImplementationOnce(() => {
vi.spyOn(LegacyESLint.prototype, 'getRulesMetaForResults').mockImplementationOnce(() => {
return {
'prefer-const': {
docs: {
Expand Down
Loading