eslint-plugin-boundaries 5.1.0 → 5.2.0-beta.2

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 (115) hide show
  1. package/README.md +12 -0
  2. package/dist/{configs/config.d.ts → Config/Config.d.ts} +3 -3
  3. package/dist/{configs/config.js → Config/Config.js} +25 -22
  4. package/dist/{configs/recommended.d.ts → Config/Recommended.d.ts} +1 -1
  5. package/dist/{configs/recommended.js → Config/Recommended.js} +2 -2
  6. package/dist/{configs/strict.d.ts → Config/Strict.d.ts} +1 -1
  7. package/dist/{configs/strict.js → Config/Strict.js} +5 -5
  8. package/dist/Elements/Elements.d.ts +43 -0
  9. package/dist/Elements/Elements.js +108 -0
  10. package/dist/Elements/Elements.types.d.ts +5 -0
  11. package/dist/Elements/index.d.ts +2 -0
  12. package/dist/{types/Config.types.js → Elements/index.js} +2 -4
  13. package/dist/Messages/Messages.d.ts +14 -0
  14. package/dist/Messages/Messages.js +204 -0
  15. package/dist/Messages/index.d.ts +1 -0
  16. package/dist/Messages/index.js +17 -0
  17. package/dist/Public/Config.types.d.ts +2 -0
  18. package/dist/Public/Config.types.js +5 -0
  19. package/dist/Public/Rules.types.d.ts +10 -0
  20. package/dist/Public/Rules.types.js +15 -0
  21. package/dist/Public/Settings.types.d.ts +13 -0
  22. package/dist/Public/Settings.types.js +21 -0
  23. package/dist/Rules/ElementTypes.d.ts +25 -0
  24. package/dist/Rules/ElementTypes.js +279 -0
  25. package/dist/Rules/EntryPoint.js +122 -0
  26. package/dist/Rules/External.js +120 -0
  27. package/dist/Rules/NoIgnored.js +19 -0
  28. package/dist/Rules/NoPrivate.js +53 -0
  29. package/dist/Rules/NoUnknown.js +22 -0
  30. package/dist/{rules/no-unknown-files.js → Rules/NoUnknownFiles.js} +9 -7
  31. package/dist/Rules/Support/DependencyRule.d.ts +4 -0
  32. package/dist/Rules/Support/DependencyRule.js +49 -0
  33. package/dist/Rules/Support/DependencyRule.types.d.ts +17 -0
  34. package/dist/Rules/Support/Helpers.d.ts +8 -0
  35. package/dist/Rules/Support/Helpers.js +39 -0
  36. package/dist/Rules/Support/index.d.ts +3 -0
  37. package/dist/Rules/Support/index.js +19 -0
  38. package/dist/Settings/Helpers.d.ts +41 -0
  39. package/dist/Settings/Helpers.js +72 -0
  40. package/dist/Settings/Settings.d.ts +6 -0
  41. package/dist/Settings/Settings.js +49 -0
  42. package/dist/Settings/Settings.types.d.ts +458 -0
  43. package/dist/Settings/Settings.types.js +196 -0
  44. package/dist/{helpers/validations.d.ts → Settings/Validations.d.ts} +11 -5
  45. package/dist/Settings/Validations.js +355 -0
  46. package/dist/Settings/index.d.ts +4 -0
  47. package/dist/Settings/index.js +20 -0
  48. package/dist/Support/Common.d.ts +30 -0
  49. package/dist/Support/Common.js +47 -0
  50. package/dist/Support/Debug.d.ts +5 -0
  51. package/dist/Support/Debug.js +54 -0
  52. package/dist/Support/index.d.ts +2 -0
  53. package/dist/Support/index.js +18 -0
  54. package/dist/index.d.ts +2 -2
  55. package/dist/index.js +30 -30
  56. package/package.json +14 -17
  57. package/dist/configs/Config.types.d.ts +0 -41
  58. package/dist/constants/DependencyInfo.types.d.ts +0 -9
  59. package/dist/constants/DependencyInfo.types.js +0 -2
  60. package/dist/constants/ElementsInfo.types.d.ts +0 -24
  61. package/dist/constants/ElementsInfo.types.js +0 -2
  62. package/dist/constants/Options.types.d.ts +0 -180
  63. package/dist/constants/Options.types.js +0 -23
  64. package/dist/constants/plugin.d.ts +0 -7
  65. package/dist/constants/plugin.js +0 -10
  66. package/dist/constants/rules.d.ts +0 -67
  67. package/dist/constants/rules.js +0 -70
  68. package/dist/constants/settings.d.ts +0 -278
  69. package/dist/constants/settings.js +0 -186
  70. package/dist/core/cache.d.ts +0 -22
  71. package/dist/core/cache.js +0 -54
  72. package/dist/core/dependencyInfo.d.ts +0 -4
  73. package/dist/core/dependencyInfo.js +0 -73
  74. package/dist/core/elementsInfo.d.ts +0 -4
  75. package/dist/core/elementsInfo.js +0 -271
  76. package/dist/helpers/Helpers.types.d.ts +0 -5
  77. package/dist/helpers/Helpers.types.js +0 -2
  78. package/dist/helpers/Rules.types.d.ts +0 -10
  79. package/dist/helpers/Rules.types.js +0 -2
  80. package/dist/helpers/debug.d.ts +0 -4
  81. package/dist/helpers/debug.js +0 -44
  82. package/dist/helpers/messages.d.ts +0 -13
  83. package/dist/helpers/messages.js +0 -147
  84. package/dist/helpers/rules.d.ts +0 -37
  85. package/dist/helpers/rules.js +0 -206
  86. package/dist/helpers/settings.d.ts +0 -7
  87. package/dist/helpers/settings.js +0 -94
  88. package/dist/helpers/utils.d.ts +0 -10
  89. package/dist/helpers/utils.js +0 -49
  90. package/dist/helpers/validations.js +0 -241
  91. package/dist/rules/element-types.js +0 -51
  92. package/dist/rules/entry-point.js +0 -63
  93. package/dist/rules/external.d.ts +0 -3
  94. package/dist/rules/external.js +0 -169
  95. package/dist/rules/no-ignored.js +0 -21
  96. package/dist/rules/no-private.js +0 -49
  97. package/dist/rules/no-unknown.js +0 -21
  98. package/dist/rules-factories/DependencyRule.types.d.ts +0 -19
  99. package/dist/rules-factories/dependency-rule.d.ts +0 -5
  100. package/dist/rules-factories/dependency-rule.js +0 -55
  101. package/dist/types/Config.types.d.ts +0 -2
  102. package/dist/types/Rules.types.d.ts +0 -5
  103. package/dist/types/Rules.types.js +0 -11
  104. package/dist/types/Settings.types.d.ts +0 -2
  105. package/dist/types/Settings.types.js +0 -12
  106. /package/dist/{configs/Config.types.js → Elements/Elements.types.js} +0 -0
  107. /package/dist/{types → Public}/index.d.ts +0 -0
  108. /package/dist/{types → Public}/index.js +0 -0
  109. /package/dist/{rules/element-types.d.ts → Rules/EntryPoint.d.ts} +0 -0
  110. /package/dist/{rules/entry-point.d.ts → Rules/External.d.ts} +0 -0
  111. /package/dist/{rules/no-ignored.d.ts → Rules/NoIgnored.d.ts} +0 -0
  112. /package/dist/{rules/no-private.d.ts → Rules/NoPrivate.d.ts} +0 -0
  113. /package/dist/{rules/no-unknown.d.ts → Rules/NoUnknown.d.ts} +0 -0
  114. /package/dist/{rules/no-unknown-files.d.ts → Rules/NoUnknownFiles.d.ts} +0 -0
  115. /package/dist/{rules-factories → Rules/Support}/DependencyRule.types.js +0 -0
