eslint-plugin-boundaries 2.7.0 → 2.8.0

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/README.md CHANGED
@@ -259,7 +259,7 @@ Some rules require extra configuration, and it has to be defined in each specifi
259
259
 
260
260
  #### Main format of rules options
261
261
 
262
- The docs of each rule contains an specification of their own options, but __the main rules share the format in which the options have to be defined__. The format described here is valid for options of [`element-types`](docs/rules/element-types.md), [`external`](docs/rules/external.md) and [`entry-point`](docs/rules/entry-point.md) rules, __except the `message` property, which for the moment is only supported in the [`element-types`](docs/rules/element-types.md) and [`entry-point`](docs/rules/entry-point.md) rules settings.
262
+ The docs of each rule contains an specification of their own options, but __the main rules share the format in which the options have to be defined__. The format described here is valid for options of [`element-types`](docs/rules/element-types.md), [`external`](docs/rules/external.md) and [`entry-point`](docs/rules/entry-point.md) rules, __except the `message` property, which for the moment is only supported in the [`element-types`](docs/rules/element-types.md), [`entry-point`](docs/rules/entry-point.md) and [`no-private`](docs/rules/no-private.md) rules settings.
263
263
 
264
264
  Options set an "allow/disallow" value by default, and provide an array of rules. Each matching rule will override the default value and the value returned by previous matching rules. So, the final result of the options, once processed for each case, will be "allow" or "disallow", and this value will be applied by the plugin rule in the correspondant way, making it to produce an eslint error or not.
265
265
 
@@ -331,6 +331,7 @@ Available properties in error templates both from `file` or `dependency` are:
331
331
 
332
332
  * `type`: Element's type.
333
333
  * `internalPath`: File path being analyzed or imported. Relative to the element's root path.
334
+ * `parent`: If the element is child of another element, it is also available in this property, which contains correspondent `type`, `internalPath` and captured properties as well.
334
335
  * ...All captured properties are also available
335
336
 
336
337
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-boundaries",
3
- "version": "2.7.0",
3
+ "version": "2.8.0",
4
4
  "description": "Eslint plugin checking architecture boundaries between elements",
5
5
  "keywords": [
6
6
  "eslint",
@@ -79,12 +79,31 @@ function ruleElementMessage(elementPatterns, elementCapturedValues) {
79
79
  return elementMatcherMessage(elementPatterns, elementCapturedValues);
80
80
  }
81
81
 
82
+ function elementPropertiesToReplaceInTemplate(element) {
83
+ return { ...element.capturedValues, type: element.type, internalPath: element.internalPath };
84
+ }
85
+
82
86
  function customErrorMessage(message, file, dependency) {
83
- return replaceObjectValuesInTemplates(
84
- replaceObjectValuesInTemplates(message, { ...file.capturedValues, type: file.type }, "file"),
85
- { ...dependency.capturedValues, type: dependency.type, internalPath: dependency.internalPath },
87
+ let replacedMessage = replaceObjectValuesInTemplates(
88
+ replaceObjectValuesInTemplates(message, elementPropertiesToReplaceInTemplate(file), "file"),
89
+ elementPropertiesToReplaceInTemplate(dependency),
86
90
  "dependency"
87
91
  );
92
+ if (file.parents[0]) {
93
+ replacedMessage = replaceObjectValuesInTemplates(
94
+ replacedMessage,
95
+ elementPropertiesToReplaceInTemplate(file.parents[0]),
96
+ "file.parent"
97
+ );
98
+ }
99
+ if (dependency.parents[0]) {
100
+ replacedMessage = replaceObjectValuesInTemplates(
101
+ replacedMessage,
102
+ elementPropertiesToReplaceInTemplate(dependency.parents[0]),
103
+ "dependency.parent"
104
+ );
105
+ }
106
+ return replacedMessage;
88
107
  }
89
108
 
90
109
  function elementCapturedValuesMessage(capturedValues) {
@@ -3,6 +3,14 @@ const { RULE_NO_PRIVATE } = require("../constants/settings");
3
3
  const dependencyRule = require("../rules-factories/dependency-rule");
4
4
 
5
5
  const { dependencyLocation } = require("../helpers/rules");
6
+ const { customErrorMessage, elementMessage } = require("../helpers/messages");
7
+
8
+ function errorMessage(file, dependency, options) {
9
+ if (options.message) {
10
+ return customErrorMessage(options.message, file, dependency);
11
+ }
12
+ return `Dependency is private of element ${elementMessage(dependency.parents[0])}`;
13
+ }
6
14
 
7
15
  module.exports = dependencyRule(
8
16
  {
@@ -15,12 +23,15 @@ module.exports = dependencyRule(
15
23
  allowUncles: {
16
24
  type: "boolean",
17
25
  },
26
+ message: {
27
+ type: "string",
28
+ },
18
29
  },
19
30
  additionalProperties: false,
20
31
  },
21
32
  ],
22
33
  },
23
- function ({ dependency, node, context, options }) {
34
+ function ({ file, dependency, node, context, options }) {
24
35
  if (
25
36
  !dependency.isIgnored &&
26
37
  dependency.isLocal &&
@@ -32,7 +43,7 @@ module.exports = dependencyRule(
32
43
  (!options || !options.allowUncles || dependency.relationship !== "uncle")
33
44
  ) {
34
45
  context.report({
35
- message: `Dependency is private of another element`,
46
+ message: errorMessage(file, dependency, options),
36
47
  node: node,
37
48
  ...dependencyLocation(node, context),
38
49
  });