@dineroregnskab/eslint-plugin-custom-rules 2.0.5 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/node_modules/@aashutoshrathi/word-wrap/LICENSE +21 -0
  2. package/node_modules/@aashutoshrathi/word-wrap/README.md +182 -0
  3. package/node_modules/@aashutoshrathi/word-wrap/index.d.ts +50 -0
  4. package/node_modules/@aashutoshrathi/word-wrap/index.js +52 -0
  5. package/node_modules/@aashutoshrathi/word-wrap/package.json +81 -0
  6. package/node_modules/@angular-eslint/bundled-angular-compiler/README.md +1 -0
  7. package/node_modules/@angular-eslint/bundled-angular-compiler/dist/index.d.ts +5 -0
  8. package/node_modules/@angular-eslint/bundled-angular-compiler/dist/index.js +32004 -0
  9. package/node_modules/@angular-eslint/bundled-angular-compiler/package.json +19 -0
  10. package/node_modules/@angular-eslint/template-parser/LICENSE +21 -0
  11. package/node_modules/@angular-eslint/template-parser/README.md +1 -0
  12. package/node_modules/@angular-eslint/template-parser/dist/convert-source-span-to-loc.d.ts +6 -0
  13. package/node_modules/@angular-eslint/template-parser/dist/convert-source-span-to-loc.js +69 -0
  14. package/node_modules/@angular-eslint/template-parser/dist/index.d.ts +44 -0
  15. package/node_modules/@angular-eslint/template-parser/dist/index.js +219 -0
  16. package/node_modules/@angular-eslint/template-parser/package.json +28 -0
  17. package/node_modules/@eslint/eslintrc/LICENSE +19 -0
  18. package/node_modules/@eslint/eslintrc/README.md +115 -0
  19. package/node_modules/@eslint/eslintrc/conf/config-schema.js +79 -0
  20. package/node_modules/@eslint/eslintrc/conf/environments.js +215 -0
  21. package/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs +1104 -0
  22. package/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs.map +1 -0
  23. package/node_modules/@eslint/eslintrc/dist/eslintrc.cjs +4333 -0
  24. package/node_modules/@eslint/eslintrc/dist/eslintrc.cjs.map +1 -0
  25. package/node_modules/@eslint/eslintrc/lib/cascading-config-array-factory.js +532 -0
  26. package/node_modules/@eslint/eslintrc/lib/config-array/config-array.js +523 -0
  27. package/node_modules/@eslint/eslintrc/lib/config-array/config-dependency.js +115 -0
  28. package/node_modules/@eslint/eslintrc/lib/config-array/extracted-config.js +145 -0
  29. package/node_modules/@eslint/eslintrc/lib/config-array/ignore-pattern.js +238 -0
  30. package/node_modules/@eslint/eslintrc/lib/config-array/index.js +19 -0
  31. package/node_modules/@eslint/eslintrc/lib/config-array/override-tester.js +225 -0
  32. package/node_modules/@eslint/eslintrc/lib/config-array-factory.js +1149 -0
  33. package/node_modules/@eslint/eslintrc/lib/flat-compat.js +318 -0
  34. package/node_modules/@eslint/eslintrc/lib/index-universal.js +29 -0
  35. package/node_modules/@eslint/eslintrc/lib/index.js +56 -0
  36. package/node_modules/@eslint/eslintrc/lib/shared/ajv.js +191 -0
  37. package/node_modules/@eslint/eslintrc/lib/shared/config-ops.js +135 -0
  38. package/node_modules/@eslint/eslintrc/lib/shared/config-validator.js +325 -0
  39. package/node_modules/@eslint/eslintrc/lib/shared/deprecation-warnings.js +63 -0
  40. package/node_modules/@eslint/eslintrc/lib/shared/naming.js +96 -0
  41. package/node_modules/@eslint/eslintrc/lib/shared/relative-module-resolver.js +42 -0
  42. package/node_modules/@eslint/eslintrc/lib/shared/types.js +149 -0
  43. package/node_modules/@eslint/eslintrc/package.json +82 -0
  44. package/node_modules/@eslint/eslintrc/universal.js +9 -0
  45. package/node_modules/@eslint/js/LICENSE +19 -0
  46. package/node_modules/@eslint/js/README.md +57 -0
  47. package/node_modules/@eslint/js/package.json +31 -0
  48. package/node_modules/@eslint/js/src/configs/eslint-all.js +211 -0
  49. package/node_modules/@eslint/js/src/configs/eslint-recommended.js +76 -0
  50. package/node_modules/@eslint/js/src/index.js +17 -0
  51. package/node_modules/@eslint-community/eslint-utils/LICENSE +21 -0
  52. package/node_modules/@eslint-community/eslint-utils/README.md +37 -0
  53. package/node_modules/@eslint-community/eslint-utils/index.js +2068 -0
  54. package/node_modules/@eslint-community/eslint-utils/index.js.map +1 -0
  55. package/node_modules/@eslint-community/eslint-utils/index.mjs +2027 -0
  56. package/node_modules/@eslint-community/eslint-utils/index.mjs.map +1 -0
  57. package/node_modules/@eslint-community/eslint-utils/package.json +73 -0
  58. package/node_modules/@eslint-community/regexpp/LICENSE +21 -0
  59. package/node_modules/@eslint-community/regexpp/README.md +177 -0
  60. package/node_modules/@eslint-community/regexpp/index.d.ts +1065 -0
  61. package/node_modules/@eslint-community/regexpp/index.js +2747 -0
  62. package/node_modules/@eslint-community/regexpp/index.js.map +1 -0
  63. package/node_modules/@eslint-community/regexpp/index.mjs +2737 -0
  64. package/node_modules/@eslint-community/regexpp/index.mjs.map +1 -0
  65. package/node_modules/@eslint-community/regexpp/package.json +93 -0
  66. package/node_modules/@humanwhocodes/config-array/LICENSE +201 -0
  67. package/node_modules/@humanwhocodes/config-array/README.md +342 -0
  68. package/node_modules/@humanwhocodes/config-array/api.js +1061 -0
  69. package/node_modules/@humanwhocodes/config-array/package.json +61 -0
  70. package/node_modules/@humanwhocodes/module-importer/CHANGELOG.md +15 -0
  71. package/node_modules/@humanwhocodes/module-importer/LICENSE +201 -0
  72. package/node_modules/@humanwhocodes/module-importer/README.md +80 -0
  73. package/node_modules/@humanwhocodes/module-importer/dist/module-importer.cjs +22 -0
  74. package/node_modules/@humanwhocodes/module-importer/dist/module-importer.d.cts +27 -0
  75. package/node_modules/@humanwhocodes/module-importer/dist/module-importer.d.ts +2 -0
  76. package/node_modules/@humanwhocodes/module-importer/dist/module-importer.js +18 -0
  77. package/node_modules/@humanwhocodes/module-importer/package.json +65 -0
  78. package/node_modules/@humanwhocodes/module-importer/src/module-importer.cjs +81 -0
  79. package/node_modules/@humanwhocodes/module-importer/src/module-importer.js +22 -0
  80. package/node_modules/@humanwhocodes/object-schema/.eslintrc.js +29 -0
  81. package/node_modules/@humanwhocodes/object-schema/.github/workflows/nodejs-test.yml +27 -0
  82. package/node_modules/@humanwhocodes/object-schema/.github/workflows/release-please.yml +39 -0
  83. package/node_modules/@humanwhocodes/object-schema/CHANGELOG.md +26 -0
  84. package/node_modules/@humanwhocodes/object-schema/LICENSE +29 -0
  85. package/node_modules/@humanwhocodes/object-schema/README.md +234 -0
  86. package/node_modules/@humanwhocodes/object-schema/package.json +33 -0
  87. package/node_modules/@humanwhocodes/object-schema/src/index.js +7 -0
  88. package/node_modules/@humanwhocodes/object-schema/src/merge-strategy.js +53 -0
  89. package/node_modules/@humanwhocodes/object-schema/src/object-schema.js +301 -0
  90. package/node_modules/@humanwhocodes/object-schema/src/validation-strategy.js +102 -0
  91. package/node_modules/@humanwhocodes/object-schema/tests/merge-strategy.js +66 -0
  92. package/node_modules/@humanwhocodes/object-schema/tests/object-schema.js +659 -0
  93. package/node_modules/@humanwhocodes/object-schema/tests/validation-strategy.js +186 -0
  94. package/node_modules/@nodelib/fs.scandir/LICENSE +21 -0
  95. package/node_modules/@nodelib/fs.scandir/README.md +171 -0
  96. package/node_modules/@nodelib/fs.scandir/out/adapters/fs.d.ts +20 -0
  97. package/node_modules/@nodelib/fs.scandir/out/adapters/fs.js +19 -0
  98. package/node_modules/@nodelib/fs.scandir/out/constants.d.ts +4 -0
  99. package/node_modules/@nodelib/fs.scandir/out/constants.js +17 -0
  100. package/node_modules/@nodelib/fs.scandir/out/index.d.ts +12 -0
  101. package/node_modules/@nodelib/fs.scandir/out/index.js +26 -0
  102. package/node_modules/@nodelib/fs.scandir/out/providers/async.d.ts +7 -0
  103. package/node_modules/@nodelib/fs.scandir/out/providers/async.js +104 -0
  104. package/node_modules/@nodelib/fs.scandir/out/providers/common.d.ts +1 -0
  105. package/node_modules/@nodelib/fs.scandir/out/providers/common.js +13 -0
  106. package/node_modules/@nodelib/fs.scandir/out/providers/sync.d.ts +5 -0
  107. package/node_modules/@nodelib/fs.scandir/out/providers/sync.js +54 -0
  108. package/node_modules/@nodelib/fs.scandir/out/settings.d.ts +20 -0
  109. package/node_modules/@nodelib/fs.scandir/out/settings.js +24 -0
  110. package/node_modules/@nodelib/fs.scandir/out/types/index.d.ts +20 -0
  111. package/node_modules/@nodelib/fs.scandir/out/types/index.js +2 -0
  112. package/node_modules/@nodelib/fs.scandir/out/utils/fs.d.ts +2 -0
  113. package/node_modules/@nodelib/fs.scandir/out/utils/fs.js +19 -0
  114. package/node_modules/@nodelib/fs.scandir/out/utils/index.d.ts +2 -0
  115. package/node_modules/@nodelib/fs.scandir/out/utils/index.js +5 -0
  116. package/node_modules/@nodelib/fs.scandir/package.json +44 -0
  117. package/node_modules/@nodelib/fs.stat/LICENSE +21 -0
  118. package/node_modules/@nodelib/fs.stat/README.md +126 -0
  119. package/node_modules/@nodelib/fs.stat/out/adapters/fs.d.ts +13 -0
  120. package/node_modules/@nodelib/fs.stat/out/adapters/fs.js +17 -0
  121. package/node_modules/@nodelib/fs.stat/out/index.d.ts +12 -0
  122. package/node_modules/@nodelib/fs.stat/out/index.js +26 -0
  123. package/node_modules/@nodelib/fs.stat/out/providers/async.d.ts +4 -0
  124. package/node_modules/@nodelib/fs.stat/out/providers/async.js +36 -0
  125. package/node_modules/@nodelib/fs.stat/out/providers/sync.d.ts +3 -0
  126. package/node_modules/@nodelib/fs.stat/out/providers/sync.js +23 -0
  127. package/node_modules/@nodelib/fs.stat/out/settings.d.ts +16 -0
  128. package/node_modules/@nodelib/fs.stat/out/settings.js +16 -0
  129. package/node_modules/@nodelib/fs.stat/out/types/index.d.ts +4 -0
  130. package/node_modules/@nodelib/fs.stat/out/types/index.js +2 -0
  131. package/node_modules/@nodelib/fs.stat/package.json +37 -0
  132. package/node_modules/@nodelib/fs.walk/LICENSE +21 -0
  133. package/node_modules/@nodelib/fs.walk/README.md +215 -0
  134. package/node_modules/@nodelib/fs.walk/out/index.d.ts +14 -0
  135. package/node_modules/@nodelib/fs.walk/out/index.js +34 -0
  136. package/node_modules/@nodelib/fs.walk/out/providers/async.d.ts +12 -0
  137. package/node_modules/@nodelib/fs.walk/out/providers/async.js +30 -0
  138. package/node_modules/@nodelib/fs.walk/out/providers/index.d.ts +4 -0
  139. package/node_modules/@nodelib/fs.walk/out/providers/index.js +9 -0
  140. package/node_modules/@nodelib/fs.walk/out/providers/stream.d.ts +12 -0
  141. package/node_modules/@nodelib/fs.walk/out/providers/stream.js +34 -0
  142. package/node_modules/@nodelib/fs.walk/out/providers/sync.d.ts +10 -0
  143. package/node_modules/@nodelib/fs.walk/out/providers/sync.js +14 -0
  144. package/node_modules/@nodelib/fs.walk/out/readers/async.d.ts +30 -0
  145. package/node_modules/@nodelib/fs.walk/out/readers/async.js +97 -0
  146. package/node_modules/@nodelib/fs.walk/out/readers/common.d.ts +7 -0
  147. package/node_modules/@nodelib/fs.walk/out/readers/common.js +31 -0
  148. package/node_modules/@nodelib/fs.walk/out/readers/reader.d.ts +6 -0
  149. package/node_modules/@nodelib/fs.walk/out/readers/reader.js +11 -0
  150. package/node_modules/@nodelib/fs.walk/out/readers/sync.d.ts +15 -0
  151. package/node_modules/@nodelib/fs.walk/out/readers/sync.js +59 -0
  152. package/node_modules/@nodelib/fs.walk/out/settings.d.ts +30 -0
  153. package/node_modules/@nodelib/fs.walk/out/settings.js +26 -0
  154. package/node_modules/@nodelib/fs.walk/out/types/index.d.ts +8 -0
  155. package/node_modules/@nodelib/fs.walk/out/types/index.js +2 -0
  156. package/node_modules/@nodelib/fs.walk/package.json +44 -0
  157. package/node_modules/@ungap/structured-clone/.github/workflows/node.js.yml +31 -0
  158. package/node_modules/@ungap/structured-clone/LICENSE +15 -0
  159. package/node_modules/@ungap/structured-clone/README.md +95 -0
  160. package/node_modules/@ungap/structured-clone/cjs/deserialize.js +78 -0
  161. package/node_modules/@ungap/structured-clone/cjs/index.js +27 -0
  162. package/node_modules/@ungap/structured-clone/cjs/json.js +24 -0
  163. package/node_modules/@ungap/structured-clone/cjs/package.json +1 -0
  164. package/node_modules/@ungap/structured-clone/cjs/serialize.js +160 -0
  165. package/node_modules/@ungap/structured-clone/cjs/types.js +22 -0
  166. package/node_modules/@ungap/structured-clone/esm/deserialize.js +79 -0
  167. package/node_modules/@ungap/structured-clone/esm/index.js +25 -0
  168. package/node_modules/@ungap/structured-clone/esm/json.js +21 -0
  169. package/node_modules/@ungap/structured-clone/esm/serialize.js +161 -0
  170. package/node_modules/@ungap/structured-clone/esm/types.js +11 -0
  171. package/node_modules/@ungap/structured-clone/package.json +53 -0
  172. package/node_modules/@ungap/structured-clone/structured-json.js +1 -0
  173. package/package.json +1 -1
  174. package/rules/dayjs-with-timezone.js +29 -0
