immosquare-cleaner 0.1.23 → 0.1.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/lib/immosquare-cleaner/version.rb +1 -1
  3. data/linters/rubocop-3.2.2.yml +1 -0
  4. data/linters/rubocop.yml +2 -0
  5. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/LICENSE +19 -0
  6. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/README.md +71 -0
  7. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/conf/config-schema.js +79 -0
  8. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/conf/environments.js +215 -0
  9. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs +1104 -0
  10. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs.map +1 -0
  11. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/dist/eslintrc.cjs +4333 -0
  12. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/dist/eslintrc.cjs.map +1 -0
  13. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/cascading-config-array-factory.js +532 -0
  14. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/config-array/config-array.js +523 -0
  15. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/config-array/config-dependency.js +115 -0
  16. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/config-array/extracted-config.js +145 -0
  17. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/config-array/ignore-pattern.js +238 -0
  18. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/config-array/index.js +19 -0
  19. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/config-array/override-tester.js +225 -0
  20. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/config-array-factory.js +1149 -0
  21. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/flat-compat.js +318 -0
  22. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/index-universal.js +29 -0
  23. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/index.js +56 -0
  24. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/shared/ajv.js +191 -0
  25. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/shared/config-ops.js +135 -0
  26. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/shared/config-validator.js +325 -0
  27. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/shared/deprecation-warnings.js +63 -0
  28. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/shared/naming.js +96 -0
  29. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/shared/relative-module-resolver.js +42 -0
  30. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/shared/types.js +149 -0
  31. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/node_modules/strip-json-comments/index.d.ts +36 -0
  32. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/node_modules/strip-json-comments/index.js +77 -0
  33. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/node_modules/strip-json-comments/license +9 -0
  34. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/node_modules/strip-json-comments/package.json +47 -0
  35. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/node_modules/strip-json-comments/readme.md +78 -0
  36. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/package.json +82 -0
  37. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/universal.js +9 -0
  38. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/js/LICENSE +19 -0
  39. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/js/README.md +57 -0
  40. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/js/package.json +31 -0
  41. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/js/src/configs/eslint-all.js +278 -0
  42. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/js/src/configs/eslint-recommended.js +76 -0
  43. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/js/src/index.js +17 -0
  44. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/LICENSE +201 -0
  45. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/README.md +342 -0
  46. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/api.js +1061 -0
  47. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/@humanwhocodes/object-schema/CHANGELOG.md +8 -0
  48. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/@humanwhocodes/object-schema/LICENSE +29 -0
  49. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/@humanwhocodes/object-schema/README.md +234 -0
  50. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/@humanwhocodes/object-schema/package.json +33 -0
  51. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/@humanwhocodes/object-schema/src/index.js +7 -0
  52. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/@humanwhocodes/object-schema/src/merge-strategy.js +53 -0
  53. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/@humanwhocodes/object-schema/src/object-schema.js +235 -0
  54. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/@humanwhocodes/object-schema/src/validation-strategy.js +102 -0
  55. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/@humanwhocodes/object-schema/tests/merge-strategy.js +66 -0
  56. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/@humanwhocodes/object-schema/tests/object-schema.js +611 -0
  57. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/@humanwhocodes/object-schema/tests/validation-strategy.js +186 -0
  58. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/minimatch/LICENSE +15 -0
  59. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/minimatch/README.md +224 -0
  60. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/minimatch/minimatch.js +947 -0
  61. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/minimatch/node_modules/brace-expansion/LICENSE +21 -0
  62. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/minimatch/node_modules/brace-expansion/README.md +129 -0
  63. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/minimatch/node_modules/brace-expansion/index.js +201 -0
  64. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/minimatch/node_modules/brace-expansion/package.json +47 -0
  65. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/minimatch/package.json +33 -0
  66. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/package.json +61 -0
  67. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/chalk/index.d.ts +415 -0
  68. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/chalk/license +9 -0
  69. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/chalk/package.json +68 -0
  70. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/chalk/readme.md +341 -0
  71. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/chalk/source/index.js +229 -0
  72. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/chalk/source/templates.js +134 -0
  73. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/chalk/source/util.js +39 -0
  74. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/minimatch/LICENSE +15 -0
  75. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/minimatch/README.md +230 -0
  76. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/minimatch/minimatch.js +947 -0
  77. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/minimatch/node_modules/brace-expansion/LICENSE +21 -0
  78. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/minimatch/node_modules/brace-expansion/README.md +129 -0
  79. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/minimatch/node_modules/brace-expansion/index.js +201 -0
  80. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/minimatch/node_modules/brace-expansion/package.json +47 -0
  81. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/minimatch/package.json +33 -0
  82. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/strip-ansi/index.d.ts +17 -0
  83. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/strip-ansi/index.js +4 -0
  84. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/strip-ansi/license +9 -0
  85. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/strip-ansi/node_modules/ansi-regex/index.d.ts +37 -0
  86. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/strip-ansi/node_modules/ansi-regex/index.js +10 -0
  87. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/strip-ansi/node_modules/ansi-regex/license +9 -0
  88. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/strip-ansi/node_modules/ansi-regex/package.json +55 -0
  89. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/strip-ansi/node_modules/ansi-regex/readme.md +78 -0
  90. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/strip-ansi/package.json +54 -0
  91. data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/strip-ansi/readme.md +46 -0
  92. data/node_modules/eslint-plugin-import/node_modules/debug/node_modules/ms/index.js +162 -0
  93. data/node_modules/eslint-plugin-import/node_modules/debug/node_modules/ms/license.md +21 -0
  94. data/node_modules/eslint-plugin-import/node_modules/debug/node_modules/ms/package.json +38 -0
  95. data/node_modules/eslint-plugin-import/node_modules/debug/node_modules/ms/readme.md +59 -0
  96. data/node_modules/npm-check-updates/build/package.json +2 -3
  97. data/node_modules/npm-check-updates/build/src/lib/runGlobal.js +18 -11
  98. data/node_modules/npm-check-updates/build/src/lib/runGlobal.js.map +1 -1
  99. data/node_modules/npm-check-updates/build/src/package-managers/bun.js +2 -3
  100. data/node_modules/npm-check-updates/build/src/package-managers/bun.js.map +1 -1
  101. data/node_modules/npm-check-updates/build/src/package-managers/npm.js +12 -8
  102. data/node_modules/npm-check-updates/build/src/package-managers/npm.js.map +1 -1
  103. data/node_modules/npm-check-updates/build/src/package-managers/pnpm.js +37 -14
  104. data/node_modules/npm-check-updates/build/src/package-managers/pnpm.js.map +1 -1
  105. data/node_modules/npm-check-updates/build/src/package-managers/yarn.js +36 -11
  106. data/node_modules/npm-check-updates/build/src/package-managers/yarn.js.map +1 -1
  107. data/node_modules/npm-check-updates/package.json +2 -3
  108. data/node_modules/prettier/LICENSE +3 -3
  109. data/node_modules/prettier/index.cjs +1 -1
  110. data/node_modules/prettier/index.mjs +14 -22
  111. data/node_modules/prettier/package.json +1 -1
  112. data/node_modules/prettier/plugins/acorn.js +10 -10
  113. data/node_modules/prettier/plugins/acorn.mjs +10 -10
  114. data/node_modules/prettier/plugins/angular.js +1 -1
  115. data/node_modules/prettier/plugins/angular.mjs +1 -1
  116. data/node_modules/prettier/plugins/babel.js +8 -8
  117. data/node_modules/prettier/plugins/babel.mjs +8 -8
  118. data/node_modules/prettier/plugins/estree.js +24 -24
  119. data/node_modules/prettier/plugins/estree.mjs +24 -24
  120. data/node_modules/prettier/plugins/flow.js +17 -17
  121. data/node_modules/prettier/plugins/flow.mjs +17 -17
  122. data/node_modules/prettier/plugins/graphql.js +6 -6
  123. data/node_modules/prettier/plugins/graphql.mjs +6 -6
  124. data/node_modules/prettier/plugins/html.js +1 -1
  125. data/node_modules/prettier/plugins/html.mjs +1 -1
  126. data/node_modules/prettier/plugins/markdown.js +1 -1
  127. data/node_modules/prettier/plugins/markdown.mjs +1 -1
  128. data/node_modules/prettier/plugins/meriyah.js +4 -4
  129. data/node_modules/prettier/plugins/meriyah.mjs +4 -4
  130. data/node_modules/prettier/plugins/typescript.js +19 -19
  131. data/node_modules/prettier/plugins/typescript.mjs +19 -19
  132. data/node_modules/prettier/standalone.js +10 -10
  133. data/node_modules/prettier/standalone.mjs +9 -9
  134. data/package.json +2 -2
  135. metadata +95 -4
