2 * @fileoverview `ExtractedConfig` class.
4 * `ExtractedConfig` class expresses a final configuration for a specific file.
6 * It provides one method.
8 * - `toCompatibleObjectAsConfigFileContent()`
9 * Convert this configuration to the compatible object as the content of
10 * config files. It converts the loaded parser and plugins to strings.
11 * `CLIEngine#getConfigForFile(filePath)` method uses this method.
13 * `ConfigArray#extractConfig(filePath)` creates a `ExtractedConfig` instance.
15 * @author Toru Nagashima <https://github.com/mysticatea>
19 const { IgnorePattern
} = require("./ignore-pattern");
21 // For VSCode intellisense
22 /** @typedef {import("../../shared/types").ConfigData} ConfigData */
23 /** @typedef {import("../../shared/types").GlobalConf} GlobalConf */
24 /** @typedef {import("../../shared/types").SeverityConf} SeverityConf */
25 /** @typedef {import("./config-dependency").DependentParser} DependentParser */
26 /** @typedef {import("./config-dependency").DependentPlugin} DependentPlugin */
29 * Check if `xs` starts with `ys`.
31 * @param {T[]} xs The array to check.
32 * @param {T[]} ys The array that may be the first part of `xs`.
33 * @returns {boolean} `true` if `xs` starts with `ys`.
35 function startsWith(xs
, ys
) {
36 return xs
.length
>= ys
.length
&& ys
.every((y
, i
) => y
=== xs
[i
]);
40 * The class for extracted config data.
42 class ExtractedConfig
{
46 * The config name what `noInlineConfig` setting came from.
49 this.configNameOfNoInlineConfig
= "";
53 * @type {Record<string, boolean>}
59 * @type {Record<string, GlobalConf>}
64 * The glob patterns that ignore to lint.
65 * @type {(((filePath:string, dot?:boolean) => boolean) & { basePath:string; patterns:string[] }) | undefined}
67 this.ignores
= void 0;
70 * The flag that disables directive comments.
71 * @type {boolean|undefined}
73 this.noInlineConfig
= void 0;
77 * @type {DependentParser|null}
82 * Options for the parser.
85 this.parserOptions
= {};
89 * @type {Record<string, DependentPlugin>}
97 this.processor
= null;
100 * The flag that reports unused `eslint-disable` directive comments.
101 * @type {boolean|undefined}
103 this.reportUnusedDisableDirectives
= void 0;
107 * @type {Record<string, [SeverityConf, ...any[]]>}
119 * Convert this config to the compatible object as a config file content.
120 * @returns {ConfigData} The converted object.
122 toCompatibleObjectAsConfigFileContent() {
124 /* eslint-disable no-unused-vars */
125 configNameOfNoInlineConfig
: _ignore1
,
127 /* eslint-enable no-unused-vars */
132 config
.parser
= config
.parser
&& config
.parser
.filePath
;
133 config
.plugins
= Object
.keys(config
.plugins
).filter(Boolean
).reverse();
134 config
.ignorePatterns
= ignores
? ignores
.patterns
: [];
136 // Strip the default patterns from `ignorePatterns`.
137 if (startsWith(config
.ignorePatterns
, IgnorePattern
.DefaultPatterns
)) {
138 config
.ignorePatterns
=
139 config
.ignorePatterns
.slice(IgnorePattern
.DefaultPatterns
.length
);
146 module
.exports
= { ExtractedConfig
};