Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(eslint-plugin): [no-unnecessary-condition] don't report on unnecessary optional array index access whennoUncheckedIndexedAccess is enabled#10961

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@ronami
Copy link
Member

@ronamironami commentedMar 16, 2025
edited
Loading

PR Checklist

Overview

This PR addresses#10960 and disablesthe special-casing of optional array index access whennoUncheckedIndexedAccess is enabled.

This makes the rule report cases like the following:

declareconsttest:Array<{a?:string}>;// Reported by TypeScript as the object is possibly 'undefined'test[0].a;if(test[0]?.a){// Optional chaining isn't necessary heretest[0].a;}if(test[0]?.a){// Should be reported but doesn't?test[0]?.a;}

Note that this also causes the rule to report on unnecessary optional index access that's deeper in the chain (only whennoUncheckedIndexedAccess is turned on):

declareconstarr2:Array<{x:{y:{z:object}}}>;// the following (previously wasn't reported):arr2[42]?.x?.y?.z;// is auto-fixed into:arr2[42]?.x.y.z;

I've added a couple of tests to verify the rule handles these cases correctly whennoUncheckedIndexedAccess is enabled.

kirkwaiblinger, JoshuaKGoldberg, and Rel1cx reacted with thumbs up emoji
@typescript-eslint
Copy link
Contributor

Thanks for the PR,@ronami!

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 onhttps://opencollective.com/typescript-eslint.

@netlify
Copy link

netlifybot commentedMar 16, 2025
edited
Loading

Deploy Preview fortypescript-eslint ready!

NameLink
🔨 Latest commite3a479c
🔍 Latest deploy loghttps://app.netlify.com/sites/typescript-eslint/deploys/67e0613591b72a000881cbc2
😎 Deploy Previewhttps://deploy-preview-10961--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 97 (🔴 down 2 from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 98 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to yourNetlify site configuration.

@nx-cloud
Copy link

nx-cloudbot commentedMar 16, 2025
edited
Loading

View yourCI Pipeline Execution ↗ for commite3a479c.

CommandStatusDurationResult
nx run-many --target=build --exclude website --...✅ Succeeded1sView ↗
nx run-many --target=clean✅ Succeeded10sView ↗

☁️Nx Cloud last updated this comment at2025-03-24 11:52:57 UTC

@codecov
Copy link

codecovbot commentedMar 16, 2025
edited
Loading

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.97%. Comparing base(543d36c) to head(e3a479c).
Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@##             main   #10961      +/-   ##==========================================+ Coverage   87.58%   87.97%   +0.38%==========================================  Files         470      470                Lines       16095    16710     +615       Branches     4668     4711      +43     ==========================================+ Hits        14097    14700     +603- Misses       1642     1664      +22+ Partials      356      346      -10
FlagCoverage Δ
unittest87.97% <100.00%> (+0.38%)⬆️

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

Files with missing linesCoverage Δ
...slint-plugin/src/rules/no-unnecessary-condition.ts99.21% <100.00%> (+<0.01%)⬆️

... and15 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ronamironami marked this pull request as ready for reviewMarch 16, 2025 18:53
@ronamironami changed the titlefix(eslint-plugin): don't report on unnecessary optional array index access whennoUncheckedIndexedAccess is enabledfix(eslint-plugin): [no-unnecessary-condition] don't report on unnecessary optional array index access whennoUncheckedIndexedAccess is enabledMar 16, 2025
JoshuaKGoldberg
JoshuaKGoldberg previously approved these changesMar 17, 2025
Copy link
Member

@JoshuaKGoldbergJoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Nice and clean! 🧹

ronami reacted with heart emoji
@JoshuaKGoldbergJoshuaKGoldberg added the 1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we merge labelMar 17, 2025
@JoshuaKGoldbergJoshuaKGoldberg removed the 1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we merge labelMar 24, 2025
Copy link
Member

@kirkwaiblingerkirkwaiblinger left a comment

Choose a reason for hiding this comment

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

This looks great!! I definitely like the behavior that the test cases demonstrate 🙂

ronami reacted with heart emoji
@JoshuaKGoldbergJoshuaKGoldberg merged commit3241e46 intotypescript-eslint:mainMar 24, 2025
58 of 59 checks passed
@ronamironami deleted the no-unnecessary-condition-no-unchecked-index-access branchMarch 24, 2025 20:32
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsApr 1, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@kirkwaiblingerkirkwaiblingerkirkwaiblinger approved these changes

@JoshuaKGoldbergJoshuaKGoldbergJoshuaKGoldberg left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Bug: [no-unnecessary-condition] doesn't report on unnecessary optional array index access whennoUncheckedIndexedAccess is enabled

3 participants

@ronami@JoshuaKGoldberg@kirkwaiblinger

[8]ページ先頭

©2009-2025 Movatter.jp