Skip to content

Commit

Permalink
fix(keep-sorted): support literal key in object
Browse files Browse the repository at this point in the history
  • Loading branch information
hyoban committed Apr 30, 2024
1 parent 90d4e40 commit b13e945
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/commands/keep-sorted.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,44 @@ run(
}`,
errors: ['command-fix'],
},
// Some object property keys are string
{
code: d`
// @keep-sorted
export const obj = {
foo,
'bar': () => {},
apple: 1,
}`,
output: d`
// @keep-sorted
export const obj = {
'bar': () => {},
apple: 1,
foo,
}`,
errors: ['command-fix'],
},
// All object property keys are string
{
code: d`
// @keep-sorted
export const rules = {
'block-scoped-var': 'error',
'array-callback-return': 'error',
'constructor-super': 'error',
'default-case-last': 'error',
}`,
output: d`
// @keep-sorted
export const rules = {
'array-callback-return': 'error',
'block-scoped-var': 'error',
'constructor-super': 'error',
'default-case-last': 'error',
}`,
errors: ['command-fix'],
},
// Array elements
{
code: d`
Expand Down
2 changes: 2 additions & 0 deletions src/commands/keep-sorted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export const keepSorted: Command = {
(prop) => {
if (prop.type === 'Property' && prop.key.type === 'Identifier')
return prop.key.name
if (prop.type === 'Property' && prop.key.type === 'Literal')
return prop.key.raw
return null
},
)
Expand Down

0 comments on commit b13e945

Please sign in to comment.