eslint-plugin-laygrd-plugin 0.0.1 → 0.0.2
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
|
@@ -23,15 +23,28 @@ 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: [
|
|
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 || '';
|
|
40
|
+
console.log('GIVEN ALIAS:', alias);
|
|
30
41
|
|
|
31
42
|
return {
|
|
32
43
|
ImportDeclaration(node) {
|
|
44
|
+
const value = node.source.value;
|
|
45
|
+
|
|
33
46
|
// import from 'shared/Button/Button' <--- this path
|
|
34
|
-
const importSrc =
|
|
47
|
+
const importSrc = alias ? value.replace(`${alias}/`, '') : value;
|
|
35
48
|
|
|
36
49
|
// location of file where current import statement is
|
|
37
50
|
const currentFileName = context.getFilename();
|
package/package.json
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
28
|
-
|
|
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
|
});
|