eslint-plugin-laygrd-plugin 0.0.1 → 0.0.3

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 CHANGED
@@ -7,6 +7,9 @@ module.exports = {
7
7
  "plugin:eslint-plugin/recommended",
8
8
  "plugin:node/recommended",
9
9
  ],
10
+ parserOptions: {
11
+ ecmaVersion: '2020'
12
+ },
10
13
  env: {
11
14
  node: true,
12
15
  },
@@ -23,15 +23,27 @@ module.exports = {
23
23
  url: null, // URL to the documentation page for this rule
24
24
  },
25
25
  fixable: null, // Or `code` or `whitespace`
26
- schema: [], // Add a schema if the rule has options
26
+ schema: [
27
+ {
28
+ type: 'object',
29
+ properties: {
30
+ alias: {
31
+ type: 'string'
32
+ }
33
+ }
34
+ }
35
+ ], // Add a schema if the rule has options
27
36
  },
28
37
 
29
38
  create(context) {
39
+ const alias = context.options[0]?.alias || '';
30
40
 
31
41
  return {
32
42
  ImportDeclaration(node) {
43
+ const value = node.source.value;
44
+
33
45
  // import from 'shared/Button/Button' <--- this path
34
- const importSrc = node.source.value;
46
+ const importSrc = alias ? value.replace(`${alias}/`, '') : value;
35
47
 
36
48
  // location of file where current import statement is
37
49
  const currentFileName = context.getFilename();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-laygrd-plugin",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "some usefull fsd violation checkers",
5
5
  "keywords": [
6
6
  "eslint",
@@ -16,16 +16,35 @@ const rule = require("../../../lib/rules/fsd-relative-path"),
16
16
  // Tests
17
17
  //------------------------------------------------------------------------------
18
18
 
19
- const ruleTester = new RuleTester();
19
+ const ruleTester = new RuleTester({
20
+ parserOptions: { ecmaVersion: 6, sourceType: 'module' }
21
+ });
20
22
  ruleTester.run("fsd-relative-path", rule, {
21
23
  valid: [
22
- // give me some code that won't trigger a warning
24
+ {
25
+ filename: 'C:\\Users\\Desctop\\Projects\\blog_app\\src\\entities\\Rating',
26
+ code: "import { RatingCard, RatingCardTheme } from './ui/RatingCard/RatingCard'",
27
+ errors: [],
28
+ },
29
+ {
30
+ filename: 'C:\\Users\\Desctop\\Projects\\blog_app\\src\\features\\ArticleRating\\ui\\ArticleRating\\ArticleRating',
31
+ code: "import { useArticleRating } from '../../api/articleRatingApi'",
32
+ errors: [],
33
+ },
23
34
  ],
24
35
 
25
36
  invalid: [
26
37
  {
27
- code: "",
28
- errors: [{ message: "Fill me in.", type: "Me too" }],
38
+ filename: 'C:\\Users\\Desctop\\Projects\\blog_app\\src\\entities\\Rating',
39
+ code: "import { RatingCard, RatingCardTheme } from '@/entities/Rating/ui/RatingCard/RatingCard'",
40
+ errors: [{ message: "Imports within the same module must be relative, according to FSD. " }],
41
+ options: [{ alias: '@' }]
42
+ },
43
+ {
44
+ filename: 'C:\\Users\\Desctop\\Projects\\blog_app\\src\\features\\ArticleRating\\ui\\ArticleRating\\ArticleRating',
45
+ code: "import { useArticleRating } from '@/features/ArticleRating/api/articleRatingApi'",
46
+ errors: [{ message: "Imports within the same module must be relative, according to FSD. " }],
47
+ options: [{ alias: '@' }]
29
48
  },
30
49
  ],
31
50
  });