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

feat(eslint-plugin): [no-shadow] ignoreOnInitialization option #4603

Merged
merged 7 commits into from Mar 31, 2022

Conversation

Josh-Cena
Copy link
Contributor

@Josh-Cena Josh-Cena commented Feb 27, 2022

PR Checklist

Overview

Added an option to line up with base rule

@nx-cloud
Copy link

nx-cloud bot commented Feb 27, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit d39e589. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


Successfully ran 43 targets

Sent with 💌 from NxCloud.

@typescript-eslint
Copy link
Contributor

typescript-eslint bot commented Feb 27, 2022

Thanks for the PR, @Josh-Cena!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

@netlify
Copy link

netlify bot commented Feb 27, 2022

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit d39e589
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/62430019034a0700088b8439
😎 Deploy Preview https://deploy-preview-4603--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@Josh-Cena
Copy link
Contributor Author

Josh-Cena commented Feb 27, 2022

Not sure if any code should be updated to cope with this option. Seems our scope analyzer is already able to allow this:

type test = (test: string) => typeof test;

Even when ignoreFunctionTypeParameterNameValueShadow is turned off

@codecov
Copy link

codecov bot commented Feb 27, 2022

Codecov Report

Merging #4603 (d39e589) into main (9707daa) will increase coverage by 2.22%.
The diff coverage is 85.36%.

@@            Coverage Diff             @@
##             main    #4603      +/-   ##
==========================================
+ Coverage   92.06%   94.28%   +2.22%     
==========================================
  Files         355      151     -204     
  Lines       12097     8208    -3889     
  Branches     3455     2670     -785     
