From 4f99845d7fb4d1508391119452dd43f2224f108c Mon Sep 17 00:00:00 2001 From: Joel Bourbonnais Date: Tue, 12 Apr 2022 09:03:25 -0400 Subject: [PATCH] Added path normalization of '\' to '/' + Prettier --- index.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index d0d3b21..0a7fae6 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -const path = require('path'); +const path = require("path"); function isParentFolder(path) { return path.startsWith("../"); @@ -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"; @@ -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) + ); }, }); } @@ -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) + ); }, }); }