package/README.md CHANGED
@@ -320,6 +320,18 @@ You can also provide an absolute path in the environment variable, but it may be
320
320
 
321
321
  </details>
322
322
 
323
+ #### __`boundaries/cache`__
324
+
325
+ Enable or disable the cache mechanism used to boost performance. By default, it is enabled. We recommend to keep it enabled unless you experience issues. In such case, please, open an issue describing the problem.
326
+
327
+ ```js
328
+ export default [{
329
+ settings: {
330
+ "boundaries/cache": true // or false to disable the cache
331
+ }
332
+ }]
333
+ ```
334
+
323
335
  ### Predefined configurations
324
336
 
325
337
  The plugin is distributed with two different predefined configurations: "recommended" and "strict".
@@ -1,7 +1,7 @@
1
1
  import type { Linter } from "eslint";
2
- import { PLUGIN_NAME } from "../constants/plugin";
3
- import type { PluginBoundaries, Config } from "./Config.types";
4
- export * from "../types";
2
+ import type { PluginBoundaries, Config } from "../Settings";
3
+ import { PLUGIN_NAME } from "../Settings";
4
+ export * from "../Public";
5
5
  type PluginFullConfig<PluginName extends string = typeof PLUGIN_NAME> = {
6
6
  plugins: Record<PluginName, PluginBoundaries>;
7
7
  files: Linter.Config["files"];
@@ -19,35 +19,38 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.strict = exports.recommended = void 0;
21
21
  exports.createConfig = createConfig;
22
- const plugin_1 = require("../constants/plugin");
23
- const rules_1 = require("../constants/rules");
24
- const settings_1 = require("../constants/settings");
25
22
  const index_1 = __importDefault(require("../index"));
26
- const recommended_1 = __importDefault(require("./recommended"));
27
- const strict_1 = __importDefault(require("./strict"));
28
- __exportStar(require("../types"), exports);
29
- function renamePluginRules(rules, pluginName = plugin_1.PLUGIN_NAME) {
23
+ const Settings_1 = require("../Settings");
24
+ const Recommended_1 = __importDefault(require("./Recommended"));
25
+ const Strict_1 = __importDefault(require("./Strict"));
26
+ __exportStar(require("../Public"), exports);
27
+ function renamePluginRules(pluginName, rules) {
30
28
  if (!rules) {
31
29
  return {};
32
30
  }
33
- const allowedPrefixes = [plugin_1.PLUGIN_NAME, pluginName];
31
+ const allowedPrefixes = new Set([Settings_1.PLUGIN_NAME, pluginName]);
34
32
  // Return the same rules objects, but converting plugin default rule keys with provided plugin name
35
33
  return Object.entries(rules).reduce((acc, [key, value]) => {
36
34
  if (!key.includes("/")) {
37
- throw new Error(`Invalid rule key "${key}". When using createConfig, all rules must belong to eslint-plugin-boundaries. You can prefix them with the original plugin name "${plugin_1.PLUGIN_NAME}/", or with the provided plugin name "${pluginName}/".`);
35
+ throw new Error(`Invalid rule key "${key}". When using createConfig, all rules must belong to eslint-plugin-boundaries. You can prefix them with the original plugin name "${Settings_1.PLUGIN_NAME}/", or with the provided plugin name "${pluginName}/".`);
38
36
  }
39
37
  const splittedRuleKey = key.split("/");
40
38
  const rulePrefix = splittedRuleKey[0];
41
39
  const ruleName = splittedRuleKey[1];
42
- if (!allowedPrefixes.includes(rulePrefix)) {
43
- throw new Error(`Invalid rule key "${key}". When using createConfig, all rules must belong to eslint-plugin-boundaries. You can prefix them with the original plugin name "${plugin_1.PLUGIN_NAME}/", or with the provided plugin name "${pluginName}/".`);
40
+ if (!allowedPrefixes.has(rulePrefix)) {
41
+ throw new Error(`Invalid rule key "${key}". When using createConfig, all rules must belong to eslint-plugin-boundaries. You can prefix them with the original plugin name "${Settings_1.PLUGIN_NAME}/", or with the provided plugin name "${pluginName}/".`);
44
42
  }
45
- if (!(0, rules_1.isRuleShortName)(ruleName)) {
43
+ if (!(0, Settings_1.isRuleShortName)(ruleName)) {
46
44
  throw new Error(`Invalid rule name "${ruleName}". When using createConfig, all rules must belong to eslint-plugin-boundaries.`);
47
45
  }
48
- const newKey = rulePrefix === plugin_1.PLUGIN_NAME
49
- ? `${pluginName}/${key.slice(`${plugin_1.PLUGIN_NAME}/`.length)}`
50
- : key;
46
+ let newKey;
47
+ if (rulePrefix === Settings_1.PLUGIN_NAME) {
48
+ const suffix = key.slice(Settings_1.PLUGIN_NAME.length + 1);
49
+ newKey = `${pluginName}/${suffix}`;
50
+ }
51
+ else {
52
+ newKey = key;
53
+ }
51
54
  acc[newKey] = value;
52
55
  return acc;
53
56
  }, {});
@@ -81,18 +84,18 @@ function renamePluginRules(rules, pluginName = plugin_1.PLUGIN_NAME) {
81
84
  * export default [config];
82
85
  * ```
83
86
  */
84
- function createConfig(config, name = plugin_1.PLUGIN_NAME) {
87
+ function createConfig(config, name = Settings_1.PLUGIN_NAME) {
85
88
  const pluginsRegistration = {
86
89
  [name]: index_1.default,
87
90
  };
88
- if (Object.prototype.hasOwnProperty.call(config, "plugins")) {
91
+ if (Object.hasOwn(config, "plugins")) {
89
92
  throw new Error("The 'plugins' field is managed by createConfig and should not be provided in the config argument.");
90
93
  }
91
- if (Object.prototype.hasOwnProperty.call(config, "settings")) {
94
+ if (Object.hasOwn(config, "settings")) {
92
95
  const settings = config.settings;
93
96
  if (settings) {
94
97
  for (const key of Object.keys(settings)) {
95
- if (!(0, settings_1.isSettingsKey)(key)) {
98
+ if (!(0, Settings_1.isSettingsKey)(key)) {
96
99
  throw new Error(`Invalid settings key "${key}". When using createConfig, all settings keys must belong to eslint-plugin-boundaries.`);
97
100
  }
98
101
  }
@@ -109,8 +112,8 @@ function createConfig(config, name = plugin_1.PLUGIN_NAME) {
109
112
  ],
110
113
  ...config,
111
114
  plugins: pluginsRegistration,
112
- rules: renamePluginRules(config.rules, name),
115
+ rules: renamePluginRules(name, config.rules),
113
116
  };
114
117
  }
115
- exports.recommended = recommended_1.default;
116
- exports.strict = strict_1.default;
118
+ exports.recommended = Recommended_1.default;
119
+ exports.strict = Strict_1.default;
@@ -1,4 +1,4 @@
1
- import type { Config } from "./Config.types";
1
+ import type { Config } from "../Settings";
2
2
  /**
3
3
  * Recommended configuration for eslint-plugin-boundaries.
4
4
  *
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const settings_1 = require("../constants/settings");
3
+ const Settings_1 = require("../Settings");
4
4
  const { ELEMENTS,
5
5
  // rules
6
- RULE_ELEMENT_TYPES, RULE_ENTRY_POINT, RULE_EXTERNAL, RULE_NO_IGNORED, RULE_NO_PRIVATE, RULE_NO_UNKNOWN_FILES, RULE_NO_UNKNOWN, } = settings_1.SETTINGS;
6
+ RULE_ELEMENT_TYPES, RULE_ENTRY_POINT, RULE_EXTERNAL, RULE_NO_IGNORED, RULE_NO_PRIVATE, RULE_NO_UNKNOWN_FILES, RULE_NO_UNKNOWN, } = Settings_1.SETTINGS;
7
7
  // TODO In next major version: Export also files, plugin, etc.
8
8
  /**
9
9
  * Recommended configuration for eslint-plugin-boundaries.
@@ -1,4 +1,4 @@
1
- import type { Config } from "./Config.types";
1
+ import type { Config } from "../Settings";
2
2
  /**
3
3
  * Strict configuration for eslint-plugin-boundaries.
4
4
  *
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const settings_1 = require("../constants/settings");
7
- const recommended_1 = __importDefault(require("./recommended"));
8
- const { RULE_NO_IGNORED, RULE_NO_UNKNOWN_FILES, RULE_NO_UNKNOWN } = settings_1.SETTINGS;
6
+ const Settings_1 = require("../Settings");
7
+ const Recommended_1 = __importDefault(require("./Recommended"));
8
+ const { RULE_NO_IGNORED, RULE_NO_UNKNOWN_FILES, RULE_NO_UNKNOWN } = Settings_1.SETTINGS;
9
9
  // TODO In next major version: Export also files, plugin, etc.
10
10
  /**
11
11
  * Strict configuration for eslint-plugin-boundaries.
@@ -13,9 +13,9 @@ const { RULE_NO_IGNORED, RULE_NO_UNKNOWN_FILES, RULE_NO_UNKNOWN } = settings_1.S
13
13
  * It enables all rules, enforcing full compliance with defined boundaries. Unknown files and importing ignored files are not allowed.
14
14
  */
15
15
  const config = {
16
- ...recommended_1.default,
16
+ ...Recommended_1.default,
17
17
  rules: {
18
- ...recommended_1.default.rules,
18
+ ...Recommended_1.default.rules,
19
19
  [RULE_NO_IGNORED]: 2,
20
20
  [RULE_NO_UNKNOWN_FILES]: 2,
21
21
  [RULE_NO_UNKNOWN]: 2,
@@ -0,0 +1,43 @@
1
+ import type { Matcher, DependencyDescription, DependencyKind, ElementDescription } from "@boundaries/elements";
2
+ import type { Rule } from "eslint";
3
+ import type { SettingsNormalized } from "../Settings";
4
+ import type { EslintLiteralNode } from "./Elements.types";
5
+ /**
6
+ * Returns the elements matcher based on the ESLint rule context, filtering out invalid descriptors
7
+ * @param context The ESLint rule context
8
+ * @returns The elements matcher
9
+ */
10
+ export declare function getElementsMatcher(settings: SettingsNormalized): Matcher;
11
+ /**
12
+ * Returns the specifiers used in an import or export statement
13
+ * @param node The AST node representing the import or export
14
+ * @returns The list of specifiers used in the import or export
15
+ */
16
+ export declare function getSpecifiers(node: Rule.Node): string[];
17
+ /**
18
+ * Returns the description of the current file being linted
19
+ * @param fileName The file name
20
+ * @param settings The ESLint rule context settings normalized
21
+ * @returns The description of the current file being linted
22
+ */
23
+ export declare function elementDescription(fileName: string, settings: SettingsNormalized): ElementDescription;
24
+ /**
25
+ * Returns the description of a dependency node
26
+ * @param param0 The dependency node info
27
+ * @param context The ESLint rule context
28
+ * @returns The description of the dependency node
29
+ */
30
+ export declare function dependencyDescription({ node, kind, nodeKind, }: {
31
+ /** The dependency node */
32
+ node: EslintLiteralNode;
33
+ /** The kind of the dependency */
34
+ kind: DependencyKind;
35
+ /** The kind of the node generating the dependency */
36
+ nodeKind?: string;
37
+ },
38
+ /** The file name */
39
+ fileName: string,
40
+ /** The ESLint rule context settings normalized */
41
+ settings: SettingsNormalized,
42
+ /** The ESLint rule context */
43
+ context: Rule.RuleContext): DependencyDescription;
@@ -0,0 +1,108 @@
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.getElementsMatcher = getElementsMatcher;
7
+ exports.getSpecifiers = getSpecifiers;
8
+ exports.elementDescription = elementDescription;
9
+ exports.dependencyDescription = dependencyDescription;
10
+ const elements_1 = require("@boundaries/elements");
11
+ const resolve_1 = __importDefault(require("eslint-module-utils/resolve"));
12
+ const Support_1 = require("../Support");
13
+ const elements = new elements_1.Elements();
14
+ /**
15
+ * Returns the elements matcher based on the ESLint rule context, filtering out invalid descriptors
16
+ * @param context The ESLint rule context
17
+ * @returns The elements matcher
18
+ */
19
+ function getElementsMatcher(settings) {
20
+ const elementsMatcher = elements.getMatcher(settings.elementDescriptors, {
21
+ ignorePaths: settings.ignorePaths,
22
+ includePaths: settings.includePaths,
23
+ legacyTemplates: settings.legacyTemplates,
24
+ cache: settings.cache,
25
+ });
26
+ return elementsMatcher;
27
+ }
28
+ /**
29
+ * Replaces backslashes with forward slashes in a given path
30
+ * @param filePath The file path to modify
31
+ * @returns The modified file path with forward slashes
32
+ */
33
+ function replacePathSlashes(filePath) {
34
+ return filePath.replaceAll("\\", "/");
35
+ }
36
+ /**
37
+ * Transforms an absolute path into a project-relative path
38
+ * @param absolutePath The absolute path to transform
39
+ * @param rootPath The root path of the project
40
+ * @returns The relative path from the project root
41
+ */
42
+ function projectPath(absolutePath, rootPath) {
43
+ if (absolutePath) {
44
+ // TODO: Use path.relative when possible. With caution because this would break current external paths
45
+ return replacePathSlashes(absolutePath).replace(`${replacePathSlashes(rootPath)}/`, "");
46
+ }
47
+ return "";
48
+ }
49
+ /**
50
+ * Returns the specifiers used in an import or export statement
51
+ * @param node The AST node representing the import or export
52
+ * @returns The list of specifiers used in the import or export
53
+ */
54
+ function getSpecifiers(node) {
55
+ if (node.parent.type === "ImportDeclaration") {
56
+ return node.parent.specifiers
57
+ .filter((specifier) => specifier.type === "ImportSpecifier" &&
58
+ specifier.imported &&
59
+ specifier.imported.name)
60
+ .map((specifier) => specifier.imported.name);
61
+ }
62
+ if (node.parent.type === "ExportNamedDeclaration") {
63
+ return node.parent.specifiers
64
+ .filter((specifier) => specifier.type === "ExportSpecifier" &&
65
+ specifier.exported.name)
66
+ .map((specifier) => specifier.exported.name);
67
+ }
68
+ return [];
69
+ }
70
+ /**
71
+ * Returns the description of the current file being linted
72
+ * @param fileName The file name
73
+ * @param settings The ESLint rule context settings normalized
74
+ * @returns The description of the current file being linted
75
+ */
76
+ function elementDescription(fileName, settings) {
77
+ const matcher = getElementsMatcher(settings);
78
+ const path = projectPath(fileName, settings.rootPath);
79
+ const result = matcher.describeElement(path);
80
+ (0, Support_1.debugDescription)(result);
81
+ return result;
82
+ }
83
+ /**
84
+ * Returns the description of a dependency node
85
+ * @param param0 The dependency node info
86
+ * @param context The ESLint rule context
87
+ * @returns The description of the dependency node
88
+ */
89
+ function dependencyDescription({ node, kind, nodeKind, },
90
+ /** The file name */
91
+ fileName,
92
+ /** The ESLint rule context settings normalized */
93
+ settings,
94
+ /** The ESLint rule context */
95
+ context) {
96
+ const source = String(node.value);
97
+ const matcher = getElementsMatcher(settings);
98
+ const description = matcher.describeDependency({
99
+ from: projectPath(fileName, settings.rootPath),
100
+ to: projectPath((0, resolve_1.default)(source, context), settings.rootPath),
101
+ source,
102
+ kind: kind || "value", // TODO: Change by runtime in a backwards compatible way
103
+ nodeKind,
104
+ specifiers: getSpecifiers(node),
105
+ });
106
+ (0, Support_1.debugDescription)(description);
107
+ return description;
108
+ }
@@ -0,0 +1,5 @@
1
+ import type { Rule } from "eslint";
2
+ import type { Literal } from "estree";
3
+ export type EslintLiteralNode = Literal & {
4
+ parent: Rule.Node;
5
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./Elements.types";
2
+ export * from "./Elements";
@@ -14,7 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.PLUGIN_NAME = void 0;
18
- __exportStar(require("../configs/Config.types"), exports);
19
- var plugin_1 = require("../constants/plugin");
20
- Object.defineProperty(exports, "PLUGIN_NAME", { enumerable: true, get: function () { return plugin_1.PLUGIN_NAME; } });
17
+ __exportStar(require("./Elements.types"), exports);
18
+ __exportStar(require("./Elements"), exports);
@@ -0,0 +1,14 @@
1
+ import type { DependencyKind, CapturedValuesSelector, ElementParent, ElementsSelector, CapturedValues, DependencyDescription, ElementDescription } from "@boundaries/elements";
2
+ import type { RuleMatcherElementsCapturedValues } from "../Settings";
3
+ export declare function replaceObjectValuesInTemplates(strings: string | string[], object: Record<string, string>, namespace?: string | null): string | string[];
4
+ export declare function replaceObjectValuesInTemplate(template: string, object: Record<string, string>, namespace?: string | null): string;
5
+ export declare function quote(str: string | undefined | null): string;
6
+ export declare function micromatchPatternReplacingObjectsValues(pattern: string | string[] | undefined, object: Partial<RuleMatcherElementsCapturedValues>): string | string[];
7
+ export declare function ruleElementMessage(elementPatterns: ElementsSelector | undefined, elementCapturedValues: CapturedValues | null): string | import("@boundaries/elements").BaseElementSelectorData | import("@boundaries/elements").BaseElementSelectorWithOptions | CapturedValuesSelector;
8
+ export declare function customErrorMessage(message: string, dependency: DependencyDescription, report?: {}): string;
9
+ export declare function elementMessage(elementInfo: ElementDescription | ElementParent): string;
10
+ export declare function dependencyImportKindMessage(ruleImportKind: DependencyKind | undefined, dependency: DependencyDescription): string;
11
+ export declare function dependencyUsageKindMessage(ruleImportKind: DependencyKind | undefined, dependency: DependencyDescription, { suffix, prefix, }?: {
12
+ suffix?: string;
13
+ prefix?: string;
14
+ }): string;
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.replaceObjectValuesInTemplates = replaceObjectValuesInTemplates;
4
+ exports.replaceObjectValuesInTemplate = replaceObjectValuesInTemplate;
5
+ exports.quote = quote;
6
+ exports.micromatchPatternReplacingObjectsValues = micromatchPatternReplacingObjectsValues;
7
+ exports.ruleElementMessage = ruleElementMessage;
8
+ exports.customErrorMessage = customErrorMessage;
9
+ exports.elementMessage = elementMessage;
10
+ exports.dependencyImportKindMessage = dependencyImportKindMessage;
11
+ exports.dependencyUsageKindMessage = dependencyUsageKindMessage;
12
+ const elements_1 = require("@boundaries/elements");
13
+ const Support_1 = require("../Support");
14
+ function replaceObjectValueInTemplate(template, key, value, namespace) {
15
+ const keyToReplace = namespace ? `${namespace}.${key}` : key;
16
+ const regexp = new RegExp(`\\$\\{${keyToReplace}\\}`, "g");
17
+ return template.replace(regexp, value);
18
+ }
19
+ function replaceObjectValuesInTemplates(strings, object, namespace) {
20
+ const finalResult = (0, Support_1.isArray)(strings) ? [...strings] : strings;
21
+ return Object.keys(object).reduce((result, objectKey) => {
22
+ // If template is an array, replace key by value in all patterns
23
+ if ((0, Support_1.isArray)(result)) {
24
+ return result.map((resultEntry) => {
25
+ return replaceObjectValueInTemplate(resultEntry, objectKey, object[objectKey], namespace);
26
+ });
27
+ }
28
+ return replaceObjectValueInTemplate(result, objectKey, object[objectKey], namespace);
29
+ }, finalResult);
30
+ }
31
+ function replaceObjectValuesInTemplate(template, object, namespace) {
32
+ return replaceObjectValuesInTemplates(template, object, namespace);
33
+ }
34
+ function quote(str) {
35
+ return `'${str || ""}'`;
36
+ }
37
+ function typeMessage(elementMatcher) {
38
+ return `elements of type ${quote(elementMatcher)}`;
39
+ }
40
+ function categoryMessage(category) {
41
+ return `category ${quote(category)}`;
42
+ }
43
+ function propertiesConcatenator(properties, index) {
44
+ if (properties.length > 1 && index === properties.length - 1) {
45
+ return " and";
46
+ }
47
+ if (index === 0) {
48
+ return " with";
49
+ }
50
+ return ",";
51
+ }
52
+ function micromatchPatternReplacingObjectsValues(pattern, object) {
53
+ let patternToReplace = pattern;
54
+ if (!patternToReplace) {
55
+ return "";
56
+ }
57
+ // Backward compatibility. Possibly unused, because the value is already replaced in the next step.
58
+ // For the moment, keep it to avoid unexpected issues until the oncoming refactor.
59
+ if (object.from) {
60
+ patternToReplace = replaceObjectValuesInTemplates(patternToReplace, object.from);
61
+ }
62
+ return Object.keys(object).reduce((replacedPattern, namespace) => {
63
+ if (!object[namespace]) {
64
+ return replacedPattern;
65
+ }
66
+ return replaceObjectValuesInTemplates(replacedPattern, object[namespace] || {}, namespace);
67
+ }, patternToReplace);
68
+ }
69
+ function micromatchPatternMessage(micromatchPatterns, elementCapturedValues) {
70
+ const micromatchPatternsWithValues = micromatchPatternReplacingObjectsValues(micromatchPatterns, { from: elementCapturedValues || {} });
71
+ if ((0, Support_1.isArray)(micromatchPatternsWithValues)) {
72
+ if (micromatchPatternsWithValues.length === 1) {
73
+ return quote(micromatchPatternsWithValues[0]);
74
+ }
75
+ return micromatchPatternsWithValues.reduce((message, micromatchPattern, index) => {
76
+ if (index === 0) {
77
+ return quote(micromatchPattern);
78
+ }
79
+ if (index === micromatchPatternsWithValues.length - 1) {
80
+ return `${message} or ${quote(micromatchPattern)}`;
81
+ }
82
+ return `${message}, ${quote(micromatchPattern)}`;
83
+ }, "");
84
+ }
85
+ return quote(micromatchPatternsWithValues);
86
+ }
87
+ function capturedValuesMatcherMessage(capturedValuesPattern, elementCapturedValues) {
88
+ const capturedValuesPatternKeys = Object.keys(capturedValuesPattern || {});
89
+ return capturedValuesPatternKeys
90
+ .map((key) => {
91
+ return [key, capturedValuesPattern?.[key]];
92
+ })
93
+ .reduce((message, propertyNameAndMatcher, index) => {
94
+ return `${message}${propertiesConcatenator(capturedValuesPatternKeys, index)} ${propertyNameAndMatcher[0]
95
+ // TODO: Support array patterns
96
+ } ${micromatchPatternMessage(propertyNameAndMatcher[1], elementCapturedValues)}`;
97
+ }, "");
98
+ }
99
+ function elementMatcherMessage(elementMatcher, elementCapturedValues) {
100
+ if (!elementMatcher) {
101
+ return "";
102
+ }
103
+ if ((0, elements_1.isElementSelector)(elementMatcher)) {
104
+ const selector = (0, elements_1.normalizeElementsSelector)(elementMatcher);
105
+ const parts = [];
106
+ const toAdd = [];
107
+ if (selector[0].type) {
108
+ // @ts-expect-error Types have to be aligned properly
109
+ toAdd.push(typeMessage(selector[0].type));
110
+ }
111
+ if (selector[0].category) {
112
+ toAdd.push(propertiesConcatenator(parts, parts.length + toAdd.length + 1),
113
+ // @ts-expect-error Types have to be aligned properly
114
+ categoryMessage(selector[0].category));
115
+ }
116
+ if (selector[0].captured) {
117
+ toAdd.push(capturedValuesMatcherMessage(selector[0].captured, elementCapturedValues));
118
+ }
119
+ parts.push(...toAdd);
120
+ return parts.map((part) => part.trim()).join(" ");
121
+ }
122
+ // Backward compatibility. Code should not reach here normally.
123
+ if ((0, Support_1.isString)(elementMatcher)) {
124
+ return typeMessage(elementMatcher);
125
+ }
126
+ // TODO: Support array patterns
127
+ return `${typeMessage(elementMatcher[0])}${capturedValuesMatcherMessage(elementMatcher[1], elementCapturedValues)}`;
128
+ }
129
+ function ruleElementMessage(elementPatterns, elementCapturedValues) {
130
+ if ((0, Support_1.isArray)(elementPatterns)) {
131
+ if (elementPatterns.length === 1) {
132
+ return elementMatcherMessage(elementPatterns[0], elementCapturedValues);
133
+ }
134
+ return elementPatterns.reduce((message, elementPattern, index) => {
135
+ if (index === 0) {
136
+ return elementMatcherMessage(elementPattern, elementCapturedValues);
137
+ }
138
+ return `${message}, or ${elementMatcherMessage(elementPattern, elementCapturedValues)}`;
139
+ }, "");
140
+ }
141
+ return elementMatcherMessage(elementPatterns, elementCapturedValues);
142
+ }
143
+ function elementPropertiesToReplaceInTemplate(element, importKind) {
144
+ if ((0, elements_1.isElementDescription)(element)) {
145
+ return {
146
+ ...element.captured,
147
+ type: element.type || "",
148
+ internalPath: element.internalPath || "",
149
+ source: element.source || "",
150
+ importKind: importKind || "",
151
+ };
152
+ }
153
+ return {
154
+ ...element.captured,
155
+ type: element.type || "",
156
+ internalPath: "",
157
+ source: "",
158
+ importKind: importKind || "",
159
+ };
160
+ }
161
+ function customErrorMessage(message, dependency, report = {}) {
162
+ let replacedMessage = replaceObjectValuesInTemplate(replaceObjectValuesInTemplate(message, elementPropertiesToReplaceInTemplate(dependency.from, dependency.dependency.kind), "file"), elementPropertiesToReplaceInTemplate(dependency.to, dependency.dependency.kind), "dependency");
163
+ replacedMessage = replaceObjectValuesInTemplate(replaceObjectValuesInTemplate(replacedMessage, elementPropertiesToReplaceInTemplate(dependency.from, dependency.dependency.kind), "from"), elementPropertiesToReplaceInTemplate(dependency.to, dependency.dependency.kind), "target");
164
+ if (dependency.from.parents?.[0]) {
165
+ replacedMessage = replaceObjectValuesInTemplate(replacedMessage, elementPropertiesToReplaceInTemplate(dependency.from.parents?.[0], dependency.dependency.kind), "file.parent");
166
+ replacedMessage = replaceObjectValuesInTemplate(replacedMessage, elementPropertiesToReplaceInTemplate(dependency.from.parents?.[0], dependency.dependency.kind), "from.parent");
167
+ }
168
+ if (dependency.to.parents?.[0]) {
169
+ replacedMessage = replaceObjectValuesInTemplate(replacedMessage, elementPropertiesToReplaceInTemplate(dependency.to.parents?.[0], dependency.dependency.kind), "dependency.parent");
170
+ replacedMessage = replaceObjectValuesInTemplate(replacedMessage, elementPropertiesToReplaceInTemplate(dependency.to.parents?.[0], dependency.dependency.kind), "target.parent");
171
+ }
172
+ return replaceObjectValuesInTemplate(replacedMessage, report, "report");
173
+ }
174
+ function elementCapturedValuesMessage(capturedValues) {
175
+ if (!capturedValues) {
176
+ return "";
177
+ }
178
+ const capturedValuesKeys = Object.keys(capturedValues);
179
+ return capturedValuesKeys
180
+ .map((key) => {
181
+ return [key, capturedValues[key]];
182
+ })
183
+ .reduce((message, propertyNameAndValue, index) => {
184
+ return `${message}${propertiesConcatenator(capturedValuesKeys, index)} ${propertyNameAndValue[0]} ${quote(propertyNameAndValue[1])}`;
185
+ }, "");
186
+ }
187
+ function elementMessage(elementInfo) {
188
+ return `of type ${quote(elementInfo.type)}${elementCapturedValuesMessage(elementInfo.captured)}`;
189
+ }
190
+ function hasToPrintKindMessage(ruleImportKind, dependency) {
191
+ return ruleImportKind && dependency.dependency.kind;
192
+ }
193
+ function dependencyImportKindMessage(ruleImportKind, dependency) {
194
+ if (hasToPrintKindMessage(ruleImportKind, dependency)) {
195
+ return `kind ${quote(dependency.dependency.kind)} from `;
196
+ }
197
+ return "";
198
+ }
199
+ function dependencyUsageKindMessage(ruleImportKind, dependency, { suffix = " ", prefix = "", } = {}) {
200
+ if (hasToPrintKindMessage(ruleImportKind, dependency)) {
201
+ return `${prefix}${dependency.dependency.kind}${suffix}`;
202
+ }
203
+ return "";
204
+ }
@@ -0,0 +1 @@
1
+ export * from "./Messages";
@@ -0,0 +1,17 @@
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("./Messages"), exports);
@@ -0,0 +1,2 @@
1
+ export type { Rules, Config, PluginBoundaries } from "../Settings";
2
+ export { PLUGIN_NAME } from "../Settings";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PLUGIN_NAME = void 0;
4
+ var Settings_1 = require("../Settings");
5
+ Object.defineProperty(exports, "PLUGIN_NAME", { enumerable: true, get: function () { return Settings_1.PLUGIN_NAME; } });
@@ -0,0 +1,10 @@
1
+ import type { DependencyKind } from "@boundaries/elements";
2
+ export type { DependencyKind, CapturedValuesSelector, ElementSelector, ElementSelectors, ElementsSelector, ExternalLibrarySelectorOptions, ExternalLibrarySelectorWithOptions, ExternalLibrarySelector, ExternalLibrarySelectors, ExternalLibrariesSelector, ElementSelectorWithOptions, } from "@boundaries/elements";
3
+ export { isElementSelector, isElementsSelector, isExternalLibrarySelector, isExternalLibrariesSelector, } from "@boundaries/elements";
4
+ export type { RulePolicy, RuleBaseOptions, ElementTypesRule, ElementTypesRuleOptions, EntryPointRule, EntryPointRuleOptions, ExternalRule, ExternalRuleOptions, NoPrivateOptions, RuleShortName, RuleName, } from "../Settings";
5
+ export { RULE_POLICIES_MAP, isRulePolicy, RULE_SHORT_NAMES_MAP, RULE_NAMES_MAP, isRuleShortName, isRuleName, } from "../Settings";
6
+ /**
7
+ * Kind of import that the rule applies to (e.g., "type", "value")
8
+ * @deprecated Use DependencyKind instead
9
+ */
10
+ export type ImportKind = DependencyKind;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isRuleName = exports.isRuleShortName = exports.RULE_NAMES_MAP = exports.RULE_SHORT_NAMES_MAP = exports.isRulePolicy = exports.RULE_POLICIES_MAP = exports.isExternalLibrariesSelector = exports.isExternalLibrarySelector = exports.isElementsSelector = exports.isElementSelector = void 0;
4
+ var elements_1 = require("@boundaries/elements");
5
+ Object.defineProperty(exports, "isElementSelector", { enumerable: true, get: function () { return elements_1.isElementSelector; } });
6
+ Object.defineProperty(exports, "isElementsSelector", { enumerable: true, get: function () { return elements_1.isElementsSelector; } });
7
+ Object.defineProperty(exports, "isExternalLibrarySelector", { enumerable: true, get: function () { return elements_1.isExternalLibrarySelector; } });
8
+ Object.defineProperty(exports, "isExternalLibrariesSelector", { enumerable: true, get: function () { return elements_1.isExternalLibrariesSelector; } });
9
+ var Settings_1 = require("../Settings");
10
+ Object.defineProperty(exports, "RULE_POLICIES_MAP", { enumerable: true, get: function () { return Settings_1.RULE_POLICIES_MAP; } });
11
+ Object.defineProperty(exports, "isRulePolicy", { enumerable: true, get: function () { return Settings_1.isRulePolicy; } });
12
+ Object.defineProperty(exports, "RULE_SHORT_NAMES_MAP", { enumerable: true, get: function () { return Settings_1.RULE_SHORT_NAMES_MAP; } });
13
+ Object.defineProperty(exports, "RULE_NAMES_MAP", { enumerable: true, get: function () { return Settings_1.RULE_NAMES_MAP; } });
14
+ Object.defineProperty(exports, "isRuleShortName", { enumerable: true, get: function () { return Settings_1.isRuleShortName; } });
15
+ Object.defineProperty(exports, "isRuleName", { enumerable: true, get: function () { return Settings_1.isRuleName; } });
@@ -0,0 +1,13 @@
1
+ export { DEPENDENCY_KINDS_MAP, isDependencyKind } from "@boundaries/elements";
2
+ export type { ElementDescriptorMode, ElementDescriptor, ElementDescriptors, } from "@boundaries/elements";
3
+ export { ELEMENT_DESCRIPTOR_MODES_MAP, isElementDescriptorMode, } from "@boundaries/elements";
4
+ export type { Settings, IgnoreSetting, IncludeSetting, RootPathSetting, SettingsKey, DependencyNodeKey, DependencyNodeSelector, AliasSetting, } from "../Settings";
5
+ /**
6
+ * Map of the kinds of import, either a type import or a value import.
7
+ * @deprecated Use DEPENDENCY_KINDS_MAP instead
8
+ */
9
+ export declare const IMPORT_KINDS_MAP: {
10
+ readonly TYPE: "type";
11
+ readonly VALUE: "value";
12
+ };
13
+ export { isImportKind, DEPENDENCY_NODE_KEYS_MAP, isDependencyNodeKey, SETTINGS_KEYS_MAP, isSettingsKey, } from "../Settings";