eslint-plugin-fsd-paths-check 0.0.6 → 0.0.7

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.
@@ -27,32 +27,35 @@ module.exports = {
27
27
  },
28
28
 
29
29
  create(context) {
30
- const alias = context.options[0]?.alias ?? ``;
31
30
  return {
32
- ImportDeclaration(node) {
33
- const value = node.source.value;
34
- const importTo = alias ? value.replace(`${alias}`, ``) : value;
35
- const currentFile = context.getFilename();
36
-
37
- if(shouldBeRelative(currentFile, importTo)) {
38
- context.report({
39
- node,
40
- messageId: `useRelativePathWithinSlice`,
41
- fix(fixer) {
42
- const projectFromPath = getProjectPath(currentFile);
43
- const currentDir = path.dirname(projectFromPath);
44
- const relativePath = path.relative(currentDir, importTo);
45
- const finalRelativePath = relativePath.startsWith(`.`) ? relativePath : `./${relativePath}`;
46
-
47
- return fixer.replaceText(node.source, `'${finalRelativePath}'`);
48
- }
49
- });
50
- }
51
- }
31
+ ImportDeclaration: importExportDeclaration(context),
32
+ ExportNamedDeclaration: importExportDeclaration(context),
52
33
  };
53
34
  },
54
35
  };
55
36
 
37
+ const importExportDeclaration = (context) => (node) => {
38
+ const alias = context.options[0]?.alias ?? ``;
39
+ const value = node.source.value;
40
+ const pathTo = alias ? value.replace(`${alias}`, ``) : value;
41
+ const currentFile = context.getFilename();
42
+
43
+ if(shouldBeRelative(currentFile, pathTo)) {
44
+ context.report({
45
+ node,
46
+ messageId: `useRelativePathWithinSlice`,
47
+ fix(fixer) {
48
+ const projectFromPath = getProjectPath(currentFile);
49
+ const currentDir = path.dirname(projectFromPath);
50
+ const relativePath = path.relative(currentDir, pathTo);
51
+ const finalRelativePath = relativePath.startsWith(`.`) ? relativePath : `./${relativePath}`;
52
+
53
+ return fixer.replaceText(node.source, `'${finalRelativePath}'`);
54
+ }
55
+ });
56
+ }
57
+ }
58
+
56
59
  const fsdLayers = {
57
60
  'shared': 'shared',
58
61
  'entities': 'entities',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-fsd-paths-check",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Plugin to check feature sliced design paths correctness",
5
5
  "keywords": [
6
6
  "eslint",