Skip to content

Commit

Permalink
fix(lint:js): try to resolve ESLint from parent directories if not fo…
Browse files Browse the repository at this point in the history
…und (#397)
  • Loading branch information
Kocal authored Jul 5, 2019
1 parent f9bfbc6 commit a54eec1
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/plugins/lint/linters/js.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import fs from 'fs';
import path from 'path';
import API from '../../../API';
import { isPackageInstalled } from '../../../utils/package';

Expand All @@ -20,7 +22,22 @@ export default (api: API, args: CLIArgs, files: string[]): Promise<void> => {
// when requiring a plugin (`require.resolve('eslint-plugin-vue)`), it does not work.
// We have too many weird issues because it use ESLint from yProx-CLI's node_modules,
// but `eslint-plugin-vue` is from end-user directory... :(
const { CLIEngine } = require(api.resolve('node_modules/eslint'));
let eslintPath = 'node_modules/eslint';
let eslintPathResolved = api.resolve(eslintPath);
// Check in parent directory if we don't directly find ESLint (required for yProx apps)
let maxTries = 15;
while (!fs.existsSync(eslintPathResolved)) {
maxTries -= 1;
eslintPath = path.join('..', eslintPath);
eslintPathResolved = api.resolve(eslintPath);

if (maxTries === 0) {
throw new Error('Unable to locate ESLint.');
}
}

const { CLIEngine } = require(eslintPathResolved);

api.logger.log(`js (lint) :: linting ${JSON.stringify(files, null, 2)}`);

const engine = new CLIEngine(config);
Expand Down

0 comments on commit a54eec1

Please sign in to comment.