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(eslint-plugin): Add unified-signature rule#178

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

armanio123
Copy link

Adding tslint's ruleunified-signature.

@armano2armano2 added the enhancement: new plugin ruleNew rule request for eslint-plugin labelFeb 3, 2019
bradzacher
bradzacher previously approved these changesFeb 7, 2019
Copy link
Collaborator

@armano2armano2 left a comment
edited
Loading

Choose a reason for hiding this comment

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

i'm unsure if this implementation is best what we can do in here

its weird that we have to iterate over nodes few times

this is just idea and i didn't tested it but it should work:

constscopes=[];letcurrentScope={overloads:newMap(),parent:undefined,typeParameters:undefined};functioncreateScope(parent,typeParameters=undefined){scopes.push(currentScope);currentScope={overloads:newMap(),        parent,        typeParameters};}functioncheckScope(){constfailures=checkOverloads(Array.from(currentScope.overloads.values()),currentScope.typeParameters);addFailures(failures);currentScope=scopes.pop();}functionaddOverload(signature,key=null){key=key||getOverloadKey(signature);if(signature.parent===currentScope.parent&&key){constoverloads=currentScope.overloads.get(key);if(overloads!==undefined){overloads.push(signature);}else{currentScope.overloads.set(key,[signature]);}}}return{Program(node){createScope(node);},TSModuleBlock(node){createScope(node);},TSInterfaceDeclaration(node){createScope(node.body,node.typeParameters);},ClassDeclaration(node){createScope(node.body,node.typeParameters);},TSTypeLiteral(node){createScope(node);},// collect overloadsTSDeclareFunction(node){if(node.id&&!node.body){addOverload(node,node.id.name);}},TSCallSignatureDeclaration:addOverload,TSConstructSignatureDeclaration:addOverload,TSMethodSignature:addOverload,TSAbstractMethodDefinition(node){if(!node.value.body){addOverload(node);}},MethodDefinition(node){if(!node.value.body){addOverload(node);}},// validate scopes'Program:exit':checkScope,'TSModuleBlock:exit':checkScope,'TSInterfaceDeclaration:exit':checkScope,'ClassDeclaration:exit':checkScope,'TSTypeLiteral:exit':checkScope};

i still don't like this code, but at-least we don't have to iterate over nodes with custom implementation

with that you are going to be able to remove: checkStatements, checkMembers, collectOverloads.

@JamesHenry
Copy link
Member

Apologies for the conflicts, we decided to remove the counts from the ROADMAP here:#225

They are too awkward to maintain manually, so this is the last time you will have to deal with syncing that up!

j-f1 reacted with thumbs up emoji

@bradzacherbradzacher added BLOCKED: awaiting ts migration enhancement: new plugin ruleNew rule request for eslint-plugin and removed enhancement: new plugin ruleNew rule request for eslint-plugin labelsFeb 11, 2019
@JamesHenry
Copy link
Member

@armanio123 Thanks again for your contribution, when do you think you'll be able to pick this up again?

@@ -0,0 +1,616 @@
/**
* @fileoverview Warns for any two overloads that could be unified into one by using a union or an optional/rest parameter.
* @author Armando Aguirre
Copy link
Member

Choose a reason for hiding this comment

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

Sorry we've changed to using all-contributors now and removed all other occurrences of these file-level author comments, please could you remove this

Copy link
Author

Choose a reason for hiding this comment

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

Removed.

@armanio123
Copy link
Author

Added the changes requested, migrated to TS and addressed the comments as well. Let me know if there's anything else.

@codecov
Copy link

codecovbot commentedMar 11, 2019
edited
Loading

Codecov Report

Merging#178 intomaster willdecrease coverage by<.01%.
The diff coverage is97.16%.

@@            Coverage Diff            @@##           master    #178      +/-   ##=========================================- Coverage    97.2%   97.2%   -0.01%=========================================  Files          67      68       +1       Lines        2360    2501     +141       Branches      337     385      +48     =========================================+ Hits         2294    2431     +137  Misses         44      44- Partials       22      26       +4
Impacted FilesCoverage Δ
packages/eslint-plugin/src/util/misc.ts84.21% <100%> (+4.21%)⬆️
...ages/eslint-plugin/src/rules/unified-signatures.ts97.08% <97.08%> (ø)

@@ -34,7 +34,7 @@
| [`promise-function-async`] | ✅ | [`@typescript-eslint/promise-function-async`] |
| [`typedef`] | 🛑 | N/A |
| [`typedef-whitespace`] | ✅ | [`@typescript-eslint/type-annotation-spacing`] |
| [`unified-signatures`] |🛑 |N/A |
| [`unified-signatures`] | |[`@typescript-eslint/unified-signatures`] |
Copy link
Member

Choose a reason for hiding this comment

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

need to add the link at the bottom of the file or else this won't work

Copy link
Author

Choose a reason for hiding this comment

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

Fixed.

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.

need to tighten up the types if this is going to be merged.
Most of the functions have params of typeany. Ideally there should be zeroanys.

You canimport { TSESTree } from '@typescript-eslint/typescript-estree'; and use the types within that namespace to type nodes and the like.

@JamesHenry
Copy link
Member

Thanks for working through all the feedback,@armanio123!

@JamesHenryJamesHenry merged commit6ffaa0b intotypescript-eslint:masterMar 20, 2019
@JamesHenry
Copy link
Member

@uniqueiniquity is going to apply this to the TS repo this week :)

j-f1 reacted with rocket emoji

@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsApr 21, 2020
Luckeu pushed a commit to Luckeu/typescript-eslint that referenced this pull requestJun 27, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@bradzacherbradzacherbradzacher requested changes

@JamesHenryJamesHenryJamesHenry approved these changes

@armano2armano2Awaiting requested review from armano2

Assignees
No one assigned
Labels
enhancement: new plugin ruleNew rule request for eslint-plugin
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@armanio123@JamesHenry@armano2@bradzacher

[8]ページ先頭

©2009-2025 Movatter.jp