eslint-plugin-aetherys-custom-plugin 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/.eslintrc.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ root: true,
5
+ extends: [
6
+ "eslint:recommended",
7
+ "plugin:eslint-plugin/recommended",
8
+ "plugin:node/recommended",
9
+ ],
10
+ env: {
11
+ node: true,
12
+ },
13
+ overrides: [
14
+ {
15
+ files: ["tests/**/*.js"],
16
+ env: { mocha: true },
17
+ },
18
+ ],
19
+ };
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # eslint-plugin-aetherys-custom-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-aetherys-custom-plugin`:
14
+
15
+ ```sh
16
+ npm install eslint-plugin-aetherys-custom-plugin --save-dev
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ Add `aetherys-custom-plugin` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
22
+
23
+ ```json
24
+ {
25
+ "plugins": ["aetherys-custom-plugin"]
26
+ }
27
+ ```
28
+
29
+ Then configure the rules you want to use under the rules section.
30
+
31
+ ```json
32
+ {
33
+ "rules": {
34
+ "aetherys-custom-plugin/rule-name": 2
35
+ }
36
+ }
37
+ ```
38
+
39
+ ## Supported Rules
40
+
41
+ - Fill in provided rules here
@@ -0,0 +1,35 @@
1
+ # feature sliced relative path checker (path-checker)
2
+
3
+ Please describe the origin of the rule here.
4
+
5
+ ## Rule Details
6
+
7
+ This rule aims to...
8
+
9
+ Examples of **incorrect** code for this rule:
10
+
11
+ ```js
12
+
13
+ // fill me in
14
+
15
+ ```
16
+
17
+ Examples of **correct** code for this rule:
18
+
19
+ ```js
20
+
21
+ // fill me in
22
+
23
+ ```
24
+
25
+ ### Options
26
+
27
+ If there are any options, describe them here. Otherwise, delete this section.
28
+
29
+ ## When Not To Use It
30
+
31
+ Give a short description of when it would be appropriate to turn off this rule.
32
+
33
+ ## Further Reading
34
+
35
+ If there are other links that describe the issue this rule addresses, please include them here in a bulleted list.
package/lib/index.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @fileoverview plugin for production project
3
+ * @author aetherys
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,84 @@
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: "feature sliced relative path checker",
10
+ category: "Fill me in",
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\user\Desktop\prod\advanced-react\src\entities\Article
25
+ const fromFilename = context.getFilename();
26
+
27
+ if (shouldBeRelative(fromFilename, importTo)) {
28
+ context.report(
29
+ node,
30
+ "В рамках одного слайса все пути должны быть относительными",
31
+ );
32
+ }
33
+ },
34
+ };
35
+ },
36
+ };
37
+
38
+ function isPathRelative(path) {
39
+ return path === "." || path.startsWith("./") || path.startsWith("../");
40
+ }
41
+
42
+ const layers = {
43
+ entities: "entities",
44
+ features: "features",
45
+ shared: "shared",
46
+ pages: "pages",
47
+ widgets: "widgets",
48
+ };
49
+
50
+ function shouldBeRelative(from, to) {
51
+ if (isPathRelative(to)) {
52
+ return false;
53
+ }
54
+
55
+ // example entities/Article
56
+ const toArray = to.split("/");
57
+ const toLayer = toArray[0]; // entities
58
+ const toSlice = toArray[1]; // Article
59
+
60
+ if (!toLayer || !toSlice || !layers[toLayer]) {
61
+ return false;
62
+ }
63
+
64
+ const normalizedPath = path.toNamespacedPath(from);
65
+ const projectFrom = normalizedPath.split("src")[1];
66
+ const fromArray = projectFrom.split("\\");
67
+
68
+ const fromLayer = fromArray[1];
69
+ const fromSlice = fromArray[2];
70
+
71
+ if (!fromLayer || !fromSlice || !layers[fromLayer]) {
72
+ return false;
73
+ }
74
+
75
+ return fromSlice === toSlice && toLayer === fromLayer;
76
+ }
77
+
78
+ // console.log(shouldBeRelative('C:\\Users\\user\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'entities/Article/fasfasfas'))
79
+ // console.log(shouldBeRelative('C:\\Users\\user\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'entities/ASdasd/fasfasfas'))
80
+ // console.log(shouldBeRelative('C:\\Users\\user\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'features/Article/fasfasfas'))
81
+ // console.log(shouldBeRelative('C:\\Users\\user\\Desktop\\javascript\\GOOD_COURSE_test\\src\\features\\Article', 'features/Article/fasfasfas'))
82
+ // console.log(shouldBeRelative('C:\\Users\\user\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'app/index.tsx'))
83
+ // console.log(shouldBeRelative('C:/Users/user/Desktop/javascript/GOOD_COURSE_test/src/entities/Article', 'entities/Article/asfasf/asfasf'))
84
+ // console.log(shouldBeRelative('C:\\Users\\user\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', '../../model/selectors/getSidebarItems'))
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "eslint-plugin-aetherys-custom-plugin",
3
+ "version": "0.0.1",
4
+ "description": "plugin for production project",
5
+ "keywords": [
6
+ "eslint",
7
+ "eslintplugin",
8
+ "eslint-plugin"
9
+ ],
10
+ "author": "aetherys",
11
+ "main": "lib/index.js",
12
+ "scripts": {
13
+ "lint": "eslint .",
14
+ "test": "mocha tests --recursive"
15
+ },
16
+ "dependencies": {
17
+ "requireindex": "^1.2.0"
18
+ },
19
+ "devDependencies": {
20
+ "eslint": "^8.0.1",
21
+ "eslint-plugin-eslint-plugin": "^4.0.1",
22
+ "eslint-plugin-node": "^11.1.0",
23
+ "mocha": "^9.1.3"
24
+ },
25
+ "engines": {
26
+ "node": "12.x || 14.x || >= 16"
27
+ },
28
+ "peerDependencies": {
29
+ "eslint": ">=6"
30
+ },
31
+ "license": "ISC"
32
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @fileoverview feature sliced relative path checker
3
+ * @author aetherys
4
+ */
5
+ "use strict";
6
+
7
+ //------------------------------------------------------------------------------
8
+ // Requirements
9
+ //------------------------------------------------------------------------------
10
+
11
+ const rule = require("../../../lib/rules/path-checker"),
12
+ RuleTester = require("eslint").RuleTester;
13
+
14
+ //------------------------------------------------------------------------------
15
+ // Tests
16
+ //------------------------------------------------------------------------------
17
+
18
+ const ruleTester = new RuleTester();
19
+ ruleTester.run("path-checker", rule, {
20
+ valid: [
21
+ // give me some code that won't trigger a warning
22
+ ],
23
+
24
+ invalid: [
25
+ {
26
+ code: "asfsa",
27
+ errors: [{ message: "Fill me in.", type: "Me too" }],
28
+ },
29
+ ],
30
+ });