Skip to content

feat: support TypeScript syntax in no-empty-function rule #19551

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

Merged
merged 6 commits into from
Apr 9, 2025

Conversation

sethamus
Copy link
Contributor

@sethamus sethamus commented Mar 21, 2025

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[x] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)

Added support for handling TypeScript specific code that would otherwise trigger the rule.

One example of valid TypeScript specific code that would otherwise trigger the no-empty-function rule is the use of parameter properties in constructor functions.

This PR also adds four new options to the allow list:

  • "privateConstructors"
  • "protectedConstructors"
  • "decoratedFunctions"
  • "overrideMethods"

Is there anything you'd like reviewers to focus on?

Refs #19173.

@sethamus sethamus requested a review from a team as a code owner March 21, 2025 17:12
@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Mar 21, 2025
@eslint-github-bot eslint-github-bot bot added the feature This change adds a new feature to ESLint label Mar 21, 2025
@github-actions github-actions bot added the rule Relates to ESLint's core rules label Mar 21, 2025
Copy link

netlify bot commented Mar 21, 2025

Deploy Preview for docs-eslint canceled.

Name Link
🔨 Latest commit d96e55b
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/67f5168788d6ad0008729c52

@snitin315 snitin315 moved this from Needs Triage to Implementing in Triage Mar 22, 2025
@snitin315 snitin315 added the accepted There is consensus among the team that this change meets the criteria for inclusion label Mar 22, 2025
snitin315
snitin315 previously approved these changes Mar 26, 2025
Copy link
Contributor

@snitin315 snitin315 left a comment

Choose a reason for hiding this comment

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

LGTM.

I'll leave it open for others to review.

@snitin315 snitin315 moved this from Implementing to Second Review Needed in Triage Mar 26, 2025
Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Looks really close to me, just a couple touchups. 🙌

Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

The behavior of new options would be different than the options of the @typescript-eslint/no-empty-function rule.

For example, this code is currently valid for both core no-empty-function and @typescript-eslint/no-empty-function rules:

/* eslint @typescript-eslint/no-empty-function: ["error", { "allow": ["constructors", "methods"] }] */
/* eslint no-empty-function: ["error", { "allow": ["constructors", "methods"] }] */

class A {
  private constructor() { }
}

class B {
  protected constructor() { }
}

class C {
  @decorator
  foo() { }
}

class D extends C {
  override foo() { }
}

But after this change, all 4 functions would be invalid because they're no longer considered to be of constructors/methods kind, which I'm not sure is desirable and might be considered a breaking change.

@sethamus
Copy link
Contributor Author

@mdjermanovic That was definitely an oversight. I've fixed it and added tests.

Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! Leaving open for @snitin315 and @JoshuaKGoldberg to re-review.

Copy link
Contributor

@snitin315 snitin315 left a comment

Choose a reason for hiding this comment

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

LGTM, tahnks 🙌🏻.

// @JoshuaKGoldberg

Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

The source code looks very good and reasonable to me, nice! Requesting information from the team on what the stance on the >2k newly generated tests are, not blocking.

Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

If everybody else is happy, then I'm happy too ☺️

@snitin315 snitin315 merged commit dcd95aa into eslint:main Apr 9, 2025
32 checks passed
@github-project-automation github-project-automation bot moved this from Second Review Needed to Complete in Triage Apr 9, 2025
@sethamus sethamus deleted the ts-no-empty-function branch April 17, 2025 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion contributor pool feature This change adds a new feature to ESLint rule Relates to ESLint's core rules
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

4 participants