Skip to content

Commit

Permalink
fix: fixup: try to mock out eslintrc v1
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Nov 2, 2021
1 parent c964275 commit 9af66d5
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion test/lib/rule-finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ const semver = require('semver');
const eslintPkg = require('eslint/package.json');

let ModuleResolver;
let eslintRC;
try {
if (semver.satisfies(eslintPkg.version, '>= 7.12')) {
const eslintRCPkg = require('@eslint/eslintrc/package.json');
if (semver.satisfies(eslintRCPkg.version, '>= 1')) {
eslintRC = require('@eslint/eslintrc');
({ Legacy: ModuleResolver } = eslintRC);
} else if (semver.satisfies(eslintPkg.version, '>= 7.12')) {
// eslint 7.12+
ModuleResolver = require('@eslint/eslintrc/lib/shared/relative-module-resolver');
} else {
Expand Down Expand Up @@ -78,6 +83,11 @@ const getRuleFinder = proxyquire('../../src/lib/rule-finder', {
// name passed in `name` relative to the path in `relative`. We have to
// override that function, otherwise eslint fails to "load" our plugins.
//
'@eslint/eslintrc': Object.assign({
Legacy: Object.assign({}, eslintRC, {
ModuleResolver: moduleResolver,
}),
}, eslintRC),
'../shared/relative-module-resolver': moduleResolver, // in eslint < 7.12, from eslint/lib/cli-engine/config-array-factory.js
'./shared/relative-module-resolver': moduleResolver, // in eslint 7.12+, from @eslint/eslintrc/lib/config-array-factory.js
'eslint-plugin-plugin': {
Expand Down Expand Up @@ -171,6 +181,11 @@ const getRuleFinderForDedupeTests = proxyquire('../../src/lib/rule-finder', {
}
}
},
'@eslint/eslintrc': Object.assign({
Legacy: Object.assign({}, eslintRC, {
ModuleResolver: moduleResolver,
}),
}, eslintRC),
// See the long comment in `getRuleFinder` above to learn what the point of this override is.
'../shared/relative-module-resolver': dedupeModuleResolver, // in eslint < 7.12, from eslint/lib/cli-engine/config-array-factory.js
'./shared/relative-module-resolver': dedupeModuleResolver, // in eslint 7.12+, from @eslint/eslintrc/lib/config-array-factory.js
Expand Down

0 comments on commit 9af66d5

Please sign in to comment.