Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
feat(eslint-plugin): [naming-convention] add support for "override" and "async" modifiers (#5310)#5610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
feat(eslint-plugin): [naming-convention] add support for "override" and "async" modifiers (#5310)#5610
Changes fromall commits
58dbdaf
b3446d6
f59a7f3
3a2086d
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -138,6 +138,9 @@ export default util.createRule<Options, MessageIds>({ | ||
if ('readonly' in node && node.readonly) { | ||
modifiers.add(Modifiers.readonly); | ||
} | ||
if ('override' in node && node.override) { | ||
modifiers.add(Modifiers.override); | ||
} | ||
if ( | ||
node.type === AST_NODE_TYPES.TSAbstractPropertyDefinition || | ||
node.type === AST_NODE_TYPES.TSAbstractMethodDefinition | ||
@@ -182,6 +185,34 @@ export default util.createRule<Options, MessageIds>({ | ||
); | ||
} | ||
function isAsyncMemberOrProperty( | ||
propertyOrMemberNode: | ||
| TSESTree.PropertyNonComputedName | ||
| TSESTree.TSMethodSignatureNonComputedName | ||
| TSESTree.PropertyDefinitionNonComputedName | ||
| TSESTree.TSAbstractPropertyDefinitionNonComputedName | ||
| TSESTree.MethodDefinitionNonComputedName | ||
| TSESTree.TSAbstractMethodDefinitionNonComputedName, | ||
): boolean { | ||
return Boolean( | ||
'value' in propertyOrMemberNode && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Looking at this again: we generally try not to use this string I think it's fine to check in as-is, and we should separately look into making a lint rule internally that flags this kind of check. I also think I'd meant to post this in the first review but forgot 😄 ContributorAuthor
| ||
propertyOrMemberNode.value && | ||
'async' in propertyOrMemberNode.value && | ||
propertyOrMemberNode.value.async, | ||
); | ||
} | ||
function isAsyncVariableIdentifier(id: TSESTree.Identifier): boolean { | ||
return Boolean( | ||
id.parent && | ||
(('async' in id.parent && id.parent.async) || | ||
('init' in id.parent && | ||
id.parent.init && | ||
'async' in id.parent.init && | ||
id.parent.init.async)), | ||
); | ||
} | ||
return { | ||
// #region variable | ||
@@ -219,6 +250,10 @@ export default util.createRule<Options, MessageIds>({ | ||
modifiers.add(Modifiers.unused); | ||
} | ||
if (isAsyncVariableIdentifier(id)) { | ||
modifiers.add(Modifiers.async); | ||
} | ||
validator(id, modifiers); | ||
}); | ||
}, | ||
@@ -254,6 +289,10 @@ export default util.createRule<Options, MessageIds>({ | ||
modifiers.add(Modifiers.unused); | ||
} | ||
if (node.async) { | ||
modifiers.add(Modifiers.async); | ||
} | ||
validator(node.id, modifiers); | ||
}, | ||
@@ -360,6 +399,11 @@ export default util.createRule<Options, MessageIds>({ | ||
| TSESTree.TSMethodSignatureNonComputedName, | ||
): void { | ||
const modifiers = new Set<Modifiers>([Modifiers.public]); | ||
if (isAsyncMemberOrProperty(node)) { | ||
modifiers.add(Modifiers.async); | ||
} | ||
handleMember(validators.objectLiteralMethod, node, modifiers); | ||
}, | ||
@@ -376,6 +420,11 @@ export default util.createRule<Options, MessageIds>({ | ||
| TSESTree.TSAbstractMethodDefinitionNonComputedName, | ||
): void { | ||
const modifiers = getMemberModifiers(node); | ||
if (isAsyncMemberOrProperty(node)) { | ||
modifiers.add(Modifiers.async); | ||
} | ||
handleMember(validators.classMethod, node, modifiers); | ||
}, | ||
Uh oh!
There was an error while loading.Please reload this page.