@@ -0,0 +1,1149 @@
1
+ /**
2
+ * @fileoverview The factory of `ConfigArray` objects.
3
+ *
4
+ * This class provides methods to create `ConfigArray` instance.
5
+ *
6
+ * - `create(configData, options)`
7
+ * Create a `ConfigArray` instance from a config data. This is to handle CLI
8
+ * options except `--config`.
9
+ * - `loadFile(filePath, options)`
10
+ * Create a `ConfigArray` instance from a config file. This is to handle
11
+ * `--config` option. If the file was not found, throws the following error:
12
+ * - If the filename was `*.js`, a `MODULE_NOT_FOUND` error.
13
+ * - If the filename was `package.json`, an IO error or an
14
+ * `ESLINT_CONFIG_FIELD_NOT_FOUND` error.
15
+ * - Otherwise, an IO error such as `ENOENT`.
16
+ * - `loadInDirectory(directoryPath, options)`
17
+ * Create a `ConfigArray` instance from a config file which is on a given
18
+ * directory. This tries to load `.eslintrc.*` or `package.json`. If not
19
+ * found, returns an empty `ConfigArray`.
20
+ * - `loadESLintIgnore(filePath)`
21
+ * Create a `ConfigArray` instance from a config file that is `.eslintignore`
22
+ * format. This is to handle `--ignore-path` option.
23
+ * - `loadDefaultESLintIgnore()`
24
+ * Create a `ConfigArray` instance from `.eslintignore` or `package.json` in
25
+ * the current working directory.
26
+ *
27
+ * `ConfigArrayFactory` class has the responsibility that loads configuration
28
+ * files, including loading `extends`, `parser`, and `plugins`. The created
29
+ * `ConfigArray` instance has the loaded `extends`, `parser`, and `plugins`.
30
+ *
31
+ * But this class doesn't handle cascading. `CascadingConfigArrayFactory` class
32
+ * handles cascading and hierarchy.
33
+ *
34
+ * @author Toru Nagashima <https://github.com/mysticatea>
35
+ */
36
+
37
+ //------------------------------------------------------------------------------
38
+ // Requirements
39
+ //------------------------------------------------------------------------------
40
+
41
+ import debugOrig from "debug";
42
+ import fs from "fs";
43
+ import importFresh from "import-fresh";
44
+ import { createRequire } from "module";
45
+ import path from "path";
46
+ import stripComments from "strip-json-comments";
47
+
48
+ import {
49
+ ConfigArray,
50
+ ConfigDependency,
51
+ IgnorePattern,
52
+ OverrideTester
53
+ } from "./config-array/index.js";
54
+ import ConfigValidator from "./shared/config-validator.js";
55
+ import * as naming from "./shared/naming.js";
56
+ import * as ModuleResolver from "./shared/relative-module-resolver.js";
57
+
58
+ const require = createRequire(import.meta.url);
59
+
60
+ const debug = debugOrig("eslintrc:config-array-factory");
61
+
62
+ //------------------------------------------------------------------------------
63
+ // Helpers
64
+ //------------------------------------------------------------------------------
65
+
66
+ const configFilenames = [
67
+ ".eslintrc.js",
68
+ ".eslintrc.cjs",
69
+ ".eslintrc.yaml",
70
+ ".eslintrc.yml",
71
+ ".eslintrc.json",
72
+ ".eslintrc",
73
+ "package.json"
74
+ ];
75
+
76
+ // Define types for VSCode IntelliSense.
77
+ /** @typedef {import("./shared/types").ConfigData} ConfigData */
78
+ /** @typedef {import("./shared/types").OverrideConfigData} OverrideConfigData */
79
+ /** @typedef {import("./shared/types").Parser} Parser */
80
+ /** @typedef {import("./shared/types").Plugin} Plugin */
81
+ /** @typedef {import("./shared/types").Rule} Rule */
82
+ /** @typedef {import("./config-array/config-dependency").DependentParser} DependentParser */
83
+ /** @typedef {import("./config-array/config-dependency").DependentPlugin} DependentPlugin */
84
+ /** @typedef {ConfigArray[0]} ConfigArrayElement */
85
+
86
+ /**
87
+ * @typedef {Object} ConfigArrayFactoryOptions
88
+ * @property {Map<string,Plugin>} [additionalPluginPool] The map for additional plugins.
89
+ * @property {string} [cwd] The path to the current working directory.
90
+ * @property {string} [resolvePluginsRelativeTo] A path to the directory that plugins should be resolved from. Defaults to `cwd`.
91
+ * @property {Map<string,Rule>} builtInRules The rules that are built in to ESLint.
92
+ * @property {Object} [resolver=ModuleResolver] The module resolver object.
93
+ * @property {string} eslintAllPath The path to the definitions for eslint:all.
94
+ * @property {Function} getEslintAllConfig Returns the config data for eslint:all.
95
+ * @property {string} eslintRecommendedPath The path to the definitions for eslint:recommended.
96
+ * @property {Function} getEslintRecommendedConfig Returns the config data for eslint:recommended.
97
+ */
98
+
99
+ /**
100
+ * @typedef {Object} ConfigArrayFactoryInternalSlots
101
+ * @property {Map<string,Plugin>} additionalPluginPool The map for additional plugins.
102
+ * @property {string} cwd The path to the current working directory.
103
+ * @property {string | undefined} resolvePluginsRelativeTo An absolute path the the directory that plugins should be resolved from.
104
+ * @property {Map<string,Rule>} builtInRules The rules that are built in to ESLint.
105
+ * @property {Object} [resolver=ModuleResolver] The module resolver object.
106
+ * @property {string} eslintAllPath The path to the definitions for eslint:all.
107
+ * @property {Function} getEslintAllConfig Returns the config data for eslint:all.
108
+ * @property {string} eslintRecommendedPath The path to the definitions for eslint:recommended.
109
+ * @property {Function} getEslintRecommendedConfig Returns the config data for eslint:recommended.
110
+ */
111
+
112
+ /**
113
+ * @typedef {Object} ConfigArrayFactoryLoadingContext
114
+ * @property {string} filePath The path to the current configuration.
115
+ * @property {string} matchBasePath The base path to resolve relative paths in `overrides[].files`, `overrides[].excludedFiles`, and `ignorePatterns`.
116
+ * @property {string} name The name of the current configuration.
117
+ * @property {string} pluginBasePath The base path to resolve plugins.
118
+ * @property {"config" | "ignore" | "implicit-processor"} type The type of the current configuration. This is `"config"` in normal. This is `"ignore"` if it came from `.eslintignore`. This is `"implicit-processor"` if it came from legacy file-extension processors.
119
+ */
120
+
121
+ /**
122
+ * @typedef {Object} ConfigArrayFactoryLoadingContext
123
+ * @property {string} filePath The path to the current configuration.
124
+ * @property {string} matchBasePath The base path to resolve relative paths in `overrides[].files`, `overrides[].excludedFiles`, and `ignorePatterns`.
125
+ * @property {string} name The name of the current configuration.
126
+ * @property {"config" | "ignore" | "implicit-processor"} type The type of the current configuration. This is `"config"` in normal. This is `"ignore"` if it came from `.eslintignore`. This is `"implicit-processor"` if it came from legacy file-extension processors.
127
+ */
128
+
129
+ /** @type {WeakMap<ConfigArrayFactory, ConfigArrayFactoryInternalSlots>} */
130
+ const internalSlotsMap = new WeakMap();
131
+
132
+ /** @type {WeakMap<object, Plugin>} */
133
+ const normalizedPlugins = new WeakMap();
134
+
135
+ /**
136
+ * Check if a given string is a file path.
137
+ * @param {string} nameOrPath A module name or file path.
138
+ * @returns {boolean} `true` if the `nameOrPath` is a file path.
139
+ */
140
+ function isFilePath(nameOrPath) {
141
+ return (
142
+ /^\.{1,2}[/\\]/u.test(nameOrPath) ||
143
+ path.isAbsolute(nameOrPath)
144
+ );
145
+ }
146
+
147
+ /**
148
+ * Convenience wrapper for synchronously reading file contents.
149
+ * @param {string} filePath The filename to read.
150
+ * @returns {string} The file contents, with the BOM removed.
151
+ * @private
152
+ */
153
+ function readFile(filePath) {
154
+ return fs.readFileSync(filePath, "utf8").replace(/^\ufeff/u, "");
155
+ }
156
+
157
+ /**
158
+ * Loads a YAML configuration from a file.
159
+ * @param {string} filePath The filename to load.
160
+ * @returns {ConfigData} The configuration object from the file.
161
+ * @throws {Error} If the file cannot be read.
162
+ * @private
163
+ */
164
+ function loadYAMLConfigFile(filePath) {
165
+ debug(`Loading YAML config file: ${filePath}`);
166
+
167
+ // lazy load YAML to improve performance when not used
168
+ const yaml = require("js-yaml");
169
+
170
+ try {
171
+
172
+ // empty YAML file can be null, so always use
173
+ return yaml.load(readFile(filePath)) || {};
174
+ } catch (e) {
175
+ debug(`Error reading YAML file: ${filePath}`);
176
+ e.message = `Cannot read config file: ${filePath}\nError: ${e.message}`;
177
+ throw e;
178
+ }
179
+ }
180
+
181
+ /**
182
+ * Loads a JSON configuration from a file.
183
+ * @param {string} filePath The filename to load.
184
+ * @returns {ConfigData} The configuration object from the file.
185
+ * @throws {Error} If the file cannot be read.
186
+ * @private
187
+ */
188
+ function loadJSONConfigFile(filePath) {
189
+ debug(`Loading JSON config file: ${filePath}`);
190
+
191
+ try {
192
+ return JSON.parse(stripComments(readFile(filePath)));
193
+ } catch (e) {
194
+ debug(`Error reading JSON file: ${filePath}`);
195
+ e.message = `Cannot read config file: ${filePath}\nError: ${e.message}`;
196
+ e.messageTemplate = "failed-to-read-json";
197
+ e.messageData = {
198
+ path: filePath,
199
+ message: e.message
200
+ };
201
+ throw e;
202
+ }
203
+ }
204
+
205
+ /**
206
+ * Loads a legacy (.eslintrc) configuration from a file.
207
+ * @param {string} filePath The filename to load.
208
+ * @returns {ConfigData} The configuration object from the file.
209
+ * @throws {Error} If the file cannot be read.
210
+ * @private
211
+ */
212
+ function loadLegacyConfigFile(filePath) {
213
+ debug(`Loading legacy config file: ${filePath}`);
214
+
215
+ // lazy load YAML to improve performance when not used
216
+ const yaml = require("js-yaml");
217
+
218
+ try {
219
+ return yaml.load(stripComments(readFile(filePath))) || /* istanbul ignore next */ {};
220
+ } catch (e) {
221
+ debug("Error reading YAML file: %s\n%o", filePath, e);
222
+ e.message = `Cannot read config file: ${filePath}\nError: ${e.message}`;
223
+ throw e;
224
+ }
225
+ }
226
+
227
+ /**
228
+ * Loads a JavaScript configuration from a file.
229
+ * @param {string} filePath The filename to load.
230
+ * @returns {ConfigData} The configuration object from the file.
231
+ * @throws {Error} If the file cannot be read.
232
+ * @private
233
+ */
234
+ function loadJSConfigFile(filePath) {
235
+ debug(`Loading JS config file: ${filePath}`);
236
+ try {
237
+ return importFresh(filePath);
238
+ } catch (e) {
239
+ debug(`Error reading JavaScript file: ${filePath}`);
240
+ e.message = `Cannot read config file: ${filePath}\nError: ${e.message}`;
241
+ throw e;
242
+ }
243
+ }
244
+
245
+ /**
246
+ * Loads a configuration from a package.json file.
247
+ * @param {string} filePath The filename to load.
248
+ * @returns {ConfigData} The configuration object from the file.
249
+ * @throws {Error} If the file cannot be read.
250
+ * @private
251
+ */
252
+ function loadPackageJSONConfigFile(filePath) {
253
+ debug(`Loading package.json config file: ${filePath}`);
254
+ try {
255
+ const packageData = loadJSONConfigFile(filePath);
256
+
257
+ if (!Object.hasOwnProperty.call(packageData, "eslintConfig")) {
258
+ throw Object.assign(
259
+ new Error("package.json file doesn't have 'eslintConfig' field."),
260
+ { code: "ESLINT_CONFIG_FIELD_NOT_FOUND" }
261
+ );
262
+ }
263
+
264
+ return packageData.eslintConfig;
265
+ } catch (e) {
266
+ debug(`Error reading package.json file: ${filePath}`);
267
+ e.message = `Cannot read config file: ${filePath}\nError: ${e.message}`;
268
+ throw e;
269
+ }
270
+ }
271
+
272
+ /**
273
+ * Loads a `.eslintignore` from a file.
274
+ * @param {string} filePath The filename to load.
275
+ * @returns {string[]} The ignore patterns from the file.
276
+ * @private
277
+ */
278
+ function loadESLintIgnoreFile(filePath) {
279
+ debug(`Loading .eslintignore file: ${filePath}`);
280
+
281
+ try {
282
+ return readFile(filePath)
283
+ .split(/\r?\n/gu)
284
+ .filter(line => line.trim() !== "" && !line.startsWith("#"));
285
+ } catch (e) {
286
+ debug(`Error reading .eslintignore file: ${filePath}`);
287
+ e.message = `Cannot read .eslintignore file: ${filePath}\nError: ${e.message}`;
288
+ throw e;
289
+ }
290
+ }
291
+
292
+ /**
293
+ * Creates an error to notify about a missing config to extend from.
294
+ * @param {string} configName The name of the missing config.
295
+ * @param {string} importerName The name of the config that imported the missing config
296
+ * @param {string} messageTemplate The text template to source error strings from.
297
+ * @returns {Error} The error object to throw
298
+ * @private
299
+ */
300
+ function configInvalidError(configName, importerName, messageTemplate) {
301
+ return Object.assign(
302
+ new Error(`Failed to load config "${configName}" to extend from.`),
303
+ {
304
+ messageTemplate,
305
+ messageData: { configName, importerName }
306
+ }
307
+ );
308
+ }
309
+
310
+ /**
311
+ * Loads a configuration file regardless of the source. Inspects the file path
312
+ * to determine the correctly way to load the config file.
313
+ * @param {string} filePath The path to the configuration.
314
+ * @returns {ConfigData|null} The configuration information.
315
+ * @private
316
+ */
317
+ function loadConfigFile(filePath) {
318
+ switch (path.extname(filePath)) {
319
+ case ".js":
320
+ case ".cjs":
321
+ return loadJSConfigFile(filePath);
322
+
323
+ case ".json":
324
+ if (path.basename(filePath) === "package.json") {
325
+ return loadPackageJSONConfigFile(filePath);
326
+ }
327
+ return loadJSONConfigFile(filePath);
328
+
329
+ case ".yaml":
330
+ case ".yml":
331
+ return loadYAMLConfigFile(filePath);
332
+
333
+ default:
334
+ return loadLegacyConfigFile(filePath);
335
+ }
336
+ }
337
+
338
+ /**
339
+ * Write debug log.
340
+ * @param {string} request The requested module name.
341
+ * @param {string} relativeTo The file path to resolve the request relative to.
342
+ * @param {string} filePath The resolved file path.
343
+ * @returns {void}
344
+ */
345
+ function writeDebugLogForLoading(request, relativeTo, filePath) {
346
+ /* istanbul ignore next */
347
+ if (debug.enabled) {
348
+ let nameAndVersion = null;
349
+
350
+ try {
351
+ const packageJsonPath = ModuleResolver.resolve(
352
+ `${request}/package.json`,
353
+ relativeTo
354
+ );
355
+ const { version = "unknown" } = require(packageJsonPath);
356
+
357
+ nameAndVersion = `${request}@${version}`;
358
+ } catch (error) {
359
+ debug("package.json was not found:", error.message);
360
+ nameAndVersion = request;
361
+ }
362
+
363
+ debug("Loaded: %s (%s)", nameAndVersion, filePath);
364
+ }
365
+ }
366
+
367
+ /**
368
+ * Create a new context with default values.
369
+ * @param {ConfigArrayFactoryInternalSlots} slots The internal slots.
370
+ * @param {"config" | "ignore" | "implicit-processor" | undefined} providedType The type of the current configuration. Default is `"config"`.
371
+ * @param {string | undefined} providedName The name of the current configuration. Default is the relative path from `cwd` to `filePath`.
372
+ * @param {string | undefined} providedFilePath The path to the current configuration. Default is empty string.
373
+ * @param {string | undefined} providedMatchBasePath The type of the current configuration. Default is the directory of `filePath` or `cwd`.
374
+ * @returns {ConfigArrayFactoryLoadingContext} The created context.
375
+ */
376
+ function createContext(
377
+ { cwd, resolvePluginsRelativeTo },
378
+ providedType,
379
+ providedName,
380
+ providedFilePath,
381
+ providedMatchBasePath
382
+ ) {
383
+ const filePath = providedFilePath
384
+ ? path.resolve(cwd, providedFilePath)
385
+ : "";
386
+ const matchBasePath =
387
+ (providedMatchBasePath && path.resolve(cwd, providedMatchBasePath)) ||
388
+ (filePath && path.dirname(filePath)) ||
389
+ cwd;
390
+ const name =
391
+ providedName ||
392
+ (filePath && path.relative(cwd, filePath)) ||
393
+ "";
394
+ const pluginBasePath =
395
+ resolvePluginsRelativeTo ||
396
+ (filePath && path.dirname(filePath)) ||
397
+ cwd;
398
+ const type = providedType || "config";
399
+
400
+ return { filePath, matchBasePath, name, pluginBasePath, type };
401
+ }
402
+
403
+ /**
404
+ * Normalize a given plugin.
405
+ * - Ensure the object to have four properties: configs, environments, processors, and rules.
406
+ * - Ensure the object to not have other properties.
407
+ * @param {Plugin} plugin The plugin to normalize.
408
+ * @returns {Plugin} The normalized plugin.
409
+ */
410
+ function normalizePlugin(plugin) {
411
+
412
+ // first check the cache
413
+ let normalizedPlugin = normalizedPlugins.get(plugin);
414
+
415
+ if (normalizedPlugin) {
416
+ return normalizedPlugin;
417
+ }
418
+
419
+ normalizedPlugin = {
420
+ configs: plugin.configs || {},
421
+ environments: plugin.environments || {},
422
+ processors: plugin.processors || {},
423
+ rules: plugin.rules || {}
424
+ };
425
+
426
+ // save the reference for later
427
+ normalizedPlugins.set(plugin, normalizedPlugin);
428
+
429
+ return normalizedPlugin;
430
+ }
431
+
432
+ //------------------------------------------------------------------------------
433
+ // Public Interface
434
+ //------------------------------------------------------------------------------
435
+
436
+ /**
437
+ * The factory of `ConfigArray` objects.
438
+ */
439
+ class ConfigArrayFactory {
440
+
441
+ /**
442
+ * Initialize this instance.
443
+ * @param {ConfigArrayFactoryOptions} [options] The map for additional plugins.
444
+ */
445
+ constructor({
446
+ additionalPluginPool = new Map(),
447
+ cwd = process.cwd(),
448
+ resolvePluginsRelativeTo,
449
+ builtInRules,
450
+ resolver = ModuleResolver,
451
+ eslintAllPath,
452
+ getEslintAllConfig,
453
+ eslintRecommendedPath,
454
+ getEslintRecommendedConfig
455
+ } = {}) {
456
+ internalSlotsMap.set(this, {
457
+ additionalPluginPool,
458
+ cwd,
459
+ resolvePluginsRelativeTo:
460
+ resolvePluginsRelativeTo &&
461
+ path.resolve(cwd, resolvePluginsRelativeTo),
462
+ builtInRules,
463
+ resolver,
464
+ eslintAllPath,
465
+ getEslintAllConfig,
466
+ eslintRecommendedPath,
467
+ getEslintRecommendedConfig
468
+ });
469
+ }
470
+
471
+ /**
472
+ * Create `ConfigArray` instance from a config data.
473
+ * @param {ConfigData|null} configData The config data to create.
474
+ * @param {Object} [options] The options.
475
+ * @param {string} [options.basePath] The base path to resolve relative paths in `overrides[].files`, `overrides[].excludedFiles`, and `ignorePatterns`.
476
+ * @param {string} [options.filePath] The path to this config data.
477
+ * @param {string} [options.name] The config name.
478
+ * @returns {ConfigArray} Loaded config.
479
+ */
480
+ create(configData, { basePath, filePath, name } = {}) {
481
+ if (!configData) {
482
+ return new ConfigArray();
483
+ }
484
+
485
+ const slots = internalSlotsMap.get(this);
486
+ const ctx = createContext(slots, "config", name, filePath, basePath);
487
+ const elements = this._normalizeConfigData(configData, ctx);
488
+
489
+ return new ConfigArray(...elements);
490
+ }
491
+
492
+ /**
493
+ * Load a config file.
494
+ * @param {string} filePath The path to a config file.
495
+ * @param {Object} [options] The options.
496
+ * @param {string} [options.basePath] The base path to resolve relative paths in `overrides[].files`, `overrides[].excludedFiles`, and `ignorePatterns`.
497
+ * @param {string} [options.name] The config name.
498
+ * @returns {ConfigArray} Loaded config.
499
+ */
500
+ loadFile(filePath, { basePath, name } = {}) {
501
+ const slots = internalSlotsMap.get(this);
502
+ const ctx = createContext(slots, "config", name, filePath, basePath);
503
+
504
+ return new ConfigArray(...this._loadConfigData(ctx));
505
+ }
506
+
507
+ /**
508
+ * Load the config file on a given directory if exists.
509
+ * @param {string} directoryPath The path to a directory.
510
+ * @param {Object} [options] The options.
511
+ * @param {string} [options.basePath] The base path to resolve relative paths in `overrides[].files`, `overrides[].excludedFiles`, and `ignorePatterns`.
512
+ * @param {string} [options.name] The config name.
513
+ * @returns {ConfigArray} Loaded config. An empty `ConfigArray` if any config doesn't exist.
514
+ */
515
+ loadInDirectory(directoryPath, { basePath, name } = {}) {
516
+ const slots = internalSlotsMap.get(this);
517
+
518
+ for (const filename of configFilenames) {
519
+ const ctx = createContext(
520
+ slots,
521
+ "config",
522
+ name,
523
+ path.join(directoryPath, filename),
524
+ basePath
525
+ );
526
+
527
+ if (fs.existsSync(ctx.filePath) && fs.statSync(ctx.filePath).isFile()) {
528
+ let configData;
529
+
530
+ try {
531
+ configData = loadConfigFile(ctx.filePath);
532
+ } catch (error) {
533
+ if (!error || error.code !== "ESLINT_CONFIG_FIELD_NOT_FOUND") {
534
+ throw error;
535
+ }
536
+ }
537
+
538
+ if (configData) {
539
+ debug(`Config file found: ${ctx.filePath}`);
540
+ return new ConfigArray(
541
+ ...this._normalizeConfigData(configData, ctx)
542
+ );
543
+ }
544
+ }
545
+ }
546
+
547
+ debug(`Config file not found on ${directoryPath}`);
548
+ return new ConfigArray();
549
+ }
550
+
551
+ /**
552
+ * Check if a config file on a given directory exists or not.
553
+ * @param {string} directoryPath The path to a directory.
554
+ * @returns {string | null} The path to the found config file. If not found then null.
555
+ */
556
+ static getPathToConfigFileInDirectory(directoryPath) {
557
+ for (const filename of configFilenames) {
558
+ const filePath = path.join(directoryPath, filename);
559
+
560
+ if (fs.existsSync(filePath)) {
561
+ if (filename === "package.json") {
562
+ try {
563
+ loadPackageJSONConfigFile(filePath);
564
+ return filePath;
565
+ } catch { /* ignore */ }
566
+ } else {
567
+ return filePath;
568
+ }
569
+ }
570
+ }
571
+ return null;
572
+ }
573
+
574
+ /**
575
+ * Load `.eslintignore` file.
576
+ * @param {string} filePath The path to a `.eslintignore` file to load.
577
+ * @returns {ConfigArray} Loaded config. An empty `ConfigArray` if any config doesn't exist.
578
+ */
579
+ loadESLintIgnore(filePath) {
580
+ const slots = internalSlotsMap.get(this);
581
+ const ctx = createContext(
582
+ slots,
583
+ "ignore",
584
+ void 0,
585
+ filePath,
586
+ slots.cwd
587
+ );
588
+ const ignorePatterns = loadESLintIgnoreFile(ctx.filePath);
589
+
590
+ return new ConfigArray(
591
+ ...this._normalizeESLintIgnoreData(ignorePatterns, ctx)
592
+ );
593
+ }
594
+
595
+ /**
596
+ * Load `.eslintignore` file in the current working directory.
597
+ * @returns {ConfigArray} Loaded config. An empty `ConfigArray` if any config doesn't exist.
598
+ */
599
+ loadDefaultESLintIgnore() {
600
+ const slots = internalSlotsMap.get(this);
601
+ const eslintIgnorePath = path.resolve(slots.cwd, ".eslintignore");
602
+ const packageJsonPath = path.resolve(slots.cwd, "package.json");
603
+
604
+ if (fs.existsSync(eslintIgnorePath)) {
605
+ return this.loadESLintIgnore(eslintIgnorePath);
606
+ }
607
+ if (fs.existsSync(packageJsonPath)) {
608
+ const data = loadJSONConfigFile(packageJsonPath);
609
+
610
+ if (Object.hasOwnProperty.call(data, "eslintIgnore")) {
611
+ if (!Array.isArray(data.eslintIgnore)) {
612
+ throw new Error("Package.json eslintIgnore property requires an array of paths");
613
+ }
614
+ const ctx = createContext(
615
+ slots,
616
+ "ignore",
617
+ "eslintIgnore in package.json",
618
+ packageJsonPath,
619
+ slots.cwd
620
+ );
621
+
622
+ return new ConfigArray(
623
+ ...this._normalizeESLintIgnoreData(data.eslintIgnore, ctx)
624
+ );
625
+ }
626
+ }
627
+
628
+ return new ConfigArray();
629
+ }
630
+
631
+ /**
632
+ * Load a given config file.
633
+ * @param {ConfigArrayFactoryLoadingContext} ctx The loading context.
634
+ * @returns {IterableIterator<ConfigArrayElement>} Loaded config.
635
+ * @private
636
+ */
637
+ _loadConfigData(ctx) {
638
+ return this._normalizeConfigData(loadConfigFile(ctx.filePath), ctx);
639
+ }
640
+
641
+ /**
642
+ * Normalize a given `.eslintignore` data to config array elements.
643
+ * @param {string[]} ignorePatterns The patterns to ignore files.
644
+ * @param {ConfigArrayFactoryLoadingContext} ctx The loading context.
645
+ * @returns {IterableIterator<ConfigArrayElement>} The normalized config.
646
+ * @private
647
+ */
648
+ *_normalizeESLintIgnoreData(ignorePatterns, ctx) {
649
+ const elements = this._normalizeObjectConfigData(
650
+ { ignorePatterns },
651
+ ctx
652
+ );
653
+
654
+ // Set `ignorePattern.loose` flag for backward compatibility.
655
+ for (const element of elements) {
656
+ if (element.ignorePattern) {
657
+ element.ignorePattern.loose = true;
658
+ }
659
+ yield element;
660
+ }
661
+ }
662
+
663
+ /**
664
+ * Normalize a given config to an array.
665
+ * @param {ConfigData} configData The config data to normalize.
666
+ * @param {ConfigArrayFactoryLoadingContext} ctx The loading context.
667
+ * @returns {IterableIterator<ConfigArrayElement>} The normalized config.
668
+ * @private
669
+ */
670
+ _normalizeConfigData(configData, ctx) {
671
+ const validator = new ConfigValidator();
672
+
673
+ validator.validateConfigSchema(configData, ctx.name || ctx.filePath);
674
+ return this._normalizeObjectConfigData(configData, ctx);
675
+ }
676
+
677
+ /**
678
+ * Normalize a given config to an array.
679
+ * @param {ConfigData|OverrideConfigData} configData The config data to normalize.
680
+ * @param {ConfigArrayFactoryLoadingContext} ctx The loading context.
681
+ * @returns {IterableIterator<ConfigArrayElement>} The normalized config.
682
+ * @private
683
+ */
684
+ *_normalizeObjectConfigData(configData, ctx) {
685
+ const { files, excludedFiles, ...configBody } = configData;
686
+ const criteria = OverrideTester.create(
687
+ files,
688
+ excludedFiles,
689
+ ctx.matchBasePath
690
+ );
691
+ const elements = this._normalizeObjectConfigDataBody(configBody, ctx);
692
+
693
+ // Apply the criteria to every element.
694
+ for (const element of elements) {
695
+
696
+ /*
697
+ * Merge the criteria.
698
+ * This is for the `overrides` entries that came from the
699
+ * configurations of `overrides[].extends`.
700
+ */
701
+ element.criteria = OverrideTester.and(criteria, element.criteria);
702
+
703
+ /*
704
+ * Remove `root` property to ignore `root` settings which came from
705
+ * `extends` in `overrides`.
706
+ */
707
+ if (element.criteria) {
708
+ element.root = void 0;
709
+ }
710
+
711
+ yield element;
712
+ }
713
+ }
714
+
715
+ /**
716
+ * Normalize a given config to an array.
717
+ * @param {ConfigData} configData The config data to normalize.
718
+ * @param {ConfigArrayFactoryLoadingContext} ctx The loading context.
719
+ * @returns {IterableIterator<ConfigArrayElement>} The normalized config.
720
+ * @private
721
+ */
722
+ *_normalizeObjectConfigDataBody(
723
+ {
724
+ env,
725
+ extends: extend,
726
+ globals,
727
+ ignorePatterns,
728
+ noInlineConfig,
729
+ parser: parserName,
730
+ parserOptions,
731
+ plugins: pluginList,
732
+ processor,
733
+ reportUnusedDisableDirectives,
734
+ root,
735
+ rules,
736
+ settings,
737
+ overrides: overrideList = []
738
+ },
739
+ ctx
740
+ ) {
741
+ const extendList = Array.isArray(extend) ? extend : [extend];
742
+ const ignorePattern = ignorePatterns && new IgnorePattern(
743
+ Array.isArray(ignorePatterns) ? ignorePatterns : [ignorePatterns],
744
+ ctx.matchBasePath
745
+ );
746
+
747
+ // Flatten `extends`.
748
+ for (const extendName of extendList.filter(Boolean)) {
749
+ yield* this._loadExtends(extendName, ctx);
750
+ }
751
+
752
+ // Load parser & plugins.
753
+ const parser = parserName && this._loadParser(parserName, ctx);
754
+ const plugins = pluginList && this._loadPlugins(pluginList, ctx);
755
+
756
+ // Yield pseudo config data for file extension processors.
757
+ if (plugins) {
758
+ yield* this._takeFileExtensionProcessors(plugins, ctx);
759
+ }
760
+
761
+ // Yield the config data except `extends` and `overrides`.
762
+ yield {
763
+
764
+ // Debug information.
765
+ type: ctx.type,
766
+ name: ctx.name,
767
+ filePath: ctx.filePath,
768
+
769
+ // Config data.
770
+ criteria: null,
771
+ env,
772
+ globals,
773
+ ignorePattern,
774
+ noInlineConfig,
775
+ parser,
776
+ parserOptions,
777
+ plugins,
778
+ processor,
779
+ reportUnusedDisableDirectives,
780
+ root,
781
+ rules,
782
+ settings
783
+ };
784
+
785
+ // Flatten `overries`.
786
+ for (let i = 0; i < overrideList.length; ++i) {
787
+ yield* this._normalizeObjectConfigData(
788
+ overrideList[i],
789
+ { ...ctx, name: `${ctx.name}#overrides[${i}]` }
790
+ );
791
+ }
792
+ }
793
+
794
+ /**
795
+ * Load configs of an element in `extends`.
796
+ * @param {string} extendName The name of a base config.
797
+ * @param {ConfigArrayFactoryLoadingContext} ctx The loading context.
798
+ * @returns {IterableIterator<ConfigArrayElement>} The normalized config.
799
+ * @private
800
+ */
801
+ _loadExtends(extendName, ctx) {
802
+ debug("Loading {extends:%j} relative to %s", extendName, ctx.filePath);
803
+ try {
804
+ if (extendName.startsWith("eslint:")) {
805
+ return this._loadExtendedBuiltInConfig(extendName, ctx);
806
+ }
807
+ if (extendName.startsWith("plugin:")) {
808
+ return this._loadExtendedPluginConfig(extendName, ctx);
809
+ }
810
+ return this._loadExtendedShareableConfig(extendName, ctx);
811
+ } catch (error) {
812
+ error.message += `\nReferenced from: ${ctx.filePath || ctx.name}`;
813
+ throw error;
814
+ }
815
+ }
816
+
817
+ /**
818
+ * Load configs of an element in `extends`.
819
+ * @param {string} extendName The name of a base config.
820
+ * @param {ConfigArrayFactoryLoadingContext} ctx The loading context.
821
+ * @returns {IterableIterator<ConfigArrayElement>} The normalized config.
822
+ * @private
823
+ */
824
+ _loadExtendedBuiltInConfig(extendName, ctx) {
825
+ const {
826
+ eslintAllPath,
827
+ getEslintAllConfig,
828
+ eslintRecommendedPath,
829
+ getEslintRecommendedConfig
830
+ } = internalSlotsMap.get(this);
831
+
832
+ if (extendName === "eslint:recommended") {
833
+ const name = `${ctx.name} » ${extendName}`;
834
+
835
+ if (getEslintRecommendedConfig) {
836
+ if (typeof getEslintRecommendedConfig !== "function") {
837
+ throw new Error(`getEslintRecommendedConfig must be a function instead of '${getEslintRecommendedConfig}'`);
838
+ }
839
+ return this._normalizeConfigData(getEslintRecommendedConfig(), { ...ctx, name, filePath: "" });
840
+ }
841
+ return this._loadConfigData({
842
+ ...ctx,
843
+ name,
844
+ filePath: eslintRecommendedPath
845
+ });
846
+ }
847
+ if (extendName === "eslint:all") {
848
+ const name = `${ctx.name} » ${extendName}`;
849
+
850
+ if (getEslintAllConfig) {
851
+ if (typeof getEslintAllConfig !== "function") {
852
+ throw new Error(`getEslintAllConfig must be a function instead of '${getEslintAllConfig}'`);
853
+ }
854
+ return this._normalizeConfigData(getEslintAllConfig(), { ...ctx, name, filePath: "" });
855
+ }
856
+ return this._loadConfigData({
857
+ ...ctx,
858
+ name,
859
+ filePath: eslintAllPath
860
+ });
861
+ }
862
+
863
+ throw configInvalidError(extendName, ctx.name, "extend-config-missing");
864
+ }
865
+
866
+ /**
867
+ * Load configs of an element in `extends`.
868
+ * @param {string} extendName The name of a base config.
869
+ * @param {ConfigArrayFactoryLoadingContext} ctx The loading context.
870
+ * @returns {IterableIterator<ConfigArrayElement>} The normalized config.
871
+ * @private
872
+ */
873
+ _loadExtendedPluginConfig(extendName, ctx) {
874
+ const slashIndex = extendName.lastIndexOf("/");
875
+
876
+ if (slashIndex === -1) {
877
+ throw configInvalidError(extendName, ctx.filePath, "plugin-invalid");
878
+ }
879
+
880
+ const pluginName = extendName.slice("plugin:".length, slashIndex);
881
+ const configName = extendName.slice(slashIndex + 1);
882
+
883
+ if (isFilePath(pluginName)) {
884
+ throw new Error("'extends' cannot use a file path for plugins.");
885
+ }
886
+
887
+ const plugin = this._loadPlugin(pluginName, ctx);
888
+ const configData =
889
+ plugin.definition &&
890
+ plugin.definition.configs[configName];
891
+
892
+ if (configData) {
893
+ return this._normalizeConfigData(configData, {
894
+ ...ctx,
895
+ filePath: plugin.filePath || ctx.filePath,
896
+ name: `${ctx.name} » plugin:${plugin.id}/${configName}`
897
+ });
898
+ }
899
+
900
+ throw plugin.error || configInvalidError(extendName, ctx.filePath, "extend-config-missing");
901
+ }
902
+
903
+ /**
904
+ * Load configs of an element in `extends`.
905
+ * @param {string} extendName The name of a base config.
906
+ * @param {ConfigArrayFactoryLoadingContext} ctx The loading context.
907
+ * @returns {IterableIterator<ConfigArrayElement>} The normalized config.
908
+ * @private
909
+ */
910
+ _loadExtendedShareableConfig(extendName, ctx) {
911
+ const { cwd, resolver } = internalSlotsMap.get(this);
912
+ const relativeTo = ctx.filePath || path.join(cwd, "__placeholder__.js");
913
+ let request;
914
+
915
+ if (isFilePath(extendName)) {
916
+ request = extendName;
917
+ } else if (extendName.startsWith(".")) {
918
+ request = `./${extendName}`; // For backward compatibility. A ton of tests depended on this behavior.
919
+ } else {
920
+ request = naming.normalizePackageName(
921
+ extendName,
922
+ "eslint-config"
923
+ );
924
+ }
925
+
926
+ let filePath;
927
+
928
+ try {
929
+ filePath = resolver.resolve(request, relativeTo);
930
+ } catch (error) {
931
+ /* istanbul ignore else */
932
+ if (error && error.code === "MODULE_NOT_FOUND") {
933
+ throw configInvalidError(extendName, ctx.filePath, "extend-config-missing");
934
+ }
935
+ throw error;
936
+ }
937
+
938
+ writeDebugLogForLoading(request, relativeTo, filePath);
939
+ return this._loadConfigData({
940
+ ...ctx,
941
+ filePath,
942
+ name: `${ctx.name} » ${request}`
943
+ });
944
+ }
945
+
946
+ /**
947
+ * Load given plugins.
948
+ * @param {string[]} names The plugin names to load.
949
+ * @param {ConfigArrayFactoryLoadingContext} ctx The loading context.
950
+ * @returns {Record<string,DependentPlugin>} The loaded parser.
951
+ * @private
952
+ */
953
+ _loadPlugins(names, ctx) {
954
+ return names.reduce((map, name) => {
955
+ if (isFilePath(name)) {
956
+ throw new Error("Plugins array cannot includes file paths.");
957
+ }
958
+ const plugin = this._loadPlugin(name, ctx);
959
+
960
+ map[plugin.id] = plugin;
961
+
962
+ return map;
963
+ }, {});
964
+ }
965
+
966
+ /**
967
+ * Load a given parser.
968
+ * @param {string} nameOrPath The package name or the path to a parser file.
969
+ * @param {ConfigArrayFactoryLoadingContext} ctx The loading context.
970
+ * @returns {DependentParser} The loaded parser.
971
+ */
972
+ _loadParser(nameOrPath, ctx) {
973
+ debug("Loading parser %j from %s", nameOrPath, ctx.filePath);
974
+
975
+ const { cwd, resolver } = internalSlotsMap.get(this);
976
+ const relativeTo = ctx.filePath || path.join(cwd, "__placeholder__.js");
977
+
978
+ try {
979
+ const filePath = resolver.resolve(nameOrPath, relativeTo);
980
+
981
+ writeDebugLogForLoading(nameOrPath, relativeTo, filePath);
982
+
983
+ return new ConfigDependency({
984
+ definition: require(filePath),
985
+ filePath,
986
+ id: nameOrPath,
987
+ importerName: ctx.name,
988
+ importerPath: ctx.filePath
989
+ });
990
+ } catch (error) {
991
+
992
+ // If the parser name is "espree", load the espree of ESLint.
993
+ if (nameOrPath === "espree") {
994
+ debug("Fallback espree.");
995
+ return new ConfigDependency({
996
+ definition: require("espree"),
997
+ filePath: require.resolve("espree"),
998
+ id: nameOrPath,
999
+ importerName: ctx.name,
1000
+ importerPath: ctx.filePath
1001
+ });
1002
+ }
1003
+
1004
+ debug("Failed to load parser '%s' declared in '%s'.", nameOrPath, ctx.name);
1005
+ error.message = `Failed to load parser '${nameOrPath}' declared in '${ctx.name}': ${error.message}`;
1006
+
1007
+ return new ConfigDependency({
1008
+ error,
1009
+ id: nameOrPath,
1010
+ importerName: ctx.name,
1011
+ importerPath: ctx.filePath
1012
+ });
1013
+ }
1014
+ }
1015
+
1016
+ /**
1017
+ * Load a given plugin.
1018
+ * @param {string} name The plugin name to load.
1019
+ * @param {ConfigArrayFactoryLoadingContext} ctx The loading context.
1020
+ * @returns {DependentPlugin} The loaded plugin.
1021
+ * @private
1022
+ */
1023
+ _loadPlugin(name, ctx) {
1024
+ debug("Loading plugin %j from %s", name, ctx.filePath);
1025
+
1026
+ const { additionalPluginPool, resolver } = internalSlotsMap.get(this);
1027
+ const request = naming.normalizePackageName(name, "eslint-plugin");
1028
+ const id = naming.getShorthandName(request, "eslint-plugin");
1029
+ const relativeTo = path.join(ctx.pluginBasePath, "__placeholder__.js");
1030
+
1031
+ if (name.match(/\s+/u)) {
1032
+ const error = Object.assign(
1033
+ new Error(`Whitespace found in plugin name '${name}'`),
1034
+ {
1035
+ messageTemplate: "whitespace-found",
1036
+ messageData: { pluginName: request }
1037
+ }
1038
+ );
1039
+
1040
+ return new ConfigDependency({
1041
+ error,
1042
+ id,
1043
+ importerName: ctx.name,
1044
+ importerPath: ctx.filePath
1045
+ });
1046
+ }
1047
+
1048
+ // Check for additional pool.
1049
+ const plugin =
1050
+ additionalPluginPool.get(request) ||
1051
+ additionalPluginPool.get(id);
1052
+
1053
+ if (plugin) {
1054
+ return new ConfigDependency({
1055
+ definition: normalizePlugin(plugin),
1056
+ filePath: "", // It's unknown where the plugin came from.
1057
+ id,
1058
+ importerName: ctx.name,
1059
+ importerPath: ctx.filePath
1060
+ });
1061
+ }
1062
+
1063
+ let filePath;
1064
+ let error;
1065
+
1066
+ try {
1067
+ filePath = resolver.resolve(request, relativeTo);
1068
+ } catch (resolveError) {
1069
+ error = resolveError;
1070
+ /* istanbul ignore else */
1071
+ if (error && error.code === "MODULE_NOT_FOUND") {
1072
+ error.messageTemplate = "plugin-missing";
1073
+ error.messageData = {
1074
+ pluginName: request,
1075
+ resolvePluginsRelativeTo: ctx.pluginBasePath,
1076
+ importerName: ctx.name
1077
+ };
1078
+ }
1079
+ }
1080
+
1081
+ if (filePath) {
1082
+ try {
1083
+ writeDebugLogForLoading(request, relativeTo, filePath);
1084
+
1085
+ const startTime = Date.now();
1086
+ const pluginDefinition = require(filePath);
1087
+
1088
+ debug(`Plugin ${filePath} loaded in: ${Date.now() - startTime}ms`);
1089
+
1090
+ return new ConfigDependency({
1091
+ definition: normalizePlugin(pluginDefinition),
1092
+ filePath,
1093
+ id,
1094
+ importerName: ctx.name,
1095
+ importerPath: ctx.filePath
1096
+ });
1097
+ } catch (loadError) {
1098
+ error = loadError;
1099
+ }
1100
+ }
1101
+
1102
+ debug("Failed to load plugin '%s' declared in '%s'.", name, ctx.name);
1103
+ error.message = `Failed to load plugin '${name}' declared in '${ctx.name}': ${error.message}`;
1104
+ return new ConfigDependency({
1105
+ error,
1106
+ id,
1107
+ importerName: ctx.name,
1108
+ importerPath: ctx.filePath
1109
+ });
1110
+ }
1111
+
1112
+ /**
1113
+ * Take file expression processors as config array elements.
1114
+ * @param {Record<string,DependentPlugin>} plugins The plugin definitions.
1115
+ * @param {ConfigArrayFactoryLoadingContext} ctx The loading context.
1116
+ * @returns {IterableIterator<ConfigArrayElement>} The config array elements of file expression processors.
1117
+ * @private
1118
+ */
1119
+ *_takeFileExtensionProcessors(plugins, ctx) {
1120
+ for (const pluginId of Object.keys(plugins)) {
1121
+ const processors =
1122
+ plugins[pluginId] &&
1123
+ plugins[pluginId].definition &&
1124
+ plugins[pluginId].definition.processors;
1125
+
1126
+ if (!processors) {
1127
+ continue;
1128
+ }
1129
+
1130
+ for (const processorId of Object.keys(processors)) {
1131
+ if (processorId.startsWith(".")) {
1132
+ yield* this._normalizeObjectConfigData(
1133
+ {
1134
+ files: [`*${processorId}`],
1135
+ processor: `${pluginId}/${processorId}`
1136
+ },
1137
+ {
1138
+ ...ctx,
1139
+ type: "implicit-processor",
1140
+ name: `${ctx.name}#processors["${pluginId}/${processorId}"]`
1141
+ }
1142
+ );
1143
+ }
1144
+ }
1145
+ }
1146
+ }
1147
+ }
1148
+
1149
+ export { ConfigArrayFactory, createContext };