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

@typescript-eslint typescript-eslint bot commented Oct 15, 2020

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

@aggmoulik aggmoulik commented Oct 15, 2020

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 label Oct 15, 2020
@codecov
Copy link

@codecov 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

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

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);
}
Comment on lines 100 to 109

This comment has been minimized.

@bradzacher

bradzacher Oct 18, 2020
Member

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);
}
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;
}
}
}
`,
Comment on lines 352 to 362

This comment has been minimized.

@bradzacher

bradzacher Oct 18, 2020
Member

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;
}
}
}
`,
aggmoulik added 4 commits Oct 19, 2020
…ode reviews

Signed-off-by: Moulik Aggarwal <qwertymoulik@gmail.com>
Signed-off-by: Moulik Aggarwal <qwertymoulik@gmail.com>
…-eslint into method-signature
@aggmoulik
Copy link
Contributor Author

@aggmoulik aggmoulik commented Oct 19, 2020

Hy @bradzacher , I have updated things you suggested.

Copy link
Member

@bradzacher bradzacher left a comment

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
8 checks passed
8 checks passed
Typecheck
Details
Unit tests Unit tests
Details
Code style and lint
Details
Run integration tests on primary Node.js version
Details
Run unit tests on other Node.js versions (10.x)
Details
Run unit tests on other Node.js versions (14.x)
Details
Publish the latest code as a canary version
Details
Semantic Pull Request ready to be squashed
Details
@aggmoulik
Copy link
Contributor Author

@aggmoulik aggmoulik commented Oct 20, 2020

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

@bradzacher
Copy link
Member

@bradzacher bradzacher commented Oct 20, 2020

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

This was referenced Oct 26, 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.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants