Skip to content

Commit

Permalink
fix: dont replace incorrectly for single quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
ljbc1994 committed Jul 30, 2021
1 parent 2a97089 commit b38aa07
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
29 changes: 19 additions & 10 deletions lib/rules/prefer.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,19 +275,28 @@ module.exports = {
const ignoreSingleQuotes =
matches.reduce((all, match) => {
const value = match[0];
let isQuote = false
let isQuote = false;

if (pluginOptions.inputFormat === "all" && isSingleQuote(value)) {
isQuote = true
isQuote = true;
}
if (pluginOptions.inputFormat === "character" && value === MAPPINGS.singleQuote.character) {
isQuote = true
if (
pluginOptions.inputFormat === "character" &&
value === MAPPINGS.singleQuote.character
) {
isQuote = true;
}
if (pluginOptions.inputFormat === "unicode" && value === MAPPINGS.singleQuote.unicode) {
isQuote = true
if (
pluginOptions.inputFormat === "unicode" &&
value === MAPPINGS.singleQuote.unicode
) {
isQuote = true;
}
if (pluginOptions.inputFormat === "alphanumeric" && value === MAPPINGS.singleQuote.alphanumeric) {
isQuote = true
if (
pluginOptions.inputFormat === "alphanumeric" &&
value === MAPPINGS.singleQuote.alphanumeric
) {
isQuote = true;
}

return all + (isQuote ? 1 : 0);
Expand Down Expand Up @@ -340,9 +349,9 @@ module.exports = {

if (isSingleQuote && ignoreSingleQuotes) {
replacement = null;
} else {
seek(characterData.value.length - 1);
}

seek(characterData.value.length - 1);
}

if (replacement) {
Expand Down
28 changes: 28 additions & 0 deletions tests/libs/rules/prefer.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,33 @@ ruleTester.run("smart-quotes", rule, {
},
],
},

{
code: `
<Text>
Uh-uh. You know, with you it&apos;s always, &apos;Me, me, me!&apos; Wll,
guess that! Now it&apos;s my turn! So you just shut up and pay
attention! You&apos;re mean to me. You insult me and you don&apos;t
appreciate anything that I do! You&apos;re always pushing me around
or pushing me away.
</Text>
`,
output: `
<Text>
Uh-uh. You know, with you it&apos;s always, &apos;Me, me, me!&apos; Wll,
guess that! Now it&apos;s my turn! So you just shut up and pay
attention! You&apos;re mean to me. You insult me and you don&apos;t
appreciate anything that I do! You&apos;re always pushing me around
or pushing me away.
</Text>
`,
options: ["all"],
errors: [
{
message: `Strings must use curly quotes.`,
type: "JSXText",
},
],
}
],
});

0 comments on commit b38aa07

Please sign in to comment.