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

feat(typescript-estree): throw on invalid update expressions#7202

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

Merged

Conversation

Josh-Cena
Copy link
Member

@Josh-CenaJosh-Cena commentedJul 12, 2023
edited
Loading

PR Checklist

Overview

We should be able to report on things likea() = 1 and1 = 1 as well, but I didn't do this because things like{ a } = 1 makes it a little more complicated.

@typescript-eslint
Copy link
Contributor

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

@netlify
Copy link

netlifybot commentedJul 12, 2023
edited
Loading

Deploy Preview fortypescript-eslint ready!

NameLink
🔨 Latest commitd6d6d70
🔍 Latest deploy loghttps://app.netlify.com/sites/typescript-eslint/deploys/657a67374fea510008a9a791
😎 Deploy Previewhttps://deploy-preview-7202--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: 96 (🔴 down 1 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (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 commentedJul 12, 2023
edited
Loading

☁️ Nx Cloud Report

CI is running/has finished running commands for commit94cc251. 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


🟥 Failed Commands
nx test eslint-plugin --coverage=false
✅ Successfully ran 19 targets

Sent with 💌 fromNxCloud.

@bradzacherbradzacher added the enhancementNew feature or request labelJul 17, 2023
@bradzacher
Copy link
Member

bradzacher commentedJul 17, 2023
edited
Loading

I had a look at the TS codebase and it's a bit messy with regard to this class of errors.

Here's a few snippets I can find:

I can't link thechecker.ts file in GH cos it's too big but here are the relevant lines:

functioncheckReferenceExpression(expr:Expression,invalidReferenceMessage:DiagnosticMessage,invalidOptionalChainMessage:DiagnosticMessage):boolean{// References are combinations of identifiers, parentheses, and property accesses.constnode=skipOuterExpressions(expr,OuterExpressionKinds.Assertions|OuterExpressionKinds.Parentheses);if(node.kind!==SyntaxKind.Identifier&&!isAccessExpression(node)){error(expr,invalidReferenceMessage);returnfalse;}if(node.flags&NodeFlags.OptionalChain){error(expr,invalidOptionalChainMessage);returnfalse;}returntrue;}
exportfunctionisAccessExpression(node:Node):node isAccessExpression{returnnode.kind===SyntaxKind.PropertyAccessExpression||node.kind===SyntaxKind.ElementAccessExpression;}

and

functioncheckReferenceAssignment(target:Expression,sourceType:Type,checkMode?:CheckMode):Type{consttargetType=checkExpression(target,checkMode);consterror=target.parent.kind===SyntaxKind.SpreadAssignment ?Diagnostics.The_target_of_an_object_rest_assignment_must_be_a_variable_or_a_property_access :Diagnostics.The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access;constoptionalError=target.parent.kind===SyntaxKind.SpreadAssignment ?Diagnostics.The_target_of_an_object_rest_assignment_may_not_be_an_optional_property_access :Diagnostics.The_left_hand_side_of_an_assignment_expression_may_not_be_an_optional_property_access;if(checkReferenceExpression(target,error,optionalError)){checkTypeAssignableToAndOptionallyElaborate(sourceType,targetType,target,target);}if(isPrivateIdentifierPropertyAccessExpression(target)){checkExternalEmitHelpers(target.parent,ExternalEmitHelpers.ClassPrivateFieldSet);}returnsourceType;}functioncheckReferenceExpression(expr:Expression,invalidReferenceMessage:DiagnosticMessage,invalidOptionalChainMessage:DiagnosticMessage):boolean{// References are combinations of identifiers, parentheses, and property accesses.constnode=skipOuterExpressions(expr,OuterExpressionKinds.Assertions|OuterExpressionKinds.Parentheses);if(node.kind!==SyntaxKind.Identifier&&!isAccessExpression(node)){error(expr,invalidReferenceMessage);returnfalse;}if(node.flags&NodeFlags.OptionalChain){error(expr,invalidOptionalChainMessage);returnfalse;}returntrue;}
exportfunctionisPrivateIdentifierPropertyAccessExpression(node:Node):node isPrivateIdentifierPropertyAccessExpression{returnisPropertyAccessExpression(node)&&isPrivateIdentifier(node.name);}

JoshuaKGoldberg
JoshuaKGoldberg previously approved these changesJul 17, 2023
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.

LGTM - glad you're diving into this@Josh-Cena!

@bradzacher - since you commented in the issue I'll wait for your review for a bit.

@JoshuaKGoldbergJoshuaKGoldberg added the 1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we merge labelJul 17, 2023
Copy link
Member

@bradzacherbradzacher left a comment

Choose a reason for hiding this comment

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

These are also semantically valid assignment:

declareletx:1;(xas1)=1;(<1>x)=1;(xsatisfies1)=1;

Which is covered by theskipOuterExpressions(expr, OuterExpressionKinds.Assertions | OuterExpressionKinds.Parentheses); line in the TS codebase.

Also currently this is invalid (for now):

declareconsty:{z:number};y?.z=1;

I don't know if we have handling for cases like this (if we don't - do we want to add them in this PR?):

declareconstz:string[];let[ ...a=[]]=z;let{ ...b={}}=z;

Other than that looking good!

@bradzacherbradzacher added awaiting responseIssues waiting for a reply from the OP or another party and removed 1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we merge labelsJul 18, 2023
@Josh-Cena
Copy link
MemberAuthor

let[ ...a=[]]=z;let{ ...b={}}=z;

This PR only deals with update expressions, not assignment or declaration, so not those atm.

I'll add the assertion ones.

bradzacher reacted with thumbs up emoji

@fisker
Copy link
Contributor

@Josh-Cena

Side question: when I work on invalid AST checks, I feel it's hard to debug, maybe we need find a better way to run test on single fixture, do you feel the same?

@bradzacher
Copy link
Member

@fisker I did build this into the infra to make it possible to filter the tests:

https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/ast-spec/tests/fixtures.test.ts#L21-L25

But I agree that it's not a very good DevX and pretty hacky. Open to suggestions to improve it!

@fisker
Copy link
Contributor

fisker commentedJul 28, 2023
edited
Loading

I hope we run test from each directory, so we can
jest packages/ast-spec/src/expression/UpdateExpression/fixtures/_error_/literal/.

Similar to Prettier's approachhttps://github.com/prettier/prettier/blob/6ed37ad85731e4e62d81481d40dfd98c6a675a10/tests/format/js/array-spread/jsfmt.spec.js#L1

@JoshuaKGoldbergJoshuaKGoldberg removed the awaiting responseIssues waiting for a reply from the OP or another party labelOct 18, 2023
Copy link
Member

@bradzacherbradzacher left a comment

Choose a reason for hiding this comment

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

just one comment otherwise
youhavemystamp

}
return true;
case SyntaxKind.ParenthesizedExpression:
case SyntaxKind.TypeAssertionExpression:
Copy link
Member

