fix(eslint-plugin): [method-signature-style] don't auto-fix interfaces within namespaces #2678
Conversation
Signed-off-by: Moulik Aggarwal <qwertymoulik@gmail.com>
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! |
…ipt-eslint into method-signature
Fixes #2340 |
Signed-off-by: Moulik Aggarwal <qwertymoulik@gmail.com>
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Signed-off-by: Moulik Aggarwal <qwertymoulik@gmail.com>
the logic itself LGTM - just two comments. |
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); | ||
} |
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);
}
We can remove the any
here with the catch-all Node
type
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; | ||
} | ||
} | ||
} | ||
`, |
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;
}
}
}
`,
indent the example one line, and then you can use the fixer to auto-format the code block
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; | |
} | |
} | |
} | |
`, |
…ode reviews Signed-off-by: Moulik Aggarwal <qwertymoulik@gmail.com>
Signed-off-by: Moulik Aggarwal <qwertymoulik@gmail.com>
…-eslint into method-signature
Hy @bradzacher , I have updated things you suggested. |
LGTM - thanks for your contribution! |
e012049
into
typescript-eslint:master
Hy @bradzacher, Can you please add |
I thought they only need a tag if they weren't going to be merged in October? |
Fixes #2340
Signed-off-by: Moulik Aggarwal qwertymoulik@gmail.com