eslint-plugin-gapone-plugin 0.0.8
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 +68 -0
- package/lib/helpers/index.js +7 -0
- package/lib/index.js +18 -0
- package/lib/rules/path-cheker.js +96 -0
- package/lib/rules/public-api-imports.js +67 -0
- package/package.json +42 -0
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# eslint-plugin-max-plugin
|
|
2
|
+
|
|
3
|
+
plugin for production project
|
|
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-max-plugin-path-checker`:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install eslint-plugin-max-plugin-path-checker --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-max-plugin` and add `max-plugin` to the `plugins` key:
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
import { defineConfig } from "eslint/config";
|
|
25
|
+
import max-plugin from "eslint-plugin-max-plugin";
|
|
26
|
+
|
|
27
|
+
export default defineConfig([
|
|
28
|
+
{
|
|
29
|
+
plugins: {
|
|
30
|
+
max-plugin
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
]);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Then configure the rules you want to use under the `rules` key.
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
import { defineConfig } from "eslint/config";
|
|
40
|
+
import max-plugin from "eslint-plugin-max-plugin";
|
|
41
|
+
|
|
42
|
+
export default defineConfig([
|
|
43
|
+
{
|
|
44
|
+
plugins: {
|
|
45
|
+
max-plugin
|
|
46
|
+
},
|
|
47
|
+
rules: {
|
|
48
|
+
"max-plugin/rule-name": "warn"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
]);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Configurations
|
|
55
|
+
|
|
56
|
+
<!-- begin auto-generated configs list -->
|
|
57
|
+
|
|
58
|
+
TODO: Run eslint-doc-generator to generate the configs list (or delete this section if no configs are offered).
|
|
59
|
+
|
|
60
|
+
<!-- end auto-generated configs list -->
|
|
61
|
+
|
|
62
|
+
## Rules
|
|
63
|
+
|
|
64
|
+
<!-- begin auto-generated rules list -->
|
|
65
|
+
|
|
66
|
+
TODO: Run eslint-doc-generator to generate the rules list.
|
|
67
|
+
|
|
68
|
+
<!-- end auto-generated rules list -->
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview plugin for production project
|
|
3
|
+
* @author max
|
|
4
|
+
*/
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
//------------------------------------------------------------------------------
|
|
8
|
+
// Requirements
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
const requireIndex = require('requireindex');
|
|
12
|
+
|
|
13
|
+
//------------------------------------------------------------------------------
|
|
14
|
+
// Plugin Definition
|
|
15
|
+
//------------------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
// import all rules in lib/rules
|
|
18
|
+
module.exports.rules = requireIndex(__dirname + '/rules');
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { isPathRelative } = require('../helpers');
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
meta: {
|
|
7
|
+
type: 'problem', // `problem`, `suggestion`, or `layout`
|
|
8
|
+
docs: {
|
|
9
|
+
description: 'feature sliced relative path cheker',
|
|
10
|
+
recommended: false,
|
|
11
|
+
url: null, // URL to the documentation page for this rule
|
|
12
|
+
},
|
|
13
|
+
fixable: null, // Or `code` or `whitespace`
|
|
14
|
+
schema: [
|
|
15
|
+
{
|
|
16
|
+
type: 'object',
|
|
17
|
+
properties: {
|
|
18
|
+
alias: {
|
|
19
|
+
type: 'string',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
], // Add a schema if the rule has options
|
|
24
|
+
messages: {
|
|
25
|
+
invalidPath:
|
|
26
|
+
'В рамках одного слайса все пути должны быть относительными',
|
|
27
|
+
}, // Add messageId and message
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
create(context) {
|
|
31
|
+
const alias = context.options[0]?.alias || '';
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
ImportDeclaration(node) {
|
|
35
|
+
// "Example" app/entities/Article
|
|
36
|
+
const value = node.source.value;
|
|
37
|
+
const importTo = alias ? value.replace(`${alias}/`, '') : value;
|
|
38
|
+
|
|
39
|
+
// "Example" D:\frontEnd\full-case\src\entities/Article
|
|
40
|
+
const fromFilename = context.getFilename();
|
|
41
|
+
|
|
42
|
+
if (shouldBeRelation(fromFilename, importTo)) {
|
|
43
|
+
context.report({
|
|
44
|
+
node,
|
|
45
|
+
messageId: 'invalidPath',
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const layers = {
|
|
54
|
+
entities: 'entities',
|
|
55
|
+
features: 'features',
|
|
56
|
+
shared: 'shared',
|
|
57
|
+
pages: 'pages',
|
|
58
|
+
widgets: 'widgets',
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
function shouldBeRelation(from, to) {
|
|
62
|
+
if (isPathRelative(to)) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// "Example" app/entities/Article
|
|
67
|
+
const toArray = to.split('/');
|
|
68
|
+
const toLayer = toArray[0]; // entities (СЛОЙ)
|
|
69
|
+
const toSlice = toArray[1]; // Article (СЛАЙС)
|
|
70
|
+
|
|
71
|
+
if (!toLayer || !toSlice || !layers[toLayer]) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const normalizedPath = path.toNamespacedPath(from);
|
|
76
|
+
const projectFrom = normalizedPath.split('src')[1];
|
|
77
|
+
const fromArray = projectFrom.split('\\');
|
|
78
|
+
console.log(fromArray);
|
|
79
|
+
|
|
80
|
+
const fromLayer = fromArray[1];
|
|
81
|
+
const fromSlice = fromArray[2];
|
|
82
|
+
|
|
83
|
+
if (!fromLayer || !fromSlice || !layers[fromLayer]) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return fromSlice == toSlice && toLayer === fromLayer;
|
|
88
|
+
// "Example" D:\frontEnd\full-case\src\entities/Article
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// console.log(
|
|
92
|
+
// shouldBeRelation(
|
|
93
|
+
// 'D:\\frontEnd\\full-case\\src\\entities\\Article\\index.tsx',
|
|
94
|
+
// 'entities/Article'
|
|
95
|
+
// )
|
|
96
|
+
// );
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const { isPathRelative } = require('../helpers');
|
|
2
|
+
|
|
3
|
+
/** @type {import('eslint').Rule.RuleModule} */
|
|
4
|
+
module.exports = {
|
|
5
|
+
meta: {
|
|
6
|
+
type: 'problem', // `problem`, `suggestion`, or `layout`
|
|
7
|
+
docs: {
|
|
8
|
+
description: 'desc',
|
|
9
|
+
recommended: false,
|
|
10
|
+
url: null, // URL to the documentation page for this rule
|
|
11
|
+
},
|
|
12
|
+
fixable: null, // Or `code` or `whitespace`
|
|
13
|
+
schema: [
|
|
14
|
+
{
|
|
15
|
+
type: 'object',
|
|
16
|
+
properties: {
|
|
17
|
+
alias: {
|
|
18
|
+
type: 'string',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
], // Add a schema if the rule has options
|
|
23
|
+
messages: {
|
|
24
|
+
noPublicApiImports:
|
|
25
|
+
'Абсолютный импорт разрешен только из Public Api (index.ts)',
|
|
26
|
+
}, // Add messageId and message
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
create(context) {
|
|
30
|
+
const alias = context.options[0]?.alias || '';
|
|
31
|
+
|
|
32
|
+
const checkingLayers = {
|
|
33
|
+
entities: 'entities',
|
|
34
|
+
features: 'features',
|
|
35
|
+
pages: 'pages',
|
|
36
|
+
widgets: 'widgets',
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
ImportDeclaration(node) {
|
|
41
|
+
const value = node.source.value;
|
|
42
|
+
const importTo = alias ? value.replace(`${alias}/`, '') : value;
|
|
43
|
+
|
|
44
|
+
if (isPathRelative(importTo)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const segments = importTo.split('/');
|
|
49
|
+
|
|
50
|
+
const layer = segments[0];
|
|
51
|
+
|
|
52
|
+
if (!checkingLayers[layer]) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const isImportNotFromPublickApi = segments.length > 2;
|
|
57
|
+
|
|
58
|
+
if (isImportNotFromPublickApi) {
|
|
59
|
+
context.report({
|
|
60
|
+
node,
|
|
61
|
+
messageId: 'noPublicApiImports',
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "eslint-plugin-gapone-plugin",
|
|
3
|
+
"version": "0.0.8",
|
|
4
|
+
"description": "plugin for production project",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"eslint",
|
|
7
|
+
"eslintplugin",
|
|
8
|
+
"eslint-plugin"
|
|
9
|
+
],
|
|
10
|
+
"author": "max",
|
|
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
|
+
}
|