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

chore: extract AST check from convert.ts to ast-checks.ts#11748

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

Open
Lonercode wants to merge17 commits intotypescript-eslint:main
base:main
Choose a base branch
Loading
fromLonercode:extract-ast-checks-from-converter

Conversation

@Lonercode
Copy link

PR Checklist

Overview

This PR extracts the AST check (checkForStatementDeclaration) fromconvert.ts to a fileast-checks.ts as requested in the issue due to the increasing length of code in the file. Therefore, a new fie has been added (ast-checks.ts), one modified (convert.ts) and tests have been run.

@typescript-eslint
Copy link
Contributor

Thanks for the PR,@Lonercode!

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 commentedNov 9, 2025
edited
Loading

Deploy Preview fortypescript-eslint ready!

NameLink
🔨 Latest commit29a9c73
🔍 Latest deploy loghttps://app.netlify.com/projects/typescript-eslint/deploys/692889024bd90500080490fe
😎 Deploy Previewhttps://deploy-preview-11748--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: 92 (🔴 down 6 from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 92 (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 project configuration.

@nx-cloud
Copy link

nx-cloudbot commentedNov 9, 2025
edited
Loading

View yourCI Pipeline Execution ↗ for commit29a9c73

CommandStatusDurationResult
nx test eslint-plugin --coverage=false✅ Succeeded5m 14sView ↗
nx run-many -t lint✅ Succeeded3m 16sView ↗
nx run-many -t typecheck✅ Succeeded2m 9sView ↗
nx test typescript-estree --coverage=false✅ Succeeded21sView ↗
nx test eslint-plugin-internal --coverage=false✅ Succeeded11sView ↗
nx run types:build✅ Succeeded2sView ↗
nx run generate-configs✅ Succeeded7sView ↗
nx run integration-tests:test✅ Succeeded3sView ↗
Additional runs (29)✅ Succeeded...View ↗

☁️Nx Cloud last updated this comment at2025-11-27 17:35:07 UTC

@LonercodeLonercode changed the titleChore: Extract AST check from convert.ts to ast-checks.tschore: Extract AST check from convert.ts to ast-checks.tsNov 9, 2025
@codecov
Copy link

codecovbot commentedNov 9, 2025
edited
Loading

Codecov Report

❌ Patch coverage is25.75758% with49 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.48%. Comparing base (3252978) to head (29a9c73).
⚠️ Report is 2 commits behind head on main.

Files with missing linesPatch %Lines
...kages/typescript-estree/src/check-syntax-errors.ts20.96%49 Missing⚠️

❌ Your patch check has failed because the patch coverage (25.75%) is below the target coverage (90.00%). You can increase the patch coverage or adjust thetarget coverage.

Additional details and impacted files
@@            Coverage Diff             @@##             main   #11748      +/-   ##==========================================- Coverage   90.49%   90.48%   -0.01%==========================================  Files         522      523       +1       Lines       53360    53375      +15       Branches     8911     8913       +2     ==========================================+ Hits        48286    48298      +12- Misses       5059     5062       +3  Partials       15       15
FlagCoverage Δ
unittest90.48% <25.75%> (-0.01%)⬇️

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

Files with missing linesCoverage Δ
packages/typescript-estree/src/convert.ts31.33% <100.00%> (+0.46%)⬆️
...kages/typescript-estree/src/check-syntax-errors.ts20.96% <20.96%> (ø)
🚀 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.

@LonercodeLonercode changed the titlechore: Extract AST check from convert.ts to ast-checks.tschore: extract AST check from convert.ts to ast-checks.tsNov 9, 2025
@fisker
Copy link
Contributor

Can we run the AST check fromhttps://github.com/Lonercode/typescript-eslint/blob/65803e4127b9557ec6cf4802df12e588370d9930/packages/typescript-estree/src/convert.ts#L509, and have a big switch-case in the new file to check every ts node?

Lonercode reacted with thumbs up emoji

@Lonercode
Copy link
Author

Can we run the AST check fromhttps://github.com/Lonercode/typescript-eslint/blob/65803e4127b9557ec6cf4802df12e588370d9930/packages/typescript-estree/src/convert.ts#L509, and have a big switch-case in the new file to check every ts node?

AST checkcheckModifier function is inhttps://github.com/Lonercode/typescript-eslint/blob/65803e4127b9557ec6cf4802df12e588370d9930/packages/typescript-estree/src/check-modifiers.ts#L139. Do you mean it should be in the new file with a check for every ts node? Or I modifycheckForStatementDeclaration in the new file?

