eslint-plugin-fsd-paths-check 0.0.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.
- package/README.md +71 -0
- package/lib/index.js +22 -0
- package/lib/rules/enforce-relative-path-within-slice.js +68 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# eslint-plugin-path-check
|
|
2
|
+
|
|
3
|
+
plugin to check typescript imports
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
You'll first need to install [ESLint](https://eslint.org/):
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm i eslint --save-dev
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Next, install `eslint-plugin-path-check`:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install eslint-plugin-path-check --save-dev
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
In your [configuration file](https://eslint.org/docs/latest/use/configure/configuration-files#configuration-file), import the plugin `eslint-plugin-path-check` and add `path-check` to the `plugins` key:
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
import { defineConfig } from "eslint/config";
|
|
25
|
+
import path-check from "eslint-plugin-path-check";
|
|
26
|
+
|
|
27
|
+
export default defineConfig([
|
|
28
|
+
{
|
|
29
|
+
plugins: {
|
|
30
|
+
path-check
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
]);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
Then configure the rules you want to use under the `rules` key.
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
import { defineConfig } from "eslint/config";
|
|
41
|
+
import path-check from "eslint-plugin-path-check";
|
|
42
|
+
|
|
43
|
+
export default defineConfig([
|
|
44
|
+
{
|
|
45
|
+
plugins: {
|
|
46
|
+
path-check
|
|
47
|
+
},
|
|
48
|
+
rules: {
|
|
49
|
+
"path-check/rule-name": "warn"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
]);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
## Configurations
|
|
58
|
+
|
|
59
|
+
<!-- begin auto-generated configs list -->
|
|
60
|
+
TODO: Run eslint-doc-generator to generate the configs list (or delete this section if no configs are offered).
|
|
61
|
+
<!-- end auto-generated configs list -->
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
## Rules
|
|
66
|
+
|
|
67
|
+
<!-- begin auto-generated rules list -->
|
|
68
|
+
TODO: Run eslint-doc-generator to generate the rules list.
|
|
69
|
+
<!-- end auto-generated rules list -->
|
|
70
|
+
|
|
71
|
+
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview plugin to check typescript imports
|
|
3
|
+
* @author borispopygai
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
//------------------------------------------------------------------------------
|
|
8
|
+
// Requirements
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
const requireIndex = require("requireindex");
|
|
12
|
+
|
|
13
|
+
//------------------------------------------------------------------------------
|
|
14
|
+
// Plugin Definition
|
|
15
|
+
//------------------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
// import all rules in lib/rules
|
|
19
|
+
module.exports.rules = requireIndex(__dirname + "/rules");
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const path = require("path");
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
meta: {
|
|
7
|
+
type: null, // `problem`, `suggestion`, or `layout`
|
|
8
|
+
docs: {
|
|
9
|
+
description: "FSD relative path check",
|
|
10
|
+
recommended: false,
|
|
11
|
+
url: null, // URL to the documentation page for this rule
|
|
12
|
+
},
|
|
13
|
+
fixable: null, // Or `code` or `whitespace`
|
|
14
|
+
schema: [], // Add a schema if the rule has options
|
|
15
|
+
messages: {}, // Add messageId and message
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
create(context) {
|
|
19
|
+
return {
|
|
20
|
+
ImportDeclaration(node) {
|
|
21
|
+
const importTo = node.source.value;
|
|
22
|
+
const currentFile = context.getFilename();
|
|
23
|
+
|
|
24
|
+
if(shouldBeRelative(currentFile, importTo)) {
|
|
25
|
+
context.report(node, `Imports within the slice should be relative`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const fsdLayers = {
|
|
33
|
+
'shared': 'shared',
|
|
34
|
+
'entities': 'entities',
|
|
35
|
+
'features': 'features',
|
|
36
|
+
'widgets': 'widgets',
|
|
37
|
+
'pages': 'pages',
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function isPathRelative(path) {
|
|
41
|
+
return path === `.` || path.startsWith(`./`) || path.startsWith('../');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function shouldBeRelative(from, to) {
|
|
45
|
+
if(isPathRelative(to)) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const toArray = to.split('/');
|
|
50
|
+
const toLayer = toArray[0];
|
|
51
|
+
const toSlice = toArray[1];
|
|
52
|
+
|
|
53
|
+
if(!toLayer || !toSlice || !fsdLayers[toLayer]) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const fromNormalized = path.toNamespacedPath(from);
|
|
58
|
+
const fromProject = fromNormalized.split(`src/`)[1];
|
|
59
|
+
const fromArray = fromProject.split('/');
|
|
60
|
+
const fromLayer = fromArray[0];
|
|
61
|
+
const fromSlice = fromArray[1];
|
|
62
|
+
|
|
63
|
+
if(!fromLayer || !fromSlice || !fsdLayers[fromLayer]) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return fromSlice === toSlice && fromLayer === toLayer;
|
|
68
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "eslint-plugin-fsd-paths-check",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "plugin to check feature sliced design paths correctness",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"eslint",
|
|
7
|
+
"eslintplugin",
|
|
8
|
+
"eslint-plugin",
|
|
9
|
+
"feature-sliced design"
|
|
10
|
+
],
|
|
11
|
+
"author": "affimojas",
|
|
12
|
+
"main": "./lib/index.js",
|
|
13
|
+
"exports": "./lib/index.js",
|
|
14
|
+
"files": [
|
|
15
|
+
"lib"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"lint": "npm-run-all \"lint:*\"",
|
|
19
|
+
"lint:eslint-docs": "npm-run-all \"update:eslint-docs -- --check\"",
|
|
20
|
+
"lint:js": "eslint .",
|
|
21
|
+
"test": "mocha tests --recursive",
|
|
22
|
+
"update:eslint-docs": "eslint-doc-generator"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"requireindex": "^1.2.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"eslint": "^8.26.0",
|
|
29
|
+
"@eslint/js": "^8.26.0",
|
|
30
|
+
"eslint-doc-generator": "^2.0.0",
|
|
31
|
+
"eslint-plugin-eslint-plugin": "^6.0.0",
|
|
32
|
+
"eslint-plugin-n": "^17.0.0",
|
|
33
|
+
"mocha": "^11.0.0",
|
|
34
|
+
"npm-run-all2": "^6.1.2"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": "^20.19.0 || ^22.13.0 || >=24"
|
|
38
|
+
},
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
41
|
+
}
|