Skip to content

Commit

Permalink
Merge pull request #5 from joelbourbon/fix-backslash-windows
Browse files Browse the repository at this point in the history
Added path normalization of '\' to '/' + Prettier
  • Loading branch information
MelvinVermeer authored Apr 19, 2022
2 parents 9d445a4 + 4f99845 commit a576242
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const path = require('path');
const path = require("path");

function isParentFolder(path) {
return path.startsWith("../");
Expand All @@ -9,7 +9,13 @@ function isSameFolder(path) {
}

function getAbsolutePath(relativePath, context) {
return path.relative(context.getCwd(), path.join(path.dirname(context.getFilename()), relativePath));
return path
.relative(
context.getCwd(),
path.join(path.dirname(context.getFilename()), relativePath)
)
.split(path.sep)
.join("/");
}

const message = "import statements should have an absolute path";
Expand All @@ -32,7 +38,10 @@ module.exports = {
node,
message: message,
fix: function (fixer) {
return fixer.replaceTextRange([node.source.range[0] + 1, node.source.range[1] - 1], getAbsolutePath(path, context));
return fixer.replaceTextRange(
[node.source.range[0] + 1, node.source.range[1] - 1],
getAbsolutePath(path, context)
);
},
});
}
Expand All @@ -42,7 +51,10 @@ module.exports = {
node,
message: message,
fix: function (fixer) {
return fixer.replaceTextRange([node.source.range[0] + 1, node.source.range[1] - 1], getAbsolutePath(path, context));
return fixer.replaceTextRange(
[node.source.range[0] + 1, node.source.range[1] - 1],
getAbsolutePath(path, context)
);
},
});
}
Expand Down

0 comments on commit a576242

Please sign in to comment.