diff --git a/test/sort-interfaces.test.ts b/test/sort-interfaces.test.ts index 73d0cf6e..9fa18d5c 100644 --- a/test/sort-interfaces.test.ts +++ b/test/sort-interfaces.test.ts @@ -487,6 +487,43 @@ describe(RULE_NAME, () => { ], }) }) + + it(`${RULE_NAME}(${type}): sorts interfaces with semi and comments on the same line`, () => { + ruleTester.run(RULE_NAME, rule, { + valid: [], + invalid: [ + { + code: dedent` + interface Researcher { + rescuer: 'Tokita Kōsaku'; // Character + occupation: string; // Professional direction + } + `, + output: dedent` + interface Researcher { + occupation: string; // Professional direction + rescuer: 'Tokita Kōsaku'; // Character + } + `, + options: [ + { + type: SortType.alphabetical, + order: SortOrder.asc, + }, + ], + errors: [ + { + messageId: 'unexpectedInterfacePropertiesOrder', + data: { + left: 'rescuer', + right: 'occupation', + }, + }, + ], + }, + ], + }) + }) }) describe(`${RULE_NAME}: sorting by natural order`, () => { @@ -966,6 +1003,43 @@ describe(RULE_NAME, () => { ], }) }) + + it(`${RULE_NAME}(${type}): sorts interfaces with semi and comments on the same line`, () => { + ruleTester.run(RULE_NAME, rule, { + valid: [], + invalid: [ + { + code: dedent` + interface Researcher { + rescuer: 'Tokita Kōsaku'; // Character + occupation: string; // Professional direction + } + `, + output: dedent` + interface Researcher { + occupation: string; // Professional direction + rescuer: 'Tokita Kōsaku'; // Character + } + `, + options: [ + { + type: SortType.natural, + order: SortOrder.asc, + }, + ], + errors: [ + { + messageId: 'unexpectedInterfacePropertiesOrder', + data: { + left: 'rescuer', + right: 'occupation', + }, + }, + ], + }, + ], + }) + }) }) describe(`${RULE_NAME}: sorting by line length`, () => { @@ -1391,6 +1465,43 @@ describe(RULE_NAME, () => { ], }) }) + + it(`${RULE_NAME}(${type}): sorts interfaces with semi and comments on the same line`, () => { + ruleTester.run(RULE_NAME, rule, { + valid: [], + invalid: [ + { + code: dedent` + interface Researcher { + occupation: string; // Professional direction + rescuer: 'Tokita Kōsaku'; // Character + } + `, + output: dedent` + interface Researcher { + rescuer: 'Tokita Kōsaku'; // Character + occupation: string; // Professional direction + } + `, + options: [ + { + type: SortType['line-length'], + order: SortOrder.desc, + }, + ], + errors: [ + { + messageId: 'unexpectedInterfacePropertiesOrder', + data: { + left: 'occupation', + right: 'rescuer', + }, + }, + ], + }, + ], + }) + }) }) describe(`${RULE_NAME}: misc`, () => { diff --git a/utils/get-node-range.ts b/utils/get-node-range.ts index bead3cc1..0a271090 100644 --- a/utils/get-node-range.ts +++ b/utils/get-node-range.ts @@ -37,9 +37,7 @@ export let getNodeRange = ( count: 2, }) - if (node.loc.start.line !== tokensAfter.at(1)?.loc.start.line) { - end += 1 - } else { + if (node.loc.start.line === tokensAfter.at(1)?.loc.start.line) { end -= 1 } } diff --git a/utils/make-fixes.ts b/utils/make-fixes.ts index fce79bbf..6494c48b 100644 --- a/utils/make-fixes.ts +++ b/utils/make-fixes.ts @@ -46,5 +46,6 @@ export let makeFixes = ( ) } }) + return fixes }