You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
9
9
### Changed
10
10
### Fixed
11
11
### Removed
12
+
### BREAKING CHANGES
13
+
14
+
## [4.0.0] - 2023-12-01
15
+
16
+
### Added
17
+
18
+
- feat(#213): Add `dependency-nodes` setting to allow analyzing dependencies from additional nodes, such as exports or dynamic imports.
19
+
- feat: Add `additional-dependency-nodes` setting to add custom dependency nodes to the default ones. For example, you could enable to analyze dependencies in `jest.mock(...)`, etc.
20
+
21
+
### BREAKING CHANGES
22
+
23
+
- fix: Fixed the error position in multiline imports. See ["how to migrate from v3 to v4" guide](./docs/guides/how-to-migrate-from-v3-to-v4.md).
Copy file name to clipboardExpand all lines: README.md
+67-15Lines changed: 67 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,9 @@
8
8
9
9
In words of Robert C. Martin, _"Software architecture is the art of drawing lines that I call boundaries. Those boundaries separate software elements from one another, and restrict those on one side from knowing about those on the other."__([\*acknowledgements](#acknowledgements))_
10
10
11
-
__This plugin ensures that your architecture boundaries are respected by the elements in your project__ checking the folders and files structure and the `import` statements (_Read the [main rules overview chapter](#main-rules-overview) for better comprehension._). __It is not a replacement for [eslint-plugin-import](https://www.npmjs.com/package/eslint-plugin-import), on the contrary, the combination of both plugins is recommended.__
11
+
__This plugin ensures that your architecture boundaries are respected by the elements in your project__ checking the folders and files structure and the dependencies between them. __It is not a replacement for [eslint-plugin-import](https://www.npmjs.com/package/eslint-plugin-import), on the contrary, the combination of both plugins is recommended.__
12
+
13
+
By default, __the plugin works by checking `import` statements, but it is also able to analyze exports, dynamic imports, and can be configured to check any other [AST nodes](https://eslint.org/docs/latest/extend/selectors)__. (_Read the [main rules overview](#main-rules-overview) and [configuration](#configuration) chapters for better comprehension_)
12
14
13
15
## Table of Contents
14
16
@@ -33,6 +35,7 @@ __This plugin ensures that your architecture boundaries are respected by the ele
33
35
*[Advanced example](#advanced-example)
34
36
-[Resolvers](#resolvers)
35
37
-[Usage with TypeScript](#usage-with-typescript)
38
+
-[Migration guides](#migration-guides)
36
39
-[Debug mode](#debug-mode)
37
40
-[Acknowledgements](#acknowledgements)
38
41
-[Contributing](#contributing)
@@ -59,15 +62,11 @@ Activate the plugin and one of the canned configs in your `.eslintrc.(yml|json|j
59
62
}
60
63
```
61
64
62
-
## Migrating from v1.x
63
-
64
-
New v2.0.0 release has introduced many breaking changes. If you were using v1.x, you should [read the "how to migrate from v1 to v2" guide](./docs/guides/how-to-migrate-from-v1-to-v2.md).
65
-
66
65
## Overview
67
66
68
-
All of the plugin rules need to be able to identify the elements in the project, so, first of all you have to define your project elements using the `boundaries/elements` setting.
67
+
All of the plugin rules need to be able to identify the elements in the project, so, first of all you have to define your project element types by using the `boundaries/elements` setting.
69
68
70
-
The plugin will use the provided patterns to identify each file or local `import`statement as one of the element types.
69
+
The plugin will use the provided patterns to identify each file as one of the element types. It will also assign a type to each dependency detected in the [dependency nodes (`import`or other statements)](#boundariesdependency-nodes), and it will check if the relationship between the dependent element and the dependency is allowed or not.
71
70
72
71
```json
73
72
{
@@ -92,7 +91,7 @@ The plugin will use the provided patterns to identify each file or local `import
92
91
93
92
This is only a basic example of configuration. The plugin can be configured to identify elements being a file, or elements being a folder containing files. It also supports capturing path fragments to be used afterwards on each rule options, etc. __Read the [configuration chapter](#configuration) for further info, as configuring it properly is crucial__ to take advantage of all of the plugin features.
94
93
95
-
Once your project elements are defined, you can use them to configure each rule using its own options. For example, you could define which elements can be dependencies of other ones configuring the `element-types` rule as in:
94
+
Once your project element types are defined, you can use them to configure each rule using its own options. For example, you could define which elements can be dependencies of other ones by configuring the `element-types` rule as in:
96
95
97
96
```json
98
97
{
@@ -114,7 +113,7 @@ Once your project elements are defined, you can use them to configure each rule
114
113
}
115
114
```
116
115
117
-
> The plugin won't apply rules to a file or `import` when it does not recognize its element type, but you can force all files in your project to belong to an element type enabling the [boundaries/no-unknown-files](docs/rules/no-unknown-files.md) rule.
116
+
> The plugin won't apply rules to a file or dependency when it does not recognize its element type, but you can force all files in your project to belong to an element type by enabling the [boundaries/no-unknown-files](docs/rules/no-unknown-files.md) rule.
118
117
119
118
## Main rules overview
120
119
@@ -202,6 +201,52 @@ Define patterns to recognize each file in the project as one of this element typ
202
201
203
202
> Tip: You can enable the [debug mode](#debug-mode) when configuring the plugin, and you will get information about the type assigned to each file in the project, as well as captured properties and values.
204
203
204
+
#### __`boundaries/dependency-nodes`__
205
+
206
+
This setting allows to modify built-in default dependency nodes. By default, the plugin will analyze only the `import` statements. All the rules defined for the plugin will be applicable to the nodes defined in this setting.
207
+
208
+
The setting should be an array of the following strings:
If you want to define custom dependency nodes, such as `jest.mock(...)`, use [additional-dependency-nodes](#boundariesadditional-dependency-nodes) setting.
215
+
216
+
For example, if you want to analyze the `import` and `dynamic-import` statements, you should use the following value:
This setting allows to define custom dependency nodes to analyze. All the rules defined for the plugin will be applicable to the nodes defined in this setting.
225
+
226
+
The setting should be an array of objects with the following structure:
227
+
228
+
*__`selector`__: The [esquery selector](https://github.com/estools/esquery) for the `Literal` node in which dependency source are defined. For example, to analyze `jest.mock(...)` calls you could use this [AST selector](https://eslint.org/docs/latest/extend/selectors): `CallExpression[callee.object.name=jest][callee.property.name=mock] > Literal:first-child`.
229
+
*__`kind`__: The kind of dependency, possible values are: `"value"` or `"type"`. It is available only when using TypeScript.
Files or dependencies not matching these [`micromatch` patterns](https://github.com/micromatch/micromatch) will be ignored by the plugin. If this option is not provided, all files will be included.
@@ -235,7 +280,7 @@ Use this setting only if you are facing issues with the plugin when executing th
235
280
<details>
236
281
<summary>How to define the root path of the project</summary>
237
282
238
-
By default, the plugin uses the current working directory (`process.cwd()`) as root path of the project. This path is used as the base path when resolving file matchers from rules and `boundaries/elements` settings. This is specially important when using the `basePattern` option or the `full` mode in the `boundaries/elements` setting. This may produce unexpected results [when the lint command is executed from a different path than the project root](https://github.com/javierbrea/eslint-plugin-boundaries/issues/296). To fix this, you can define a different root path using this option.
283
+
By default, the plugin uses the current working directory (`process.cwd()`) as root path of the project. This path is used as the base path when resolving file matchers from rules and `boundaries/elements` settings. This is specially important when using the `basePattern` option or the `full` mode in the `boundaries/elements` setting. This may produce unexpected results [when the lint command is executed from a different path than the project root](https://github.com/javierbrea/eslint-plugin-boundaries/issues/296). To fix this, you can define a different root path by using this option.
239
284
240
285
For example, supposing that the `.eslintrc.js` file is located in the project root, you could define the root path as in:
241
286
@@ -257,12 +302,9 @@ You can also provide an absolute path in the environment variable, but it may be
257
302
258
303
</details>
259
304
260
-
261
-
262
305
### Predefined configurations
263
306
264
-
This plugin is distributed with two different predefined configurations: "recommended" and "strict".
265
-
307
+
The plugin is distributed with two different predefined configurations: "recommended" and "strict".
266
308
267
309
#### Recommended
268
310
@@ -333,7 +375,7 @@ Remember that:
333
375
334
376
*__`from/target`__: `<element matchers>` Depending of the rule to which the options are for, the rule will be applied only if the file being analyzed matches with this element matcher (`from`), or the dependency being imported matches with this element matcher (`target`).
335
377
*__`disallow/allow`__: `<value matchers>` If the plugin rule target matches with this, then the result of the rule will be "disallow/allow". Each rule will require a type of value here depending of what it is checking. In the case of the `element-types` rule, for example, another `<element matcher>` has to be provided in order to check the type of the local dependency.
336
-
*__`importKind`__: `<string>`_Optional_. It is useful only when using TypeScript, as it allows to define if the rule applies when the dependency is being imported as a value or as a type. It can be also defined as an array of strings, or a micromatch pattern. Note that possible values to match with are `"value"`, `"type"` or `"typeof"`. For example, you could define that "components" can import "helpers" as a value, but not as a type. So, `import { helper } from "helpers/helper-a"` would be allowed, but `import type { Helper } from "helpers/helper-a"` would be disallowed.
378
+
*__`importKind`__: `<string>`_Optional_. It is useful only when using TypeScript, because it allows to define if the rule applies when the dependency is being imported as a value or as a type. It can be also defined as an array of strings, or a micromatch pattern. Note that possible values to match with are `"value"`, `"type"` or `"typeof"`. For example, you could define that "components" can import "helpers" as a value, but not as a type. So, `import { helper } from "helpers/helper-a"` would be allowed, but `import type { Helper } from "helpers/helper-a"` would be disallowed.
337
379
*__`message`__: `<string>` Optional. If the rule results in an error, the plugin will return this message instead of the default one. Read [error messages](#error-messages) for further info.
338
380
339
381
> Tip: Properties `from/target` and `disallow/allow` can receive a single matcher, or an array of matchers.
@@ -511,6 +553,16 @@ module.exports = {
511
553
512
554
In case you face any issue configuring it, you can also [use this repository as a guide](https://github.com/javierbrea/epb-ts-example). It contains a fully working and tested example.
513
555
556
+
## Migration guides
557
+
558
+
### Migrating from v3.x
559
+
560
+
New v4.0.0 release has introduced breaking changes. If you were using v3.x, you should [read the "how to migrate from v3 to v4" guide](./docs/guides/how-to-migrate-from-v3-to-v4.md).
561
+
562
+
### Migrating from v1.x
563
+
564
+
New v2.0.0 release has introduced many breaking changes. If you were using v1.x, you should [read the "how to migrate from v1 to v2" guide](./docs/guides/how-to-migrate-from-v1-to-v2.md).
565
+
514
566
## Debug mode
515
567
516
568
In order to help during the configuration process, the plugin can trace information about the files and imports being analyzed. The information includes the file path, the assigned element type, the captured values, etc. So, it can help you to check that your `elements` setting works as expected. You can enable it using the `ESLINT_PLUGIN_BOUNDARIES_DEBUG` environment variable.
There is only one breaking change in the v4.0.0 release. We've fixed the bug that caused ESLint to incorrectly mark the error position for multiline imports.
11
+
12
+
Previous behavior:
13
+
14
+
```js
15
+
import {
16
+
// ----^ (start of the error)
17
+
ComponentA
18
+
} from'./components/component-a';
19
+
// -----------------------------^ (end of the error)
20
+
```
21
+
22
+
Fixed behavior:
23
+
24
+
```js
25
+
import {
26
+
ComponentA
27
+
} from'./components/component-a';
28
+
// ----^ (start) ---------------^ (end)
29
+
```
30
+
31
+
## How to migrate
32
+
33
+
You need to adjust your `eslint-disable-next-line` directives to match the new position.
0 commit comments