-
-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Avoid dirname for built-in configs. #71
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7ed74f7
feat: Avoid dirname for built-in configs.
daidodo 32470f6
feat: Avoid dirname for built-in configs.
daidodo db72ec3
Merge branch 'issue15575-2' of https://github.com/daidodo/eslintrc in…
daidodo b4803f0
feat: Avoid dirname for built-in configs.
daidodo 57457ec
feat: Avoid dirname for built-in configs.
daidodo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,22 +38,23 @@ | |
// Requirements | ||
//------------------------------------------------------------------------------ | ||
|
||
import debugOrig from "debug"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
import importFresh from "import-fresh"; | ||
import { createRequire } from "module"; | ||
import path from "path"; | ||
import stripComments from "strip-json-comments"; | ||
import ConfigValidator from "./shared/config-validator.js"; | ||
import * as naming from "./shared/naming.js"; | ||
import * as ModuleResolver from "./shared/relative-module-resolver.js"; | ||
|
||
import { | ||
ConfigArray, | ||
ConfigDependency, | ||
IgnorePattern, | ||
OverrideTester | ||
} from "./config-array/index.js"; | ||
import debugOrig from "debug"; | ||
import ConfigValidator from "./shared/config-validator.js"; | ||
import * as naming from "./shared/naming.js"; | ||
import * as ModuleResolver from "./shared/relative-module-resolver.js"; | ||
|
||
import { createRequire } from "module"; | ||
const require = createRequire(import.meta.url); | ||
|
||
const debug = debugOrig("eslintrc:config-array-factory"); | ||
|
@@ -90,7 +91,9 @@ const configFilenames = [ | |
* @property {Map<string,Rule>} builtInRules The rules that are built in to ESLint. | ||
* @property {Object} [resolver=ModuleResolver] The module resolver object. | ||
* @property {string} eslintAllPath The path to the definitions for eslint:all. | ||
* @property {Function} getEslintAllConfig Returns the config data for eslint:all. | ||
* @property {string} eslintRecommendedPath The path to the definitions for eslint:recommended. | ||
* @property {Function} getEslintRecommendedConfig Returns the config data for eslint:recommended. | ||
*/ | ||
|
||
/** | ||
|
@@ -101,7 +104,9 @@ const configFilenames = [ | |
* @property {Map<string,Rule>} builtInRules The rules that are built in to ESLint. | ||
* @property {Object} [resolver=ModuleResolver] The module resolver object. | ||
* @property {string} eslintAllPath The path to the definitions for eslint:all. | ||
* @property {Function} getEslintAllConfig Returns the config data for eslint:all. | ||
* @property {string} eslintRecommendedPath The path to the definitions for eslint:recommended. | ||
* @property {Function} getEslintRecommendedConfig Returns the config data for eslint:recommended. | ||
*/ | ||
|
||
/** | ||
|
@@ -428,7 +433,9 @@ class ConfigArrayFactory { | |
builtInRules, | ||
resolver = ModuleResolver, | ||
eslintAllPath, | ||
eslintRecommendedPath | ||
getEslintAllConfig, | ||
eslintRecommendedPath, | ||
getEslintRecommendedConfig | ||
} = {}) { | ||
internalSlotsMap.set(this, { | ||
additionalPluginPool, | ||
|
@@ -439,7 +446,9 @@ class ConfigArrayFactory { | |
builtInRules, | ||
resolver, | ||
eslintAllPath, | ||
eslintRecommendedPath | ||
getEslintAllConfig, | ||
eslintRecommendedPath, | ||
getEslintRecommendedConfig | ||
}); | ||
} | ||
|
||
|
@@ -797,20 +806,35 @@ class ConfigArrayFactory { | |
* @private | ||
*/ | ||
_loadExtendedBuiltInConfig(extendName, ctx) { | ||
const { eslintAllPath, eslintRecommendedPath } = internalSlotsMap.get(this); | ||
const { | ||
eslintAllPath, | ||
getEslintAllConfig, | ||
eslintRecommendedPath, | ||
getEslintRecommendedConfig | ||
} = internalSlotsMap.get(this); | ||
|
||
if (extendName === "eslint:recommended") { | ||
const name = `${ctx.name} » ${extendName}`; | ||
|
||
if (getEslintRecommendedConfig) { | ||
return this._normalizeConfigData(getEslintRecommendedConfig(), { ...ctx, name }); | ||
mdjermanovic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return this._loadConfigData({ | ||
...ctx, | ||
filePath: eslintRecommendedPath, | ||
name: `${ctx.name} » ${extendName}` | ||
name, | ||
filePath: eslintRecommendedPath | ||
}); | ||
} | ||
if (extendName === "eslint:all") { | ||
const name = `${ctx.name} » ${extendName}`; | ||
|
||
if (getEslintAllConfig) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for getEslintAllConfig There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
return this._normalizeConfigData(getEslintAllConfig(), { ...ctx, name }); | ||
mdjermanovic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return this._loadConfigData({ | ||
...ctx, | ||
filePath: eslintAllPath, | ||
name: `${ctx.name} » ${extendName}` | ||
name, | ||
filePath: eslintAllPath | ||
}); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add in a check here to make sure getEslintRecommendedConfig is a function, and throw an error if not? I can picture this being difficult to debug if someone passes a nonfunction accidentally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.