@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.
Files changed (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +798 -0
  3. package/dist/Config/Config.d.ts +40 -0
  4. package/dist/Config/Config.js +119 -0
  5. package/dist/Config/Recommended.d.ts +10 -0
  6. package/dist/Config/Recommended.js +36 -0
  7. package/dist/Config/Strict.d.ts +8 -0
  8. package/dist/Config/Strict.js +26 -0
  9. package/dist/Elements/Elements.d.ts +43 -0
  10. package/dist/Elements/Elements.js +107 -0
  11. package/dist/Elements/Elements.types.d.ts +5 -0
  12. package/dist/Elements/Elements.types.js +2 -0
  13. package/dist/Elements/index.d.ts +2 -0
  14. package/dist/Elements/index.js +18 -0
  15. package/dist/Messages/Messages.d.ts +14 -0
  16. package/dist/Messages/Messages.js +204 -0
  17. package/dist/Messages/index.d.ts +1 -0
  18. package/dist/Messages/index.js +17 -0
  19. package/dist/Public/Config.types.d.ts +2 -0
  20. package/dist/Public/Config.types.js +5 -0
  21. package/dist/Public/Rules.types.d.ts +10 -0
  22. package/dist/Public/Rules.types.js +15 -0
  23. package/dist/Public/Settings.types.d.ts +13 -0
  24. package/dist/Public/Settings.types.js +21 -0
  25. package/dist/Public/index.d.ts +3 -0
  26. package/dist/Public/index.js +19 -0
  27. package/dist/Rules/ElementTypes.d.ts +25 -0
  28. package/dist/Rules/ElementTypes.js +269 -0
  29. package/dist/Rules/EntryPoint.d.ts +2 -0
  30. package/dist/Rules/EntryPoint.js +122 -0
  31. package/dist/Rules/External.d.ts +2 -0
  32. package/dist/Rules/External.js +119 -0
  33. package/dist/Rules/NoIgnored.d.ts +2 -0
  34. package/dist/Rules/NoIgnored.js +19 -0
  35. package/dist/Rules/NoPrivate.d.ts +2 -0
  36. package/dist/Rules/NoPrivate.js +53 -0
  37. package/dist/Rules/NoUnknown.d.ts +2 -0
  38. package/dist/Rules/NoUnknown.js +22 -0
  39. package/dist/Rules/NoUnknownFiles.d.ts +3 -0
  40. package/dist/Rules/NoUnknownFiles.js +29 -0
  41. package/dist/Rules/Support/DependencyRule.d.ts +4 -0
  42. package/dist/Rules/Support/DependencyRule.js +49 -0
  43. package/dist/Rules/Support/DependencyRule.types.d.ts +17 -0
  44. package/dist/Rules/Support/DependencyRule.types.js +2 -0
  45. package/dist/Rules/Support/Helpers.d.ts +8 -0
  46. package/dist/Rules/Support/Helpers.js +39 -0
  47. package/dist/Rules/Support/index.d.ts +3 -0
  48. package/dist/Rules/Support/index.js +19 -0
  49. package/dist/Settings/Helpers.d.ts +41 -0
  50. package/dist/Settings/Helpers.js +72 -0
  51. package/dist/Settings/Settings.d.ts +6 -0
  52. package/dist/Settings/Settings.js +49 -0
  53. package/dist/Settings/Settings.types.d.ts +448 -0
  54. package/dist/Settings/Settings.types.js +190 -0
  55. package/dist/Settings/Validations.d.ts +137 -0
  56. package/dist/Settings/Validations.js +359 -0
  57. package/dist/Settings/index.d.ts +4 -0
  58. package/dist/Settings/index.js +20 -0
  59. package/dist/Support/Common.d.ts +30 -0
  60. package/dist/Support/Common.js +47 -0
  61. package/dist/Support/Debug.d.ts +5 -0
  62. package/dist/Support/Debug.js +54 -0
  63. package/dist/Support/index.d.ts +2 -0
  64. package/dist/Support/index.js +18 -0
  65. package/dist/index.d.ts +8 -0
  66. package/dist/index.js +76 -0
  67. package/package.json +81 -0
@@ -0,0 +1,448 @@
1
+ import type { DependencyKind, ElementDescriptors, ElementsSelector, CapturedValues, ExternalLibrariesSelector } from "@boundaries/elements";
2
+ import type { ESLint, Linter, Rule } from "eslint";
3
+ export declare const PLUGIN_NAME: "boundaries";
4
+ export declare const PLUGIN_ENV_VARS_PREFIX: "ESLINT_PLUGIN_BOUNDARIES";
5
+ export declare const REPO_URL: "https://github.com/javierbrea/eslint-plugin-boundaries";
6
+ export declare const PLUGIN_ISSUES_URL: "https://github.com/javierbrea/eslint-plugin-boundaries/issues";
7
+ export declare const DEPENDENCY_NODE_REQUIRE: "require";
8
+ export declare const DEPENDENCY_NODE_IMPORT: "import";
9
+ export declare const DEPENDENCY_NODE_DYNAMIC_IMPORT: "dynamic-import";
10
+ export declare const DEPENDENCY_NODE_EXPORT: "export";
11
+ export declare const ELEMENT_TYPES: "element-types";
12
+ export declare const ENTRY_POINT: "entry-point";
13
+ export declare const EXTERNAL: "external";
14
+ export declare const NO_IGNORED: "no-ignored";
15
+ export declare const NO_PRIVATE: "no-private";
16
+ export declare const NO_UNKNOWN_FILES: "no-unknown-files";
17
+ export declare const NO_UNKNOWN: "no-unknown";
18
+ /**
19
+ * Map of all rule short names, without the plugin prefix.
20
+ */
21
+ export declare const RULE_SHORT_NAMES_MAP: {
22
+ readonly ELEMENT_TYPES: "element-types";
23
+ readonly ENTRY_POINT: "entry-point";
24
+ readonly EXTERNAL: "external";
25
+ readonly NO_IGNORED: "no-ignored";
26
+ readonly NO_PRIVATE: "no-private";
27
+ readonly NO_UNKNOWN_FILES: "no-unknown-files";
28
+ readonly NO_UNKNOWN: "no-unknown";
29
+ };
30
+ /**
31
+ * Map of all rule names, including the default plugin prefix.
32
+ */
33
+ export declare const RULE_NAMES_MAP: {
34
+ readonly ELEMENT_TYPES: "boundaries/element-types";
35
+ readonly ENTRY_POINT: "boundaries/entry-point";
36
+ readonly EXTERNAL: "boundaries/external";
37
+ readonly NO_IGNORED: "boundaries/no-ignored";
38
+ readonly NO_PRIVATE: "boundaries/no-private";
39
+ readonly NO_UNKNOWN_FILES: "boundaries/no-unknown-files";
40
+ readonly NO_UNKNOWN: "boundaries/no-unknown";
41
+ };
42
+ /**
43
+ * List of all rule names
44
+ */
45
+ export declare const RULE_NAMES: readonly ("boundaries/element-types" | "boundaries/entry-point" | "boundaries/external" | "boundaries/no-ignored" | "boundaries/no-private" | "boundaries/no-unknown-files" | "boundaries/no-unknown")[];
46
+ /**
47
+ * Type representing all valid rule names, including the default plugin prefix.
48
+ */
49
+ export type RuleName = (typeof RULE_NAMES)[number];
50
+ /**
51
+ * List of all rule names, including the default plugin prefix.
52
+ */
53
+ export type RuleNames = typeof RULE_NAMES;
54
+ /**
55
+ * List of all rule short names, without the plugin prefix.
56
+ */
57
+ export declare const RULE_SHORT_NAMES: readonly ("external" | "element-types" | "entry-point" | "no-ignored" | "no-private" | "no-unknown-files" | "no-unknown")[];
58
+ /**
59
+ * Type representing all valid rule short names, without the plugin prefix.
60
+ */
61
+ export type RuleShortName = (typeof RULE_SHORT_NAMES)[number];
62
+ /**
63
+ * List of all rule short names, without the plugin prefix.
64
+ */
65
+ export type RuleShortNames = typeof RULE_SHORT_NAMES;
66
+ /**
67
+ * Main key used in rule definitions.
68
+ */
69
+ export declare const FROM: "from";
70
+ /**
71
+ * Different types of dependency nodes supported by the plugin by default.
72
+ * Each type corresponds to a common way of importing or requiring modules in JavaScript/TypeScript.
73
+ */
74
+ export declare const DEPENDENCY_NODE_KEYS_MAP: {
75
+ /**
76
+ * CommonJS require statements, e.g., `const module = require('module')`.
77
+ */
78
+ readonly REQUIRE: "require";
79
+ /**
80
+ * ES6 import statements, e.g., `import module from 'module'`.
81
+ */
82
+ readonly IMPORT: "import";
83
+ /**
84
+ * Dynamic import statements, e.g., `import('module')`.
85
+ */
86
+ readonly DYNAMIC_IMPORT: "dynamic-import";
87
+ /**
88
+ * Export statements, e.g., `export { module } from 'source'`.
89
+ */
90
+ readonly EXPORT: "export";
91
+ };
92
+ /**
93
+ * Keys of the different types of dependency nodes supported by the plugin by default.
94
+ */
95
+ export type DependencyNodeKey = (typeof DEPENDENCY_NODE_KEYS_MAP)[keyof typeof DEPENDENCY_NODE_KEYS_MAP];
96
+ /**
97
+ * Additional custom dependency node selector to consider when analyzing dependencies.
98
+ * Each entry defines a selector and its kind (either 'type' or 'value').
99
+ * This allows for extending the default dependency nodes with project-specific patterns.
100
+ */
101
+ export type DependencyNodeSelector = {
102
+ /** A selector string to identify the dependency node in the AST */
103
+ selector: string;
104
+ /** The kind of import, either 'type' or 'value' */
105
+ kind: DependencyKind;
106
+ /** Name to assign to the dependency node. Useful to identify the kind of node selector in rules */
107
+ name?: string;
108
+ };
109
+ export declare const SETTINGS: {
110
+ readonly ELEMENTS: "boundaries/elements";
111
+ readonly IGNORE: "boundaries/ignore";
112
+ readonly INCLUDE: "boundaries/include";
113
+ readonly ROOT_PATH: "boundaries/root-path";
114
+ readonly DEPENDENCY_NODES: "boundaries/dependency-nodes";
115
+ readonly ADDITIONAL_DEPENDENCY_NODES: "boundaries/additional-dependency-nodes";
116
+ readonly LEGACY_TEMPLATES: "boundaries/legacy-templates";
117
+ readonly DEBUG: "ESLINT_PLUGIN_BOUNDARIES_DEBUG";
118
+ readonly ENV_ROOT_PATH: "ESLINT_PLUGIN_BOUNDARIES_ROOT_PATH";
119
+ readonly RULE_ELEMENT_TYPES: "boundaries/element-types";
120
+ readonly RULE_ENTRY_POINT: "boundaries/entry-point";
121
+ readonly RULE_EXTERNAL: "boundaries/external";
122
+ readonly RULE_NO_IGNORED: "boundaries/no-ignored";
123
+ readonly RULE_NO_PRIVATE: "boundaries/no-private";
124
+ readonly RULE_NO_UNKNOWN_FILES: "boundaries/no-unknown-files";
125
+ readonly RULE_NO_UNKNOWN: "boundaries/no-unknown";
126
+ readonly TYPES: "boundaries/types";
127
+ readonly ALIAS: "boundaries/alias";
128
+ readonly VALID_MODES: readonly ["folder", "file", "full"];
129
+ readonly VALID_DEPENDENCY_NODE_KINDS: readonly ["value", "type"];
130
+ readonly DEFAULT_DEPENDENCY_NODES: {
131
+ readonly require: readonly [{
132
+ readonly selector: "CallExpression[callee.name=require] > Literal";
133
+ readonly kind: "value";
134
+ }];
135
+ readonly import: readonly [{
136
+ readonly selector: "ImportDeclaration:not([importKind=type]) > Literal";
137
+ readonly kind: "value";
138
+ }, {
139
+ readonly selector: "ImportDeclaration[importKind=type] > Literal";
140
+ readonly kind: "type";
141
+ }];
142
+ readonly "dynamic-import": readonly [{
143
+ readonly selector: "ImportExpression > Literal";
144
+ readonly kind: "value";
145
+ }];
146
+ readonly export: readonly [{
147
+ readonly selector: "ExportAllDeclaration:not([exportKind=type]) > Literal";
148
+ readonly kind: "value";
149
+ }, {
150
+ readonly selector: "ExportAllDeclaration[exportKind=type] > Literal";
151
+ readonly kind: "type";
152
+ }, {
153
+ readonly selector: "ExportNamedDeclaration:not([exportKind=type]) > Literal";
154
+ readonly kind: "value";
155
+ }, {
156
+ readonly selector: "ExportNamedDeclaration[exportKind=type] > Literal";
157
+ readonly kind: "type";
158
+ }];
159
+ };
160
+ };
161
+ /**
162
+ * Map of the valid keys for the plugin settings.
163
+ */
164
+ export declare const SETTINGS_KEYS_MAP: {
165
+ readonly ELEMENTS: "boundaries/elements";
166
+ readonly IGNORE: "boundaries/ignore";
167
+ readonly INCLUDE: "boundaries/include";
168
+ readonly ROOT_PATH: "boundaries/root-path";
169
+ readonly DEPENDENCY_NODES: "boundaries/dependency-nodes";
170
+ readonly ADDITIONAL_DEPENDENCY_NODES: "boundaries/additional-dependency-nodes";
171
+ readonly LEGACY_TEMPLATES: "boundaries/legacy-templates";
172
+ /** @deprecated Use 'ELEMENTS' instead */
173
+ readonly TYPES: "boundaries/types";
174
+ /** @deprecated Use import/resolver settings instead */
175
+ readonly ALIAS: "boundaries/alias";
176
+ };
177
+ /**
178
+ * Default value for the legacy templates setting.
179
+ */
180
+ export declare const LEGACY_TEMPLATES_DEFAULT: true;
181
+ /**
182
+ * Valid keys for the plugin settings.
183
+ */
184
+ export type SettingsKey = (typeof SETTINGS_KEYS_MAP)[keyof typeof SETTINGS_KEYS_MAP];
185
+ /**
186
+ * List of glob patterns to include when analyzing dependencies.
187
+ * If specified, only files matching these patterns will be included in the plugin analysis.
188
+ */
189
+ export type IncludeSetting = string | string[];
190
+ /**
191
+ * List of glob patterns to ignore when analyzing dependencies.
192
+ * Files matching these patterns will be excluded from the plugin analysis.
193
+ */
194
+ export type IgnoreSetting = string | string[];
195
+ /**
196
+ * Root path of the project. This is used to resolve relative paths in element patterns.
197
+ * Can also be set via the ESLINT_PLUGIN_BOUNDARIES_ROOT_PATH environment variable.
198
+ */
199
+ export type RootPathSetting = string;
200
+ /**
201
+ * Alias settings to define path aliases for module resolution.
202
+ * Each key is an alias and its value is the corresponding path.
203
+ * @deprecated Use "import/resolver" settings instead
204
+ */
205
+ export type AliasSetting = Record<string, string>;
206
+ /**
207
+ * Settings for the eslint-plugin-boundaries plugin.
208
+ */
209
+ export type Settings = {
210
+ /**
211
+ * Element descriptors to define the different elements (or layers) in your project.
212
+ * Each element descriptor includes a type, a pattern to match files, and optional settings like mode and capture groups.
213
+ */
214
+ [SETTINGS_KEYS_MAP.ELEMENTS]?: ElementDescriptors;
215
+ /**
216
+ * List of glob patterns to ignore when analyzing dependencies.
217
+ * Files matching these patterns will be excluded from the plugin analysis.
218
+ */
219
+ [SETTINGS_KEYS_MAP.IGNORE]?: IgnoreSetting;
220
+ /**
221
+ * List of glob patterns to include when analyzing dependencies.
222
+ * If specified, only files matching these patterns will be included in the plugin analysis.
223
+ */
224
+ [SETTINGS_KEYS_MAP.INCLUDE]?: IncludeSetting;
225
+ /**
226
+ * Root path of the project. This is used to resolve relative paths in element patterns.
227
+ * Can also be set via the ESLINT_PLUGIN_BOUNDARIES_ROOT_PATH environment variable.
228
+ */
229
+ [SETTINGS_KEYS_MAP.ROOT_PATH]?: RootPathSetting;
230
+ /**
231
+ * Specifies which dependency nodes (import types) to consider when analyzing dependencies.
232
+ * Each key corresponds to a type of dependency node (e.g., import, require, dynamic-import, export) and maps to an array of selectors defining how to identify those nodes in the AST.
233
+ * If not specified, only 'import' nodes will be considered by default.
234
+ */
235
+ [SETTINGS_KEYS_MAP.DEPENDENCY_NODES]?: DependencyNodeKey[];
236
+ /**
237
+ * Additional custom dependency node selectors to consider when analyzing dependencies.
238
+ * Each entry defines a selector and its kind (either 'type' or 'value').
239
+ * This allows for extending the default dependency nodes with project-specific patterns.
240
+ */
241
+ [SETTINGS_KEYS_MAP.ADDITIONAL_DEPENDENCY_NODES]?: DependencyNodeSelector[];
242
+ /**
243
+ * Whether to enable legacy template syntax support (default: `true`, but it will be `false` in future major releases).
244
+ * This enables:
245
+ * - Using `${variable}` syntax in templates for backward compatibility
246
+ * - Passing captured values from elements to template data at first object level. This might override existing keys in the elements data objects.
247
+ */
248
+ [SETTINGS_KEYS_MAP.LEGACY_TEMPLATES]?: boolean;
249
+ /** @deprecated Use "boundaries/elements" setting instead */
250
+ [SETTINGS_KEYS_MAP.TYPES]?: ElementDescriptors;
251
+ /** @deprecated Use "import/resolver" setting instead */
252
+ [SETTINGS_KEYS_MAP.ALIAS]?: AliasSetting;
253
+ };
254
+ /**
255
+ * Normalized settings for the eslint-plugin-boundaries plugin.
256
+ * All settings have default values applied.
257
+ */
258
+ export type SettingsNormalized = {
259
+ /** Element descriptors */
260
+ elementDescriptors: ElementDescriptors;
261
+ /** Element type names extracted from the descriptors. Used to validate selectors defined as strings in rules */
262
+ elementTypeNames: string[];
263
+ /** List of glob patterns to ignore when analyzing dependencies */
264
+ ignorePaths: string[] | undefined;
265
+ /** List of glob patterns to include when analyzing dependencies */
266
+ includePaths: string[] | undefined;
267
+ /** Root path of the project */
268
+ rootPath: string;
269
+ /** Dependency nodes to consider when analyzing dependencies */
270
+ dependencyNodes: DependencyNodeSelector[];
271
+ /** Whether legacy template syntax support is enabled */
272
+ legacyTemplates: boolean;
273
+ };
274
+ /**
275
+ * Eslint boundaries plugin rules.
276
+ * By default, rule names are prefixed with "boundaries/", but it can be customized via the `PluginName` generic parameter.
277
+ *
278
+ * @template PluginName - The name of the plugin, defaults to "boundaries". It defines the prefix for the rule names.
279
+ */
280
+ export type Rules<PluginName extends string = typeof PLUGIN_NAME> = {
281
+ [K in `${PluginName}/${typeof ELEMENT_TYPES | typeof ENTRY_POINT | typeof EXTERNAL | typeof NO_IGNORED | typeof NO_PRIVATE | typeof NO_UNKNOWN_FILES | typeof NO_UNKNOWN}`]?: K extends `${PluginName}/${typeof ELEMENT_TYPES}` ? Linter.RuleEntry<ElementTypesRuleOptions[]> : K extends `${PluginName}/${typeof ENTRY_POINT}` ? Linter.RuleEntry<EntryPointRuleOptions[]> : K extends `${PluginName}/${typeof EXTERNAL}` ? Linter.RuleEntry<ExternalRuleOptions[]> : K extends `${PluginName}/${typeof NO_PRIVATE}` ? Linter.RuleEntry<NoPrivateOptions[]> : Linter.RuleEntry<never>;
282
+ };
283
+ /**
284
+ * ESLint configuration with optional settings and rules specific to the boundaries plugin.
285
+ */
286
+ export interface Config<PluginName extends string = typeof PLUGIN_NAME> extends Linter.Config {
287
+ /**
288
+ * Optional settings specific to the boundaries plugin.
289
+ */
290
+ settings?: Settings;
291
+ /**
292
+ * Optional rules specific to the boundaries plugin.
293
+ */
294
+ rules?: Rules<PluginName>;
295
+ }
296
+ /**
297
+ * ESLint plugin interface for the boundaries plugin, including metadata, rules, and configurations.
298
+ */
299
+ export interface PluginBoundaries extends ESLint.Plugin {
300
+ meta: {
301
+ name: string;
302
+ version: string;
303
+ };
304
+ rules: Record<RuleShortName, Rule.RuleModule>;
305
+ configs: {
306
+ recommended: Config;
307
+ strict: Config;
308
+ };
309
+ }
310
+ export type RuleMetaDefinition = {
311
+ type?: Rule.RuleMetaData["type"];
312
+ /** The description of the rule */
313
+ description: string;
314
+ /** The name of the rule */
315
+ ruleName: RuleName;
316
+ /** The schema of the rule options */
317
+ schema?: Rule.RuleMetaData["schema"];
318
+ };
319
+ export declare const RULE_POLICY_ALLOW: "allow";
320
+ export declare const RULE_POLICY_DISALLOW: "disallow";
321
+ /**
322
+ * Map containing the available rule policies.
323
+ */
324
+ export declare const RULE_POLICIES_MAP: {
325
+ readonly ALLOW: "allow";
326
+ readonly DISALLOW: "disallow";
327
+ };
328
+ /**
329
+ * Policy for rules, either allowing or disallowing certain dependencies.
330
+ */
331
+ export type RulePolicy = (typeof RULE_POLICIES_MAP)[keyof typeof RULE_POLICIES_MAP];
332
+ /**
333
+ * Base options for some rules, including default policy and custom message.
334
+ */
335
+ export type RuleBaseOptions = {
336
+ /** Default policy for all the rules (allow or disallow) */
337
+ default?: RulePolicy;
338
+ /** Custom message for all rule violations. It can be overridden at the rule level. */
339
+ message?: string;
340
+ };
341
+ export type RuleReport = {
342
+ message?: string;
343
+ isDefault?: boolean;
344
+ importKind?: DependencyKind;
345
+ disallow?: ElementsSelector;
346
+ element: ElementsSelector;
347
+ index: number;
348
+ };
349
+ export type RuleResultReport = {
350
+ path: string | null;
351
+ specifiers?: string[];
352
+ };
353
+ export type RuleResult = {
354
+ result: boolean;
355
+ ruleReport: RuleReport | null;
356
+ report: RuleResultReport | null;
357
+ };
358
+ export type RuleMatcherElementsCapturedValues = {
359
+ from: CapturedValues;
360
+ target: CapturedValues;
361
+ };
362
+ /**
363
+ * Rule that defines allowed or disallowed dependencies between different element types.
364
+ */
365
+ export type ElementTypesRule = {
366
+ /** Selectors of the source elements that the rule applies to (the elements importing) */
367
+ from?: ElementsSelector;
368
+ /** Selectors of the target elements that are disallowed to be imported */
369
+ to?: ElementsSelector;
370
+ /** Selectors of the elements that are disallowed to be imported */
371
+ disallow?: ElementsSelector;
372
+ /** Selectors of the elements that are allowed to be imported */
373
+ allow?: ElementsSelector;
374
+ /** Kind of import that the rule applies to (e.g., "type", "value") */
375
+ importKind?: DependencyKind;
376
+ /** Custom message for rule violations */
377
+ message?: string;
378
+ };
379
+ /**
380
+ * Options for the element-types rule, including default policy and specific rules.
381
+ */
382
+ export type ElementTypesRuleOptions = Omit<RuleBaseOptions, "rules"> & {
383
+ /** Specific rules for defining boundaries between elements */
384
+ rules?: ElementTypesRule[];
385
+ };
386
+ /**
387
+ * Rule that defines entry points for specific element types, controlling which files can be imported.
388
+ */
389
+ export type EntryPointRule = {
390
+ /** Selectors of the elements that the rule applies to (the elements being imported) */
391
+ target: ElementsSelector;
392
+ /** Micromatch patterns of the files that are disallowed to import from other elements. Relative to the element path */
393
+ disallow?: string[];
394
+ /** Micromatch patterns of the files that are allowed to import from other elements. Relative to the element path */
395
+ allow?: string[];
396
+ /** Kind of import that the rule applies to (e.g., "type", "value") */
397
+ importKind?: DependencyKind;
398
+ /** Custom message for rule violations */
399
+ message?: string;
400
+ };
401
+ /**
402
+ * Options for the entry-point rule, including default policy and specific rules.
403
+ */
404
+ export type EntryPointRuleOptions = Omit<RuleBaseOptions, "rules"> & {
405
+ /** Specific rules for defining entry points between elements */
406
+ rules?: EntryPointRule[];
407
+ };
408
+ /**
409
+ * Rule that defines allowed or disallowed external library imports for specific element types.
410
+ */
411
+ export type ExternalRule = {
412
+ /** Selectors of the source elements that the rule applies to (the elements importing) */
413
+ from: ElementsSelector;
414
+ /** Selectors of the external libraries that are disallowed to be imported */
415
+ disallow?: ExternalLibrariesSelector;
416
+ /** Selectors of the external libraries that are allowed to be imported */
417
+ allow?: ExternalLibrariesSelector;
418
+ /** Kind of import that the rule applies to (e.g., "type", "value") */
419
+ importKind?: DependencyKind;
420
+ /** Custom message for rule violations */
421
+ message?: string;
422
+ };
423
+ /**
424
+ * Options for the external rule, including default policy and specific rules.
425
+ */
426
+ export type ExternalRuleOptions = Omit<RuleBaseOptions, "rules"> & {
427
+ /** Specific rules for defining allowed or disallowed external library imports */
428
+ rules?: ExternalRule[];
429
+ };
430
+ /**
431
+ * Options for the no-private rule, which restricts imports of private elements.
432
+ * Private elements are those that are children of another elements in the folder structure.
433
+ * This rules enables that private elements can't be used by anyone except its parent (or any other descendant of the parent when `allowUncles` option is enabled)
434
+ */
435
+ export type NoPrivateOptions = {
436
+ /** Whether to allow imports from "uncle" elements (elements sharing the same ancestor) */
437
+ allowUncles?: boolean;
438
+ /** Custom message for rule violations */
439
+ message?: string;
440
+ };
441
+ export type RuleOptionsWithRules = ExternalRuleOptions | EntryPointRuleOptions | ElementTypesRuleOptions;
442
+ export type RuleOptions = RuleOptionsWithRules | NoPrivateOptions;
443
+ export type RuleOptionsRules = ExternalRule | EntryPointRule | ElementTypesRule;
444
+ export type RuleMainKey = "from" | "to" | "target";
445
+ export type ValidateRulesOptions = {
446
+ mainKey?: RuleMainKey;
447
+ onlyMainKey?: boolean;
448
+ };
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RULE_POLICIES_MAP = exports.RULE_POLICY_DISALLOW = exports.RULE_POLICY_ALLOW = exports.LEGACY_TEMPLATES_DEFAULT = exports.SETTINGS_KEYS_MAP = exports.SETTINGS = exports.DEPENDENCY_NODE_KEYS_MAP = exports.FROM = exports.RULE_SHORT_NAMES = exports.RULE_NAMES = exports.RULE_NAMES_MAP = exports.RULE_SHORT_NAMES_MAP = exports.NO_UNKNOWN = exports.NO_UNKNOWN_FILES = exports.NO_PRIVATE = exports.NO_IGNORED = exports.EXTERNAL = exports.ENTRY_POINT = exports.ELEMENT_TYPES = exports.DEPENDENCY_NODE_EXPORT = exports.DEPENDENCY_NODE_DYNAMIC_IMPORT = exports.DEPENDENCY_NODE_IMPORT = exports.DEPENDENCY_NODE_REQUIRE = exports.PLUGIN_ISSUES_URL = exports.REPO_URL = exports.PLUGIN_ENV_VARS_PREFIX = exports.PLUGIN_NAME = void 0;
4
+ // Plugin constants
5
+ exports.PLUGIN_NAME = "boundaries";
6
+ exports.PLUGIN_ENV_VARS_PREFIX = "ESLINT_PLUGIN_BOUNDARIES";
7
+ exports.REPO_URL = "https://github.com/javierbrea/eslint-plugin-boundaries";
8
+ exports.PLUGIN_ISSUES_URL = `${exports.REPO_URL}/issues`;
9
+ exports.DEPENDENCY_NODE_REQUIRE = "require";
10
+ exports.DEPENDENCY_NODE_IMPORT = "import";
11
+ exports.DEPENDENCY_NODE_DYNAMIC_IMPORT = "dynamic-import";
12
+ exports.DEPENDENCY_NODE_EXPORT = "export";
13
+ // Rule short names
14
+ exports.ELEMENT_TYPES = "element-types";
15
+ exports.ENTRY_POINT = "entry-point";
16
+ exports.EXTERNAL = "external";
17
+ exports.NO_IGNORED = "no-ignored";
18
+ exports.NO_PRIVATE = "no-private";
19
+ exports.NO_UNKNOWN_FILES = "no-unknown-files";
20
+ exports.NO_UNKNOWN = "no-unknown";
21
+ /**
22
+ * Map of all rule short names, without the plugin prefix.
23
+ */
24
+ exports.RULE_SHORT_NAMES_MAP = {
25
+ ELEMENT_TYPES: exports.ELEMENT_TYPES,
26
+ ENTRY_POINT: exports.ENTRY_POINT,
27
+ EXTERNAL: exports.EXTERNAL,
28
+ NO_IGNORED: exports.NO_IGNORED,
29
+ NO_PRIVATE: exports.NO_PRIVATE,
30
+ NO_UNKNOWN_FILES: exports.NO_UNKNOWN_FILES,
31
+ NO_UNKNOWN: exports.NO_UNKNOWN,
32
+ };
33
+ const ELEMENT_TYPES_FULL = `${exports.PLUGIN_NAME}/${exports.ELEMENT_TYPES}`;
34
+ const ENTRY_POINT_FULL = `${exports.PLUGIN_NAME}/${exports.ENTRY_POINT}`;
35
+ const EXTERNAL_FULL = `${exports.PLUGIN_NAME}/${exports.EXTERNAL}`;
36
+ const NO_IGNORED_FULL = `${exports.PLUGIN_NAME}/${exports.NO_IGNORED}`;
37
+ const NO_PRIVATE_FULL = `${exports.PLUGIN_NAME}/${exports.NO_PRIVATE}`;
38
+ const NO_UNKNOWN_FILES_FULL = `${exports.PLUGIN_NAME}/${exports.NO_UNKNOWN_FILES}`;
39
+ const NO_UNKNOWN_FULL = `${exports.PLUGIN_NAME}/${exports.NO_UNKNOWN}`;
40
+ /**
41
+ * Map of all rule names, including the default plugin prefix.
42
+ */
43
+ exports.RULE_NAMES_MAP = {
44
+ ELEMENT_TYPES: ELEMENT_TYPES_FULL,
45
+ ENTRY_POINT: ENTRY_POINT_FULL,
46
+ EXTERNAL: EXTERNAL_FULL,
47
+ NO_IGNORED: NO_IGNORED_FULL,
48
+ NO_PRIVATE: NO_PRIVATE_FULL,
49
+ NO_UNKNOWN_FILES: NO_UNKNOWN_FILES_FULL,
50
+ NO_UNKNOWN: NO_UNKNOWN_FULL,
51
+ };
52
+ /**
53
+ * List of all rule names
54
+ */
55
+ exports.RULE_NAMES = [...Object.values(exports.RULE_NAMES_MAP)];
56
+ /**
57
+ * List of all rule short names, without the plugin prefix.
58
+ */
59
+ exports.RULE_SHORT_NAMES = [
60
+ ...Object.values(exports.RULE_SHORT_NAMES_MAP),
61
+ ];
62
+ /**
63
+ * Main key used in rule definitions.
64
+ */
65
+ exports.FROM = "from";
66
+ /**
67
+ * Different types of dependency nodes supported by the plugin by default.
68
+ * Each type corresponds to a common way of importing or requiring modules in JavaScript/TypeScript.
69
+ */
70
+ exports.DEPENDENCY_NODE_KEYS_MAP = {
71
+ /**
72
+ * CommonJS require statements, e.g., `const module = require('module')`.
73
+ */
74
+ REQUIRE: exports.DEPENDENCY_NODE_REQUIRE,
75
+ /**
76
+ * ES6 import statements, e.g., `import module from 'module'`.
77
+ */
78
+ IMPORT: exports.DEPENDENCY_NODE_IMPORT,
79
+ /**
80
+ * Dynamic import statements, e.g., `import('module')`.
81
+ */
82
+ DYNAMIC_IMPORT: exports.DEPENDENCY_NODE_DYNAMIC_IMPORT,
83
+ /**
84
+ * Export statements, e.g., `export { module } from 'source'`.
85
+ */
86
+ EXPORT: exports.DEPENDENCY_NODE_EXPORT,
87
+ };
88
+ exports.SETTINGS = {
89
+ // settings
90
+ ELEMENTS: `${exports.PLUGIN_NAME}/elements`,
91
+ IGNORE: `${exports.PLUGIN_NAME}/ignore`,
92
+ INCLUDE: `${exports.PLUGIN_NAME}/include`,
93
+ ROOT_PATH: `${exports.PLUGIN_NAME}/root-path`,
94
+ DEPENDENCY_NODES: `${exports.PLUGIN_NAME}/dependency-nodes`,
95
+ ADDITIONAL_DEPENDENCY_NODES: `${exports.PLUGIN_NAME}/additional-dependency-nodes`,
96
+ LEGACY_TEMPLATES: `${exports.PLUGIN_NAME}/legacy-templates`,
97
+ // env vars
98
+ DEBUG: `${exports.PLUGIN_ENV_VARS_PREFIX}_DEBUG`,
99
+ ENV_ROOT_PATH: `${exports.PLUGIN_ENV_VARS_PREFIX}_ROOT_PATH`,
100
+ // rules
101
+ RULE_ELEMENT_TYPES: `${exports.PLUGIN_NAME}/${exports.ELEMENT_TYPES}`,
102
+ RULE_ENTRY_POINT: `${exports.PLUGIN_NAME}/${exports.ENTRY_POINT}`,
103
+ RULE_EXTERNAL: `${exports.PLUGIN_NAME}/${exports.EXTERNAL}`,
104
+ RULE_NO_IGNORED: `${exports.PLUGIN_NAME}/${exports.NO_IGNORED}`,
105
+ RULE_NO_PRIVATE: `${exports.PLUGIN_NAME}/${exports.NO_PRIVATE}`,
106
+ RULE_NO_UNKNOWN_FILES: `${exports.PLUGIN_NAME}/${exports.NO_UNKNOWN_FILES}`,
107
+ RULE_NO_UNKNOWN: `${exports.PLUGIN_NAME}/${exports.NO_UNKNOWN}`,
108
+ // deprecated settings
109
+ TYPES: `${exports.PLUGIN_NAME}/types`,
110
+ ALIAS: `${exports.PLUGIN_NAME}/alias`,
111
+ // elements settings properties,
112
+ VALID_MODES: ["folder", "file", "full"],
113
+ VALID_DEPENDENCY_NODE_KINDS: ["value", "type"],
114
+ DEFAULT_DEPENDENCY_NODES: {
115
+ [exports.DEPENDENCY_NODE_KEYS_MAP.REQUIRE]: [
116
+ // Note: detects "require('source')"
117
+ {
118
+ selector: "CallExpression[callee.name=require] > Literal",
119
+ kind: "value",
120
+ },
121
+ ],
122
+ [exports.DEPENDENCY_NODE_KEYS_MAP.IMPORT]: [
123
+ // Note: detects "import x from 'source'"
124
+ {
125
+ selector: "ImportDeclaration:not([importKind=type]) > Literal",
126
+ kind: "value",
127
+ },
128
+ // Note: detects "import type x from 'source'"
129
+ {
130
+ selector: "ImportDeclaration[importKind=type] > Literal",
131
+ kind: "type",
132
+ },
133
+ ],
134
+ [exports.DEPENDENCY_NODE_KEYS_MAP.DYNAMIC_IMPORT]: [
135
+ // Note: detects "import('source')"
136
+ { selector: "ImportExpression > Literal", kind: "value" },
137
+ ],
138
+ [exports.DEPENDENCY_NODE_KEYS_MAP.EXPORT]: [
139
+ // Note: detects "export * from 'source'";
140
+ {
141
+ selector: "ExportAllDeclaration:not([exportKind=type]) > Literal",
142
+ kind: "value",
143
+ },
144
+ // Note: detects "export type * from 'source'";
145
+ {
146
+ selector: "ExportAllDeclaration[exportKind=type] > Literal",
147
+ kind: "type",
148
+ },
149
+ // Note: detects "export { x } from 'source'";
150
+ {
151
+ selector: "ExportNamedDeclaration:not([exportKind=type]) > Literal",
152
+ kind: "value",
153
+ },
154
+ // Note: detects "export type { x } from 'source'";
155
+ {
156
+ selector: "ExportNamedDeclaration[exportKind=type] > Literal",
157
+ kind: "type",
158
+ },
159
+ ],
160
+ },
161
+ };
162
+ /**
163
+ * Map of the valid keys for the plugin settings.
164
+ */
165
+ exports.SETTINGS_KEYS_MAP = {
166
+ ELEMENTS: exports.SETTINGS.ELEMENTS,
167
+ IGNORE: exports.SETTINGS.IGNORE,
168
+ INCLUDE: exports.SETTINGS.INCLUDE,
169
+ ROOT_PATH: exports.SETTINGS.ROOT_PATH,
170
+ DEPENDENCY_NODES: exports.SETTINGS.DEPENDENCY_NODES,
171
+ ADDITIONAL_DEPENDENCY_NODES: exports.SETTINGS.ADDITIONAL_DEPENDENCY_NODES,
172
+ LEGACY_TEMPLATES: exports.SETTINGS.LEGACY_TEMPLATES,
173
+ /** @deprecated Use 'ELEMENTS' instead */
174
+ TYPES: exports.SETTINGS.TYPES,
175
+ /** @deprecated Use import/resolver settings instead */
176
+ ALIAS: exports.SETTINGS.ALIAS,
177
+ };
178
+ /**
179
+ * Default value for the legacy templates setting.
180
+ */
181
+ exports.LEGACY_TEMPLATES_DEFAULT = true;
182
+ exports.RULE_POLICY_ALLOW = "allow";
183
+ exports.RULE_POLICY_DISALLOW = "disallow";
184
+ /**
185
+ * Map containing the available rule policies.
186
+ */
187
+ exports.RULE_POLICIES_MAP = {
188
+ ALLOW: exports.RULE_POLICY_ALLOW,
189
+ DISALLOW: exports.RULE_POLICY_DISALLOW,
190
+ };