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

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/eslint-plugin-custom-rules.js +2 -0
  2. package/package.json +1 -1
  3. package/node_modules/@aashutoshrathi/word-wrap/LICENSE +0 -21
  4. package/node_modules/@aashutoshrathi/word-wrap/README.md +0 -182
  5. package/node_modules/@aashutoshrathi/word-wrap/index.d.ts +0 -50
  6. package/node_modules/@aashutoshrathi/word-wrap/index.js +0 -52
  7. package/node_modules/@aashutoshrathi/word-wrap/package.json +0 -81
  8. package/node_modules/@angular-eslint/bundled-angular-compiler/README.md +0 -1
  9. package/node_modules/@angular-eslint/bundled-angular-compiler/dist/index.d.ts +0 -5
  10. package/node_modules/@angular-eslint/bundled-angular-compiler/dist/index.js +0 -32004
  11. package/node_modules/@angular-eslint/bundled-angular-compiler/package.json +0 -19
  12. package/node_modules/@angular-eslint/template-parser/LICENSE +0 -21
  13. package/node_modules/@angular-eslint/template-parser/README.md +0 -1
  14. package/node_modules/@angular-eslint/template-parser/dist/convert-source-span-to-loc.d.ts +0 -6
  15. package/node_modules/@angular-eslint/template-parser/dist/convert-source-span-to-loc.js +0 -69
  16. package/node_modules/@angular-eslint/template-parser/dist/index.d.ts +0 -44
  17. package/node_modules/@angular-eslint/template-parser/dist/index.js +0 -219
  18. package/node_modules/@angular-eslint/template-parser/package.json +0 -28
  19. package/node_modules/@eslint/eslintrc/LICENSE +0 -19
  20. package/node_modules/@eslint/eslintrc/README.md +0 -115
  21. package/node_modules/@eslint/eslintrc/conf/config-schema.js +0 -79
  22. package/node_modules/@eslint/eslintrc/conf/environments.js +0 -215
  23. package/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs +0 -1104
  24. package/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs.map +0 -1
  25. package/node_modules/@eslint/eslintrc/dist/eslintrc.cjs +0 -4333
  26. package/node_modules/@eslint/eslintrc/dist/eslintrc.cjs.map +0 -1
  27. package/node_modules/@eslint/eslintrc/lib/cascading-config-array-factory.js +0 -532
  28. package/node_modules/@eslint/eslintrc/lib/config-array/config-array.js +0 -523
  29. package/node_modules/@eslint/eslintrc/lib/config-array/config-dependency.js +0 -115
  30. package/node_modules/@eslint/eslintrc/lib/config-array/extracted-config.js +0 -145
  31. package/node_modules/@eslint/eslintrc/lib/config-array/ignore-pattern.js +0 -238
  32. package/node_modules/@eslint/eslintrc/lib/config-array/index.js +0 -19
  33. package/node_modules/@eslint/eslintrc/lib/config-array/override-tester.js +0 -225
  34. package/node_modules/@eslint/eslintrc/lib/config-array-factory.js +0 -1149
  35. package/node_modules/@eslint/eslintrc/lib/flat-compat.js +0 -318
  36. package/node_modules/@eslint/eslintrc/lib/index-universal.js +0 -29
  37. package/node_modules/@eslint/eslintrc/lib/index.js +0 -56
  38. package/node_modules/@eslint/eslintrc/lib/shared/ajv.js +0 -191
  39. package/node_modules/@eslint/eslintrc/lib/shared/config-ops.js +0 -135
  40. package/node_modules/@eslint/eslintrc/lib/shared/config-validator.js +0 -325
  41. package/node_modules/@eslint/eslintrc/lib/shared/deprecation-warnings.js +0 -63
  42. package/node_modules/@eslint/eslintrc/lib/shared/naming.js +0 -96
  43. package/node_modules/@eslint/eslintrc/lib/shared/relative-module-resolver.js +0 -42
  44. package/node_modules/@eslint/eslintrc/lib/shared/types.js +0 -149
  45. package/node_modules/@eslint/eslintrc/package.json +0 -82
  46. package/node_modules/@eslint/eslintrc/universal.js +0 -9
  47. package/node_modules/@eslint/js/LICENSE +0 -19
  48. package/node_modules/@eslint/js/README.md +0 -57
  49. package/node_modules/@eslint/js/package.json +0 -31
  50. package/node_modules/@eslint/js/src/configs/eslint-all.js +0 -211
  51. package/node_modules/@eslint/js/src/configs/eslint-recommended.js +0 -76
  52. package/node_modules/@eslint/js/src/index.js +0 -17
  53. package/node_modules/@eslint-community/eslint-utils/LICENSE +0 -21
  54. package/node_modules/@eslint-community/eslint-utils/README.md +0 -37
  55. package/node_modules/@eslint-community/eslint-utils/index.js +0 -2068
  56. package/node_modules/@eslint-community/eslint-utils/index.js.map +0 -1
  57. package/node_modules/@eslint-community/eslint-utils/index.mjs +0 -2027
  58. package/node_modules/@eslint-community/eslint-utils/index.mjs.map +0 -1
  59. package/node_modules/@eslint-community/eslint-utils/package.json +0 -73
  60. package/node_modules/@eslint-community/regexpp/LICENSE +0 -21
  61. package/node_modules/@eslint-community/regexpp/README.md +0 -177
  62. package/node_modules/@eslint-community/regexpp/index.d.ts +0 -1065
  63. package/node_modules/@eslint-community/regexpp/index.js +0 -2747
  64. package/node_modules/@eslint-community/regexpp/index.js.map +0 -1
  65. package/node_modules/@eslint-community/regexpp/index.mjs +0 -2737
  66. package/node_modules/@eslint-community/regexpp/index.mjs.map +0 -1
  67. package/node_modules/@eslint-community/regexpp/package.json +0 -93
  68. package/node_modules/@humanwhocodes/config-array/LICENSE +0 -201
  69. package/node_modules/@humanwhocodes/config-array/README.md +0 -342
  70. package/node_modules/@humanwhocodes/config-array/api.js +0 -1061
  71. package/node_modules/@humanwhocodes/config-array/package.json +0 -61
  72. package/node_modules/@humanwhocodes/module-importer/CHANGELOG.md +0 -15
  73. package/node_modules/@humanwhocodes/module-importer/LICENSE +0 -201
  74. package/node_modules/@humanwhocodes/module-importer/README.md +0 -80
  75. package/node_modules/@humanwhocodes/module-importer/dist/module-importer.cjs +0 -22
  76. package/node_modules/@humanwhocodes/module-importer/dist/module-importer.d.cts +0 -27
  77. package/node_modules/@humanwhocodes/module-importer/dist/module-importer.d.ts +0 -2
  78. package/node_modules/@humanwhocodes/module-importer/dist/module-importer.js +0 -18
  79. package/node_modules/@humanwhocodes/module-importer/package.json +0 -65
  80. package/node_modules/@humanwhocodes/module-importer/src/module-importer.cjs +0 -81
  81. package/node_modules/@humanwhocodes/module-importer/src/module-importer.js +0 -22
  82. package/node_modules/@humanwhocodes/object-schema/.eslintrc.js +0 -29
  83. package/node_modules/@humanwhocodes/object-schema/.github/workflows/nodejs-test.yml +0 -27
  84. package/node_modules/@humanwhocodes/object-schema/.github/workflows/release-please.yml +0 -39
  85. package/node_modules/@humanwhocodes/object-schema/CHANGELOG.md +0 -26
  86. package/node_modules/@humanwhocodes/object-schema/LICENSE +0 -29
  87. package/node_modules/@humanwhocodes/object-schema/README.md +0 -234
  88. package/node_modules/@humanwhocodes/object-schema/package.json +0 -33
  89. package/node_modules/@humanwhocodes/object-schema/src/index.js +0 -7
  90. package/node_modules/@humanwhocodes/object-schema/src/merge-strategy.js +0 -53
  91. package/node_modules/@humanwhocodes/object-schema/src/object-schema.js +0 -301
  92. package/node_modules/@humanwhocodes/object-schema/src/validation-strategy.js +0 -102
  93. package/node_modules/@humanwhocodes/object-schema/tests/merge-strategy.js +0 -66
  94. package/node_modules/@humanwhocodes/object-schema/tests/object-schema.js +0 -659
  95. package/node_modules/@humanwhocodes/object-schema/tests/validation-strategy.js +0 -186
  96. package/node_modules/@nodelib/fs.scandir/LICENSE +0 -21
  97. package/node_modules/@nodelib/fs.scandir/README.md +0 -171
  98. package/node_modules/@nodelib/fs.scandir/out/adapters/fs.d.ts +0 -20
  99. package/node_modules/@nodelib/fs.scandir/out/adapters/fs.js +0 -19
  100. package/node_modules/@nodelib/fs.scandir/out/constants.d.ts +0 -4
  101. package/node_modules/@nodelib/fs.scandir/out/constants.js +0 -17
  102. package/node_modules/@nodelib/fs.scandir/out/index.d.ts +0 -12
  103. package/node_modules/@nodelib/fs.scandir/out/index.js +0 -26
  104. package/node_modules/@nodelib/fs.scandir/out/providers/async.d.ts +0 -7
  105. package/node_modules/@nodelib/fs.scandir/out/providers/async.js +0 -104
  106. package/node_modules/@nodelib/fs.scandir/out/providers/common.d.ts +0 -1
  107. package/node_modules/@nodelib/fs.scandir/out/providers/common.js +0 -13
  108. package/node_modules/@nodelib/fs.scandir/out/providers/sync.d.ts +0 -5
  109. package/node_modules/@nodelib/fs.scandir/out/providers/sync.js +0 -54
  110. package/node_modules/@nodelib/fs.scandir/out/settings.d.ts +0 -20
  111. package/node_modules/@nodelib/fs.scandir/out/settings.js +0 -24
  112. package/node_modules/@nodelib/fs.scandir/out/types/index.d.ts +0 -20
  113. package/node_modules/@nodelib/fs.scandir/out/types/index.js +0 -2
  114. package/node_modules/@nodelib/fs.scandir/out/utils/fs.d.ts +0 -2
  115. package/node_modules/@nodelib/fs.scandir/out/utils/fs.js +0 -19
  116. package/node_modules/@nodelib/fs.scandir/out/utils/index.d.ts +0 -2
  117. package/node_modules/@nodelib/fs.scandir/out/utils/index.js +0 -5
  118. package/node_modules/@nodelib/fs.scandir/package.json +0 -44
  119. package/node_modules/@nodelib/fs.stat/LICENSE +0 -21
  120. package/node_modules/@nodelib/fs.stat/README.md +0 -126
  121. package/node_modules/@nodelib/fs.stat/out/adapters/fs.d.ts +0 -13
  122. package/node_modules/@nodelib/fs.stat/out/adapters/fs.js +0 -17
  123. package/node_modules/@nodelib/fs.stat/out/index.d.ts +0 -12
  124. package/node_modules/@nodelib/fs.stat/out/index.js +0 -26
  125. package/node_modules/@nodelib/fs.stat/out/providers/async.d.ts +0 -4
  126. package/node_modules/@nodelib/fs.stat/out/providers/async.js +0 -36
  127. package/node_modules/@nodelib/fs.stat/out/providers/sync.d.ts +0 -3
  128. package/node_modules/@nodelib/fs.stat/out/providers/sync.js +0 -23
  129. package/node_modules/@nodelib/fs.stat/out/settings.d.ts +0 -16
  130. package/node_modules/@nodelib/fs.stat/out/settings.js +0 -16
  131. package/node_modules/@nodelib/fs.stat/out/types/index.d.ts +0 -4
  132. package/node_modules/@nodelib/fs.stat/out/types/index.js +0 -2
  133. package/node_modules/@nodelib/fs.stat/package.json +0 -37
  134. package/node_modules/@nodelib/fs.walk/LICENSE +0 -21
  135. package/node_modules/@nodelib/fs.walk/README.md +0 -215
  136. package/node_modules/@nodelib/fs.walk/out/index.d.ts +0 -14
  137. package/node_modules/@nodelib/fs.walk/out/index.js +0 -34
  138. package/node_modules/@nodelib/fs.walk/out/providers/async.d.ts +0 -12
  139. package/node_modules/@nodelib/fs.walk/out/providers/async.js +0 -30
  140. package/node_modules/@nodelib/fs.walk/out/providers/index.d.ts +0 -4
  141. package/node_modules/@nodelib/fs.walk/out/providers/index.js +0 -9
  142. package/node_modules/@nodelib/fs.walk/out/providers/stream.d.ts +0 -12
  143. package/node_modules/@nodelib/fs.walk/out/providers/stream.js +0 -34
  144. package/node_modules/@nodelib/fs.walk/out/providers/sync.d.ts +0 -10
  145. package/node_modules/@nodelib/fs.walk/out/providers/sync.js +0 -14
  146. package/node_modules/@nodelib/fs.walk/out/readers/async.d.ts +0 -30
  147. package/node_modules/@nodelib/fs.walk/out/readers/async.js +0 -97
  148. package/node_modules/@nodelib/fs.walk/out/readers/common.d.ts +0 -7
  149. package/node_modules/@nodelib/fs.walk/out/readers/common.js +0 -31
  150. package/node_modules/@nodelib/fs.walk/out/readers/reader.d.ts +0 -6
  151. package/node_modules/@nodelib/fs.walk/out/readers/reader.js +0 -11
  152. package/node_modules/@nodelib/fs.walk/out/readers/sync.d.ts +0 -15
  153. package/node_modules/@nodelib/fs.walk/out/readers/sync.js +0 -59
  154. package/node_modules/@nodelib/fs.walk/out/settings.d.ts +0 -30
  155. package/node_modules/@nodelib/fs.walk/out/settings.js +0 -26
  156. package/node_modules/@nodelib/fs.walk/out/types/index.d.ts +0 -8
  157. package/node_modules/@nodelib/fs.walk/out/types/index.js +0 -2
  158. package/node_modules/@nodelib/fs.walk/package.json +0 -44
  159. package/node_modules/@ungap/structured-clone/.github/workflows/node.js.yml +0 -31
  160. package/node_modules/@ungap/structured-clone/LICENSE +0 -15
  161. package/node_modules/@ungap/structured-clone/README.md +0 -95
  162. package/node_modules/@ungap/structured-clone/cjs/deserialize.js +0 -78
  163. package/node_modules/@ungap/structured-clone/cjs/index.js +0 -27
  164. package/node_modules/@ungap/structured-clone/cjs/json.js +0 -24
  165. package/node_modules/@ungap/structured-clone/cjs/package.json +0 -1
  166. package/node_modules/@ungap/structured-clone/cjs/serialize.js +0 -160
  167. package/node_modules/@ungap/structured-clone/cjs/types.js +0 -22
  168. package/node_modules/@ungap/structured-clone/esm/deserialize.js +0 -79
  169. package/node_modules/@ungap/structured-clone/esm/index.js +0 -25
  170. package/node_modules/@ungap/structured-clone/esm/json.js +0 -21
  171. package/node_modules/@ungap/structured-clone/esm/serialize.js +0 -161
  172. package/node_modules/@ungap/structured-clone/esm/types.js +0 -11
  173. package/node_modules/@ungap/structured-clone/package.json +0 -53
  174. package/node_modules/@ungap/structured-clone/structured-json.js +0 -1
