Skip to content

Commit

Permalink
馃悰 Support optional ? token
Browse files Browse the repository at this point in the history
  • Loading branch information
coyotte508 committed Dec 15, 2022
1 parent eebb18f commit 69b27ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
13 changes: 2 additions & 11 deletions packages/eslint-plugin/src/rules/key-spacing.ts
Expand Up @@ -84,18 +84,9 @@ export default util.createRule<Options, MessageIds>({
/**
* To handle index signatures, be able to get the end position of the parameters
*/
function getKeyLocEnd(
node:
| TSESTree.TSIndexSignature
| TSESTree.TSPropertySignature
| TSESTree.PropertyDefinition,
): TSESTree.Position {
if ('key' in node) {
return node.key.loc.end;
}

function getKeyLocEnd(node: KeyTypeNode): TSESTree.Position {
return getLastTokenBeforeColon(
node.parameters[node.parameters.length - 1],
'key' in node ? node.key : node.parameters[node.parameters.length - 1],
).loc.end;
}

Expand Down
8 changes: 8 additions & 0 deletions packages/eslint-plugin/tests/rules/key-spacing.test.ts
Expand Up @@ -16,6 +16,10 @@ ruleTester.run('key-spacing', rule, {
code: 'interface X {\n a: number;\n abc: string\n};',
options: [{ align: 'value' }],
},
{
code: 'interface X {\n a?: number;\n abc: string\n};',
options: [{ align: 'value' }],
},
{
code: 'interface X {\n a: number;\n // Some comment\n abc: string\n};',
options: [{ align: 'value' }],
Expand All @@ -36,6 +40,10 @@ ruleTester.run('key-spacing', rule, {
code: 'class X {\n a: number;\n abc: string\n};',
options: [{ align: 'value' }],
},
{
code: 'class X {\n a?: number;\n abc: string\n};',
options: [{ align: 'value' }],
},
{
code: 'class X {\n a: number;\n\n abc: string\n};',
options: [{ align: 'value' }],
Expand Down

0 comments on commit 69b27ef

Please sign in to comment.