Skip to content

Commit

Permalink
fix: ignore string quotes in sort-array-includes rule
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Jul 30, 2023
1 parent f4a0e25 commit ec2e2f5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 30 deletions.
2 changes: 1 addition & 1 deletion rules/sort-array-includes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
accumulator.at(0)!.push({
name:
element.type === AST_NODE_TYPES.Literal
? element.raw
? `${element.value}`
: source.text.slice(...element.range),
size: rangeToDiff(element.range),
type: element.type,
Expand Down
69 changes: 40 additions & 29 deletions test/sort-array-includes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe(RULE_NAME, () => {
{
messageId: 'unexpectedArrayIncludesOrder',
data: {
left: "'Cart Titan'",
left: 'Cart Titan',
right: '...otherTitans',
},
},
Expand Down Expand Up @@ -165,8 +165,8 @@ describe(RULE_NAME, () => {
{
messageId: 'unexpectedArrayIncludesOrder',
data: {
left: "'Genos'",
right: "'Bang'",
left: 'Genos',
right: 'Bang',
},
},
],
Expand Down Expand Up @@ -211,7 +211,7 @@ describe(RULE_NAME, () => {
messageId: 'unexpectedArrayIncludesOrder',
data: {
left: '...graceFieldOrphans',
right: "'Norman'",
right: 'Norman',
},
},
],
Expand Down Expand Up @@ -268,8 +268,8 @@ describe(RULE_NAME, () => {
{
messageId: 'unexpectedArrayIncludesOrder',
data: {
left: "'Sonozaki Shion'",
right: "'Maebara Keiichi'",
left: 'Sonozaki Shion',
right: 'Maebara Keiichi',
},
},
],
Expand All @@ -288,12 +288,12 @@ describe(RULE_NAME, () => {
{
code: dedent`
[
...otherTitans,
'Armored Titan',
'Attack Titan',
'Beast Titan',
'Cart Titan',
'War Hammer Titan',
...otherTitans,
].includes(titan)
`,
options: [
Expand All @@ -318,12 +318,12 @@ describe(RULE_NAME, () => {
`,
output: dedent`
[
...otherTitans,
'Armored Titan',
'Attack Titan',
'Beast Titan',
'Cart Titan',
'War Hammer Titan',
...otherTitans,
].includes(titan)
`,
options: [
Expand All @@ -336,8 +336,8 @@ describe(RULE_NAME, () => {
{
messageId: 'unexpectedArrayIncludesOrder',
data: {
left: '...otherTitans',
right: "'Beast Titan'",
left: 'Cart Titan',
right: '...otherTitans',
},
},
],
Expand Down Expand Up @@ -434,8 +434,8 @@ describe(RULE_NAME, () => {
{
messageId: 'unexpectedArrayIncludesOrder',
data: {
left: "'Genos'",
right: "'Bang'",
left: 'Genos',
right: 'Bang',
},
},
],
Expand Down Expand Up @@ -480,7 +480,7 @@ describe(RULE_NAME, () => {
messageId: 'unexpectedArrayIncludesOrder',
data: {
left: '...graceFieldOrphans',
right: "'Norman'",
right: 'Norman',
},
},
],
Expand Down Expand Up @@ -537,8 +537,8 @@ describe(RULE_NAME, () => {
{
messageId: 'unexpectedArrayIncludesOrder',
data: {
left: "'Sonozaki Shion'",
right: "'Maebara Keiichi'",
left: 'Sonozaki Shion',
right: 'Maebara Keiichi',
},
},
],
Expand Down Expand Up @@ -605,15 +605,15 @@ describe(RULE_NAME, () => {
{
messageId: 'unexpectedArrayIncludesOrder',
data: {
left: "'Cart Titan'",
left: 'Cart Titan',
right: '...otherTitans',
},
},
{
messageId: 'unexpectedArrayIncludesOrder',
data: {
left: "'Beast Titan'",
right: "'War Hammer Titan'",
left: 'Beast Titan',
right: 'War Hammer Titan',
},
},
],
Expand Down Expand Up @@ -710,8 +710,8 @@ describe(RULE_NAME, () => {
{
messageId: 'unexpectedArrayIncludesOrder',
data: {
left: "'King'",
right: "'Saitama'",
left: 'King',
right: 'Saitama',
},
},
],
Expand Down Expand Up @@ -756,7 +756,7 @@ describe(RULE_NAME, () => {
messageId: 'unexpectedArrayIncludesOrder',
data: {
left: '...graceFieldOrphans',
right: "'Norman'",
right: 'Norman',
},
},
],
Expand Down Expand Up @@ -813,15 +813,15 @@ describe(RULE_NAME, () => {
{
messageId: 'unexpectedArrayIncludesOrder',
data: {
left: "'Ryūgū Rena'",
right: "'Sonozaki Shion'",
left: 'Ryūgū Rena',
right: 'Sonozaki Shion',
},
},
{
messageId: 'unexpectedArrayIncludesOrder',
data: {
left: "'Sonozaki Shion'",
right: "'Maebara Keiichi'",
left: 'Sonozaki Shion',
right: 'Maebara Keiichi',
},
},
],
Expand Down Expand Up @@ -877,15 +877,15 @@ describe(RULE_NAME, () => {
{
messageId: 'unexpectedArrayIncludesOrder',
data: {
left: "'Shusei Kagari'",
right: "'Akane Tsunemori'",
left: 'Shusei Kagari',
right: 'Akane Tsunemori',
},
},
{
messageId: 'unexpectedArrayIncludesOrder',
data: {
left: "'Tomomi Masaoka'",
right: "'Nobuchika Ginoza'",
left: 'Tomomi Masaoka',
right: 'Nobuchika Ginoza',
},
},
],
Expand All @@ -900,5 +900,16 @@ describe(RULE_NAME, () => {
invalid: [],
})
})

it(`${RULE_NAME}: ignores quotes of strings`, () => {
ruleTester.run(RULE_NAME, rule, {
valid: [
dedent`
['Burger King', "McDonald's", 'Subway'].includes(name)
`,
],
invalid: [],
})
})
})
})

0 comments on commit ec2e2f5

Please sign in to comment.