Skip to content

Commit 0f948fe

Browse files
authored
Merge pull request #43 from vitonsky/29-use-consistent-quotes
feat: preserve quote style
2 parents 00e4fb9 + 6699938 commit 0f948fe

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/rules/alias.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,12 @@ tester.run('paths-alias', rule, {
6464
errors: ['Update import to @bar/x/y/z'],
6565
output: `import z from '@bar/x/y/z';`,
6666
},
67+
{
68+
name: 'quotes style for string must be preserved for any fix',
69+
filename: path.resolve('./src/index.ts'),
70+
code: `import z from "./foo/x/y/z";`,
71+
errors: ['Update import to @foo/x/y/z'],
72+
output: `import z from "@foo/x/y/z";`,
73+
},
6774
],
6875
});

src/rules/alias.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,14 @@ const rule: Rule.RuleModule = {
129129
node,
130130
message: `Update import to ${replacement}`,
131131
fix(fixer) {
132-
// TODO: preserve quotes
133-
const quote = `'`;
132+
const acceptableQuoteSymbols = [`'`, `"`];
133+
const originalStringQuote = node.source.raw?.slice(0, 1);
134+
const quote =
135+
originalStringQuote &&
136+
acceptableQuoteSymbols.includes(originalStringQuote)
137+
? originalStringQuote
138+
: acceptableQuoteSymbols[0];
139+
134140
return fixer.replaceText(
135141
node.source,
136142
quote + replacement + quote,

0 commit comments

Comments
 (0)