Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(eslint-plugin): add TSPropertySignature with TSFunctionType annotation to typeMethod selector #6645

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 20 additions & 14 deletions packages/eslint-plugin/src/rules/naming-convention.ts
Expand Up @@ -394,20 +394,21 @@ export default util.createRule<Options, MessageIds>({
},
},

'TSPropertySignature[computed = false]': {
validator: validators.typeProperty,
handler: (
node: TSESTree.TSPropertySignatureNonComputedName,
validator,
): void => {
const modifiers = new Set<Modifiers>([Modifiers.public]);
if (node.readonly) {
modifiers.add(Modifiers.readonly);
}
'TSPropertySignature[computed = false][typeAnnotation.typeAnnotation.type != "TSFunctionType"]':
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if this typeAnnotation.typeAnnotation.type part should be moved to some variable. It is later used in L466 in typeMethod selector

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know, we've been leaning away from using these fancier queries, and instead towards simpler, more readable ones. eslint-community/eslint-plugin-eslint-plugin#339

Not requesting changes here as we haven't taken action on that yet & this file already has a lot of complex queries. Just food for thought. 😄

{
validator: validators.typeProperty,
handler: (
node: TSESTree.TSPropertySignatureNonComputedName,
validator,
): void => {
const modifiers = new Set<Modifiers>([Modifiers.public]);
if (node.readonly) {
modifiers.add(Modifiers.readonly);
kozlovvski marked this conversation as resolved.
Show resolved Hide resolved
}

handleMember(validator, node, modifiers);
handleMember(validator, node, modifiers);
},
},
},

// #endregion property

Expand Down Expand Up @@ -460,10 +461,15 @@ export default util.createRule<Options, MessageIds>({
},
},

'TSMethodSignature[computed = false]': {
[[
'TSMethodSignature[computed = false]',
'TSPropertySignature[computed = false][typeAnnotation.typeAnnotation.type = "TSFunctionType"]',
].join(', ')]: {
validator: validators.typeMethod,
handler: (
node: TSESTree.TSMethodSignatureNonComputedName,
node:
| TSESTree.TSMethodSignatureNonComputedName
| TSESTree.TSPropertySignatureNonComputedName,
validator,
): void => {
const modifiers = new Set<Modifiers>([Modifiers.public]);
Expand Down
Expand Up @@ -32,8 +32,12 @@ createTestCases([
code: [
'interface Ignored { %(): string }',
'interface Ignored { "%"(): string }',
'interface Ignored { %: () => string }',
'interface Ignored { "%": () => string }',
'type Ignored = { %(): string }',
'type Ignored = { "%"(): string }',
'type Ignored = { %: () => string }',
'type Ignored = { "%": () => string }',
],
options: {
selector: 'typeMethod',
Expand Down
Expand Up @@ -313,6 +313,30 @@ ruleTester.run('naming-convention', rule, {
{ selector: 'variable', format: ['camelCase'] },
],
},
// treat properties with function expressions as typeMethod
{
code: `
interface SOME_INTERFACE {
SomeMethod: () => void;

some_property: string;
}
`,
options: [
{
selector: 'default',
format: ['UPPER_CASE'],
},
{
selector: 'typeMethod',
format: ['PascalCase'],
},
{
selector: 'typeProperty',
format: ['snake_case'],
},
],
},
{
code: `
const camelCaseVar = 1;
Expand Down