@boundaries/eslint-plugin 5.2.0-beta.1
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.
- package/LICENSE +21 -0
- package/README.md +798 -0
- package/dist/Config/Config.d.ts +40 -0
- package/dist/Config/Config.js +119 -0
- package/dist/Config/Recommended.d.ts +10 -0
- package/dist/Config/Recommended.js +36 -0
- package/dist/Config/Strict.d.ts +8 -0
- package/dist/Config/Strict.js +26 -0
- package/dist/Elements/Elements.d.ts +43 -0
- package/dist/Elements/Elements.js +107 -0
- package/dist/Elements/Elements.types.d.ts +5 -0
- package/dist/Elements/Elements.types.js +2 -0
- package/dist/Elements/index.d.ts +2 -0
- package/dist/Elements/index.js +18 -0
- package/dist/Messages/Messages.d.ts +14 -0
- package/dist/Messages/Messages.js +204 -0
- package/dist/Messages/index.d.ts +1 -0
- package/dist/Messages/index.js +17 -0
- package/dist/Public/Config.types.d.ts +2 -0
- package/dist/Public/Config.types.js +5 -0
- package/dist/Public/Rules.types.d.ts +10 -0
- package/dist/Public/Rules.types.js +15 -0
- package/dist/Public/Settings.types.d.ts +13 -0
- package/dist/Public/Settings.types.js +21 -0
- package/dist/Public/index.d.ts +3 -0
- package/dist/Public/index.js +19 -0
- package/dist/Rules/ElementTypes.d.ts +25 -0
- package/dist/Rules/ElementTypes.js +269 -0
- package/dist/Rules/EntryPoint.d.ts +2 -0
- package/dist/Rules/EntryPoint.js +122 -0
- package/dist/Rules/External.d.ts +2 -0
- package/dist/Rules/External.js +119 -0
- package/dist/Rules/NoIgnored.d.ts +2 -0
- package/dist/Rules/NoIgnored.js +19 -0
- package/dist/Rules/NoPrivate.d.ts +2 -0
- package/dist/Rules/NoPrivate.js +53 -0
- package/dist/Rules/NoUnknown.d.ts +2 -0
- package/dist/Rules/NoUnknown.js +22 -0
- package/dist/Rules/NoUnknownFiles.d.ts +3 -0
- package/dist/Rules/NoUnknownFiles.js +29 -0
- package/dist/Rules/Support/DependencyRule.d.ts +4 -0
- package/dist/Rules/Support/DependencyRule.js +49 -0
- package/dist/Rules/Support/DependencyRule.types.d.ts +17 -0
- package/dist/Rules/Support/DependencyRule.types.js +2 -0
- package/dist/Rules/Support/Helpers.d.ts +8 -0
- package/dist/Rules/Support/Helpers.js +39 -0
- package/dist/Rules/Support/index.d.ts +3 -0
- package/dist/Rules/Support/index.js +19 -0
- package/dist/Settings/Helpers.d.ts +41 -0
- package/dist/Settings/Helpers.js +72 -0
- package/dist/Settings/Settings.d.ts +6 -0
- package/dist/Settings/Settings.js +49 -0
- package/dist/Settings/Settings.types.d.ts +448 -0
- package/dist/Settings/Settings.types.js +190 -0
- package/dist/Settings/Validations.d.ts +137 -0
- package/dist/Settings/Validations.js +359 -0
- package/dist/Settings/index.d.ts +4 -0
- package/dist/Settings/index.js +20 -0
- package/dist/Support/Common.d.ts +30 -0
- package/dist/Support/Common.js +47 -0
- package/dist/Support/Debug.d.ts +5 -0
- package/dist/Support/Debug.js +54 -0
- package/dist/Support/index.d.ts +2 -0
- package/dist/Support/index.js +18 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +76 -0
- package/package.json +81 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { ElementsSelector, ExternalLibrariesSelector, ElementDescriptor } from "@boundaries/elements";
|
|
2
|
+
import type { Rule } from "eslint";
|
|
3
|
+
import type { Settings, RuleMainKey, ValidateRulesOptions, RuleOptionsRules, SettingsNormalized } from "./Settings.types";
|
|
4
|
+
export declare function elementsMatcherSchema(matcherOptions?: Record<string, unknown>): {
|
|
5
|
+
oneOf: ({
|
|
6
|
+
type: string;
|
|
7
|
+
items?: undefined;
|
|
8
|
+
} | {
|
|
9
|
+
type: string;
|
|
10
|
+
items: {
|
|
11
|
+
oneOf: ({
|
|
12
|
+
type: string;
|
|
13
|
+
items?: undefined;
|
|
14
|
+
} | {
|
|
15
|
+
type: string;
|
|
16
|
+
items: Record<string, unknown>[];
|
|
17
|
+
})[];
|
|
18
|
+
};
|
|
19
|
+
})[];
|
|
20
|
+
};
|
|
21
|
+
export declare function rulesOptionsSchema(options?: {
|
|
22
|
+
rulesMainKey?: RuleMainKey;
|
|
23
|
+
targetMatcherOptions?: Record<string, unknown>;
|
|
24
|
+
}): {
|
|
25
|
+
type: string;
|
|
26
|
+
properties: {
|
|
27
|
+
message: {
|
|
28
|
+
type: string;
|
|
29
|
+
};
|
|
30
|
+
default: {
|
|
31
|
+
type: string;
|
|
32
|
+
enum: string[];
|
|
33
|
+
};
|
|
34
|
+
rules: {
|
|
35
|
+
type: string;
|
|
36
|
+
items: {
|
|
37
|
+
type: string;
|
|
38
|
+
properties: {
|
|
39
|
+
[x: string]: {
|
|
40
|
+
oneOf: ({
|
|
41
|
+
type: string;
|
|
42
|
+
items?: undefined;
|
|
43
|
+
} | {
|
|
44
|
+
type: string;
|
|
45
|
+
items: {
|
|
46
|
+
oneOf: ({
|
|
47
|
+
type: string;
|
|
48
|
+
items?: undefined;
|
|
49
|
+
} | {
|
|
50
|
+
type: string;
|
|
51
|
+
items: Record<string, unknown>[];
|
|
52
|
+
})[];
|
|
53
|
+
};
|
|
54
|
+
})[];
|
|
55
|
+
} | {
|
|
56
|
+
oneOf: ({
|
|
57
|
+
type: string;
|
|
58
|
+
items?: undefined;
|
|
59
|
+
} | {
|
|
60
|
+
type: string;
|
|
61
|
+
items: {
|
|
62
|
+
type: string;
|
|
63
|
+
};
|
|
64
|
+
})[];
|
|
65
|
+
type?: undefined;
|
|
66
|
+
} | {
|
|
67
|
+
type: string;
|
|
68
|
+
oneOf?: undefined;
|
|
69
|
+
};
|
|
70
|
+
allow: {
|
|
71
|
+
oneOf: ({
|
|
72
|
+
type: string;
|
|
73
|
+
items?: undefined;
|
|
74
|
+
} | {
|
|
75
|
+
type: string;
|
|
76
|
+
items: {
|
|
77
|
+
oneOf: ({
|
|
78
|
+
type: string;
|
|
79
|
+
items?: undefined;
|
|
80
|
+
} | {
|
|
81
|
+
type: string;
|
|
82
|
+
items: Record<string, unknown>[];
|
|
83
|
+
})[];
|
|
84
|
+
};
|
|
85
|
+
})[];
|
|
86
|
+
};
|
|
87
|
+
disallow: {
|
|
88
|
+
oneOf: ({
|
|
89
|
+
type: string;
|
|
90
|
+
items?: undefined;
|
|
91
|
+
} | {
|
|
92
|
+
type: string;
|
|
93
|
+
items: {
|
|
94
|
+
oneOf: ({
|
|
95
|
+
type: string;
|
|
96
|
+
items?: undefined;
|
|
97
|
+
} | {
|
|
98
|
+
type: string;
|
|
99
|
+
items: Record<string, unknown>[];
|
|
100
|
+
})[];
|
|
101
|
+
};
|
|
102
|
+
})[];
|
|
103
|
+
};
|
|
104
|
+
importKind: {
|
|
105
|
+
oneOf: ({
|
|
106
|
+
type: string;
|
|
107
|
+
items?: undefined;
|
|
108
|
+
} | {
|
|
109
|
+
type: string;
|
|
110
|
+
items: {
|
|
111
|
+
type: string;
|
|
112
|
+
};
|
|
113
|
+
})[];
|
|
114
|
+
};
|
|
115
|
+
message: {
|
|
116
|
+
type: string;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
additionalProperties: boolean;
|
|
120
|
+
anyOf: {
|
|
121
|
+
required: string[];
|
|
122
|
+
}[];
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
additionalProperties: boolean;
|
|
127
|
+
}[];
|
|
128
|
+
export declare function validateElementTypesMatcher(elementsMatcher: ElementsSelector | ExternalLibrariesSelector, settings: SettingsNormalized): void;
|
|
129
|
+
export declare function validateSettings(settings: Rule.RuleContext["settings"]): Settings;
|
|
130
|
+
/**
|
|
131
|
+
* Returns the normalized settings from the ESLint rule context
|
|
132
|
+
* @param context The ESLint rule context
|
|
133
|
+
* @returns The normalized settings
|
|
134
|
+
*/
|
|
135
|
+
export declare function getSettings(context: Rule.RuleContext): SettingsNormalized;
|
|
136
|
+
export declare function validateRules(settings: SettingsNormalized, rules?: RuleOptionsRules[], options?: ValidateRulesOptions): void;
|
|
137
|
+
export declare function isValidElementAssigner(element: unknown): element is ElementDescriptor;
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.elementsMatcherSchema = elementsMatcherSchema;
|
|
7
|
+
exports.rulesOptionsSchema = rulesOptionsSchema;
|
|
8
|
+
exports.validateElementTypesMatcher = validateElementTypesMatcher;
|
|
9
|
+
exports.validateSettings = validateSettings;
|
|
10
|
+
exports.getSettings = getSettings;
|
|
11
|
+
exports.validateRules = validateRules;
|
|
12
|
+
exports.isValidElementAssigner = isValidElementAssigner;
|
|
13
|
+
const elements_1 = require("@boundaries/elements");
|
|
14
|
+
const micromatch_1 = __importDefault(require("micromatch"));
|
|
15
|
+
const Common_1 = require("../Support/Common");
|
|
16
|
+
const Debug_1 = require("../Support/Debug");
|
|
17
|
+
const Helpers_1 = require("./Helpers");
|
|
18
|
+
const Settings_1 = require("./Settings");
|
|
19
|
+
const Settings_types_1 = require("./Settings.types");
|
|
20
|
+
const { TYPES, ALIAS, ELEMENTS, DEPENDENCY_NODES, ADDITIONAL_DEPENDENCY_NODES, VALID_DEPENDENCY_NODE_KINDS, DEFAULT_DEPENDENCY_NODES, VALID_MODES, } = Settings_types_1.SETTINGS;
|
|
21
|
+
const settingsCache = new elements_1.CacheManager();
|
|
22
|
+
const invalidMatchers = [];
|
|
23
|
+
const DEFAULT_MATCHER_OPTIONS = {
|
|
24
|
+
type: "object",
|
|
25
|
+
};
|
|
26
|
+
function elementsMatcherSchema(matcherOptions = DEFAULT_MATCHER_OPTIONS) {
|
|
27
|
+
return {
|
|
28
|
+
oneOf: [
|
|
29
|
+
{
|
|
30
|
+
type: "string", // single matcher
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
type: "array", // multiple matchers
|
|
34
|
+
items: {
|
|
35
|
+
oneOf: [
|
|
36
|
+
{
|
|
37
|
+
type: "string", // matcher with options
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
type: "array",
|
|
41
|
+
items: [
|
|
42
|
+
{
|
|
43
|
+
type: "string", // matcher
|
|
44
|
+
},
|
|
45
|
+
matcherOptions, // options
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function rulesOptionsSchema(options = {}) {
|
|
55
|
+
const mainKey = (0, Helpers_1.rulesMainKey)(options.rulesMainKey);
|
|
56
|
+
return [
|
|
57
|
+
{
|
|
58
|
+
type: "object",
|
|
59
|
+
properties: {
|
|
60
|
+
message: {
|
|
61
|
+
type: "string",
|
|
62
|
+
},
|
|
63
|
+
default: {
|
|
64
|
+
type: "string",
|
|
65
|
+
enum: ["allow", "disallow"],
|
|
66
|
+
},
|
|
67
|
+
rules: {
|
|
68
|
+
type: "array",
|
|
69
|
+
items: {
|
|
70
|
+
type: "object",
|
|
71
|
+
properties: {
|
|
72
|
+
[mainKey]: elementsMatcherSchema(),
|
|
73
|
+
allow: elementsMatcherSchema(options.targetMatcherOptions),
|
|
74
|
+
disallow: elementsMatcherSchema(options.targetMatcherOptions),
|
|
75
|
+
importKind: {
|
|
76
|
+
oneOf: [
|
|
77
|
+
{
|
|
78
|
+
type: "string",
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
type: "array",
|
|
82
|
+
items: {
|
|
83
|
+
type: "string",
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
message: {
|
|
89
|
+
type: "string",
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
additionalProperties: false,
|
|
93
|
+
anyOf: [
|
|
94
|
+
{
|
|
95
|
+
required: [mainKey, "allow", "disallow"],
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
required: [mainKey, "allow"],
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
required: [mainKey, "disallow"],
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
additionalProperties: false,
|
|
108
|
+
},
|
|
109
|
+
];
|
|
110
|
+
}
|
|
111
|
+
function isValidElementTypesMatcher(matcher, settings) {
|
|
112
|
+
const matcherToCheck = (0, Common_1.isArray)(matcher) ? matcher[0] : matcher;
|
|
113
|
+
const typeMatcherToCheck = (0, Common_1.isString)(matcherToCheck)
|
|
114
|
+
? matcherToCheck
|
|
115
|
+
: matcherToCheck.type;
|
|
116
|
+
return (!matcher ||
|
|
117
|
+
(typeMatcherToCheck &&
|
|
118
|
+
micromatch_1.default.some(settings.elementTypeNames, typeMatcherToCheck)));
|
|
119
|
+
}
|
|
120
|
+
// TODO: Remove this validation. Selectors should not be limited to element types defined in settings when using selector objects
|
|
121
|
+
function validateElementTypesMatcher(elementsMatcher, settings) {
|
|
122
|
+
const [matcher] = (0, Common_1.isArray)(elementsMatcher)
|
|
123
|
+
? elementsMatcher
|
|
124
|
+
: [elementsMatcher];
|
|
125
|
+
if (!invalidMatchers.includes(matcher) &&
|
|
126
|
+
!isValidElementTypesMatcher(matcher, settings)) {
|
|
127
|
+
invalidMatchers.push(matcher);
|
|
128
|
+
(0, Debug_1.warnOnce)(`Option '${matcher}' does not match any element type from '${ELEMENTS}' setting`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function validateElements(elements) {
|
|
132
|
+
if (!elements || !(0, Common_1.isArray)(elements) || !elements.length) {
|
|
133
|
+
(0, Debug_1.warnOnce)(`Please provide element types using the '${ELEMENTS}' setting`);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
return elements.filter(isValidElementAssigner);
|
|
137
|
+
}
|
|
138
|
+
function validateDependencyNodes(dependencyNodes) {
|
|
139
|
+
if (!dependencyNodes) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const defaultNodesNames = Object.keys(DEFAULT_DEPENDENCY_NODES);
|
|
143
|
+
const invalidFormatMessage = [
|
|
144
|
+
`Please provide a valid value in ${DEPENDENCY_NODES} setting.`,
|
|
145
|
+
`The value should be an array of the following strings:`,
|
|
146
|
+
` "${defaultNodesNames.join('", "')}".`,
|
|
147
|
+
].join(" ");
|
|
148
|
+
if (!(0, Common_1.isArray)(dependencyNodes)) {
|
|
149
|
+
(0, Debug_1.warnOnce)(invalidFormatMessage);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
for (const dependencyNode of dependencyNodes) {
|
|
153
|
+
if (!(0, Helpers_1.isDependencyNodeKey)(dependencyNode)) {
|
|
154
|
+
(0, Debug_1.warnOnce)(invalidFormatMessage);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return dependencyNodes.filter(Helpers_1.isDependencyNodeKey);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Validates the legacyTemplates setting.
|
|
161
|
+
* @param legacyTemplates The legacyTemplates setting value
|
|
162
|
+
* @returns The validated legacyTemplates value or undefined
|
|
163
|
+
*/
|
|
164
|
+
function validateLegacyTemplates(
|
|
165
|
+
/** The legacyTemplates setting value */
|
|
166
|
+
legacyTemplates) {
|
|
167
|
+
if (legacyTemplates === undefined) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if ((0, Common_1.isBoolean)(legacyTemplates)) {
|
|
171
|
+
return legacyTemplates;
|
|
172
|
+
}
|
|
173
|
+
(0, Debug_1.warnOnce)(`Please provide a valid value in '${Settings_types_1.SETTINGS_KEYS_MAP.LEGACY_TEMPLATES}' setting. The value should be a boolean.`);
|
|
174
|
+
// Value is invalid, return undefined
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
function isValidDependencyNodeSelector(selector) {
|
|
178
|
+
const isValidObject = (0, Common_1.isObject)(selector) &&
|
|
179
|
+
(0, Common_1.isString)(selector.selector) &&
|
|
180
|
+
(!selector.kind ||
|
|
181
|
+
((0, Common_1.isString)(selector.kind) &&
|
|
182
|
+
VALID_DEPENDENCY_NODE_KINDS.includes(selector.kind)));
|
|
183
|
+
if (!isValidObject) {
|
|
184
|
+
(0, Debug_1.warnOnce)(`Please provide a valid object in ${ADDITIONAL_DEPENDENCY_NODES} setting. The object should be composed of the following properties: { selector: "<esquery selector>", kind: "value" | "type" }. The invalid object will be ignored.`);
|
|
185
|
+
}
|
|
186
|
+
return isValidObject;
|
|
187
|
+
}
|
|
188
|
+
function validateAdditionalDependencyNodes(additionalDependencyNodes) {
|
|
189
|
+
if (!additionalDependencyNodes) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const invalidFormatMessage = [
|
|
193
|
+
`Please provide a valid value in ${ADDITIONAL_DEPENDENCY_NODES} setting.`,
|
|
194
|
+
"The value should be an array composed of the following objects:",
|
|
195
|
+
'{ selector: "<esquery selector>", kind: "value" | "type" }.',
|
|
196
|
+
].join(" ");
|
|
197
|
+
if (!(0, Common_1.isArray)(additionalDependencyNodes)) {
|
|
198
|
+
(0, Debug_1.warnOnce)(invalidFormatMessage);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
return additionalDependencyNodes.filter(isValidDependencyNodeSelector);
|
|
202
|
+
}
|
|
203
|
+
function deprecateAlias(aliases) {
|
|
204
|
+
if (aliases) {
|
|
205
|
+
(0, Debug_1.warnOnce)(`Defining aliases in '${ALIAS}' setting is deprecated. Please use 'import/resolver' setting`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function deprecateTypes(types) {
|
|
209
|
+
if (types) {
|
|
210
|
+
(0, Debug_1.warnOnce)(`'${TYPES}' setting is deprecated. Please use '${ELEMENTS}' instead`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function validateIgnore(ignore) {
|
|
214
|
+
if (!ignore) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if ((0, Common_1.isString)(ignore) || ((0, Common_1.isArray)(ignore) && ignore.every(Common_1.isString))) {
|
|
218
|
+
return ignore;
|
|
219
|
+
}
|
|
220
|
+
(0, Debug_1.warnOnce)(`Please provide a valid value in '${Settings_types_1.SETTINGS_KEYS_MAP.IGNORE}' setting. The value should be a string or an array of strings.`);
|
|
221
|
+
}
|
|
222
|
+
function validateInclude(include) {
|
|
223
|
+
if (!include) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if ((0, Common_1.isString)(include) || ((0, Common_1.isArray)(include) && include.every(Common_1.isString))) {
|
|
227
|
+
return include;
|
|
228
|
+
}
|
|
229
|
+
(0, Debug_1.warnOnce)(`Please provide a valid value in '${Settings_types_1.SETTINGS_KEYS_MAP.INCLUDE}' setting. The value should be a string or an array of strings.`);
|
|
230
|
+
}
|
|
231
|
+
function validateRootPath(rootPath) {
|
|
232
|
+
if (!rootPath) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
if ((0, Common_1.isString)(rootPath)) {
|
|
236
|
+
return rootPath;
|
|
237
|
+
}
|
|
238
|
+
(0, Debug_1.warnOnce)(`Please provide a valid value in '${Settings_types_1.SETTINGS_KEYS_MAP.ROOT_PATH}' setting. The value should be a string.`);
|
|
239
|
+
}
|
|
240
|
+
function validateSettings(settings) {
|
|
241
|
+
deprecateTypes(settings[TYPES]);
|
|
242
|
+
deprecateAlias(settings[ALIAS]);
|
|
243
|
+
return {
|
|
244
|
+
[Settings_types_1.SETTINGS_KEYS_MAP.ELEMENTS]: validateElements(settings[ELEMENTS] || settings[TYPES]),
|
|
245
|
+
[Settings_types_1.SETTINGS_KEYS_MAP.IGNORE]: validateIgnore(settings[Settings_types_1.SETTINGS_KEYS_MAP.IGNORE]),
|
|
246
|
+
[Settings_types_1.SETTINGS_KEYS_MAP.INCLUDE]: validateInclude(settings[Settings_types_1.SETTINGS_KEYS_MAP.INCLUDE]),
|
|
247
|
+
[Settings_types_1.SETTINGS_KEYS_MAP.ROOT_PATH]: validateRootPath(settings[Settings_types_1.SETTINGS_KEYS_MAP.ROOT_PATH]),
|
|
248
|
+
[Settings_types_1.SETTINGS_KEYS_MAP.DEPENDENCY_NODES]: validateDependencyNodes(settings[DEPENDENCY_NODES]),
|
|
249
|
+
[Settings_types_1.SETTINGS_KEYS_MAP.LEGACY_TEMPLATES]: validateLegacyTemplates(settings[Settings_types_1.SETTINGS_KEYS_MAP.LEGACY_TEMPLATES]),
|
|
250
|
+
[Settings_types_1.SETTINGS_KEYS_MAP.ADDITIONAL_DEPENDENCY_NODES]: validateAdditionalDependencyNodes(settings[ADDITIONAL_DEPENDENCY_NODES]),
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Returns the normalized settings from the ESLint rule context
|
|
255
|
+
* @param context The ESLint rule context
|
|
256
|
+
* @returns The normalized settings
|
|
257
|
+
*/
|
|
258
|
+
function getSettings(context) {
|
|
259
|
+
if (settingsCache.has(context.settings)) {
|
|
260
|
+
return settingsCache.get(context.settings);
|
|
261
|
+
}
|
|
262
|
+
const validatedSettings = validateSettings(context.settings);
|
|
263
|
+
const dependencyNodesSetting = (0, Common_1.getArrayOrNull)(validatedSettings[Settings_types_1.SETTINGS_KEYS_MAP.DEPENDENCY_NODES]);
|
|
264
|
+
const additionalDependencyNodesSetting = (0, Common_1.getArrayOrNull)(validatedSettings[ADDITIONAL_DEPENDENCY_NODES]);
|
|
265
|
+
const dependencyNodes =
|
|
266
|
+
// TODO In next major version, make this default to all types of nodes!!!
|
|
267
|
+
(dependencyNodesSetting || [Settings_types_1.DEPENDENCY_NODE_KEYS_MAP.IMPORT])
|
|
268
|
+
.flatMap((dependencyNode) => [
|
|
269
|
+
...DEFAULT_DEPENDENCY_NODES[dependencyNode],
|
|
270
|
+
])
|
|
271
|
+
.filter(Boolean);
|
|
272
|
+
const additionalDependencyNodes = additionalDependencyNodesSetting || [];
|
|
273
|
+
const ignoreSetting = validatedSettings[Settings_types_1.SETTINGS_KEYS_MAP.IGNORE];
|
|
274
|
+
const ignorePaths = (0, Common_1.isString)(ignoreSetting) ? [ignoreSetting] : ignoreSetting;
|
|
275
|
+
const includeSetting = validatedSettings[Settings_types_1.SETTINGS_KEYS_MAP.INCLUDE];
|
|
276
|
+
const includePaths = (0, Common_1.isString)(includeSetting)
|
|
277
|
+
? [includeSetting]
|
|
278
|
+
: includeSetting;
|
|
279
|
+
const descriptors = (0, Settings_1.transformLegacyTypes)(validatedSettings[ELEMENTS]);
|
|
280
|
+
// NOTE: Filter valid descriptors only to avoid a breaking change for the moment
|
|
281
|
+
const validDescriptors = descriptors.filter(elements_1.isElementDescriptor);
|
|
282
|
+
const invalidDescriptors = descriptors.filter((desc) => !(0, elements_1.isElementDescriptor)(desc));
|
|
283
|
+
if (invalidDescriptors.length > 0) {
|
|
284
|
+
/*
|
|
285
|
+
* TODO: Report invalid descriptors in ESLint context as a warning in a separate rule:
|
|
286
|
+
* context.report({
|
|
287
|
+
* message: `Some element descriptors are invalid and will be ignored: ${JSON.stringify(
|
|
288
|
+
* invalidDescriptors,
|
|
289
|
+
* )}`,
|
|
290
|
+
* loc: { line: 1, column: 0 },
|
|
291
|
+
* });
|
|
292
|
+
*/
|
|
293
|
+
(0, Debug_1.warnOnce)(`Some element descriptors are invalid and will be ignored: ${JSON.stringify(invalidDescriptors)}`);
|
|
294
|
+
}
|
|
295
|
+
const result = {
|
|
296
|
+
elementDescriptors: validDescriptors,
|
|
297
|
+
elementTypeNames: (0, Settings_1.getElementsTypeNames)(validDescriptors),
|
|
298
|
+
ignorePaths,
|
|
299
|
+
includePaths,
|
|
300
|
+
rootPath: (0, Settings_1.getRootPath)(validatedSettings),
|
|
301
|
+
dependencyNodes: [...dependencyNodes, ...additionalDependencyNodes],
|
|
302
|
+
legacyTemplates: validatedSettings[Settings_types_1.SETTINGS_KEYS_MAP.LEGACY_TEMPLATES] ??
|
|
303
|
+
Settings_types_1.LEGACY_TEMPLATES_DEFAULT,
|
|
304
|
+
};
|
|
305
|
+
settingsCache.set(context.settings, result);
|
|
306
|
+
return result;
|
|
307
|
+
}
|
|
308
|
+
function validateRules(settings, rules = [], options = {}) {
|
|
309
|
+
const mainKey = (0, Helpers_1.rulesMainKey)(options.mainKey);
|
|
310
|
+
for (const rule of rules) {
|
|
311
|
+
//@ts-expect-error TODO: Add a different schema validation for each rule type, so keys are properly validated
|
|
312
|
+
validateElementTypesMatcher([rule[mainKey]], settings);
|
|
313
|
+
if (!options.onlyMainKey) {
|
|
314
|
+
if (rule.allow) {
|
|
315
|
+
validateElementTypesMatcher(rule.allow, settings);
|
|
316
|
+
}
|
|
317
|
+
if (rule.disallow) {
|
|
318
|
+
validateElementTypesMatcher(rule.disallow, settings);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
function isValidElementAssigner(element) {
|
|
324
|
+
if (!element) {
|
|
325
|
+
(0, Debug_1.warnOnce)(`Please provide a valid object to define element types in '${ELEMENTS}' setting`);
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
if ((0, Helpers_1.isLegacyType)(element)) {
|
|
329
|
+
(0, Debug_1.warnOnce)(`Defining elements as strings in settings is deprecated. Will be automatically converted, but this feature will be removed in next major versions`);
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
const isObjectElement = (0, Common_1.isObject)(element);
|
|
334
|
+
if (!isObjectElement) {
|
|
335
|
+
(0, Debug_1.warnOnce)(`Please provide a valid object to define element types in '${ELEMENTS}' setting`);
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
if (!element.type || !(0, Common_1.isString)(element.type)) {
|
|
339
|
+
(0, Debug_1.warnOnce)(`Please provide type in '${ELEMENTS}' setting`);
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
if (element.mode &&
|
|
343
|
+
(0, Common_1.isString)(element.mode) &&
|
|
344
|
+
!VALID_MODES.includes(element.mode)) {
|
|
345
|
+
(0, Debug_1.warnOnce)(`Invalid mode property of type ${element.type} in '${ELEMENTS}' setting. Should be one of ${VALID_MODES.join(",")}. Default value "${VALID_MODES[0]}" will be used instead`);
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
if (!element.pattern ||
|
|
349
|
+
!((0, Common_1.isString)(element.pattern) || (0, Common_1.isArray)(element.pattern))) {
|
|
350
|
+
(0, Debug_1.warnOnce)(`Please provide a valid pattern to type ${element.type} in '${ELEMENTS}' setting`);
|
|
351
|
+
return false;
|
|
352
|
+
}
|
|
353
|
+
if (element.capture && !(0, Common_1.isArray)(element.capture)) {
|
|
354
|
+
(0, Debug_1.warnOnce)(`Invalid capture property of type ${element.type} in '${ELEMENTS}' setting`);
|
|
355
|
+
return false;
|
|
356
|
+
}
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Settings"), exports);
|
|
18
|
+
__exportStar(require("./Validations"), exports);
|
|
19
|
+
__exportStar(require("./Settings.types"), exports);
|
|
20
|
+
__exportStar(require("./Helpers"), exports);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines if the provided object is an array.
|
|
3
|
+
* @param object The object to check.
|
|
4
|
+
* @returns True if the object is an array, false otherwise.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isArray(object: unknown): object is unknown[];
|
|
7
|
+
/**
|
|
8
|
+
* Determines if the provided object is a string.
|
|
9
|
+
* @param object The object to check.
|
|
10
|
+
* @returns True if the object is a string, false otherwise.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isString(object: unknown): object is string;
|
|
13
|
+
/**
|
|
14
|
+
* Determines if the provided object is a boolean.
|
|
15
|
+
* @param object The object to check.
|
|
16
|
+
* @returns True if the object is a boolean, false otherwise.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isBoolean(object: unknown): object is boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Determines if the provided object is a non-null object (but not an array).
|
|
21
|
+
* @param object The object to check.
|
|
22
|
+
* @returns True if the object is a non-null object, false otherwise.
|
|
23
|
+
*/
|
|
24
|
+
export declare function isObject(object: unknown): object is Record<string, unknown>;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the value as an array if it is an array, or null otherwise.
|
|
27
|
+
* @param value The value to check.
|
|
28
|
+
* @returns The value as an array or null.
|
|
29
|
+
*/
|
|
30
|
+
export declare function getArrayOrNull<T>(value: unknown): T[] | null;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isArray = isArray;
|
|
4
|
+
exports.isString = isString;
|
|
5
|
+
exports.isBoolean = isBoolean;
|
|
6
|
+
exports.isObject = isObject;
|
|
7
|
+
exports.getArrayOrNull = getArrayOrNull;
|
|
8
|
+
/**
|
|
9
|
+
* Determines if the provided object is an array.
|
|
10
|
+
* @param object The object to check.
|
|
11
|
+
* @returns True if the object is an array, false otherwise.
|
|
12
|
+
*/
|
|
13
|
+
function isArray(object) {
|
|
14
|
+
return Array.isArray(object);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Determines if the provided object is a string.
|
|
18
|
+
* @param object The object to check.
|
|
19
|
+
* @returns True if the object is a string, false otherwise.
|
|
20
|
+
*/
|
|
21
|
+
function isString(object) {
|
|
22
|
+
return typeof object === "string";
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Determines if the provided object is a boolean.
|
|
26
|
+
* @param object The object to check.
|
|
27
|
+
* @returns True if the object is a boolean, false otherwise.
|
|
28
|
+
*/
|
|
29
|
+
function isBoolean(object) {
|
|
30
|
+
return typeof object === "boolean";
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Determines if the provided object is a non-null object (but not an array).
|
|
34
|
+
* @param object The object to check.
|
|
35
|
+
* @returns True if the object is a non-null object, false otherwise.
|
|
36
|
+
*/
|
|
37
|
+
function isObject(object) {
|
|
38
|
+
return typeof object === "object" && object !== null && !isArray(object);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Returns the value as an array if it is an array, or null otherwise.
|
|
42
|
+
* @param value The value to check.
|
|
43
|
+
* @returns The value as an array or null.
|
|
44
|
+
*/
|
|
45
|
+
function getArrayOrNull(value) {
|
|
46
|
+
return isArray(value) ? value : null;
|
|
47
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { DependencyDescription, ElementDescription } from "@boundaries/elements";
|
|
2
|
+
export declare function warn(message: string): void;
|
|
3
|
+
export declare function success(message: string): void;
|
|
4
|
+
export declare function warnOnce(message: string): void;
|
|
5
|
+
export declare function debugDescription(elementDescription: ElementDescription | DependencyDescription): void;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.warn = warn;
|
|
7
|
+
exports.success = success;
|
|
8
|
+
exports.warnOnce = warnOnce;
|
|
9
|
+
exports.debugDescription = debugDescription;
|
|
10
|
+
const elements_1 = require("@boundaries/elements");
|
|
11
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
12
|
+
const Settings_1 = require("../Settings");
|
|
13
|
+
const warns = [];
|
|
14
|
+
const debuggedFiles = [];
|
|
15
|
+
const COLORS_MAP = {
|
|
16
|
+
gray: "gray",
|
|
17
|
+
green: "green",
|
|
18
|
+
yellow: "yellow",
|
|
19
|
+
};
|
|
20
|
+
function trace(message, color) {
|
|
21
|
+
// eslint-disable-next-line no-console
|
|
22
|
+
console.log(chalk_1.default[COLORS_MAP[color]](`[${Settings_1.PLUGIN_NAME}]: ${message}`));
|
|
23
|
+
}
|
|
24
|
+
function warn(message) {
|
|
25
|
+
trace(message, COLORS_MAP.yellow);
|
|
26
|
+
}
|
|
27
|
+
function success(message) {
|
|
28
|
+
trace(message, COLORS_MAP.green);
|
|
29
|
+
}
|
|
30
|
+
function warnOnce(message) {
|
|
31
|
+
if (!warns.includes(message)) {
|
|
32
|
+
warns.push(message);
|
|
33
|
+
warn(message);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function debugDescription(elementDescription) {
|
|
37
|
+
const isDependency = (0, elements_1.isDependencyDescription)(elementDescription);
|
|
38
|
+
const key = isDependency
|
|
39
|
+
? elementDescription.to.source
|
|
40
|
+
: elementDescription.path || "";
|
|
41
|
+
const type = isDependency
|
|
42
|
+
? elementDescription.to.type
|
|
43
|
+
: elementDescription.type;
|
|
44
|
+
if ((0, Settings_1.isDebugModeEnabled)() && !debuggedFiles.includes(key)) {
|
|
45
|
+
debuggedFiles.push(key);
|
|
46
|
+
if (type) {
|
|
47
|
+
success(`'${key}' is of type '${type}'`);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
warn(`'${key}' is of unknown type`);
|
|
51
|
+
}
|
|
52
|
+
trace(`\n${JSON.stringify(elementDescription, null, 2)}`, COLORS_MAP.gray);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Common"), exports);
|
|
18
|
+
__exportStar(require("./Debug"), exports);
|