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

Print rule's documentation links #186

Merged
merged 11 commits into from
Mar 22, 2022
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@
exports[`Programmable API 1`] = `
"- 8 files (0 file passed, 8 files failed) checked.
- 57 problems (56 errors, 1 warning) found.
┌─────────────────────────────┬───────┬─────────┬────────────┬─────────────────┐
│ Rule │ Error │ Warning │ is fixable │ has suggestions │
├─────────────────────────────┼───────┼─────────┼────────────┼─────────────────┤
│ ban-exponentiation-operator │ 8 │ 0 │ 0 │ 0 │
├─────────────────────────────┼───────┼─────────┼────────────┼─────────────────┤
│ semi │ 12 │ 1 │ 13 │ 0 │
├─────────────────────────────┼───────┼─────────┼────────────┼─────────────────┤
│ import/order │ 3 │ 0 │ 3 │ 0 │
├─────────────────────────────┼───────┼─────────┼────────────┼─────────────────┤
│ prefer-const │ 4 │ 0 │ 4 │ 0 │
├─────────────────────────────┼───────┼─────────┼────────────┼─────────────────┤
│ no-unused-vars │ 7 │ 0 │ 0 │ 0 │
├─────────────────────────────┼───────┼─────────┼────────────┼─────────────────┤
│ no-useless-escape │ 5 │ 0 │ 0 │ 5 │
├─────────────────────────────┼───────┼─────────┼────────────┼─────────────────┤
│ no-unsafe-negation │ 5 │ 0 │ 0 │ 5 │
├─────────────────────────────┼───────┼─────────┼────────────┼─────────────────┤
│ arrow-body-style │ 12 │ 0 │ 12 │ 0 │
└─────────────────────────────┴───────┴─────────┴────────────┴─────────────────┘"
╔═════════════════════════════╤═══════╤═════════╤════════════╤═════════════════╗
║ Rule │ Error │ Warning │ is fixable │ has suggestions ║
╟─────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ ban-exponentiation-operator │ 8 │ 0 │ 0 │ 0 ║
╟─────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ semi │ 12 │ 1 │ 13 │ 0 ║
╟─────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ import/order │ 3 │ 0 │ 3 │ 0 ║
╟─────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ prefer-const │ 4 │ 0 │ 4 │ 0 ║
╟─────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ no-unused-vars │ 7 │ 0 │ 0 │ 0 ║
╟─────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ no-useless-escape │ 5 │ 0 │ 0 │ 5 ║
╟─────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ no-unsafe-negation │ 5 │ 0 │ 0 │ 5 ║
╟─────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ arrow-body-style │ 12 │ 0 │ 12 │ 0 ║
╚═════════════════════════════╧═══════╧═════════╧════════════╧═════════════════╝
"
`;