@@ -1,135 +0,0 @@
1
- /**
2
- * @fileoverview Config file operations. This file must be usable in the browser,
3
- * so no Node-specific code can be here.
4
- * @author Nicholas C. Zakas
5
- */
6
-
7
- //------------------------------------------------------------------------------
8
- // Private
9
- //------------------------------------------------------------------------------
10
-
11
- const RULE_SEVERITY_STRINGS = ["off", "warn", "error"],
12
- RULE_SEVERITY = RULE_SEVERITY_STRINGS.reduce((map, value, index) => {
13
- map[value] = index;
14
- return map;
15
- }, {}),
16
- VALID_SEVERITIES = [0, 1, 2, "off", "warn", "error"];
17
-
18
- //------------------------------------------------------------------------------
19
- // Public Interface
20
- //------------------------------------------------------------------------------
21
-
22
- /**
23
- * Normalizes the severity value of a rule's configuration to a number
24
- * @param {(number|string|[number, ...*]|[string, ...*])} ruleConfig A rule's configuration value, generally
25
- * received from the user. A valid config value is either 0, 1, 2, the string "off" (treated the same as 0),
26
- * the string "warn" (treated the same as 1), the string "error" (treated the same as 2), or an array
27
- * whose first element is one of the above values. Strings are matched case-insensitively.
28
- * @returns {(0|1|2)} The numeric severity value if the config value was valid, otherwise 0.
29
- */
30
- function getRuleSeverity(ruleConfig) {
31
- const severityValue = Array.isArray(ruleConfig) ? ruleConfig[0] : ruleConfig;
32
-
33
- if (severityValue === 0 || severityValue === 1 || severityValue === 2) {
34
- return severityValue;
35
- }
36
-
37
- if (typeof severityValue === "string") {
38
- return RULE_SEVERITY[severityValue.toLowerCase()] || 0;
39
- }
40
-
41
- return 0;
42
- }
43
-
44
- /**
45
- * Converts old-style severity settings (0, 1, 2) into new-style
46
- * severity settings (off, warn, error) for all rules. Assumption is that severity
47
- * values have already been validated as correct.
48
- * @param {Object} config The config object to normalize.
49
- * @returns {void}
50
- */
51
- function normalizeToStrings(config) {
52
-
53
- if (config.rules) {
54
- Object.keys(config.rules).forEach(ruleId => {
55
- const ruleConfig = config.rules[ruleId];
56
-
57
- if (typeof ruleConfig === "number") {
58
- config.rules[ruleId] = RULE_SEVERITY_STRINGS[ruleConfig] || RULE_SEVERITY_STRINGS[0];
59
- } else if (Array.isArray(ruleConfig) && typeof ruleConfig[0] === "number") {
60
- ruleConfig[0] = RULE_SEVERITY_STRINGS[ruleConfig[0]] || RULE_SEVERITY_STRINGS[0];
61
- }
62
- });
63
- }
64
- }
65
-
66
- /**
67
- * Determines if the severity for the given rule configuration represents an error.
68
- * @param {int|string|Array} ruleConfig The configuration for an individual rule.
69
- * @returns {boolean} True if the rule represents an error, false if not.
70
- */
71
- function isErrorSeverity(ruleConfig) {
72
- return getRuleSeverity(ruleConfig) === 2;
73
- }
74
-
75
- /**
76
- * Checks whether a given config has valid severity or not.
77
- * @param {number|string|Array} ruleConfig The configuration for an individual rule.
78
- * @returns {boolean} `true` if the configuration has valid severity.
79
- */
80
- function isValidSeverity(ruleConfig) {
81
- let severity = Array.isArray(ruleConfig) ? ruleConfig[0] : ruleConfig;
82
-
83
- if (typeof severity === "string") {
84
- severity = severity.toLowerCase();
85
- }
86
- return VALID_SEVERITIES.indexOf(severity) !== -1;
87
- }
88
-
89
- /**
90
- * Checks whether every rule of a given config has valid severity or not.
91
- * @param {Object} config The configuration for rules.
92
- * @returns {boolean} `true` if the configuration has valid severity.
93
- */
94
- function isEverySeverityValid(config) {
95
- return Object.keys(config).every(ruleId => isValidSeverity(config[ruleId]));
96
- }
97
-
98
- /**
99
- * Normalizes a value for a global in a config
100
- * @param {(boolean|string|null)} configuredValue The value given for a global in configuration or in
101
- * a global directive comment
102
- * @returns {("readable"|"writeable"|"off")} The value normalized as a string
103
- * @throws Error if global value is invalid
104
- */
105
- function normalizeConfigGlobal(configuredValue) {
106
- switch (configuredValue) {
107
- case "off":
108
- return "off";
109
-
110
- case true:
111
- case "true":
112
- case "writeable":
113
- case "writable":
114
- return "writable";
115
-
116
- case null:
117
- case false:
118
- case "false":
119
- case "readable":
120
- case "readonly":
121
- return "readonly";
122
-
123
- default:
124
- throw new Error(`'${configuredValue}' is not a valid configuration for a global (use 'readonly', 'writable', or 'off')`);
125
- }
126
- }
127
-
128
- export {
129
- getRuleSeverity,
130
- normalizeToStrings,
131
- isErrorSeverity,
132
- isValidSeverity,
133
- isEverySeverityValid,
134
- normalizeConfigGlobal
135
- };
@@ -1,325 +0,0 @@
1
- /**
2
- * @fileoverview Validates configs.
3
- * @author Brandon Mills
4
- */
5
-
6
- /* eslint class-methods-use-this: "off" */
7
-
8
- //------------------------------------------------------------------------------
9
- // Requirements
10
- //------------------------------------------------------------------------------
11
-
12
- import util from "util";
13
- import * as ConfigOps from "./config-ops.js";
14
- import { emitDeprecationWarning } from "./deprecation-warnings.js";
15
- import ajvOrig from "./ajv.js";
16
- import configSchema from "../../conf/config-schema.js";
17
- import BuiltInEnvironments from "../../conf/environments.js";
18
-
19
- const ajv = ajvOrig();
20
-
21
- const ruleValidators = new WeakMap();
22
- const noop = Function.prototype;
23
-
24
- //------------------------------------------------------------------------------
25
- // Private
26
- //------------------------------------------------------------------------------
27
- let validateSchema;
28
- const severityMap = {
29
- error: 2,
30
- warn: 1,
31
- off: 0
32
- };
33
-
34
- const validated = new WeakSet();
35
-
36
- //-----------------------------------------------------------------------------
37
- // Exports
38
- //-----------------------------------------------------------------------------
39
-
40
- export default class ConfigValidator {
41
- constructor({ builtInRules = new Map() } = {}) {
42
- this.builtInRules = builtInRules;
43
- }
44
-
45
- /**
46
- * Gets a complete options schema for a rule.
47
- * @param {{create: Function, schema: (Array|null)}} rule A new-style rule object
48
- * @returns {Object} JSON Schema for the rule's options.
49
- */
50
- getRuleOptionsSchema(rule) {
51
- if (!rule) {
52
- return null;
53
- }
54
-
55
- const schema = rule.schema || rule.meta && rule.meta.schema;
56
-
57
- // Given a tuple of schemas, insert warning level at the beginning
58
- if (Array.isArray(schema)) {
59
- if (schema.length) {
60
- return {
61
- type: "array",
62
- items: schema,
63
- minItems: 0,
64
- maxItems: schema.length
65
- };
66
- }
67
- return {
68
- type: "array",
69
- minItems: 0,
70
- maxItems: 0
71
- };
72
-
73
- }
74
-
75
- // Given a full schema, leave it alone
76
- return schema || null;
77
- }
78
-
79
- /**
80
- * Validates a rule's severity and returns the severity value. Throws an error if the severity is invalid.
81
- * @param {options} options The given options for the rule.
82
- * @returns {number|string} The rule's severity value
83
- */
84
- validateRuleSeverity(options) {
85
- const severity = Array.isArray(options) ? options[0] : options;
86
- const normSeverity = typeof severity === "string" ? severityMap[severity.toLowerCase()] : severity;
87
-
88
- if (normSeverity === 0 || normSeverity === 1 || normSeverity === 2) {
89
- return normSeverity;
90
- }
91
-
92
- throw new Error(`\tSeverity should be one of the following: 0 = off, 1 = warn, 2 = error (you passed '${util.inspect(severity).replace(/'/gu, "\"").replace(/\n/gu, "")}').\n`);
93
-
94
- }
95
-
96
- /**
97
- * Validates the non-severity options passed to a rule, based on its schema.
98
- * @param {{create: Function}} rule The rule to validate
99
- * @param {Array} localOptions The options for the rule, excluding severity
100
- * @returns {void}
101
- */
102
- validateRuleSchema(rule, localOptions) {
103
- if (!ruleValidators.has(rule)) {
104
- const schema = this.getRuleOptionsSchema(rule);
105
-
106
- if (schema) {
107
- ruleValidators.set(rule, ajv.compile(schema));
108
- }
109
- }
110
-
111
- const validateRule = ruleValidators.get(rule);
112
-
113
- if (validateRule) {
114
- validateRule(localOptions);
115
- if (validateRule.errors) {
116
- throw new Error(validateRule.errors.map(
117
- error => `\tValue ${JSON.stringify(error.data)} ${error.message}.\n`
118
- ).join(""));
119
- }
120
- }
121
- }
122
-
123
- /**
124
- * Validates a rule's options against its schema.
125
- * @param {{create: Function}|null} rule The rule that the config is being validated for
126
- * @param {string} ruleId The rule's unique name.
127
- * @param {Array|number} options The given options for the rule.
128
- * @param {string|null} source The name of the configuration source to report in any errors. If null or undefined,
129
- * no source is prepended to the message.
130
- * @returns {void}
131
- */
132
- validateRuleOptions(rule, ruleId, options, source = null) {
133
- try {
134
- const severity = this.validateRuleSeverity(options);
135
-
136
- if (severity !== 0) {
137
- this.validateRuleSchema(rule, Array.isArray(options) ? options.slice(1) : []);
138
- }
139
- } catch (err) {
140
- const enhancedMessage = `Configuration for rule "${ruleId}" is invalid:\n${err.message}`;
141
-
142
- if (typeof source === "string") {
143
- throw new Error(`${source}:\n\t${enhancedMessage}`);
144
- } else {
145
- throw new Error(enhancedMessage);
146
- }
147
- }
148
- }
149
-
150
- /**
151
- * Validates an environment object
152
- * @param {Object} environment The environment config object to validate.
153
- * @param {string} source The name of the configuration source to report in any errors.
154
- * @param {function(envId:string): Object} [getAdditionalEnv] A map from strings to loaded environments.
155
- * @returns {void}
156
- */
157
- validateEnvironment(
158
- environment,
159
- source,
160
- getAdditionalEnv = noop
161
- ) {
162
-
163
- // not having an environment is ok
164
- if (!environment) {
165
- return;
166
- }
167
-
168
- Object.keys(environment).forEach(id => {
169
- const env = getAdditionalEnv(id) || BuiltInEnvironments.get(id) || null;
170
-
171
- if (!env) {
172
- const message = `${source}:\n\tEnvironment key "${id}" is unknown\n`;
173
-
174
- throw new Error(message);
175
- }
176
- });
177
- }
178
-
179
- /**
180
- * Validates a rules config object
181
- * @param {Object} rulesConfig The rules config object to validate.
182
- * @param {string} source The name of the configuration source to report in any errors.
183
- * @param {function(ruleId:string): Object} getAdditionalRule A map from strings to loaded rules
184
- * @returns {void}
185
- */
186
- validateRules(
187
- rulesConfig,
188
- source,
189
- getAdditionalRule = noop
190
- ) {
191
- if (!rulesConfig) {
192
- return;
193
- }
194
-
195
- Object.keys(rulesConfig).forEach(id => {
196
- const rule = getAdditionalRule(id) || this.builtInRules.get(id) || null;
197
-
198
- this.validateRuleOptions(rule, id, rulesConfig[id], source);
199
- });
200
- }
201
-
202
- /**
203
- * Validates a `globals` section of a config file
204
- * @param {Object} globalsConfig The `globals` section
205
- * @param {string|null} source The name of the configuration source to report in the event of an error.
206
- * @returns {void}
207
- */
208
- validateGlobals(globalsConfig, source = null) {
209
- if (!globalsConfig) {
210
- return;
211
- }
212
-
213
- Object.entries(globalsConfig)
214
- .forEach(([configuredGlobal, configuredValue]) => {
215
- try {
216
- ConfigOps.normalizeConfigGlobal(configuredValue);
217
- } catch (err) {
218
- throw new Error(`ESLint configuration of global '${configuredGlobal}' in ${source} is invalid:\n${err.message}`);
219
- }
220
- });
221
- }
222
-
223
- /**
224
- * Validate `processor` configuration.
225
- * @param {string|undefined} processorName The processor name.
226
- * @param {string} source The name of config file.
227
- * @param {function(id:string): Processor} getProcessor The getter of defined processors.
228
- * @returns {void}
229
- */
230
- validateProcessor(processorName, source, getProcessor) {
231
- if (processorName && !getProcessor(processorName)) {
232
- throw new Error(`ESLint configuration of processor in '${source}' is invalid: '${processorName}' was not found.`);
233
- }
234
- }
235
-
236
- /**
237
- * Formats an array of schema validation errors.
238
- * @param {Array} errors An array of error messages to format.
239
- * @returns {string} Formatted error message
240
- */
241
- formatErrors(errors) {
242
- return errors.map(error => {
243
- if (error.keyword === "additionalProperties") {
244
- const formattedPropertyPath = error.dataPath.length ? `${error.dataPath.slice(1)}.${error.params.additionalProperty}` : error.params.additionalProperty;
245
-
246
- return `Unexpected top-level property "${formattedPropertyPath}"`;
247
- }
248
- if (error.keyword === "type") {
249
- const formattedField = error.dataPath.slice(1);
250
- const formattedExpectedType = Array.isArray(error.schema) ? error.schema.join("/") : error.schema;
251
- const formattedValue = JSON.stringify(error.data);
252
-
253
- return `Property "${formattedField}" is the wrong type (expected ${formattedExpectedType} but got \`${formattedValue}\`)`;
254
- }
255
-
256
- const field = error.dataPath[0] === "." ? error.dataPath.slice(1) : error.dataPath;
257
-
258
- return `"${field}" ${error.message}. Value: ${JSON.stringify(error.data)}`;
259
- }).map(message => `\t- ${message}.\n`).join("");
260
- }
261
-
262
- /**
263
- * Validates the top level properties of the config object.
264
- * @param {Object} config The config object to validate.
265
- * @param {string} source The name of the configuration source to report in any errors.
266
- * @returns {void}
267
- */
268
- validateConfigSchema(config, source = null) {
269
- validateSchema = validateSchema || ajv.compile(configSchema);
270
-
271
- if (!validateSchema(config)) {
272
- throw new Error(`ESLint configuration in ${source} is invalid:\n${this.formatErrors(validateSchema.errors)}`);
273
- }
274
-
275
- if (Object.hasOwnProperty.call(config, "ecmaFeatures")) {
276
- emitDeprecationWarning(source, "ESLINT_LEGACY_ECMAFEATURES");
277
- }
278
- }
279
-
280
- /**
281
- * Validates an entire config object.
282
- * @param {Object} config The config object to validate.
283
- * @param {string} source The name of the configuration source to report in any errors.
284
- * @param {function(ruleId:string): Object} [getAdditionalRule] A map from strings to loaded rules.
285
- * @param {function(envId:string): Object} [getAdditionalEnv] A map from strings to loaded envs.
286
- * @returns {void}
287
- */
288
- validate(config, source, getAdditionalRule, getAdditionalEnv) {
289
- this.validateConfigSchema(config, source);
290
- this.validateRules(config.rules, source, getAdditionalRule);
291
- this.validateEnvironment(config.env, source, getAdditionalEnv);
292
- this.validateGlobals(config.globals, source);
293
-
294
- for (const override of config.overrides || []) {
295
- this.validateRules(override.rules, source, getAdditionalRule);
296
- this.validateEnvironment(override.env, source, getAdditionalEnv);
297
- this.validateGlobals(config.globals, source);
298
- }
299
- }
300
-
301
- /**
302
- * Validate config array object.
303
- * @param {ConfigArray} configArray The config array to validate.
304
- * @returns {void}
305
- */
306
- validateConfigArray(configArray) {
307
- const getPluginEnv = Map.prototype.get.bind(configArray.pluginEnvironments);
308
- const getPluginProcessor = Map.prototype.get.bind(configArray.pluginProcessors);
309
- const getPluginRule = Map.prototype.get.bind(configArray.pluginRules);
310
-
311
- // Validate.
312
- for (const element of configArray) {
313
- if (validated.has(element)) {
314
- continue;
315
- }
316
- validated.add(element);
317
-
318
- this.validateEnvironment(element.env, element.name, getPluginEnv);
319
- this.validateGlobals(element.globals, element.name);
320
- this.validateProcessor(element.processor, element.name, getPluginProcessor);
321
- this.validateRules(element.rules, element.name, getPluginRule);
322
- }
323
- }
324
-
325
- }
@@ -1,63 +0,0 @@
1
- /**
2
- * @fileoverview Provide the function that emits deprecation warnings.
3
- * @author Toru Nagashima <http://github.com/mysticatea>
4
- */
5
-
6
- //------------------------------------------------------------------------------
7
- // Requirements
8
- //------------------------------------------------------------------------------
9
-
10
- import path from "path";
11
-
12
- //------------------------------------------------------------------------------
13
- // Private
14
- //------------------------------------------------------------------------------
15
-
16
- // Defitions for deprecation warnings.
17
- const deprecationWarningMessages = {
18
- ESLINT_LEGACY_ECMAFEATURES:
19
- "The 'ecmaFeatures' config file property is deprecated and has no effect.",
20
- ESLINT_PERSONAL_CONFIG_LOAD:
21
- "'~/.eslintrc.*' config files have been deprecated. " +
22
- "Please use a config file per project or the '--config' option.",
23
- ESLINT_PERSONAL_CONFIG_SUPPRESS:
24
- "'~/.eslintrc.*' config files have been deprecated. " +
25
- "Please remove it or add 'root:true' to the config files in your " +
26
- "projects in order to avoid loading '~/.eslintrc.*' accidentally."
27
- };
28
-
29
- const sourceFileErrorCache = new Set();
30
-
31
- /**
32
- * Emits a deprecation warning containing a given filepath. A new deprecation warning is emitted
33
- * for each unique file path, but repeated invocations with the same file path have no effect.
34
- * No warnings are emitted if the `--no-deprecation` or `--no-warnings` Node runtime flags are active.
35
- * @param {string} source The name of the configuration source to report the warning for.
36
- * @param {string} errorCode The warning message to show.
37
- * @returns {void}
38
- */
39
- function emitDeprecationWarning(source, errorCode) {
40
- const cacheKey = JSON.stringify({ source, errorCode });
41
-
42
- if (sourceFileErrorCache.has(cacheKey)) {
43
- return;
44
- }
45
- sourceFileErrorCache.add(cacheKey);
46
-
47
- const rel = path.relative(process.cwd(), source);
48
- const message = deprecationWarningMessages[errorCode];
49
-
50
- process.emitWarning(
51
- `${message} (found in "${rel}")`,
52
- "DeprecationWarning",
53
- errorCode
54
- );
55
- }
56
-
57
- //------------------------------------------------------------------------------
58
- // Public Interface
59
- //------------------------------------------------------------------------------
60
-
61
- export {
62
- emitDeprecationWarning
63
- };
@@ -1,96 +0,0 @@
1
- /**
2
- * @fileoverview Common helpers for naming of plugins, formatters and configs
3
- */
4
-
5
- const NAMESPACE_REGEX = /^@.*\//iu;
6
-
7
- /**
8
- * Brings package name to correct format based on prefix
9
- * @param {string} name The name of the package.
10
- * @param {string} prefix Can be either "eslint-plugin", "eslint-config" or "eslint-formatter"
11
- * @returns {string} Normalized name of the package
12
- * @private
13
- */
14
- function normalizePackageName(name, prefix) {
15
- let normalizedName = name;
16
-
17
- /**
18
- * On Windows, name can come in with Windows slashes instead of Unix slashes.
19
- * Normalize to Unix first to avoid errors later on.
20
- * https://github.com/eslint/eslint/issues/5644
21
- */
22
- if (normalizedName.includes("\\")) {
23
- normalizedName = normalizedName.replace(/\\/gu, "/");
24
- }
25
-
26
- if (normalizedName.charAt(0) === "@") {
27
-
28
- /**
29
- * it's a scoped package
30
- * package name is the prefix, or just a username
31
- */
32
- const scopedPackageShortcutRegex = new RegExp(`^(@[^/]+)(?:/(?:${prefix})?)?$`, "u"),
33
- scopedPackageNameRegex = new RegExp(`^${prefix}(-|$)`, "u");
34
-
35
- if (scopedPackageShortcutRegex.test(normalizedName)) {
36
- normalizedName = normalizedName.replace(scopedPackageShortcutRegex, `$1/${prefix}`);
37
- } else if (!scopedPackageNameRegex.test(normalizedName.split("/")[1])) {
38
-
39
- /**
40
- * for scoped packages, insert the prefix after the first / unless
41
- * the path is already @scope/eslint or @scope/eslint-xxx-yyy
42
- */
43
- normalizedName = normalizedName.replace(/^@([^/]+)\/(.*)$/u, `@$1/${prefix}-$2`);
44
- }
45
- } else if (!normalizedName.startsWith(`${prefix}-`)) {
46
- normalizedName = `${prefix}-${normalizedName}`;
47
- }
48
-
49
- return normalizedName;
50
- }
51
-
52
- /**
53
- * Removes the prefix from a fullname.
54
- * @param {string} fullname The term which may have the prefix.
55
- * @param {string} prefix The prefix to remove.
56
- * @returns {string} The term without prefix.
57
- */
58
- function getShorthandName(fullname, prefix) {
59
- if (fullname[0] === "@") {
60
- let matchResult = new RegExp(`^(@[^/]+)/${prefix}$`, "u").exec(fullname);
61
-
62
- if (matchResult) {
63
- return matchResult[1];
64
- }
65
-
66
- matchResult = new RegExp(`^(@[^/]+)/${prefix}-(.+)$`, "u").exec(fullname);
67
- if (matchResult) {
68
- return `${matchResult[1]}/${matchResult[2]}`;
69
- }
70
- } else if (fullname.startsWith(`${prefix}-`)) {
71
- return fullname.slice(prefix.length + 1);
72
- }
73
-
74
- return fullname;
75
- }
76
-
77
- /**
78
- * Gets the scope (namespace) of a term.
79
- * @param {string} term The term which may have the namespace.
80
- * @returns {string} The namespace of the term if it has one.
81
- */
82
- function getNamespaceFromTerm(term) {
83
- const match = term.match(NAMESPACE_REGEX);
84
-
85
- return match ? match[0] : "";
86
- }
87
-
88
- //------------------------------------------------------------------------------
89
- // Public Interface
90
- //------------------------------------------------------------------------------
91
-
92
- export {
93
- normalizePackageName,
94
- getShorthandName,
95
- getNamespaceFromTerm
96
- };
@@ -1,42 +0,0 @@
1
- /**
2
- * Utility for resolving a module relative to another module
3
- * @author Teddy Katz
4
- */
5
-
6
- import Module from "module";
7
-
8
- /*
9
- * `Module.createRequire` is added in v12.2.0. It supports URL as well.
10
- * We only support the case where the argument is a filepath, not a URL.
11
- */
12
- const createRequire = Module.createRequire;
13
-
14
- /**
15
- * Resolves a Node module relative to another module
16
- * @param {string} moduleName The name of a Node module, or a path to a Node module.
17
- * @param {string} relativeToPath An absolute path indicating the module that `moduleName` should be resolved relative to. This must be
18
- * a file rather than a directory, but the file need not actually exist.
19
- * @returns {string} The absolute path that would result from calling `require.resolve(moduleName)` in a file located at `relativeToPath`
20
- */
21
- function resolve(moduleName, relativeToPath) {
22
- try {
23
- return createRequire(relativeToPath).resolve(moduleName);
24
- } catch (error) {
25
-
26
- // This `if` block is for older Node.js than 12.0.0. We can remove this block in the future.
27
- if (
28
- typeof error === "object" &&
29
- error !== null &&
30
- error.code === "MODULE_NOT_FOUND" &&
31
- !error.requireStack &&
32
- error.message.includes(moduleName)
33
- ) {
34
- error.message += `\nRequire stack:\n- ${relativeToPath}`;
35
- }
36
- throw error;
37
- }
38
- }
39
-
40
- export {
41
- resolve
42
- };