@@ -0,0 +1,145 @@
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
+
18
+ import { IgnorePattern } from "./ignore-pattern.js";
19
+
20
+ // For VSCode intellisense
21
+ /** @typedef {import("../../shared/types").ConfigData} ConfigData */
22
+ /** @typedef {import("../../shared/types").GlobalConf} GlobalConf */
23
+ /** @typedef {import("../../shared/types").SeverityConf} SeverityConf */
24
+ /** @typedef {import("./config-dependency").DependentParser} DependentParser */
25
+ /** @typedef {import("./config-dependency").DependentPlugin} DependentPlugin */
26
+
27
+ /**
28
+ * Check if `xs` starts with `ys`.
29
+ * @template T
30
+ * @param {T[]} xs The array to check.
31
+ * @param {T[]} ys The array that may be the first part of `xs`.
32
+ * @returns {boolean} `true` if `xs` starts with `ys`.
33
+ */
34
+ function startsWith(xs, ys) {
35
+ return xs.length >= ys.length && ys.every((y, i) => y === xs[i]);
36
+ }
37
+
38
+ /**
39
+ * The class for extracted config data.
40
+ */
41
+ class ExtractedConfig {
42
+ constructor() {
43
+
44
+ /**
45
+ * The config name what `noInlineConfig` setting came from.
46
+ * @type {string}
47
+ */
48
+ this.configNameOfNoInlineConfig = "";
49
+
50
+ /**
51
+ * Environments.
52
+ * @type {Record<string, boolean>}
53
+ */
54
+ this.env = {};
55
+
56
+ /**
57
+ * Global variables.
58
+ * @type {Record<string, GlobalConf>}
59
+ */
60
+ this.globals = {};
61
+
62
+ /**
63
+ * The glob patterns that ignore to lint.
64
+ * @type {(((filePath:string, dot?:boolean) => boolean) & { basePath:string; patterns:string[] }) | undefined}
65
+ */
66
+ this.ignores = void 0;
67
+
68
+ /**
69
+ * The flag that disables directive comments.
70
+ * @type {boolean|undefined}
71
+ */
72
+ this.noInlineConfig = void 0;
73
+
74
+ /**
75
+ * Parser definition.
76
+ * @type {DependentParser|null}
77
+ */
78
+ this.parser = null;
79
+
80
+ /**
81
+ * Options for the parser.
82
+ * @type {Object}
83
+ */
84
+ this.parserOptions = {};
85
+
86
+ /**
87
+ * Plugin definitions.
88
+ * @type {Record<string, DependentPlugin>}
89
+ */
90
+ this.plugins = {};
91
+
92
+ /**
93
+ * Processor ID.
94
+ * @type {string|null}
95
+ */
96
+ this.processor = null;
97
+
98
+ /**
99
+ * The flag that reports unused `eslint-disable` directive comments.
100
+ * @type {boolean|undefined}
101
+ */
102
+ this.reportUnusedDisableDirectives = void 0;
103
+
104
+ /**
105
+ * Rule settings.
106
+ * @type {Record<string, [SeverityConf, ...any[]]>}
107
+ */
108
+ this.rules = {};
109
+
110
+ /**
111
+ * Shared settings.
112
+ * @type {Object}
113
+ */
114
+ this.settings = {};
115
+ }
116
+
117
+ /**
118
+ * Convert this config to the compatible object as a config file content.
119
+ * @returns {ConfigData} The converted object.
120
+ */
121
+ toCompatibleObjectAsConfigFileContent() {
122
+ const {
123
+ /* eslint-disable no-unused-vars */
124
+ configNameOfNoInlineConfig: _ignore1,
125
+ processor: _ignore2,
126
+ /* eslint-enable no-unused-vars */
127
+ ignores,
128
+ ...config
129
+ } = this;
130
+
131
+ config.parser = config.parser && config.parser.filePath;
132
+ config.plugins = Object.keys(config.plugins).filter(Boolean).reverse();
133
+ config.ignorePatterns = ignores ? ignores.patterns : [];
134
+
135
+ // Strip the default patterns from `ignorePatterns`.
136
+ if (startsWith(config.ignorePatterns, IgnorePattern.DefaultPatterns)) {
137
+ config.ignorePatterns =
138
+ config.ignorePatterns.slice(IgnorePattern.DefaultPatterns.length);
139
+ }
140
+
141
+ return config;
142
+ }
143
+ }
144
+
145
+ export { ExtractedConfig };
@@ -0,0 +1,238 @@
1
+ /**
2
+ * @fileoverview `IgnorePattern` class.
3
+ *
4
+ * `IgnorePattern` class has the set of glob patterns and the base path.
5
+ *
6
+ * It provides two static methods.
7
+ *
8
+ * - `IgnorePattern.createDefaultIgnore(cwd)`
9
+ * Create the default predicate function.
10
+ * - `IgnorePattern.createIgnore(ignorePatterns)`
11
+ * Create the predicate function from multiple `IgnorePattern` objects.
12
+ *
13
+ * It provides two properties and a method.
14
+ *
15
+ * - `patterns`
16
+ * The glob patterns that ignore to lint.
17
+ * - `basePath`
18
+ * The base path of the glob patterns. If absolute paths existed in the
19
+ * glob patterns, those are handled as relative paths to the base path.
20
+ * - `getPatternsRelativeTo(basePath)`
21
+ * Get `patterns` as modified for a given base path. It modifies the
22
+ * absolute paths in the patterns as prepending the difference of two base
23
+ * paths.
24
+ *
25
+ * `ConfigArrayFactory` creates `IgnorePattern` objects when it processes
26
+ * `ignorePatterns` properties.
27
+ *
28
+ * @author Toru Nagashima <https://github.com/mysticatea>
29
+ */
30
+
31
+ //------------------------------------------------------------------------------
32
+ // Requirements
33
+ //------------------------------------------------------------------------------
34
+
35
+ import assert from "assert";
36
+ import path from "path";
37
+ import ignore from "ignore";
38
+ import debugOrig from "debug";
39
+
40
+ const debug = debugOrig("eslintrc:ignore-pattern");
41
+
42
+ /** @typedef {ReturnType<import("ignore").default>} Ignore */
43
+
44
+ //------------------------------------------------------------------------------
45
+ // Helpers
46
+ //------------------------------------------------------------------------------
47
+
48
+ /**
49
+ * Get the path to the common ancestor directory of given paths.
50
+ * @param {string[]} sourcePaths The paths to calculate the common ancestor.
51
+ * @returns {string} The path to the common ancestor directory.
52
+ */
53
+ function getCommonAncestorPath(sourcePaths) {
54
+ let result = sourcePaths[0];
55
+
56
+ for (let i = 1; i < sourcePaths.length; ++i) {
57
+ const a = result;
58
+ const b = sourcePaths[i];
59
+
60
+ // Set the shorter one (it's the common ancestor if one includes the other).
61
+ result = a.length < b.length ? a : b;
62
+
63
+ // Set the common ancestor.
64
+ for (let j = 0, lastSepPos = 0; j < a.length && j < b.length; ++j) {
65
+ if (a[j] !== b[j]) {
66
+ result = a.slice(0, lastSepPos);
67
+ break;
68
+ }
69
+ if (a[j] === path.sep) {
70
+ lastSepPos = j;
71
+ }
72
+ }
73
+ }
74
+
75
+ let resolvedResult = result || path.sep;
76
+
77
+ // if Windows common ancestor is root of drive must have trailing slash to be absolute.
78
+ if (resolvedResult && resolvedResult.endsWith(":") && process.platform === "win32") {
79
+ resolvedResult += path.sep;
80
+ }
81
+ return resolvedResult;
82
+ }
83
+
84
+ /**
85
+ * Make relative path.
86
+ * @param {string} from The source path to get relative path.
87
+ * @param {string} to The destination path to get relative path.
88
+ * @returns {string} The relative path.
89
+ */
90
+ function relative(from, to) {
91
+ const relPath = path.relative(from, to);
92
+
93
+ if (path.sep === "/") {
94
+ return relPath;
95
+ }
96
+ return relPath.split(path.sep).join("/");
97
+ }
98
+
99
+ /**
100
+ * Get the trailing slash if existed.
101
+ * @param {string} filePath The path to check.
102
+ * @returns {string} The trailing slash if existed.
103
+ */
104
+ function dirSuffix(filePath) {
105
+ const isDir = (
106
+ filePath.endsWith(path.sep) ||
107
+ (process.platform === "win32" && filePath.endsWith("/"))
108
+ );
109
+
110
+ return isDir ? "/" : "";
111
+ }
112
+
113
+ const DefaultPatterns = Object.freeze(["/**/node_modules/*"]);
114
+ const DotPatterns = Object.freeze([".*", "!.eslintrc.*", "!../"]);
115
+
116
+ //------------------------------------------------------------------------------
117
+ // Public
118
+ //------------------------------------------------------------------------------
119
+
120
+ class IgnorePattern {
121
+
122
+ /**
123
+ * The default patterns.
124
+ * @type {string[]}
125
+ */
126
+ static get DefaultPatterns() {
127
+ return DefaultPatterns;
128
+ }
129
+
130
+ /**
131
+ * Create the default predicate function.
132
+ * @param {string} cwd The current working directory.
133
+ * @returns {((filePath:string, dot:boolean) => boolean) & {basePath:string; patterns:string[]}}
134
+ * The preficate function.
135
+ * The first argument is an absolute path that is checked.
136
+ * The second argument is the flag to not ignore dotfiles.
137
+ * If the predicate function returned `true`, it means the path should be ignored.
138
+ */
139
+ static createDefaultIgnore(cwd) {
140
+ return this.createIgnore([new IgnorePattern(DefaultPatterns, cwd)]);
141
+ }
142
+
143
+ /**
144
+ * Create the predicate function from multiple `IgnorePattern` objects.
145
+ * @param {IgnorePattern[]} ignorePatterns The list of ignore patterns.
146
+ * @returns {((filePath:string, dot?:boolean) => boolean) & {basePath:string; patterns:string[]}}
147
+ * The preficate function.
148
+ * The first argument is an absolute path that is checked.
149
+ * The second argument is the flag to not ignore dotfiles.
150
+ * If the predicate function returned `true`, it means the path should be ignored.
151
+ */
152
+ static createIgnore(ignorePatterns) {
153
+ debug("Create with: %o", ignorePatterns);
154
+
155
+ const basePath = getCommonAncestorPath(ignorePatterns.map(p => p.basePath));
156
+ const patterns = [].concat(
157
+ ...ignorePatterns.map(p => p.getPatternsRelativeTo(basePath))
158
+ );
159
+ const ig = ignore({ allowRelativePaths: true }).add([...DotPatterns, ...patterns]);
160
+ const dotIg = ignore({ allowRelativePaths: true }).add(patterns);
161
+
162
+ debug(" processed: %o", { basePath, patterns });
163
+
164
+ return Object.assign(
165
+ (filePath, dot = false) => {
166
+ assert(path.isAbsolute(filePath), "'filePath' should be an absolute path.");
167
+ const relPathRaw = relative(basePath, filePath);
168
+ const relPath = relPathRaw && (relPathRaw + dirSuffix(filePath));
169
+ const adoptedIg = dot ? dotIg : ig;
170
+ const result = relPath !== "" && adoptedIg.ignores(relPath);
171
+
172
+ debug("Check", { filePath, dot, relativePath: relPath, result });
173
+ return result;
174
+ },
175
+ { basePath, patterns }
176
+ );
177
+ }
178
+
179
+ /**
180
+ * Initialize a new `IgnorePattern` instance.
181
+ * @param {string[]} patterns The glob patterns that ignore to lint.
182
+ * @param {string} basePath The base path of `patterns`.
183
+ */
184
+ constructor(patterns, basePath) {
185
+ assert(path.isAbsolute(basePath), "'basePath' should be an absolute path.");
186
+
187
+ /**
188
+ * The glob patterns that ignore to lint.
189
+ * @type {string[]}
190
+ */
191
+ this.patterns = patterns;
192
+
193
+ /**
194
+ * The base path of `patterns`.
195
+ * @type {string}
196
+ */
197
+ this.basePath = basePath;
198
+
199
+ /**
200
+ * If `true` then patterns which don't start with `/` will match the paths to the outside of `basePath`. Defaults to `false`.
201
+ *
202
+ * It's set `true` for `.eslintignore`, `package.json`, and `--ignore-path` for backward compatibility.
203
+ * It's `false` as-is for `ignorePatterns` property in config files.
204
+ * @type {boolean}
205
+ */
206
+ this.loose = false;
207
+ }
208
+
209
+ /**
210
+ * Get `patterns` as modified for a given base path. It modifies the
211
+ * absolute paths in the patterns as prepending the difference of two base
212
+ * paths.
213
+ * @param {string} newBasePath The base path.
214
+ * @returns {string[]} Modifired patterns.
215
+ */
216
+ getPatternsRelativeTo(newBasePath) {
217
+ assert(path.isAbsolute(newBasePath), "'newBasePath' should be an absolute path.");
218
+ const { basePath, loose, patterns } = this;
219
+
220
+ if (newBasePath === basePath) {
221
+ return patterns;
222
+ }
223
+ const prefix = `/${relative(newBasePath, basePath)}`;
224
+
225
+ return patterns.map(pattern => {
226
+ const negative = pattern.startsWith("!");
227
+ const head = negative ? "!" : "";
228
+ const body = negative ? pattern.slice(1) : pattern;
229
+
230
+ if (body.startsWith("/") || body.startsWith("../")) {
231
+ return `${head}${prefix}${body}`;
232
+ }
233
+ return loose ? pattern : `${head}${prefix}/**/${body}`;
234
+ });
235
+ }
236
+ }
237
+
238
+ export { IgnorePattern };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @fileoverview `ConfigArray` class.
3
+ * @author Toru Nagashima <https://github.com/mysticatea>
4
+ */
5
+
6
+ import { ConfigArray, getUsedExtractedConfigs } from "./config-array.js";
7
+ import { ConfigDependency } from "./config-dependency.js";
8
+ import { ExtractedConfig } from "./extracted-config.js";
9
+ import { IgnorePattern } from "./ignore-pattern.js";
10
+ import { OverrideTester } from "./override-tester.js";
11
+
12
+ export {
13
+ ConfigArray,
14
+ ConfigDependency,
15
+ ExtractedConfig,
16
+ IgnorePattern,
17
+ OverrideTester,
18
+ getUsedExtractedConfigs
19
+ };
@@ -0,0 +1,225 @@
1
+ /**
2
+ * @fileoverview `OverrideTester` class.
3
+ *
4
+ * `OverrideTester` class handles `files` property and `excludedFiles` property
5
+ * of `overrides` config.
6
+ *
7
+ * It provides one method.
8
+ *
9
+ * - `test(filePath)`
10
+ * Test if a file path matches the pair of `files` property and
11
+ * `excludedFiles` property. The `filePath` argument must be an absolute
12
+ * path.
13
+ *
14
+ * `ConfigArrayFactory` creates `OverrideTester` objects when it processes
15
+ * `overrides` properties.
16
+ *
17
+ * @author Toru Nagashima <https://github.com/mysticatea>
18
+ */
19
+
20
+ import assert from "assert";
21
+ import path from "path";
22
+ import util from "util";
23
+ import minimatch from "minimatch";
24
+
25
+ const { Minimatch } = minimatch;
26
+
27
+ const minimatchOpts = { dot: true, matchBase: true };
28
+
29
+ /**
30
+ * @typedef {Object} Pattern
31
+ * @property {InstanceType<Minimatch>[] | null} includes The positive matchers.
32
+ * @property {InstanceType<Minimatch>[] | null} excludes The negative matchers.
33
+ */
34
+
35
+ /**
36
+ * Normalize a given pattern to an array.
37
+ * @param {string|string[]|undefined} patterns A glob pattern or an array of glob patterns.
38
+ * @returns {string[]|null} Normalized patterns.
39
+ * @private
40
+ */
41
+ function normalizePatterns(patterns) {
42
+ if (Array.isArray(patterns)) {
43
+ return patterns.filter(Boolean);
44
+ }
45
+ if (typeof patterns === "string" && patterns) {
46
+ return [patterns];
47
+ }
48
+ return [];
49
+ }
50
+
51
+ /**
52
+ * Create the matchers of given patterns.
53
+ * @param {string[]} patterns The patterns.
54
+ * @returns {InstanceType<Minimatch>[] | null} The matchers.
55
+ */
56
+ function toMatcher(patterns) {
57
+ if (patterns.length === 0) {
58
+ return null;
59
+ }
60
+ return patterns.map(pattern => {
61
+ if (/^\.[/\\]/u.test(pattern)) {
62
+ return new Minimatch(
63
+ pattern.slice(2),
64
+
65
+ // `./*.js` should not match with `subdir/foo.js`
66
+ { ...minimatchOpts, matchBase: false }
67
+ );
68
+ }
69
+ return new Minimatch(pattern, minimatchOpts);
70
+ });
71
+ }
72
+
73
+ /**
74
+ * Convert a given matcher to string.
75
+ * @param {Pattern} matchers The matchers.
76
+ * @returns {string} The string expression of the matcher.
77
+ */
78
+ function patternToJson({ includes, excludes }) {
79
+ return {
80
+ includes: includes && includes.map(m => m.pattern),
81
+ excludes: excludes && excludes.map(m => m.pattern)
82
+ };
83
+ }
84
+
85
+ /**
86
+ * The class to test given paths are matched by the patterns.
87
+ */
88
+ class OverrideTester {
89
+
90
+ /**
91
+ * Create a tester with given criteria.
92
+ * If there are no criteria, returns `null`.
93
+ * @param {string|string[]} files The glob patterns for included files.
94
+ * @param {string|string[]} excludedFiles The glob patterns for excluded files.
95
+ * @param {string} basePath The path to the base directory to test paths.
96
+ * @returns {OverrideTester|null} The created instance or `null`.
97
+ */
98
+ static create(files, excludedFiles, basePath) {
99
+ const includePatterns = normalizePatterns(files);
100
+ const excludePatterns = normalizePatterns(excludedFiles);
101
+ let endsWithWildcard = false;
102
+
103
+ if (includePatterns.length === 0) {
104
+ return null;
105
+ }
106
+
107
+ // Rejects absolute paths or relative paths to parents.
108
+ for (const pattern of includePatterns) {
109
+ if (path.isAbsolute(pattern) || pattern.includes("..")) {
110
+ throw new Error(`Invalid override pattern (expected relative path not containing '..'): ${pattern}`);
111
+ }
112
+ if (pattern.endsWith("*")) {
113
+ endsWithWildcard = true;
114
+ }
115
+ }
116
+ for (const pattern of excludePatterns) {
117
+ if (path.isAbsolute(pattern) || pattern.includes("..")) {
118
+ throw new Error(`Invalid override pattern (expected relative path not containing '..'): ${pattern}`);
119
+ }
120
+ }
121
+
122
+ const includes = toMatcher(includePatterns);
123
+ const excludes = toMatcher(excludePatterns);
124
+
125
+ return new OverrideTester(
126
+ [{ includes, excludes }],
127
+ basePath,
128
+ endsWithWildcard
129
+ );
130
+ }
131
+
132
+ /**
133
+ * Combine two testers by logical and.
134
+ * If either of the testers was `null`, returns the other tester.
135
+ * The `basePath` property of the two must be the same value.
136
+ * @param {OverrideTester|null} a A tester.
137
+ * @param {OverrideTester|null} b Another tester.
138
+ * @returns {OverrideTester|null} Combined tester.
139
+ */
140
+ static and(a, b) {
141
+ if (!b) {
142
+ return a && new OverrideTester(
143
+ a.patterns,
144
+ a.basePath,
145
+ a.endsWithWildcard
146
+ );
147
+ }
148
+ if (!a) {
149
+ return new OverrideTester(
150
+ b.patterns,
151
+ b.basePath,
152
+ b.endsWithWildcard
153
+ );
154
+ }
155
+
156
+ assert.strictEqual(a.basePath, b.basePath);
157
+ return new OverrideTester(
158
+ a.patterns.concat(b.patterns),
159
+ a.basePath,
160
+ a.endsWithWildcard || b.endsWithWildcard
161
+ );
162
+ }
163
+
164
+ /**
165
+ * Initialize this instance.
166
+ * @param {Pattern[]} patterns The matchers.
167
+ * @param {string} basePath The base path.
168
+ * @param {boolean} endsWithWildcard If `true` then a pattern ends with `*`.
169
+ */
170
+ constructor(patterns, basePath, endsWithWildcard = false) {
171
+
172
+ /** @type {Pattern[]} */
173
+ this.patterns = patterns;
174
+
175
+ /** @type {string} */
176
+ this.basePath = basePath;
177
+
178
+ /** @type {boolean} */
179
+ this.endsWithWildcard = endsWithWildcard;
180
+ }
181
+
182
+ /**
183
+ * Test if a given path is matched or not.
184
+ * @param {string} filePath The absolute path to the target file.
185
+ * @returns {boolean} `true` if the path was matched.
186
+ */
187
+ test(filePath) {
188
+ if (typeof filePath !== "string" || !path.isAbsolute(filePath)) {
189
+ throw new Error(`'filePath' should be an absolute path, but got ${filePath}.`);
190
+ }
191
+ const relativePath = path.relative(this.basePath, filePath);
192
+
193
+ return this.patterns.every(({ includes, excludes }) => (
194
+ (!includes || includes.some(m => m.match(relativePath))) &&
195
+ (!excludes || !excludes.some(m => m.match(relativePath)))
196
+ ));
197
+ }
198
+
199
+ // eslint-disable-next-line jsdoc/require-description
200
+ /**
201
+ * @returns {Object} a JSON compatible object.
202
+ */
203
+ toJSON() {
204
+ if (this.patterns.length === 1) {
205
+ return {
206
+ ...patternToJson(this.patterns[0]),
207
+ basePath: this.basePath
208
+ };
209
+ }
210
+ return {
211
+ AND: this.patterns.map(patternToJson),
212
+ basePath: this.basePath
213
+ };
214
+ }
215
+
216
+ // eslint-disable-next-line jsdoc/require-description
217
+ /**
218
+ * @returns {Object} an object to display by `console.log()`.
219
+ */
220
+ [util.inspect.custom]() {
221
+ return this.toJSON();
222
+ }
223
+ }
224
+
225
+ export { OverrideTester };