exports[`Programmable API 2`] = `
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"lint:tsc:test": "tsc -p tsconfig.test.json --noEmit",
"lint:eslint": "eslint --ignore-pattern '/fixtures/' --ignore-pattern '/e2e-test/' .",
"lint:prettier": "prettier --check .",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --colors",
"test": "FORCE_HYPERLINK=1 NODE_OPTIONS=--experimental-vm-modules jest --colors",
"postbuild:test": "./run-e2e-test.sh",
"postbuild:benchmark": "node benchmark/run.js"
},
Expand All @@ -27,7 +27,6 @@
"@jest/types": "^27.5.1",
"@mizdra/eslint-config-mizdra": "^1.1.0",
"@mizdra/prettier-config-mizdra": "^0.4.0",
"@types/cli-table": "^0.3.0",
"@types/eslint": "^8.4.1",
"@types/estraverse": "^5.1.1",
"@types/estree": "^0.0.51",
Expand All @@ -54,14 +53,14 @@
"boxen": "^6.2.1",
"cachedir": "^2.3.0",
"chalk": "^5.0.0",
"cli-table": "^0.3.11",
"comlink": "^4.3.1",
"enquirer": "^2.3.6",
"eslint-formatter-codeframe": "^7.32.1",
"estraverse": "^5.3.0",
"is-installed-globally": "^0.4.0",
"node-pager": "^0.3.6",
"ora": "^6.0.1",
"table": "^6.8.0",
"terminal-link": "^3.0.0",
"yargs": "^16.2.0"
},
Expand Down
39 changes: 20 additions & 19 deletions src/__snapshots__/core.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1675,23 +1675,24 @@ exports[`Core printDetailsOfResults 1`] = `
exports[`Core printSummaryOfResults 1`] = `
"- 11 files (2 files passed, 9 files failed) checked.
- 58 problems (57 errors, 1 warning) found.
┌─────────────────────────────┬───────┬─────────┬────────────┬─────────────────┐
│ Rule │ Error │ Warning │ is fixable │ has suggestions │
├─────────────────────────────┼───────┼─────────┼────────────┼─────────────────┤
│ semi │ 14 │ 1 │ 15 │ 0 │
├─────────────────────────────┼───────┼─────────┼────────────┼─────────────────┤
│ import/order │ 3 │ 0 │ 3 │ 0 │
├─────────────────────────────┼───────┼─────────┼────────────┼─────────────────┤
│ prefer-const │ 4 │ 0 │ 4 │ 0 │
├─────────────────────────────┼───────┼─────────┼────────────┼─────────────────┤
│ no-unused-vars │ 11 │ 0 │ 0 │ 0 │
├─────────────────────────────┼───────┼─────────┼────────────┼─────────────────┤
│ ban-exponentiation-operator │ 2 │ 0 │ 0 │ 0 │
├─────────────────────────────┼───────┼─────────┼────────────┼─────────────────┤
│ no-useless-escape │ 5 │ 0 │ 0 │ 5 │
├─────────────────────────────┼───────┼─────────┼────────────┼─────────────────┤
│ no-unsafe-negation │ 5 │ 0 │ 0 │ 5 │
├─────────────────────────────┼───────┼─────────┼────────────┼─────────────────┤
│ arrow-body-style │ 12 │ 0 │ 12 │ 0 │
└─────────────────────────────┴───────┴─────────┴────────────┴─────────────────┘"
╔═════════════════════════════╤═══════╤═════════╤════════════╤═════════════════╗
║ Rule │ Error │ Warning │ is fixable │ has suggestions ║
╟─────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ ]8;;https://eslint.org/docs/rules/semisemi]8;; │ 14 │ 1 │ 15 │ 0 ║
╟─────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ ]8;;https://github.com/import-js/eslint-plugin-import/blob/v2.25.4/docs/rules/order.mdimport/order]8;; │ 3 │ 0 │ 3 │ 0 ║
╟─────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ ]8;;https://eslint.org/docs/rules/prefer-constprefer-const]8;; │ 4 │ 0 │ 4 │ 0 ║
╟─────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ ]8;;https://eslint.org/docs/rules/no-unused-varsno-unused-vars]8;; │ 11 │ 0 │ 0 │ 0 ║
╟─────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ ban-exponentiation-operator │ 2 │ 0 │ 0 │ 0 ║
╟─────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ ]8;;https://eslint.org/docs/rules/no-useless-escapeno-useless-escape]8;; │ 5 │ 0 │ 0 │ 5 ║
╟─────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ ]8;;https://eslint.org/docs/rules/no-unsafe-negationno-unsafe-negation]8;; │ 5 │ 0 │ 0 │ 5 ║
╟─────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ ]8;;https://eslint.org/docs/rules/arrow-body-stylearrow-body-style]8;; │ 12 │ 0 │ 12 │ 0 ║
╚═════════════════════════════╧═══════╧═════════╧════════════╧═════════════════╝
"
`;
16 changes: 15 additions & 1 deletion src/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { wrap } from 'comlink';
import nodeEndpoint from 'comlink/dist/esm/node-adapter.mjs';
// eslint-disable-next-line @typescript-eslint/no-require-imports
import isInstalledGlobally = require('is-installed-globally');
import terminalLink from 'terminal-link';
import { warn } from '../cli/log.js';
import { parseArgv } from '../cli/parse-argv.js';
import { SerializableCore } from '../core-worker.js';
Expand All @@ -29,7 +30,20 @@ export async function run(options: Options) {

// Directly executing the Core API will hog the main thread and halt the spinner.
// So we wrap it with comlink and run it on the Worker.
const worker = new Worker(join(dirname(fileURLToPath(import.meta.url)), '..', 'core-worker.js'));
const worker = new Worker(join(dirname(fileURLToPath(import.meta.url)), '..', 'core-worker.js'), {
env: {
...process.env,
// NOTE:
// - `terminal-link` uses `supports-hyperlinks` and `supports-color` to determine if a terminal that supports hyperlinks is in use.
// - If the terminal does not support hyperlinks, it will fallback to not print the link.
// - However, due to the specifications of Node.js, the decision does not work well on worker_threads.
// - So here we use a special environment variable to force the printing mode to be switched.
// ref: https://github.com/chalk/supports-color/issues/97, https://github.com/nodejs/node/issues/26946
FORCE_HYPERLINK: terminalLink.isSupported ? '1' : '0',
Copy link
Owner Author

Choose a reason for hiding this comment

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

Workaround 1

},
// NOTE: Pass CLI options (--experimental-import-meta-resolve, etc.) to the worker
execArgv: process.execArgv,
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const ProxiedCore = wrap<typeof SerializableCore>((nodeEndpoint as any)(worker));
const core = await new ProxiedCore(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 @@ -4,6 +4,8 @@ import { ESLint, Linter } from 'eslint';
import { Core, DEFAULT_BASE_CONFIG } from './core.js';
import { cleanupFixturesCopy, getSnapshotOfChangedFiles, setupFixturesCopy } from './test-util/fixtures.js';

const testIf = (condition: boolean) => (condition ? test : test.skip);

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

// Normalize `message` for the snapshot.
Expand Down Expand Up @@ -89,7 +91,8 @@ describe('Core', () => {
const results = await core.lint();
expect(normalizeResults(results)).toMatchSnapshot();
});
test('printSummaryOfResults', async () => {
// This test fails because the documentation url is not supported in eslint 7.0.0. Therefore, ignore this test.
testIf(ESLint.version !== '7.0.0')('printSummaryOfResults', async () => {
const results = await core.lint();
expect(core.formatResultSummary(results)).toMatchSnapshot();
});
Expand Down
Loading