@fisker
Copy link
Contributor

No need change check-modifiers.ts.

In the new file export a function to check ts node, it callscheckModifier and do other checks currently lives in convert.ts


caseSyntaxKind.ForInStatement:
this.#checkForStatementDeclaration(node.initializer,node.kind);
this.#checkTSNode(node,node.initializer,node.kind);
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be able to be removed?

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.

What fisker said 🙂

Lonercode reacted with thumbs up emoji
@JoshuaKGoldbergJoshuaKGoldberg added the awaiting responseIssues waiting for a reply from the OP or another party labelNov 18, 2025
@Lonercode
Copy link
Author

@fisker Please let me know if I need to remove every call to the ast check function from convert.ts.

@fisker
Copy link
Contributor

checkTSNode should only call inconverter, like the oldcheckModofiers did.

}

checkModifiers(node);
checkTSNode(node,this.#throwError,initializer,kind);
Copy link
Contributor

Choose a reason for hiding this comment

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

initializer andkind should access fromnode directly in the check function.

import{checkModifiers}from'./check-modifiers';
import{isValidAssignmentTarget}from'./node-utils';

exportfunctioncheckTSNode(
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer export ascheckSyntaxError, and rename the file accordingly.


exportfunctioncheckTSNode(
node:ts.Node,
throwError:(
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't be necessary to pass, after we merge#11775

Copy link
Author

Choose a reason for hiding this comment

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

This means we should remove thethrowError parameter then?

Copy link
Contributor

@fiskerfiskerNov 26, 2025
edited
Loading

Choose a reason for hiding this comment

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

#11775 is merged, we should be able to throw directly.

}
}

exportfunctioncheckForStatementDeclaration(
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be an internal functionality, no need export.

@@ -0,0 +1,196 @@
import*astsfrom'typescript';
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is unnecessary, they have already been well tested.

Copy link
Author

@LonercodeLonercodeNov 23, 2025
edited
Loading

Choose a reason for hiding this comment

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

Was trying to align with codecov requirements. I can remove the file if it could still be merged. Should we also skip testing the newcheckSyntaxError function?

Comment on lines 12 to 27
checkForStatementDeclaration(
(nodeasts.ForInStatement|ts.ForOfStatement).initializer,
node.kind,
);
break;
}
default:{
break;
}
}
}

functioncheckForStatementDeclaration(
initializer:ts.ForInitializer,
kind:ts.SyntaxKind,
):void{
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
checkForStatementDeclaration(
(nodeasts.ForInStatement|ts.ForOfStatement).initializer,
node.kind,
);
break;
}
default:{
break;
}
}
}
functioncheckForStatementDeclaration(
initializer:ts.ForInitializer,
kind:ts.SyntaxKind,
):void{
checkForStatementDeclaration(node);
break;
}
default:{
break;
}
}
}
functioncheckForStatementDeclaration(node:ts.ForInStatement|ts.ForOfStatement):void{
const{initializer, kind}=node;

Copy link
Author

Choose a reason for hiding this comment

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

The only issue with this is that an error is thrown unless I specify the node type incheckForStatementDeclaration so I may still need to docheckForStatmentDeclaration(node as ts.ForInStatment | ts.ForOfStatment) when calling it incheckSyntaxErrors

Copy link
Contributor

Choose a reason for hiding this comment

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

Ts can't narrow type?

Looking at the difference,

checkSyntaxError(node: ts.Node)

whileconvertNode usesTSNode

https://github.com/Lonercode/typescript-eslint/blob/ee1ada9db5229902f70faa19dc27950dc457cc7d/packages/typescript-estree/src/convert.ts#L666

maybe change to it will fix the issue?

Copy link
Contributor

Choose a reason for hiding this comment

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

As I tested, it works

image

Copy link
Author

Choose a reason for hiding this comment

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

That's true but if I do this, I get an error in the converter method inconvert.ts as node ists.Node notTSNode:

ts-eslint-err

Copy link
Contributor

@fiskerfiskerNov 27, 2025
edited
Loading

Choose a reason for hiding this comment

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

How about

function checkSyntaxError(tsNode: ts.node): void {checkModifiers(tsNode)const node = tsNode as TSNode;switch (...) {}}

convert.ts also do similar.

Copy link
Author

Choose a reason for hiding this comment

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

That works :)


