Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prefix on absolute path #12

Closed
richard-lopes-ifood opened this issue Jul 17, 2022 · 2 comments
Closed

Add prefix on absolute path #12

richard-lopes-ifood opened this issue Jul 17, 2022 · 2 comments

Comments

@richard-lopes-ifood
Copy link

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.

@GabriFila
Copy link

This would be very useful 😍

@Danones
Copy link

Danones commented Oct 28, 2022

I was looking to have this feature implemented as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants