@conarti/eslint-plugin-feature-sliced 1.0.3 → 1.0.4
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/CHANGELOG.md +27 -18
- package/README.md +132 -142
- package/dist/lib/fsd-lib/extract-slice.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,21 +1,30 @@
|
|
|
1
|
-
## [1.0.
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
### Bug Fixes
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
## [1.0.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
###
|
|
14
|
-
|
|
15
|
-
* **configs:** add config
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
## [1.0.4](https://github.com/conarti/eslint-plugin-fsd/compare/v1.0.3...v1.0.4) (2023-07-03)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* correct resolve slice if it contains layer name ([52c2bc7](https://github.com/conarti/eslint-plugin-fsd/commit/52c2bc7b02a16281cf7171dbfac8ee25de34030d))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## [1.0.3](https://github.com/conarti/eslint-plugin-fsd/compare/v1.0.2...v1.0.3) (2023-06-27)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* **configs:** add 'rules' config definition at main entry point ([a9eba73](https://github.com/conarti/eslint-plugin-fsd/commit/a9eba7319090177d284c9d846afb31f8f024d2d0))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## [1.0.2](https://github.com/conarti/eslint-plugin-fsd/compare/v1.0.1...v1.0.2) (2023-06-27)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* **configs:** add config contain only rules ([e811a84](https://github.com/conarti/eslint-plugin-fsd/commit/e811a84900f63c95c72efa960e58c591b2d456d5))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
19
28
|
## [1.0.1](https://github.com/conarti/eslint-plugin-fsd/compare/v1.0.0...v1.0.1) (2023-06-27)
|
|
20
29
|
|
|
21
30
|
### Bug Fixes
|
package/README.md
CHANGED
|
@@ -1,142 +1,132 @@
|
|
|
1
|
-
# eslint-plugin-
|
|
2
|
-
|
|
3
|
-
Feature-sliced design methodology plugin.
|
|
4
|
-
|
|
5
|
-
_Attention: the plugin is being actively developed and is in **beta**.
|
|
6
|
-
The names of rules and configurations may change in new versions.
|
|
7
|
-
If you find a bug, please open an issue or pull request.
|
|
8
|
-
Feel free to contribute_
|
|
9
|
-
|
|
10
|
-
## Features
|
|
11
|
-
|
|
12
|
-
- Works with any framework
|
|
13
|
-
|
|
14
|
-
- Support for **any aliases** out of the box
|
|
15
|
-
|
|
16
|
-
```javascript
|
|
17
|
-
import { AppButton } from "~/shared/ui/app-button";
|
|
18
|
-
import { AppButton } from "@/shared/ui/app-button";
|
|
19
|
-
import { AppButton } from "@shared/ui/app-button";
|
|
20
|
-
import { AppButton } from "$shared/ui/app-button";
|
|
21
|
-
import { AppButton } from "$@#$%%shared/ui/app-button";
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
- Checks for absolute and relative paths
|
|
25
|
-
|
|
26
|
-
```javascript
|
|
27
|
-
// file: src/widgets/TheHeader/ui/TheHeader.stories.tsx
|
|
28
|
-
|
|
29
|
-
import { TheHeader } from './TheHeader'; // valid
|
|
30
|
-
import { TheHeader } from 'src/widgets/TheHeader'; // error: should relative
|
|
31
|
-
import { TheHeader } from 'widgets/TheHeader'; // error: should relative
|
|
32
|
-
import { useBar } from '../../../shared/hooks'; // error: should absolute
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
- Checks for imports from public api and fix them
|
|
36
|
-
|
|
37
|
-
```javascript
|
|
38
|
-
// file: src/features/search-articles/...
|
|
39
|
-
|
|
40
|
-
import { addCommentFormActions, addCommentFormReducer } from 'entities/Article/model/file.ts'; // error
|
|
41
|
-
// fix: import { addCommentFormActions, addCommentFormReducer } from 'entities/Article';
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
- Sort imports
|
|
45
|
-
|
|
46
|
-
```javascript
|
|
47
|
-
import axios from "axios"; // 1) external libs
|
|
48
|
-
import { Header } from "widgets/header"; // 2.1) Layers: widgets
|
|
49
|
-
import { Zero } from "widgets/zero"; // 2.1) Layers: widget
|
|
50
|
-
import { LoginForm } from "features/login-form"; // 2.2) Layers: features
|
|
51
|
-
import { globalEntities } from "entities"; // 2.4) Layers: entities
|
|
52
|
-
import { authModel } from "entities/auth"; // 2.4) Layers: entities
|
|
53
|
-
import { Cart } from "entities/cart"; // 2.4) Layers: entities
|
|
54
|
-
import { One } from "entities/one"; // 2.4) Layers: entities
|
|
55
|
-
import { Two } from "entities/two"; // 2.4) Layers: entities
|
|
56
|
-
import { debounce } from "shared/lib/fp"; // 2.5) Layers: shared
|
|
57
|
-
import { Button } from "shared/ui"; // 2.5) Layers: shared
|
|
58
|
-
import { Input } from "shared/ui"; // 2.5) Layers: shared
|
|
59
|
-
import { data } from "../fixtures"; // 3) parent
|
|
60
|
-
import { getSmth } from "./lib"; // 4) sibling
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## Installation
|
|
64
|
-
|
|
65
|
-
You'll first need to install [ESLint](https://eslint.org/):
|
|
66
|
-
|
|
67
|
-
```sh
|
|
68
|
-
npm i eslint --save-dev
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
Next, install
|
|
72
|
-
|
|
73
|
-
```sh
|
|
74
|
-
npm install -D eslint-plugin-
|
|
75
|
-
# or by yarn
|
|
76
|
-
yarn add -D eslint-plugin-
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
"
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).
|
|
135
|
-
💡 Suggestion fix (no automatic fix)
|
|
136
|
-
|
|
137
|
-
| Name | Description | 🔧 |
|
|
138
|
-
|:-------------------------------------------------------------------|:------------------------------------------|:---|
|
|
139
|
-
| [conarti-fsd/layers-slices](rules/layers-slices/README.md) | Checks layer imports | |
|
|
140
|
-
| [conarti-fsd/absolute-relative](rules/absolute-relative/README.md) | Checks for absolute and relative paths | |
|
|
141
|
-
| [conarti-fsd/public-api](rules/public-api/README.md) | Check for module imports from public api | 💡 |
|
|
142
|
-
| import/order | Sort imports using 'eslint-plugin-import' | 🔧 |
|
|
1
|
+
# @conarti/eslint-plugin-feature-sliced
|
|
2
|
+
|
|
3
|
+
Feature-sliced design methodology plugin.
|
|
4
|
+
|
|
5
|
+
_Attention: the plugin is being actively developed and is in **beta**.
|
|
6
|
+
The names of rules and configurations may change in new versions.
|
|
7
|
+
If you find a bug, please open an issue or pull request.
|
|
8
|
+
Feel free to contribute_
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- Works with any framework
|
|
13
|
+
|
|
14
|
+
- Support for **any aliases** out of the box
|
|
15
|
+
|
|
16
|
+
```javascript
|
|
17
|
+
import { AppButton } from "~/shared/ui/app-button";
|
|
18
|
+
import { AppButton } from "@/shared/ui/app-button";
|
|
19
|
+
import { AppButton } from "@shared/ui/app-button";
|
|
20
|
+
import { AppButton } from "$shared/ui/app-button";
|
|
21
|
+
import { AppButton } from "$@#$%%shared/ui/app-button";
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
- Checks for absolute and relative paths
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
// file: src/widgets/TheHeader/ui/TheHeader.stories.tsx
|
|
28
|
+
|
|
29
|
+
import { TheHeader } from './TheHeader'; // valid
|
|
30
|
+
import { TheHeader } from 'src/widgets/TheHeader'; // error: should relative
|
|
31
|
+
import { TheHeader } from 'widgets/TheHeader'; // error: should relative
|
|
32
|
+
import { useBar } from '../../../shared/hooks'; // error: should absolute
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
- Checks for imports from public api and fix them
|
|
36
|
+
|
|
37
|
+
```javascript
|
|
38
|
+
// file: src/features/search-articles/...
|
|
39
|
+
|
|
40
|
+
import { addCommentFormActions, addCommentFormReducer } from 'entities/Article/model/file.ts'; // error
|
|
41
|
+
// fix: import { addCommentFormActions, addCommentFormReducer } from 'entities/Article';
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
- Sort imports
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
import axios from "axios"; // 1) external libs
|
|
48
|
+
import { Header } from "widgets/header"; // 2.1) Layers: widgets
|
|
49
|
+
import { Zero } from "widgets/zero"; // 2.1) Layers: widget
|
|
50
|
+
import { LoginForm } from "features/login-form"; // 2.2) Layers: features
|
|
51
|
+
import { globalEntities } from "entities"; // 2.4) Layers: entities
|
|
52
|
+
import { authModel } from "entities/auth"; // 2.4) Layers: entities
|
|
53
|
+
import { Cart } from "entities/cart"; // 2.4) Layers: entities
|
|
54
|
+
import { One } from "entities/one"; // 2.4) Layers: entities
|
|
55
|
+
import { Two } from "entities/two"; // 2.4) Layers: entities
|
|
56
|
+
import { debounce } from "shared/lib/fp"; // 2.5) Layers: shared
|
|
57
|
+
import { Button } from "shared/ui"; // 2.5) Layers: shared
|
|
58
|
+
import { Input } from "shared/ui"; // 2.5) Layers: shared
|
|
59
|
+
import { data } from "../fixtures"; // 3) parent
|
|
60
|
+
import { getSmth } from "./lib"; // 4) sibling
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Installation
|
|
64
|
+
|
|
65
|
+
You'll first need to install [ESLint](https://eslint.org/):
|
|
66
|
+
|
|
67
|
+
```sh
|
|
68
|
+
npm i eslint --save-dev
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Next, install `@conarti/eslint-plugin-feature-sliced` and dependencies:
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
npm install -D @conarti/eslint-plugin-feature-sliced eslint-plugin-import
|
|
75
|
+
# or by yarn
|
|
76
|
+
yarn add -D @conarti/eslint-plugin-feature-sliced eslint-plugin-import
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Note: 'eslint-plugin-import' is optional. You can skip installing this plugin if you don't need to sort imports in your code.
|
|
80
|
+
|
|
81
|
+
## Quick Usage
|
|
82
|
+
|
|
83
|
+
Add `@conarti/feature-sliced/recommended` to extends section of your `.eslintrc` configuration file.
|
|
84
|
+
It enables all rules and additional recommended configs of other eslint plugins, like `eslint-plugin-import`.
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
88
|
+
"extends": [
|
|
89
|
+
"plugin:@conarti/feature-sliced/recommended"
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Customisation
|
|
95
|
+
|
|
96
|
+
If you want to use only plugin rules, add `@conarti/feature-sliced/rules` instead.
|
|
97
|
+
|
|
98
|
+
```json
|
|
99
|
+
{
|
|
100
|
+
"extends": [
|
|
101
|
+
"plugin:@conarti/feature-sliced/rules"
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
If you only want to use certain rules, you can add them individually. To do this, you need to add `@conarti/feature-sliced` to the 'plugins'
|
|
107
|
+
section of the configuration file and add the desired rules to the 'rules' section. Also now you don't need to use the 'extends' section like before
|
|
108
|
+
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"plugins": [
|
|
112
|
+
"@conarti/feature-sliced"
|
|
113
|
+
],
|
|
114
|
+
"rules": {
|
|
115
|
+
"@conarti/feature-sliced/layers-slices": "error",
|
|
116
|
+
"@conarti/feature-sliced/absolute-relative": "error",
|
|
117
|
+
"@conarti/feature-sliced/public-api": "error"
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Rules
|
|
123
|
+
|
|
124
|
+
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).
|
|
125
|
+
💡 Suggestion fix (no automatic fix)
|
|
126
|
+
|
|
127
|
+
| Name | Description | 🔧 |
|
|
128
|
+
|:------------------------------------------------------------------------------------|:------------------------------------------|:---|
|
|
129
|
+
| [@conarti/feature-sliced/layers-slices](docs/rules/layers-slices/README.md) | Checks layer imports | |
|
|
130
|
+
| [@conarti/feature-sliced/absolute-relative](docs/rules/absolute-relative/README.md) | Checks for absolute and relative paths | |
|
|
131
|
+
| [@conarti/feature-sliced/public-api](docs/rules/public-api/README.md) | Check for module imports from public api | 💡 |
|
|
132
|
+
| import/order | Sort imports using 'eslint-plugin-import' | 🔧 |
|
|
@@ -5,6 +5,6 @@ const config_1 = require("../../config");
|
|
|
5
5
|
const shared_1 = require("../shared");
|
|
6
6
|
function extractSlice(targetPath) {
|
|
7
7
|
const targetPathWithoutCurrentFileName = targetPath.replace(/\/\w+\.\w+$/, '');
|
|
8
|
-
return (0, shared_1.getByRegExp)(targetPathWithoutCurrentFileName, new RegExp(`(?<=(${config_1.layersWithSlices.join('|')})\\/)(\\w|-)+`, 'ig')
|
|
8
|
+
return (0, shared_1.getByRegExp)(targetPathWithoutCurrentFileName, new RegExp(`(?<=(${config_1.layersWithSlices.join('|')})\\/)(\\w|-)+`, 'ig'));
|
|
9
9
|
}
|
|
10
10
|
exports.extractSlice = extractSlice;
|
package/package.json
CHANGED