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(typescript-estree): add strict type mapping to parserServices.esTreeNodeToTSNodeMap #1382

Merged
merged 11 commits into from Jan 9, 2020
Merged

Conversation

armano2
Copy link
Member

@armano2 armano2 commented Dec 26, 2019

I'm unsure if we actually want this change and if place where type is defined is good one.

i was also thinking about name: ParserServicesConvertibleTypes


rules that will have to be updated to use more strict types instead of Node:

  • no-unnecessary-condition
  • no-unnecessary-qualifier
  • no-unused-vars-experimental
  • prefer-readonly
  • prefer-regexp-exec
  • prefer-string-starts-ends-with
  • promise-function-async
  • restrict-plus-operands
  • restrict-template-expressions
  • strict-boolean-expressions

@bradzacher what do you think about this?


for example in prefer-regexp-exec function isStringType is used to check type but as argument it accepts TSESTree.Node and it should TSESTree.LeftHandSideExpression

@typescript-eslint

This comment has been minimized.

@armano2 armano2 marked this pull request as ready for review December 26, 2019 04:43
@bradzacher
Copy link
Member

bradzacher commented Dec 26, 2019

there are a lot of places that I just dropped in TSESTree.Node when it doesn't actually matter what the node type is (no explicit checks on props, etc).

Instead of using an excludes, I think it would be a good idea to strictly type the get method on ParserWeakMap - we know the mapping that exists because we own the conversion logic, so we should be able to do something similar to RuleListener.

Also for Program:exit, could you just add that to the RuleListener list? It's a pretty common pattern.

For the getter on ParserWeakMap, and for RuleListener, we should probably just create a build script to generate the files.

WDYT?

@bradzacher bradzacher changed the title fix(typescript-eslint): correct types of service node maps fix: correct types of service node maps Dec 26, 2019
@bradzacher bradzacher added the bug Something isn't working label Dec 26, 2019
@armano2 armano2 added the DO NOT MERGE PRs which should not be merged yet label Dec 26, 2019
@armano2
Copy link
Member Author

armano2 commented Jan 6, 2020

@bradzacher type mapping is added, i'm unsure if we should expose it to plugins

Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

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

I was actually thinking we should do something like this, but I was too lazy to go through the parser logic and pull out the mapping. So thanks!

I think this is a good idea, and I like the idea of removing the manual conversion as I wouldn't be surprised if we got it wrong around the place.

Could you also run the no-unnecessary-type-arguments rule to fix up any manual annotations that are now unnecessary?

packages/typescript-estree/src/convert.ts Outdated Show resolved Hide resolved
packages/typescript-estree/src/parser-options.ts Outdated Show resolved Hide resolved
packages/experimental-utils/src/index.ts Outdated Show resolved Hide resolved
Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

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

LGTM - one question then I'm happy for this to merge.

@armano2 armano2 removed the DO NOT MERGE PRs which should not be merged yet label Jan 9, 2020
@armano2 armano2 added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin package: typescript-estree Issues related to @typescript-eslint/typescript-estree labels Jan 9, 2020
@bradzacher bradzacher changed the title fix: correct types of service node maps feat(typescript-estree): add strict type mapping to parserServices.esTreeNodeToTSNodeMap Jan 9, 2020
@bradzacher bradzacher added enhancement New feature or request and removed bug Something isn't working labels Jan 9, 2020
@bradzacher
Copy link
Member

There wasn't a bug before, just relaxed types; so switching this to a feat, it's an enhancement and strictification of the types we already provided.

@bradzacher bradzacher merged commit d3d70a3 into typescript-eslint:master Jan 9, 2020
@armano2 armano2 deleted the esTreeNodeToTSNodeMap branch January 9, 2020 22:31
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin package: typescript-estree Issues related to @typescript-eslint/typescript-estree
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants