eslint-plugin-advanced-app 0.0.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 +71 -0
- package/lib/index.js +22 -0
- package/lib/rules/path-checker.js +82 -0
- package/package.json +42 -0
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# eslint-plugin-advanced-app
|
|
2
|
+
|
|
3
|
+
custom plugin for check fsd import
|
|
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-advanced-app`:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install eslint-plugin-advanced-app --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-advanced-app` and add `advanced-app` to the `plugins` key:
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
import { defineConfig } from "eslint/config";
|
|
25
|
+
import advanced-app from "eslint-plugin-advanced-app";
|
|
26
|
+
|
|
27
|
+
export default defineConfig([
|
|
28
|
+
{
|
|
29
|
+
plugins: {
|
|
30
|
+
advanced-app
|
|
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 advanced-app from "eslint-plugin-advanced-app";
|
|
42
|
+
|
|
43
|
+
export default defineConfig([
|
|
44
|
+
{
|
|
45
|
+
plugins: {
|
|
46
|
+
advanced-app
|
|
47
|
+
},
|
|
48
|
+
rules: {
|
|
49
|
+
"advanced-app/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 custom plugin for check fsd import
|
|
3
|
+
* @author Andrey
|
|
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,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
meta: {
|
|
8
|
+
type: null, // `problem`, `suggestion`, or `layout`
|
|
9
|
+
docs: {
|
|
10
|
+
description: "feature sliced relative path checker",
|
|
11
|
+
recommended: false,
|
|
12
|
+
url: null, // URL to the documentation page for this rule
|
|
13
|
+
},
|
|
14
|
+
fixable: null, // Or `code` or `whitespace`
|
|
15
|
+
schema: [], // Add a schema if the rule has options
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
create(context) {
|
|
19
|
+
return {
|
|
20
|
+
ImportDeclaration(node) {
|
|
21
|
+
// example app/entities/Article
|
|
22
|
+
const importTo = node.source.value;
|
|
23
|
+
|
|
24
|
+
// example C:\Users\tim\Desktop\javascript\production_project\src\entities\Article
|
|
25
|
+
const fromFilename = context.getFilename();
|
|
26
|
+
|
|
27
|
+
if(shouldBeRelative(fromFilename, importTo)) {
|
|
28
|
+
context.report(node, 'В рамках одного слайса все пути должны быть относительными');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function isPathRelative(path) {
|
|
36
|
+
return path === '.' || path.startsWith('./') || path.startsWith('../')
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const layers = {
|
|
40
|
+
'entities': 'entities',
|
|
41
|
+
'features': 'features',
|
|
42
|
+
'shared': 'shared',
|
|
43
|
+
'pages': 'pages',
|
|
44
|
+
'widgets': 'widgets',
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function shouldBeRelative(from, to) {
|
|
48
|
+
if(isPathRelative(to)) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// example entities/Article
|
|
53
|
+
const toArray = to.split('/')
|
|
54
|
+
const toLayer = toArray[0]; // entities
|
|
55
|
+
const toSlice = toArray[1]; // Article
|
|
56
|
+
|
|
57
|
+
if(!toLayer || !toSlice || !layers[toLayer]) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const normalizedPath = path.toNamespacedPath(from);
|
|
62
|
+
const projectFrom = normalizedPath.split('src')[1];
|
|
63
|
+
const fromArray = projectFrom.split('\\')
|
|
64
|
+
|
|
65
|
+
const fromLayer = fromArray[1];
|
|
66
|
+
const fromSlice = fromArray[2];
|
|
67
|
+
|
|
68
|
+
if(!fromLayer || !fromSlice || !layers[fromLayer]) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return fromSlice === toSlice && toLayer === fromLayer;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'entities/Article/fasfasfas'))
|
|
76
|
+
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'entities/ASdasd/fasfasfas'))
|
|
77
|
+
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'features/Article/fasfasfas'))
|
|
78
|
+
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\features\\Article', 'features/Article/fasfasfas'))
|
|
79
|
+
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'app/index.tsx'))
|
|
80
|
+
// console.log(shouldBeRelative('C:/Users/tim/Desktop/javascript/GOOD_COURSE_test/src/entities/Article', 'entities/Article/asfasf/asfasf'))
|
|
81
|
+
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', '../../model/selectors/getSidebarItems'))
|
|
82
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "eslint-plugin-advanced-app",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "custom plugin for check fsd import",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"eslint",
|
|
7
|
+
"eslintplugin",
|
|
8
|
+
"eslint-plugin"
|
|
9
|
+
],
|
|
10
|
+
"author": "Andrey",
|
|
11
|
+
"main": "./lib/index.js",
|
|
12
|
+
"exports": "./lib/index.js",
|
|
13
|
+
"files": [
|
|
14
|
+
"lib"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"lint": "npm-run-all \"lint:*\"",
|
|
18
|
+
"lint:eslint-docs": "npm-run-all \"update:eslint-docs -- --check\"",
|
|
19
|
+
"lint:js": "eslint .",
|
|
20
|
+
"test": "mocha tests --recursive",
|
|
21
|
+
"update:eslint-docs": "eslint-doc-generator"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"requireindex": "^1.2.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"eslint": "^9.0.0",
|
|
28
|
+
"@eslint/js": "^9.0.0",
|
|
29
|
+
"eslint-doc-generator": "^2.0.0",
|
|
30
|
+
"eslint-plugin-eslint-plugin": "^6.0.0",
|
|
31
|
+
"eslint-plugin-n": "^17.0.0",
|
|
32
|
+
"mocha": "^11.0.0",
|
|
33
|
+
"npm-run-all2": "^6.1.2"
|
|
34
|
+
},
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"eslint": ">=8.57.0"
|
|
40
|
+
},
|
|
41
|
+
"license": "MIT"
|
|
42
|
+
}
|