eslint-plugin-no-relative-import-paths
eslint-plugin-no-relative-import-paths copied to clipboard
Add prefix on absolute path
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch [email protected]
for the project I'm working on.
Here is the diff that solved my problem:
diff --git a/node_modules/eslint-plugin-no-relative-import-paths/index.js b/node_modules/eslint-plugin-no-relative-import-paths/index.js
index 430fb5e..c13444e 100644
--- a/node_modules/eslint-plugin-no-relative-import-paths/index.js
+++ b/node_modules/eslint-plugin-no-relative-import-paths/index.js
@@ -15,14 +15,15 @@ function isSameFolder(path) {
return path.startsWith("./");
}
-function getAbsolutePath(relativePath, context, rootDir) {
- return path
- .relative(
+function getAbsolutePath(relativePath, context, rootDir, prefix) {
+ return [
+ prefix,
+ ...path.relative(
context.getCwd() + (rootDir !== '' ? path.sep + rootDir : ''),
path.join(path.dirname(context.getFilename()), relativePath)
)
.split(path.sep)
- .join("/");
+ ].join("/");``
}
const message = "import statements should have an absolute path";
@@ -35,9 +36,10 @@ module.exports = {
fixable: "code",
},
create: function (context) {
- const { allowSameFolder, rootDir } = {
+ const { allowSameFolder, rootDir, prefix } = {
allowSameFolder: context.options[0].allowSameFolder || false,
rootDir: context.options[0].rootDir || '',
+ prefix: context.options[0].prefix || '',
};
return {
@@ -50,7 +52,7 @@ module.exports = {
fix: function (fixer) {
return fixer.replaceTextRange(
[node.source.range[0] + 1, node.source.range[1] - 1],
- getAbsolutePath(path, context, rootDir || '')
+ getAbsolutePath(path, context, rootDir || '', prefix)
);
},
});
@@ -63,7 +65,7 @@ module.exports = {
fix: function (fixer) {
return fixer.replaceTextRange(
[node.source.range[0] + 1, node.source.range[1] - 1],
- getAbsolutePath(path, context, rootDir || '')
+ getAbsolutePath(path, context, rootDir || '', prefix)
);
},
});
This issue body was partially generated by patch-package.
This would be very useful 😍
I was looking to have this feature implemented as well.