eslint-plugin-fsd-paths-check 0.0.13 → 0.0.14
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/lib/helpers/getNormalizedProjectPath.js +12 -0
- package/lib/helpers/isSameModuleImport.js +2 -2
- package/lib/rules/enforce-public-api-imports.js +0 -1
- package/lib/rules/enforce-relative-path-within-slice.js +2 -5
- package/lib/rules/forbid-imports-from-upper-slices.js +3 -3
- package/package.json +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const {toNamespacedPath} = require("path");
|
|
2
|
+
|
|
3
|
+
function getNormalizedProjectPath(fullPath) {
|
|
4
|
+
const fromNamespaced = toNamespacedPath(fullPath);
|
|
5
|
+
const fromNormalized = fromNamespaced.split(`\\`).join(`/`);
|
|
6
|
+
|
|
7
|
+
return fromNormalized.split(`src/`)[1];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
getNormalizedProjectPath
|
|
12
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const { isPathRelative } = require("./isPathRelative");
|
|
2
2
|
const path = require("path");
|
|
3
|
+
const { getNormalizedProjectPath } = require("./getNormalizedProjectPath");
|
|
3
4
|
|
|
4
5
|
function isSameModuleImport(from, to, fsdLayers, noSlicesLayers) {
|
|
5
6
|
if(isPathRelative(to)) {
|
|
@@ -15,8 +16,7 @@ function isSameModuleImport(from, to, fsdLayers, noSlicesLayers) {
|
|
|
15
16
|
return false;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
const
|
|
19
|
-
const fromProject = fromNormalized.split(`src/`)[1];
|
|
19
|
+
const fromProject = getNormalizedProjectPath(from)
|
|
20
20
|
|
|
21
21
|
if(!fromProject) {
|
|
22
22
|
return false;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const { isSameModuleImport } = require("../helpers/isSameModuleImport");
|
|
5
|
+
const { getNormalizedProjectPath } = require("../helpers/getNormalizedProjectPath");
|
|
5
6
|
|
|
6
7
|
const fsdLayers = {
|
|
7
8
|
'shared': 'shared',
|
|
@@ -62,7 +63,7 @@ const importExportDeclaration = (context) => (node) => {
|
|
|
62
63
|
node,
|
|
63
64
|
messageId: `useRelativePathWithinSlice`,
|
|
64
65
|
fix(fixer) {
|
|
65
|
-
const projectFromPath =
|
|
66
|
+
const projectFromPath = getNormalizedProjectPath(currentFile);
|
|
66
67
|
const currentDir = path.dirname(projectFromPath);
|
|
67
68
|
const relativePath = path.relative(currentDir, pathTo);
|
|
68
69
|
const finalRelativePath = relativePath.startsWith(`.`) ? relativePath : `./${relativePath}`;
|
|
@@ -73,8 +74,4 @@ const importExportDeclaration = (context) => (node) => {
|
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
function getProjectPath(fullPath) {
|
|
77
|
-
const fromNormalized = path.toNamespacedPath(fullPath);
|
|
78
77
|
|
|
79
|
-
return fromNormalized.split(`src/`)[1];
|
|
80
|
-
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const {isPathRelative} = require("../helpers/isPathRelative");
|
|
5
5
|
const micromatch = require("micromatch");
|
|
6
|
+
const {getNormalizedProjectPath} = require("../helpers/getNormalizedProjectPath");
|
|
6
7
|
|
|
7
8
|
const fsdLayers = {
|
|
8
9
|
'shared': 'shared',
|
|
@@ -61,11 +62,10 @@ const importExportDeclaration = (context) => (node) => {
|
|
|
61
62
|
const { alias = '', ignoreImportPatterns = [] } = context.options[0] ?? {};
|
|
62
63
|
|
|
63
64
|
const getCurrentFileLayer = (currentFilePath) => {
|
|
64
|
-
const
|
|
65
|
-
const projectPath = normalizedPath?.split('src')[1];
|
|
65
|
+
const projectPath = getNormalizedProjectPath(currentFilePath)
|
|
66
66
|
const segments = projectPath?.split('/');
|
|
67
67
|
|
|
68
|
-
return segments?.[
|
|
68
|
+
return segments?.[0];
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
const getImportLayer = (value) => {
|