.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / @eslint / eslintrc / lib / config-array / extracted-config.js
1 /**
2  * @fileoverview `ExtractedConfig` class.
3  *
4  * `ExtractedConfig` class expresses a final configuration for a specific file.
5  *
6  * It provides one method.
7  *
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.
12  *
13  * `ConfigArray#extractConfig(filePath)` creates a `ExtractedConfig` instance.
14  *
15  * @author Toru Nagashima <https://github.com/mysticatea>
16  */
17 "use strict";
18
19 const { IgnorePattern } = require("./ignore-pattern");
20
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 */
27
28 /**
29  * Check if `xs` starts with `ys`.
30  * @template T
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`.
34  */
35 function startsWith(xs, ys) {
36     return xs.length >= ys.length && ys.every((y, i) => y === xs[i]);
37 }
38
39 /**
40  * The class for extracted config data.
41  */
42 class ExtractedConfig {
43     constructor() {
44
45         /**
46          * The config name what `noInlineConfig` setting came from.
47          * @type {string}
48          */
49         this.configNameOfNoInlineConfig = "";
50
51         /**
52          * Environments.
53          * @type {Record<string, boolean>}
54          */
55         this.env = {};
56
57         /**
58          * Global variables.
59          * @type {Record<string, GlobalConf>}
60          */
61         this.globals = {};
62
63         /**
64          * The glob patterns that ignore to lint.
65          * @type {(((filePath:string, dot?:boolean) => boolean) & { basePath:string; patterns:string[] }) | undefined}
66          */
67         this.ignores = void 0;
68
69         /**
70          * The flag that disables directive comments.
71          * @type {boolean|undefined}
72          */
73         this.noInlineConfig = void 0;
74
75         /**
76          * Parser definition.
77          * @type {DependentParser|null}
78          */
79         this.parser = null;
80
81         /**
82          * Options for the parser.
83          * @type {Object}
84          */
85         this.parserOptions = {};
86
87         /**
88          * Plugin definitions.
89          * @type {Record<string, DependentPlugin>}
90          */
91         this.plugins = {};
92
93         /**
94          * Processor ID.
95          * @type {string|null}
96          */
97         this.processor = null;
98
99         /**
100          * The flag that reports unused `eslint-disable` directive comments.
101          * @type {boolean|undefined}
102          */
103         this.reportUnusedDisableDirectives = void 0;
104
105         /**
106          * Rule settings.
107          * @type {Record<string, [SeverityConf, ...any[]]>}
108          */
109         this.rules = {};
110
111         /**
112          * Shared settings.
113          * @type {Object}
114          */
115         this.settings = {};
116     }
117
118     /**
119      * Convert this config to the compatible object as a config file content.
120      * @returns {ConfigData} The converted object.
121      */
122     toCompatibleObjectAsConfigFileContent() {
123         const {
124             /* eslint-disable no-unused-vars */
125             configNameOfNoInlineConfig: _ignore1,
126             processor: _ignore2,
127             /* eslint-enable no-unused-vars */
128             ignores,
129             ...config
130         } = this;
131
132         config.parser = config.parser && config.parser.filePath;
133         config.plugins = Object.keys(config.plugins).filter(Boolean).reverse();
134         config.ignorePatterns = ignores ? ignores.patterns : [];
135
136         // Strip the default patterns from `ignorePatterns`.
137         if (startsWith(config.ignorePatterns, IgnorePattern.DefaultPatterns)) {
138             config.ignorePatterns =
139                 config.ignorePatterns.slice(IgnorePattern.DefaultPatterns.length);
140         }
141
142         return config;
143     }
144 }
145
146 module.exports = { ExtractedConfig };