Skip to content

Commit

Permalink
fix: run eslint from PATH (#654)
Browse files Browse the repository at this point in the history
Rationale:
- npm and Yarn both put (a directory containing) the eslint binary on PATH during "npm run foo", so take advantage of that to invoke eslint in a way that is compatible with Yarn workspaces.
- (Node that `node_modules/eslint/...` may not exist, because the module may have been installed in another `node_modules` further up the filesystem tree. Yarn does ensure that the binary gets symlinked into `node_modules/.bin`.)
- This should fix issue #490.
  • Loading branch information
richardbarrell-calvium authored Sep 29, 2023
1 parent 50926fe commit 5dc2a76
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ export async function run(verb: string, files: string[]): Promise<boolean> {
case 'lint':
case 'check': {
try {
await execa('node', ['./node_modules/eslint/bin/eslint', ...flags], {
stdio: 'inherit',
});
await execa('eslint', flags, {stdio: 'inherit'});
return true;
} catch (e) {
return false;
Expand All @@ -152,13 +150,7 @@ export async function run(verb: string, files: string[]): Promise<boolean> {
case 'fix': {
const fixFlag = options.dryRun ? '--fix-dry-run' : '--fix';
try {
await execa(
'node',
['./node_modules/eslint/bin/eslint', fixFlag, ...flags],
{
stdio: 'inherit',
}
);
await execa('eslint', [fixFlag, ...flags], {stdio: 'inherit'});
return true;
} catch (e) {
console.error(e);
Expand Down

0 comments on commit 5dc2a76

Please sign in to comment.