-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Update: Implement FlatConfigArray (refs #13481) #14321
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
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
0d6db1b
Update: Implement FlatConfigArray (refs #13481)
nzakas 003aa0a
Upgrade config-array package
nzakas f596b2b
Add schemas for linterOptions, processor, plugins
nzakas 919d8c8
Continue implementing config schemas
nzakas 07aac9a
RulesSchema start
nzakas 5e9521a
Add initial finalization step
nzakas 99b6591
Default config
nzakas 516bd79
Strict mode
nzakas 72eddee
Start rule validation
nzakas d50b2dd
Finish FlatConfigArray implementation
nzakas 3189abc
Remove too-new syntax
nzakas ede77e6
Fix default config
nzakas 0bfe125
fix test
nzakas 12df97b
Update tests/lib/config/flat-config-array.js
nzakas c8ce1aa
Update tests/lib/config/flat-config-array.js
nzakas e7f7dbc
Update tests/lib/config/flat-config-array.js
nzakas 48025f2
Update tests/lib/config/flat-config-array.js
nzakas 905a5d4
Update tests
nzakas b99f3af
fix test
nzakas 1117b31
Allow old-style plugin names
nzakas 10343ad
Fix reportUnusedDisableDirectives and add JSDoc
nzakas 40fe618
Add more tests
nzakas 70af1ec
address review comments
nzakas acabd01
Ignore only .git directory
nzakas c0bbff6
Allow null for global settings
nzakas 210e792
writeable -> writable
nzakas 6ba32a6
Remove incorrect comment
nzakas b2dcefa
Validate severity-only rule options
nzakas 0ce35cf
Add key to global error message
nzakas 553b931
deeply merge parserOptions and settings
nzakas adf4f2f
Rename defaultResultConfig
nzakas 751352d
Normalize and fix rule validations
nzakas b260002
Fix rule options merging
nzakas 9acd1c2
Fix various errors
nzakas 7b66408
Rebase onto master
nzakas 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 contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /** | ||
| * @fileoverview Default configuration | ||
| * @author Nicholas C. Zakas | ||
| */ | ||
|
|
||
| "use strict"; | ||
|
|
||
| //----------------------------------------------------------------------------- | ||
| // Requirements | ||
| //----------------------------------------------------------------------------- | ||
|
|
||
| const Rules = require("../rules"); | ||
|
|
||
| //----------------------------------------------------------------------------- | ||
| // Helpers | ||
| //----------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| exports.defaultConfig = [ | ||
| { | ||
| plugins: { | ||
| "@": { | ||
| parsers: { | ||
| espree: require("espree") | ||
| }, | ||
|
|
||
| /* | ||
| * Because we try to delay loading rules until absolutely | ||
| * necessary, a proxy allows us to hook into the lazy-loading | ||
| * aspect of the rules map while still keeping all of the | ||
| * relevant configuration inside of the config array. | ||
| */ | ||
| rules: new Proxy({}, { | ||
| get(target, property) { | ||
| return Rules.get(property); | ||
| }, | ||
|
|
||
| has(target, property) { | ||
| return Rules.has(property); | ||
| } | ||
| }) | ||
| } | ||
| }, | ||
| ignores: [ | ||
| "**/node_modules/**", | ||
| ".git/**" | ||
| ], | ||
| languageOptions: { | ||
| parser: "@/espree" | ||
| } | ||
| } | ||
| ]; | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| /** | ||
| * @fileoverview Flat Config Array | ||
| * @author Nicholas C. Zakas | ||
| */ | ||
|
|
||
| "use strict"; | ||
|
|
||
| //----------------------------------------------------------------------------- | ||
| // Requirements | ||
| //----------------------------------------------------------------------------- | ||
|
|
||
| const { ConfigArray, ConfigArraySymbol } = require("@humanwhocodes/config-array"); | ||
|
nzakas marked this conversation as resolved.
|
||
| const { flatConfigSchema } = require("./flat-config-schema"); | ||
| const { RuleValidator } = require("./rule-validator"); | ||
| const { defaultConfig } = require("./default-config"); | ||
| const recommendedConfig = require("../../conf/eslint-recommended"); | ||
| const allConfig = require("../../conf/eslint-all"); | ||
|
|
||
| //----------------------------------------------------------------------------- | ||
| // Helpers | ||
| //----------------------------------------------------------------------------- | ||
|
|
||
| const ruleValidator = new RuleValidator(); | ||
|
|
||
| /** | ||
| * Splits a plugin identifier in the form a/b/c into two parts: a/b and c. | ||
| * @param {string} identifier The identifier to parse. | ||
| * @returns {{objectName: string, pluginName: string}} The parts of the plugin | ||
| * name. | ||
| */ | ||
| function splitPluginIdentifier(identifier) { | ||
| const parts = identifier.split("/"); | ||
|
|
||
| return { | ||
| objectName: parts.pop(), | ||
| pluginName: parts.join("/") | ||
| }; | ||
| } | ||
|
nzakas marked this conversation as resolved.
|
||
|
|
||
| //----------------------------------------------------------------------------- | ||
| // Exports | ||
| //----------------------------------------------------------------------------- | ||
|
|
||
| /** | ||
| * Represents an array containing configuration information for ESLint. | ||
| */ | ||
| class FlatConfigArray extends ConfigArray { | ||
|
|
||
| /** | ||
| * Creates a new instance. | ||
| * @param {*[]} configs An array of configuration information. | ||
| * @param {{basePath: string, baseConfig: FlatConfig}} options The options | ||
| * to use for the config array instance. | ||
| */ | ||
| constructor(configs, { basePath, baseConfig = defaultConfig }) { | ||
|
mdjermanovic marked this conversation as resolved.
|
||
| super(configs, { | ||
| basePath, | ||
| schema: flatConfigSchema | ||
| }); | ||
|
|
||
| this.unshift(baseConfig); | ||
| } | ||
|
|
||
| /* eslint-disable class-methods-use-this */ | ||
| /** | ||
| * Replaces a config with another config to allow us to put strings | ||
| * in the config array that will be replaced by objects before | ||
| * normalization. | ||
| * @param {Object} config The config to preprocess. | ||
| * @returns {Object} The preprocessed config. | ||
| */ | ||
| [ConfigArraySymbol.preprocessConfig](config) { | ||
| if (config === "eslint:recommended") { | ||
| return recommendedConfig; | ||
| } | ||
|
|
||
| if (config === "eslint:all") { | ||
| return allConfig; | ||
| } | ||
|
|
||
| return config; | ||
| } | ||
|
nzakas marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Finalizes the config by replacing plugin references with their objects | ||
| * and validating rule option schemas. | ||
| * @param {Object} config The config to finalize. | ||
| * @returns {Object} The finalized config. | ||
| * @throws {TypeError} If the config is invalid. | ||
| */ | ||
| [ConfigArraySymbol.finalizeConfig](config) { | ||
|
|
||
| const { plugins, languageOptions, processor } = config; | ||
|
|
||
| // Check parser value | ||
| if (languageOptions && languageOptions.parser && typeof languageOptions.parser === "string") { | ||
| const { pluginName, objectName: parserName } = splitPluginIdentifier(languageOptions.parser); | ||
|
|
||
| if (!plugins || !plugins[pluginName] || !plugins[pluginName].parsers || !plugins[pluginName].parsers[parserName]) { | ||
| throw new TypeError(`Key "parser": Could not find "${parserName}" in plugin "${pluginName}".`); | ||
| } | ||
|
|
||
| languageOptions.parser = plugins[pluginName].parsers[parserName]; | ||
| } | ||
|
|
||
| // Check processor value | ||
| if (processor && typeof processor === "string") { | ||
| const { pluginName, objectName: processorName } = splitPluginIdentifier(processor); | ||
|
|
||
| if (!plugins || !plugins[pluginName] || !plugins[pluginName].processors || !plugins[pluginName].processors[processorName]) { | ||
| throw new TypeError(`Key "processor": Could not find "${processorName}" in plugin "${pluginName}".`); | ||
|
nzakas marked this conversation as resolved.
|
||
| } | ||
|
|
||
| config.processor = plugins[pluginName].processors[processorName]; | ||
| } | ||
|
|
||
| ruleValidator.validate(config); | ||
|
|
||
| return config; | ||
| } | ||
| /* eslint-enable class-methods-use-this */ | ||
|
|
||
| } | ||
|
|
||
| exports.FlatConfigArray = FlatConfigArray; | ||
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.
Uh oh!
There was an error while loading. Please reload this page.