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

fix(eslint-plugin): [method-signature-style] don't auto-fix interfaces within namespaces #2678

Merged
merged 8 commits into from Oct 19, 2020

Conversation

aggmoulik
Copy link
Contributor

@aggmoulik aggmoulik commented Oct 15, 2020

Fixes #2340

Signed-off-by: Moulik Aggarwal qwertymoulik@gmail.com

Signed-off-by: Moulik Aggarwal <qwertymoulik@gmail.com>
@typescript-eslint
Copy link
Contributor

Thanks for the PR, @aggmoulik!

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 on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

@aggmoulik
Copy link
Contributor Author

Fixes #2340

Signed-off-by: Moulik Aggarwal <qwertymoulik@gmail.com>
@bradzacher bradzacher changed the title fix(eslint-plugin): updated rule for interface in module declaration fix(eslint-plugin): [method-signature-style] updated rule for interface in module declaration Oct 15, 2020
@bradzacher bradzacher added the bug Something isn't working label Oct 15, 2020
@codecov
Copy link

codecov bot commented Oct 15, 2020

Codecov Report

Merging #2678 into master will decrease coverage by 0.03%.
The diff coverage is 82.35%.

@@            Coverage Diff             @@
##           master    #2678      +/-   ##
==========================================
- Coverage   92.82%   92.79%   -0.04%     
==========================================
  Files         294      294              
  Lines        9670     9682      +12     
  Branches     2712     2717       +5     
==========================================
+ Hits         8976     8984       +8     
- Misses        328      330       +2     
- Partials      366      368       +2     
Flag Coverage Δ
#unittest 92.79% <82.35%> (-0.04%) ⬇️

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

Impacted Files Coverage Δ
.../eslint-plugin/src/rules/method-signature-style.ts 89.02% <82.35%> (-3.84%) ⬇️

Signed-off-by: Moulik Aggarwal <qwertymoulik@gmail.com>
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.

the logic itself LGTM - just two comments.
thanks for working on this!

Comment on lines 100 to 109
function isNodeParentModuleDeclaration(node: any): boolean {
if (node.parent?.type === AST_NODE_TYPES.TSModuleDeclaration) {
return true;
}

if (node.parent?.type === AST_NODE_TYPES.Program) {
return false;
}
return isNodeParentModuleDeclaration(node.parent);
}
Copy link
Member

Choose a reason for hiding this comment

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

We can remove the any here with the catch-all Node type

Suggested change
function isNodeParentModuleDeclaration(node: any): boolean {
if (node.parent?.type === AST_NODE_TYPES.TSModuleDeclaration) {
return true;
}
if (node.parent?.type === AST_NODE_TYPES.Program) {
return false;
}
return isNodeParentModuleDeclaration(node.parent);
}
function isNodeParentModuleDeclaration(node: TSESTree.Node): boolean {
if (!node.parent) {
return false;
}
if (node.parent.type === AST_NODE_TYPES.TSModuleDeclaration) {
return true;
}
if (node.parent.type === AST_NODE_TYPES.Program) {
return false;
}
return isNodeParentModuleDeclaration(node.parent);
}

Comment on lines 352 to 362
code: noFormat`
declare global {
namespace jest {
interface Matchers<R, T> {
// Add overloads specific to the DOM
toHaveProp<K extends keyof DomPropsOf<T>>(name: K, value?: DomPropsOf<T>[K]): R;
toHaveProps(props: Partial<DomPropsOf<T>>): R;
}
}
}
`,
Copy link
Member

Choose a reason for hiding this comment

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

indent the example one line, and then you can use the fixer to auto-format the code block

Suggested change
code: noFormat`
declare global {
namespace jest {
interface Matchers<R, T> {
// Add overloads specific to the DOM
toHaveProp<K extends keyof DomPropsOf<T>>(name: K, value?: DomPropsOf<T>[K]): R;
toHaveProps(props: Partial<DomPropsOf<T>>): R;
}
}
}
`,
code: `
declare global {
namespace jest {
interface Matchers<R, T> {
// Add overloads specific to the DOM
toHaveProp<K extends keyof DomPropsOf<T>>(name: K, value?: DomPropsOf<T>[K]): R;
toHaveProps(props: Partial<DomPropsOf<T>>): R;
}
}
}
`,

@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label Oct 18, 2020
…ode reviews

Signed-off-by: Moulik Aggarwal <qwertymoulik@gmail.com>
Signed-off-by: Moulik Aggarwal <qwertymoulik@gmail.com>
@aggmoulik
Copy link
Contributor Author

Hy @bradzacher , I have updated things you suggested.

@bradzacher bradzacher removed the awaiting response Issues waiting for a reply from the OP or another party label Oct 19, 2020
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 - thanks for your contribution!

@bradzacher bradzacher changed the title fix(eslint-plugin): [method-signature-style] updated rule for interface in module declaration fix(eslint-plugin): [method-signature-style] don't auto-fix interfaces within namespaces Oct 19, 2020
@bradzacher bradzacher merged commit e012049 into typescript-eslint:master Oct 19, 2020
@aggmoulik
Copy link
Contributor Author

Hy @bradzacher, Can you please add hacktoberfest-accepted label here.

@bradzacher
Copy link
Member

I thought they only need a tag if they weren't going to be merged in October?

This was referenced Oct 27, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working hacktoberfest-accepted
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[method-signature-style] Using property breaks overloading for declared/global/merged types
2 participants