==========================================
- Hits        11137     7739    -3398     
+ Misses        630      261     -369     
+ Partials      330      208     -122     
Flag Coverage Δ
unittest 94.28% <85.36%> (+2.22%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/eslint-plugin/src/rules/no-shadow.ts 78.48% <85.36%> (+1.97%) ⬆️
packages/eslint-plugin/src/util/objectIterators.ts 66.66% <0.00%> (-2.57%) ⬇️
packages/eslint-plugin/src/rules/no-unused-vars.ts 95.93% <0.00%> (-2.13%) ⬇️
...es/eslint-plugin/src/rules/no-loss-of-precision.ts 83.33% <0.00%> (-1.29%) ⬇️
packages/eslint-plugin/src/util/astUtils.ts 83.33% <0.00%> (-0.88%) ⬇️
...lugin/src/rules/no-confusing-non-null-assertion.ts 82.60% <0.00%> (-0.73%) ⬇️
...int-plugin/src/rules/require-array-sort-compare.ts 88.23% <0.00%> (-0.66%) ⬇️
...eslint-plugin/src/rules/type-annotation-spacing.ts 81.94% <0.00%> (-0.25%) ⬇️
packages/eslint-plugin/src/rules/indent.ts 92.85% <0.00%> (-0.17%) ⬇️
... and 237 more

JoshuaKGoldberg
JoshuaKGoldberg previously approved these changes Feb 28, 2022
Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Super, thanks!

@Josh-Cena do you think you have time to add unit tests for this? If not no worries, since it's just a pipe-through of the base rule's config.

@JoshuaKGoldberg JoshuaKGoldberg added the 1 approval Feature PR that has an approval. label Feb 28, 2022
@Josh-Cena
Copy link
Contributor Author

Josh-Cena commented Mar 1, 2022

Hmmm... No! This rule does not pipe to the base rule but is a re-implementation. We do need to backport the upstream changes and add a test. My bad for not noticing it beforehand

@Josh-Cena Josh-Cena marked this pull request as draft Mar 1, 2022
@Josh-Cena
Copy link
Contributor Author

Josh-Cena commented Mar 1, 2022

Any reason why this rule does not delegate to the base rule? Should I refactor that in this PR? I mean... eslint/eslint#14963 has about 100 lines to add this feature, not sure if we want to duplicate all of that

@bradzacher
Copy link
Member

bradzacher commented Mar 1, 2022

Any reason why this rule does not delegate to the base rule?

At the end of the AST the base rule iterates over every single scope and variable using the scope analysis APIs and then individually reports on variables that match its internal logic.

We unfortunately can't pick-and-choose which variables the base rule might report on unless we hackily override the scope analysis APIs - which means we can't delegate! Thus we have to maintain a complete fork, sadly.

If you can figure out a clean way to refactor this to reuse the logic - feel free! I don't think that it's possible to do though.

@Josh-Cena
Copy link
Contributor Author

Josh-Cena commented Mar 1, 2022

Ugh, I see. That's unfortunate. I'll incorporate upstream changes later today.

@Josh-Cena
Copy link
Contributor Author

Josh-Cena commented Mar 1, 2022

The unit tests seem to indicate that our extension rule is reporting more errors than the base rule on the same case. Is that because of test setup, or because of our scope manager having different logics?

@JoshuaKGoldberg JoshuaKGoldberg added awaiting response Issues waiting for a reply from the OP or another party and removed 1 approval Feature PR that has an approval. labels Mar 1, 2022
@lopezjurip

This comment was marked as off-topic.

@bradzacher
Copy link
Member

bradzacher commented Mar 14, 2022

@lopezjurip - please don't comment on issues and prs asking for progress.
The progress as seen in this PR.
The volunteer contributors will progress it forward as they find the time.
Commenting asking for updates just spams everyone with an unnecessary notification.

This guideline is explicitly mentioned in our contributing guide

@Josh-Cena Josh-Cena changed the title fix(eslint-plugin): [no-shadow] allow ignoreOnInitialization option feat(eslint-plugin): [no-shadow] ignoreOnInitialization option Mar 15, 2022
@Josh-Cena
Copy link
Contributor Author

Josh-Cena commented Mar 15, 2022

Still quite clueless. If I copied the test cases from upstream, but our rule testers report 3 errors while the original test case only expects one, how could I get the data about the extra errors? How do people usually debug this?

I tried logging the variable name before context.report, but only one report is logged. I don't know where the extra errors are coming from at all.

@bradzacher
Copy link
Member

bradzacher commented Mar 15, 2022

How do people usually debug this?

you can use the vscode debugger to debug the tests - we have it configured so you just need to open the file and select the lint rule debugger.

also you can set only: true on the specific test case you're looking at so you can focus and remove noise.

@Josh-Cena
Copy link
Contributor Author

Josh-Cena commented Mar 29, 2022

I finally got time to look at this. I had to hack into eslint's rule tester so I can let it log the actual line/column of the report. Turns out that the tests on their repo would turn all source code into one line, so the line/column numbers are different from ours.

@Josh-Cena Josh-Cena marked this pull request as ready for review Mar 29, 2022
@bradzacher bradzacher added enhancement New feature or request and removed awaiting response Issues waiting for a reply from the OP or another party labels Mar 31, 2022
Copy link
Member

@bradzacher bradzacher left a comment

LGTM - thanks so much for adding this!

@bradzacher bradzacher merged commit 068ea9b into typescript-eslint:main Mar 31, 2022
17 of 18 checks passed
@Josh-Cena Josh-Cena deleted the no-shadow-option branch Mar 31, 2022
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Apr 9, 2022
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) | devDependencies | minor | [`5.17.0` -> `5.18.0`](https://renovatebot.com/diffs/npm/@typescript-eslint%2feslint-plugin/5.17.0/5.18.0) |
| [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint) | devDependencies | minor | [`5.17.0` -> `5.18.0`](https://renovatebot.com/diffs/npm/@typescript-eslint%2fparser/5.17.0/5.18.0) |

---

### Release Notes

<details>
<summary>typescript-eslint/typescript-eslint (@&#8203;typescript-eslint/eslint-plugin)</summary>

### [`v5.18.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#&#8203;5180-httpsgithubcomtypescript-eslinttypescript-eslintcomparev5170v5180-2022-04-04)

[Compare Source](typescript-eslint/typescript-eslint@v5.17.0...v5.18.0)

##### Bug Fixes

-   **eslint-plugin:** method-signature-style respect getter signature ([#&#8203;4777](typescript-eslint/typescript-eslint#4777)) ([12dd670](typescript-eslint/typescript-eslint@12dd670))

##### Features

-   **eslint-plugin:** \[no-shadow] ignoreOnInitialization option ([#&#8203;4603](typescript-eslint/typescript-eslint#4603)) ([068ea9b](typescript-eslint/typescript-eslint@068ea9b))
-   **eslint-plugin:** \[no-this-alias] report on assignment expressions ([#&#8203;4718](typescript-eslint/typescript-eslint#4718)) ([8329498](typescript-eslint/typescript-eslint@8329498))

</details>

<details>
<summary>typescript-eslint/typescript-eslint (@&#8203;typescript-eslint/parser)</summary>

### [`v5.18.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/parser/CHANGELOG.md#&#8203;5180-httpsgithubcomtypescript-eslinttypescript-eslintcomparev5170v5180-2022-04-04)

[Compare Source](typescript-eslint/typescript-eslint@v5.17.0...v5.18.0)

**Note:** Version bump only for package [@&#8203;typescript-eslint/parser](https://github.com/typescript-eslint/parser)

</details>

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

 **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1282
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[no-shadow] Add ignoreOnInitialization option to match the ESLint rule
4 participants