Choose a reason for hiding this comment

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

I might have missed it but I think we're missing a case for this

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

@bradzacher Wow, thanks for catching that! In doing so I realizedTypeAssertionExpression is only for<number>foo andfoo as number is a separate syntax kind.

bradzacher reacted with thumbs up emoji
@bradzacherbradzacher added awaiting responseIssues waiting for a reply from the OP or another party 1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we merge labelsNov 10, 2023
@Josh-CenaJosh-Cena removed the awaiting responseIssues waiting for a reply from the OP or another party labelNov 23, 2023
@bradzacherbradzacher added the awaiting responseIssues waiting for a reply from the OP or another party labelDec 6, 2023
bradzacher
bradzacher previously approved these changesDec 6, 2023
Copy link
Member

@bradzacherbradzacher left a comment

Choose a reason for hiding this comment

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

just need to get CI passing and we can merge this

fisker reacted with thumbs up emoji
@Josh-Cena

This comment was marked as outdated.

@github-actionsgithub-actionsbot removed the awaiting responseIssues waiting for a reply from the OP or another party labelDec 13, 2023
@JoshuaKGoldbergJoshuaKGoldberg merged commit1a8e0dc intotypescript-eslint:mainJan 4, 2024
@Josh-CenaJosh-Cena deleted the invalid-update branchJanuary 4, 2024 16:52
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsJan 12, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@fiskerfiskerfisker left review comments

@JoshuaKGoldbergJoshuaKGoldbergJoshuaKGoldberg left review comments

@bradzacherbradzacherAwaiting requested review from bradzacher

Assignees
No one assigned
Labels
1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we mergeenhancementNew feature or request
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Enhancement: Throw errors for invalidUpdateExpressions
4 participants
@Josh-Cena@bradzacher@fisker@JoshuaKGoldberg

[8]ページ先頭

©2009-2025 Movatter.jp