Skip to content

Commit

Permalink
fix: support exact types in sort-keys (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
Geraint White committed Aug 27, 2021
1 parent d7abd9f commit b038886
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/rules/sortKeys.js
Expand Up @@ -49,7 +49,7 @@ const generateOrderedList = (context, sort, properties) => {
// Maintain everything between the start of property including leading comments and the nextPunctuator `,` or `}`:
const nextPunctuator = source.getTokenAfter(property, {
filter: (token) => {
return token.type === 'Punctuator';
return token.type === 'Punctuator' || token.value === '|}';
},
});
const beforePunctuator = source.getTokenBefore(nextPunctuator, {
Expand Down Expand Up @@ -80,7 +80,7 @@ const generateOrderedList = (context, sort, properties) => {
// Maintain everything between the `:` and the next Punctuator `,` or `}`:
const nextPunctuator = source.getTokenAfter(property, {
filter: (token) => {
return token.type === 'Punctuator';
return token.type === 'Punctuator' || token.value === '|}';
},
});
const beforePunctuator = source.getTokenBefore(nextPunctuator, {
Expand Down Expand Up @@ -149,7 +149,7 @@ const generateFix = (node, context, sort) => {
node.properties.forEach((property, index) => {
const nextPunctuator = source.getTokenAfter(property, {
filter: (token) => {
return token.type === 'Punctuator';
return token.type === 'Punctuator' || token.value === '|}';
},
});
const beforePunctuator = source.getTokenBefore(nextPunctuator, {
Expand Down
42 changes: 42 additions & 0 deletions tests/rules/assertions/sortKeys.js
Expand Up @@ -557,6 +557,48 @@ export default {
}
`,
},

// https://github.com/gajus/eslint-plugin-flowtype/issues/493
{
code: `
export type GroupOrdersResponseType = {|
isSuccess: boolean,
code: number,
message?: string,
errorMessage: string,
result: {|
OrderNumber: string,
Orders: GroupOrderSummaryType[],
PlacedOn: string,
Status: string,
ReturnText: string,
IncludesLegacyOrder: boolean
|}
|};
`,
errors: [
{message: 'Expected type annotations to be in ascending order. "code" should be before "isSuccess".'},
{message: 'Expected type annotations to be in ascending order. "errorMessage" should be before "message".'},
{message: 'Expected type annotations to be in ascending order. "ReturnText" should be before "Status".'},
{message: 'Expected type annotations to be in ascending order. "IncludesLegacyOrder" should be before "ReturnText".'},
],
output: `
export type GroupOrdersResponseType = {|
code: number,
errorMessage: string,
isSuccess: boolean,
message?: string,
result: {|
IncludesLegacyOrder: boolean,
OrderNumber: string,
Orders: GroupOrderSummaryType[],
PlacedOn: string,
ReturnText: string,
Status: string
|}
|};
`,
},
],
misconfigured: [
{
Expand Down

0 comments on commit b038886

Please sign in to comment.