feat(ts): implement unnecessaryConstructors rule#2953
Closed
jcamino wants to merge 3 commits into
Closed
Conversation
…ypescript-eslint Verbatim copy of typescript-eslint/typescript-eslint@4ba3e02 (rule, tests, docs) as the starting point for the flint unnecessaryConstructors port. Subsequent commits adapt it to flint; diff them to see exactly what the port changed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Stage 2 of the port: reshape the upstream files to flint's rule/test/docs conventions (ruleCreator, .ts specifiers, rule-tester format, mdx frontmatter) before the full implementation pass. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Ports @typescript-eslint/no-useless-constructor (merging its ESLint-core base-rule logic) to flint's ruleCreator/services API. Includes rule, tests, docs, comparisons status, and a changeset. fixes flint-fyi#2226 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
✅ Deploy Preview for flint-fyi ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
🦋 Changeset detectedLatest commit: 78db072 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
status: accepting prsOverview
Implements
ts/unnecessaryConstructors, the flint equivalent of@typescript-eslint/no-useless-constructor.Reports constructors that are equivalent to the implicit default constructor — an empty constructor in a base class, or a derived-class constructor that only forwards its parameters to
super— with a suggestion to remove them.Provenance (staged commits)
Ported from typescript-eslint/typescript-eslint@4ba3e02e (75 LOC):
Diff commits 1→3 to see exactly what the port changed.
Note on sources: the upstream rule is an extension rule that delegates its core logic to ESLint core's
no-useless-constructorviagetESLintCoreRule. Since flint rules are self-contained, this port merges the core semantics and the TS-specific exemptions (accessibility modifiers, parameter properties, parameter decorators) into one rule; both upstream test suites were used as the edge-case reference.Behavior vs upstream
constructor(...[a, b]) { super(...arguments); }): ESLint core treats any rest element as "simple" and reports; this port requires the rest parameter to be a plain identifier and does not report. Removing such a constructor can change behavior (pattern defaults may have side effects), so the port takes the safe direction.needsPrecedingSemicolonmachinery to decide whether removing the constructor needs a separating;; this port uses class-member-shaped checks (previous member ends in an unterminated initializer, next member begins with[/*/in/instanceof). Output is identical across core's suggestion test matrix (all ported); the only known delta inserts a harmless extra;in one TS-specific corner.removeConstructorsuggestion is ported as a real flint suggestion, not dropped.Everything else is behavior parity, including: overload signatures / ambient declarations never flagged,
implements-only classes treated as base classes,'constructor'()string-key form flagged, and parentheses skipped at all expression positions.A courtesy note: rule naming for the
unnecessary*family is under discussion in #2802 — happy to rename if that lands on a different convention.Files
packages/ts/src/rules/unnecessaryConstructors.ts— the rule (self-contained port)packages/ts/src/rules/unnecessaryConstructors.test.ts— 25 invalid cases (snapshot + suggestion output each) + 43 valid casespackages/site/src/content/docs/rules/ts/unnecessaryConstructors.mdx— full rule docpackages/ts/src/plugin.ts— rule registered alphabeticallypackages/comparisons/src/data.json— existing entry marked"status": "implemented".changeset/unnecessary-constructors.md— patch changesetLocal gates
eslint --max-warnings 0·tsc -b packages/ts·vitest(rule test, 68 passing) ·vitest(comparisons) ·prettier --check— all pass locally.🤖 Generated with Claude Code