import{checkModifiers}from'./check-modifiers';
import{isValidAssignmentTarget,createError}from'./node-utils';

Copy link
Contributor

Choose a reason for hiding this comment

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

We should also define a

const SyntaxKind = ts.SyntaxKind;

here,https://github.com/Lonercode/typescript-eslint/blob/ee1ada9db5229902f70faa19dc27950dc457cc7d/packages/typescript-estree/src/convert.ts#L42

so other checks can be copied easier to here.

Lonercode reacted with thumbs up emoji

Choose a reason for hiding this comment

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

Ehh should we? We don't generally do namespace property shorthands like that in the typescript-eslint monorepo. IMO it just adds a bit of clutter.

Copy link
Contributor

@fiskerfiskerNov 27, 2025
edited
Loading

Choose a reason for hiding this comment

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

We'll add lots ofcases in switch, better align with convert.ts.

Copy link
Contributor

Choose a reason for hiding this comment

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

At least keep it before it's done?

@fisker
Copy link
Contributor

@JoshuaKGoldberg Are you fine with just one check in this PR? Or should all checks done in this one? If we want to copy variable declaration syntax check, better wait for#11777 and#11778 to merge first.

Comment on lines +21 to +23
default:{
break;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add this because ESLint complaint? Will this work?

Suggested change
default:{
break;
}
// No default

Copy link
Author

Choose a reason for hiding this comment

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

I think it's valid, exiting with the default, for now at least.

@fisker
Copy link
Contributor

Looks good to me, thanks! 🙏

Can't approve since I'm not a team member.

Lonercode reacted with thumbs up emojiJoshuaKGoldberg reacted with heart emoji

@Lonercode
Copy link
Author

Thanks@fisker

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.

Thanks for getting started on this! I think we should discuss the direction a bit.


constnode=tsNodeasTSNode;

switch(node.kind){

Choose a reason for hiding this comment

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

[Refactor] I don't think this is a positive change for the logic? Converter functions generally directly call thecheckFor* logic they need. For example, for-in and for-of statements directly callcheckForStatementDeclaration. Now this newcheckSyntaxError function has to again switch onnode.kind. That's extra code structure and work.

@fisker please correct me if I'm wrong here, but I think it'd still be in the spirit of the issue to havecheckForStatementDeclaration be a standalone function separated out fromconvert.ts, and still called directly?

As in, the diffs toconvert.ts would look more like:

+ import { checkForStatementDeclaration } from "./checks/...";...      case SyntaxKind.ForInStatement:-       this.#checkForStatementDeclaration(node.initializer, node.kind);+       checkForStatementDeclaration(node.initializer, node.kind);        return this.createNode<TSESTree.ForInStatement>(node, {...-  #checkForStatementDeclaration(...) { ... }

Copy link
Contributor

@fiskerfiskerNov 28, 2025
edited
Loading

Choose a reason for hiding this comment

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

Take this

if(
node.caseBlock.clauses.filter(
switchCase=>switchCase.kind===SyntaxKind.DefaultClause,
).length>1
){
this.#throwError(
node,
"A 'default' clause cannot appear more than once in a 'switch' statement.",
);
}
as example, normally the check just few lines (there are even simpler checks, eg:1). Not every node need such long code likeSyntaxKind.ForInStatement.

If we call from covert.ts directly after thecase ..., we'll have lot of lines to add. and forcing many functions to import/export.

I think a single call likecheckModifiers() used did and duplicate the bigswitch(){} in check-syntax-error.ts is much easier to maintain.

Most kind of node check will inline, instead of separate function.

Copy link
Author

Choose a reason for hiding this comment

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

@JoshuaKGoldberg@fisker Would it prove more efficient to separate outcheckForStatmentDeclaration? I thought the point of the issue was to extract those checks?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@JoshuaKGoldbergJoshuaKGoldbergJoshuaKGoldberg requested changes

+1 more reviewer

@fiskerfiskerfisker left review comments

Reviewers whose approvals may not affect merge requirements

Requested changes must be addressed to merge this pull request.

Assignees

No one assigned

Labels

awaiting responseIssues waiting for a reply from the OP or another party

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Repo: Extract AST check fromConverter

3 participants

@Lonercode@fisker@JoshuaKGoldberg

[8]ページ先頭

©2009-2025 Movatter.jp