Skip to content

Commit c8c4028

Browse files
committed
fix(scripts/lint): resolve ESLint plugins relative to @hover/javascript installation
This makes the ESLint configuration handle cases where package managers nest the ESLint dependencies in node_modules/@hover/javascript/node_modules
1 parent 92e40da commit c8c4028

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

src/run-script.js

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ if (script) {
1818
s
1919
.replace(scriptsPath, '')
2020
.replace(/__tests__/, '')
21+
.replace(/__mocks__/, '')
2122
.replace(/\.js$/, ''),
2223
)
2324
.filter(Boolean)
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`lint --no-cache will disable caching 1`] = `eslint --config ./src/config/eslintrc.js --ignore-path ./src/config/eslintignore --ext .js,.jsx,.ts,.tsx --no-cache .`;
3+
exports[`lint --no-cache will disable caching 1`] = `eslint --resolve-plugins-relative-to <PROJECT_ROOT>/src/scripts/__mocks__/@hover/javascript --config ./src/config/eslintrc.js --ignore-path ./src/config/eslintignore --ext .js,.jsx,.ts,.tsx --no-cache .`;
44
5-
exports[`lint calls eslint CLI with default args 1`] = `eslint --config ./src/config/eslintrc.js --ignore-path ./src/config/eslintignore --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache --ext .js,.jsx,.ts,.tsx .`;
5+
exports[`lint calls eslint CLI with default args 1`] = `eslint --resolve-plugins-relative-to <PROJECT_ROOT>/src/scripts/__mocks__/@hover/javascript --config ./src/config/eslintrc.js --ignore-path ./src/config/eslintignore --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache --ext .js,.jsx,.ts,.tsx .`;
66
7-
exports[`lint does not use built-in config with .eslintrc file 1`] = `eslint --ignore-path ./src/config/eslintignore --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache --ext .js,.jsx,.ts,.tsx .`;
7+
exports[`lint does not use built-in config with .eslintrc file 1`] = `eslint --resolve-plugins-relative-to <PROJECT_ROOT>/src/scripts/__mocks__/@hover/javascript --ignore-path ./src/config/eslintignore --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache --ext .js,.jsx,.ts,.tsx .`;
88
9-
exports[`lint does not use built-in config with .eslintrc.js file 1`] = `eslint --ignore-path ./src/config/eslintignore --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache --ext .js,.jsx,.ts,.tsx .`;
9+
exports[`lint does not use built-in config with .eslintrc.js file 1`] = `eslint --resolve-plugins-relative-to <PROJECT_ROOT>/src/scripts/__mocks__/@hover/javascript --ignore-path ./src/config/eslintignore --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache --ext .js,.jsx,.ts,.tsx .`;
1010
11-
exports[`lint does not use built-in config with --config 1`] = `eslint --ignore-path ./src/config/eslintignore --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache --ext .js,.jsx,.ts,.tsx --config ./custom-config.js .`;
11+
exports[`lint does not use built-in config with --config 1`] = `eslint --resolve-plugins-relative-to <PROJECT_ROOT>/src/scripts/__mocks__/@hover/javascript --ignore-path ./src/config/eslintignore --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache --ext .js,.jsx,.ts,.tsx --config ./custom-config.js .`;
1212
13-
exports[`lint does not use built-in config with eslintConfig pkg prop 1`] = `eslint --ignore-path ./src/config/eslintignore --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache --ext .js,.jsx,.ts,.tsx .`;
13+
exports[`lint does not use built-in config with eslintConfig pkg prop 1`] = `eslint --resolve-plugins-relative-to <PROJECT_ROOT>/src/scripts/__mocks__/@hover/javascript --ignore-path ./src/config/eslintignore --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache --ext .js,.jsx,.ts,.tsx .`;
1414
15-
exports[`lint does not use built-in ignore with .eslintignore file 1`] = `eslint --config ./src/config/eslintrc.js --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache --ext .js,.jsx,.ts,.tsx .`;
15+
exports[`lint does not use built-in ignore with .eslintignore file 1`] = `eslint --resolve-plugins-relative-to <PROJECT_ROOT>/src/scripts/__mocks__/@hover/javascript --config ./src/config/eslintrc.js --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache --ext .js,.jsx,.ts,.tsx .`;
1616
17-
exports[`lint does not use built-in ignore with --ignore-path 1`] = `eslint --config ./src/config/eslintrc.js --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache --ext .js,.jsx,.ts,.tsx --ignore-path ./my-ignore .`;
17+
exports[`lint does not use built-in ignore with --ignore-path 1`] = `eslint --resolve-plugins-relative-to <PROJECT_ROOT>/src/scripts/__mocks__/@hover/javascript --config ./src/config/eslintrc.js --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache --ext .js,.jsx,.ts,.tsx --ignore-path ./my-ignore .`;
1818
19-
exports[`lint does not use built-in ignore with eslintIgnore pkg prop 1`] = `eslint --config ./src/config/eslintrc.js --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache --ext .js,.jsx,.ts,.tsx .`;
19+
exports[`lint does not use built-in ignore with eslintIgnore pkg prop 1`] = `eslint --resolve-plugins-relative-to <PROJECT_ROOT>/src/scripts/__mocks__/@hover/javascript --config ./src/config/eslintrc.js --cache --cache-location <PROJECT_ROOT>/node_modules/.cache/.eslintcache --ext .js,.jsx,.ts,.tsx .`;

src/scripts/lint.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ const useBuiltinConfig =
1515
!hasFile('.eslintrc.json') &&
1616
!hasPkgProp('eslintConfig')
1717

18+
let resolved
19+
20+
try {
21+
resolved = require.resolve('@hover/javascript/eslint')
22+
} catch {
23+
// This is only here for internal usage as the above will not resolve
24+
}
25+
26+
const resolvePlugins = resolved
27+
? ['--resolve-plugins-relative-to', path.dirname(resolved)]
28+
: []
29+
1830
const config = useBuiltinConfig
1931
? ['--config', hereRelative('../config/eslintrc.js')]
2032
: []
@@ -44,7 +56,15 @@ const filesToApply = filesGiven ? [] : ['.']
4456

4557
const result = spawn.sync(
4658
resolveBin('eslint'),
47-
[...config, ...ignore, ...cache, ...extensions, ...args, ...filesToApply],
59+
[
60+
...resolvePlugins,
61+
...config,
62+
...ignore,
63+
...cache,
64+
...extensions,
65+
...args,
66+
...filesToApply,
67+
],
4868
{stdio: 'inherit'},
4969
)
5070

0 commit comments

Comments
 (0)