Skip to content

Commit

Permalink
fix: use name to sort method property (#497)
Browse files Browse the repository at this point in the history
this fix potential wrong result due to comments.
  • Loading branch information
imdreamrunner committed Aug 31, 2021
1 parent b038886 commit 4265b27
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/rules/sortKeys.js
Expand Up @@ -57,7 +57,7 @@ const generateOrderedList = (context, sort, properties) => {
});
const text = source.getText().slice(startIndex, beforePunctuator.range[1]);

return [property, text];
return [property, name, text];
}

const colonToken = source.getTokenBefore(property.value, {
Expand Down Expand Up @@ -123,8 +123,8 @@ const generateOrderedList = (context, sort, properties) => {
});
}
orderedList.push(...itemGroup.map((item) => {
if (item.length === 2) {
return item[1];
if (item.length === 3) {
return item[2];
}

return item[2] + ':' + item[3];
Expand Down
23 changes: 23 additions & 0 deletions tests/rules/assertions/sortKeys.js
Expand Up @@ -557,6 +557,29 @@ export default {
}
`,
},
{
code: `
type FooType = {
/* preserves block comment before a */
a: number | string | boolean,
/* preserves block comment before c */
c: number,
/* preserves block comment before b */
b(param: string): number,
}
`,
errors: [{message: 'Expected type annotations to be in ascending order. "b" should be before "c".'}],
output: `
type FooType = {
/* preserves block comment before a */
a: number | string | boolean,
/* preserves block comment before b */
b(param: string): number,
/* preserves block comment before c */
c: number,
}
`,
},

// https://github.com/gajus/eslint-plugin-flowtype/issues/493
{
Expand Down

0 comments on commit 4265b27

Please sign in to comment.