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

Use stylish as default formatter instead of eslint-formatter-codeframe #379

Merged
merged 4 commits into from
Sep 28, 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
6 changes: 1 addition & 5 deletions bin/eslint-interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,4 @@ const dir = join(dirname(fileURLToPath(import.meta.url)));

const scriptFile = resolve(dir, '_eslint-interactive.js');

spawnSync(
'node',
['--unhandled-rejections=strict', '--experimental-import-meta-resolve', scriptFile, ...process.argv.slice(2)],
{ stdio: 'inherit' },
);
spawnSync('node', ['--unhandled-rejections=strict', scriptFile, ...process.argv.slice(2)], { stdio: 'inherit' });
4 changes: 2 additions & 2 deletions e2e-test/global-installation/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test('verify installation', async () => {
expect(result.toString().trim()).toBe(VERSION);
});

test('can print error with eslint-formatter-codeframe', async () => {
test('can print error with stylish', async () => {
const child = spawn(
'eslint-interactive',
[
Expand All @@ -46,6 +46,6 @@ test('can print error with eslint-formatter-codeframe', async () => {
await streamWatcher.match(/In what way are the details displayed\?/);
child.stdin.write('0'); // Focus on `Print in terminal`
child.stdin.write(LF); // Confirm the choice
await streamWatcher.match(/Missing semicolon/); // formatted by eslint-formatter-codeframe
await streamWatcher.match(/Missing semicolon/);
child.stdin.write(ETX); // Exit
});
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"@types/yargs": "^17.0.29",
"dedent": "^1.5.1",
"eslint": "^8.57.0",
"import-meta-resolve": "^4.0.0",
"npm-run-all2": "^5.0.0",
"prettier": "3.0.3",
"stream-match": "^4.1.0",
Expand All @@ -56,7 +55,6 @@
"chalk": "^5.3.0",
"comlink": "^4.4.1",
"enquirer": "^2.4.1",
"eslint-formatter-codeframe": "^7.32.1",
"estraverse": "^5.3.0",
"find-cache-dir": "^5.0.0",
"is-installed-globally": "^1.0.0",
Expand Down
47 changes: 12 additions & 35 deletions pnpm-lock.yaml

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

21 changes: 9 additions & 12 deletions src/__snapshots__/core.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -271,18 +271,15 @@ exports[`Core > lint > returns lint results 1`] = `
exports[`Core > makeFixableAndFix 1`] = `"const _a = 1;"`;

exports[`Core > printDetailsOfResults 1`] = `
"error: Ban exponentiation operator (ban-exponentiation-operator) at <fixture>/src/ban-exponentiation-operator.js:1:1:
> 1 | 2 ** 2;
| ^


error: Definition for rule 'import/order' was not found (import/order) at <fixture>/src/import-order.js:1:1:
> 1 | import b from 'b';
| ^
2 | import a from 'a';


2 errors found."
"
<fixture>/src/ban-exponentiation-operator.js
 1:1 error Ban exponentiation operator ban-exponentiation-operator

<fixture>/src/import-order.js
 1:1 error Definition for rule 'import/order' was not found import/order
Copy link
Owner Author

Choose a reason for hiding this comment

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

It seems that the import plugin has not been loaded...


✖ 2 problems (2 errors, 0 warnings)
"
`;

exports[`Core > printSummaryOfResults 1`] = `
Expand Down
2 changes: 1 addition & 1 deletion src/cli/parse-argv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type ParsedCLIOptions = {

/** Default CLI Options */
export const cliOptionsDefaults = {
formatterName: 'codeframe',
formatterName: 'stylish',
quiet: false,
useEslintrc: true,
cache: true,
Expand Down
2 changes: 1 addition & 1 deletion src/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function run(options: Options) {
// ref: https://github.com/chalk/supports-color/issues/97, https://github.com/nodejs/node/issues/26946
FORCE_HYPERLINK: terminalLink.isSupported ? '1' : '0',
},
// NOTE: Pass CLI options (--experimental-import-meta-resolve, etc.) to the worker
// NOTE: Pass CLI options (--unhandled-rejections=strict, etc.) to the worker
execArgv: process.execArgv,
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
5 changes: 1 addition & 4 deletions src/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { dirname, join, relative } from 'node:path';
import { fileURLToPath } from 'node:url';
import dedent from 'dedent';
import { ESLint, Linter } from 'eslint';
import { resolve } from 'import-meta-resolve';
import { beforeEach, describe, expect, test, vi } from 'vitest';
import { Core } from './core.js';
import { LegacyESLint } from './eslint/use-at-your-own-risk.js';
Expand Down Expand Up @@ -149,9 +148,7 @@ const iff = await createIFF({

const core = new Core({
patterns: ['src'],
// For some reason, the test fails if `formatterName === 'codeframe'`.
// So here we overwrite it.
formatterName: fileURLToPath(resolve('eslint-formatter-codeframe', import.meta.url)),
formatterName: 'stylish',
cwd: iff.rootDir,
eslintOptions: { type: 'eslintrc', rulePaths: ['rules'] },
});
Expand Down
12 changes: 1 addition & 11 deletions src/core.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { writeFile } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import { ESLint, Rule } from 'eslint';
import isInstalledGlobally from 'is-installed-globally';
import { DescriptionPosition } from './cli/prompt.js';
import { Config, NormalizedConfig, normalizeConfig } from './config.js';
import { LegacyESLint, FlatESLint } from './eslint/use-at-your-own-risk.js';
Expand Down Expand Up @@ -112,15 +110,7 @@ export class Core {
*/
async formatResultDetails(results: ESLint.LintResult[], ruleIds: (string | null)[]): Promise<string> {
const formatterName = this.config.formatterName;

// When eslint-interactive is installed globally, eslint-formatter-codeframe will also be installed globally.
// On the other hand, `eslint.loadFormatter` cannot load the globally installed formatter by name. So here it loads them by path.
const resolvedFormatterNameOrPath =
isInstalledGlobally && formatterName === 'codeframe'
? fileURLToPath(import.meta.resolve('eslint-formatter-codeframe', import.meta.resolve('eslint-interactive')))
: formatterName;

const formatter = await this.eslint.loadFormatter(resolvedFormatterNameOrPath);
const formatter = await this.eslint.loadFormatter(formatterName);
return formatter.format(filterResultsByRuleId(results, ruleIds));
}

Expand Down
1 change: 0 additions & 1 deletion vite.config.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const baseConfig = defineConfig({
env: {
FORCE_HYPERLINK: '1',
FORCE_COLOR: '1',
NODE_OPTIONS: '--experimental-import-meta-resolve',
},
exclude: [...configDefaults.exclude, 'tmp/**'],
},
Expand Down
Loading