Skip to content

feat: add suggestion to remove parameter properties #14

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

AlexMunoz
Copy link
Contributor

@AlexMunoz AlexMunoz commented Feb 16, 2025

PR Checklist

Overview

  • Add suggestion
  • Update Docs

Copy link
Owner

@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.

A good start! This one will be a bit more involved though. 💪

@JoshuaKGoldberg JoshuaKGoldberg added the status: waiting for author Needs an action taken by the original poster label Feb 16, 2025
@JoshuaKGoldberg
Copy link
Owner

You can ignore the Compliance and Lint Docs failures, by the way. I'm taking a look now... 🤔

@JoshuaKGoldberg
Copy link
Owner

OK if you merge the latest main branch into this one, the CI complaints should go away.

As for Compliance, it's mtfoley/pr-compliance-action#401. I fixed it in this PR by switching the fix link from #011 to #11. I don't think you did anything wrong, it's just a discrepancy between what GitHub allows vs. the action.

As for the odd Compliance errors,
mtfoley/pr-compliance-action#368 -> JoshuaKGoldberg/create-typescript-app#457 has context if you're curious:

  1. PRs sent from forks don't have the same permissions for commenting on the PR
  2. The compliance action wants to give a comment requesting a change, but that fails - and the action isn't gracefully handing that failure

@AlexMunoz AlexMunoz force-pushed the feat/parameter-properties-suggestion branch from fa85c1b to 6c9db62 Compare February 18, 2025 21:44
@AlexMunoz AlexMunoz marked this pull request as draft February 18, 2025 21:45
@AlexMunoz AlexMunoz force-pushed the feat/parameter-properties-suggestion branch from 6c9db62 to 03e62b2 Compare February 23, 2025 11:12
Copy link

codecov bot commented Feb 23, 2025

Codecov Report

Attention: Patch coverage is 89.24731% with 10 lines in your changes missing coverage. Please review.

Project coverage is 96.24%. Comparing base (dda2300) to head (03e62b2).

Files with missing lines Patch % Lines
src/rules/parameter-properties.ts 89.24% 10 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main      #14      +/-   ##
===========================================
- Coverage   100.00%   96.24%   -3.76%     
===========================================
  Files            6        6              
  Lines          174      266      +92     
  Branches        18       32      +14     
===========================================
+ Hits           174      256      +82     
- Misses           0       10      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@AlexMunoz AlexMunoz force-pushed the feat/parameter-properties-suggestion branch from 03e62b2 to 0eae0e1 Compare February 23, 2025 11:24
Copy link
Contributor Author

@AlexMunoz AlexMunoz left a comment

Choose a reason for hiding this comment

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

Hello @JoshuaKGoldberg, I have a version that works, but it has some details. Could you please take a look?

@AlexMunoz AlexMunoz marked this pull request as ready for review March 11, 2025 22:56
@github-actions github-actions bot removed the status: waiting for author Needs an action taken by the original poster label Mar 11, 2025
Copy link
Owner

@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.

Great progress! 🚀

const constructor = node.parent;
if (constructor.type !== AST_NODE_TYPES.FunctionExpression) {
return;
}
Copy link
Owner

Choose a reason for hiding this comment

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

These three if statements are still missing coverage. You can check this locally with pnpm run test run --coverage -> opening coverage/index.html in a browser. For each case, >=1 of the following 3 is happening:

  • It's a good check for a real case that should be unit tested
  • The case it checks for can't be hit, and:
    • Removing it can be done without issue
    • It's helpful for type narrowing - which would mean a type assertion should be used here, with a comment to a new or existing issue on typescript-eslint to improve the AST

Copy link
Owner

@JoshuaKGoldberg JoshuaKGoldberg Mar 12, 2025

Choose a reason for hiding this comment

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

[Testing] These tests are looking good! I took a deeper look through code and think there are some more cases to handle:

  • Parameter property with both an accessibility and readonly
  • Comments before, inside, and after the parameter properties
  • Multiple parameters - both as properties and just normal ones
  • Existing properties that happen to have the same name
  • Constructor bodies with statements inside nodes inside the body e.g.:
    constructor(...) {
        {
            this.a = a;
        }
    }
    I'm not suggesting changing logic to handle deep constructor bodies better, I think it's fine as-is. This is just something to future-proof.

Apologies for not mentioning these sooner, seeing the implementation was very helpful for me to ideate how to break the suggestions.

node.expression.left.object.type ===
AST_NODE_TYPES.ThisExpression &&
node.expression.left.property.type === AST_NODE_TYPES.Identifier &&
node.expression.left.property.name === paramName,
Copy link
Owner

Choose a reason for hiding this comment

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

[Testing] Similar comment here as earlier in this file, several of these lines can be commented out without any resultant test failures.

Comment on lines +68 to +76
fix(fixer) {
const fixes: RuleFix[] = [];

fixes.push(
fixer.insertTextBefore(
classBody.body[0],
`${fieldDeclaration}\n`,
),
);
Copy link
Owner

Choose a reason for hiding this comment

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

[Style] A bit more succinct of a declaration: fixer functions can be generators! Instead of returning a full array of fixes, they can yield back each fix as they get to them. Switching over saves something like 10 lines in total 😎:

Suggested change
fix(fixer) {
const fixes: RuleFix[] = [];
fixes.push(
fixer.insertTextBefore(
classBody.body[0],
`${fieldDeclaration}\n`,
),
);
*fix(fixer) {
yield fixer.insertTextBefore(
classBody.body[0],
`${fieldDeclaration}\n`,
);

@JoshuaKGoldberg JoshuaKGoldberg added the status: waiting for author Needs an action taken by the original poster label Mar 12, 2025
@JoshuaKGoldberg
Copy link
Owner

👋 @AlexMunoz, just checking in - are you blocked on anything?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting for author Needs an action taken by the original poster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🚀 Feature: Add suggestions to parameter-properties rule
2 participants