From 720d83eeaf8815a2ea926a2c2d07988ed93d63b3 Mon Sep 17 00:00:00 2001 From: Min Idzelis Date: Thu, 1 Mar 2018 10:45:11 -0500 Subject: [PATCH 1/4] Use env var to override local eslint location --- src/utils/getLocalESLint.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utils/getLocalESLint.js b/src/utils/getLocalESLint.js index 0185aa9..a44688c 100644 --- a/src/utils/getLocalESLint.js +++ b/src/utils/getLocalESLint.js @@ -2,6 +2,10 @@ const path = require('path'); const findUp = require('find-up'); const getLocalESLint = config => { + if (process.env.ESLINT_PATH) { + // eslint-disable-next-line import/no-dynamic-require,global-require + return require(process.env.ESLINT_PATH); + } const nodeModulesPath = findUp.sync('node_modules', { cwd: config.rootDir }); // eslint-disable-next-line import/no-dynamic-require, global-require return require(path.resolve(nodeModulesPath, 'eslint')); From 3aea76d91d50e2185eadea7d6715f7bf64ec8d1b Mon Sep 17 00:00:00 2001 From: Min Idzelis Date: Sat, 3 Mar 2018 19:48:18 -0500 Subject: [PATCH 2/4] Fallback to normal require() if can't find local ESLint. --- src/utils/getLocalESLint.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/utils/getLocalESLint.js b/src/utils/getLocalESLint.js index a44688c..d05669a 100644 --- a/src/utils/getLocalESLint.js +++ b/src/utils/getLocalESLint.js @@ -2,13 +2,17 @@ const path = require('path'); const findUp = require('find-up'); const getLocalESLint = config => { - if (process.env.ESLINT_PATH) { - // eslint-disable-next-line import/no-dynamic-require,global-require - return require(process.env.ESLINT_PATH); + var nodeModulesPath = findUp.sync('node_modules', { cwd: config.rootDir }); + try { + // eslint-disable-next-line import/no-dynamic-require, global-require + return require(path.resolve(nodeModulesPath, 'eslint')); + } catch(e) { + // try resolving eslint using normal eslint resolution mechanism + try { + return require('eslint'); + } catch(ee) {} + throw e; } - const nodeModulesPath = findUp.sync('node_modules', { cwd: config.rootDir }); - // eslint-disable-next-line import/no-dynamic-require, global-require - return require(path.resolve(nodeModulesPath, 'eslint')); }; module.exports = getLocalESLint; From 1ead5a3dd9a8ec812ce6350940a6e622844146b5 Mon Sep 17 00:00:00 2001 From: Min Idzelis Date: Sat, 3 Mar 2018 20:03:16 -0500 Subject: [PATCH 3/4] Fix lint --- src/utils/getLocalESLint.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/utils/getLocalESLint.js b/src/utils/getLocalESLint.js index d05669a..bf86f70 100644 --- a/src/utils/getLocalESLint.js +++ b/src/utils/getLocalESLint.js @@ -2,15 +2,18 @@ const path = require('path'); const findUp = require('find-up'); const getLocalESLint = config => { - var nodeModulesPath = findUp.sync('node_modules', { cwd: config.rootDir }); + const nodeModulesPath = findUp.sync('node_modules', { cwd: config.rootDir }); try { // eslint-disable-next-line import/no-dynamic-require, global-require return require(path.resolve(nodeModulesPath, 'eslint')); - } catch(e) { + } catch (e) { // try resolving eslint using normal eslint resolution mechanism try { + // eslint-disable-next-line global-require return require('eslint'); - } catch(ee) {} + } catch (ee) { + // ignore + } throw e; } }; From 0f853e69a94f53c977bddf880f5b6add6073a979 Mon Sep 17 00:00:00 2001 From: Min Idzelis Date: Sat, 3 Mar 2018 20:08:58 -0500 Subject: [PATCH 4/4] Update typo in comment --- src/utils/getLocalESLint.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/getLocalESLint.js b/src/utils/getLocalESLint.js index bf86f70..71dba04 100644 --- a/src/utils/getLocalESLint.js +++ b/src/utils/getLocalESLint.js @@ -7,7 +7,7 @@ const getLocalESLint = config => { // eslint-disable-next-line import/no-dynamic-require, global-require return require(path.resolve(nodeModulesPath, 'eslint')); } catch (e) { - // try resolving eslint using normal eslint resolution mechanism + // try resolving eslint using normal node resolution mechanism try { // eslint-disable-next-line global-require return require('eslint');