Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
fix(eslint-plugin): [no-namespace] fix false positive for exported namespaces when allowDeclarations=true#4844
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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -46,12 +46,15 @@ export default util.createRule<Options, MessageIds>({ | ||
create(context, [{ allowDeclarations, allowDefinitionFiles }]) { | ||
const filename = context.getFilename(); | ||
function isDeclaration(node: TSESTree.Node): boolean { | ||
if ( | ||
node.type === AST_NODE_TYPES.TSModuleDeclaration && | ||
node.declare === true | ||
) { | ||
return true; | ||
} | ||
return node.parent != null && isDeclaration(node.parent); | ||
armano2 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
} | ||
return { | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -49,6 +49,16 @@ declare namespace foo { | ||
namespace bar { | ||
namespace baz {} | ||
} | ||
} | ||
`, | ||
options: [{ allowDeclarations: true }], | ||
}, | ||
{ | ||
code: ` | ||
export declare namespace foo { | ||
export namespace bar { | ||
namespace baz {} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I think there are few more edge cases that should be tested around declared namespaces inside a non-declared one, both exported and not: namespaceOuter{declarenamespaceDeclared{/* export */namespaceInsideDeclared{// and maybe more namespaces in here}}} | ||
} | ||
`, | ||
options: [{ allowDeclarations: true }], | ||
@@ -251,5 +261,307 @@ namespace Foo.Bar { | ||
}, | ||
], | ||
}, | ||
{ | ||
code: ` | ||
namespace A { | ||
namespace B { | ||
declare namespace C {} | ||
} | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
messageId: 'moduleSyntaxIsPreferred', | ||
line: 2, | ||
column: 1, | ||
}, | ||
{ | ||
messageId: 'moduleSyntaxIsPreferred', | ||
line: 3, | ||
column: 3, | ||
}, | ||
], | ||
options: [{ allowDeclarations: true }], | ||
}, | ||
{ | ||
code: ` | ||
namespace A { | ||
namespace B { | ||
export declare namespace C {} | ||
} | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
messageId: 'moduleSyntaxIsPreferred', | ||
line: 2, | ||
column: 1, | ||
}, | ||
{ | ||
messageId: 'moduleSyntaxIsPreferred', | ||
line: 3, | ||
column: 3, | ||
}, | ||
], | ||
options: [{ allowDeclarations: true }], | ||
}, | ||
{ | ||
code: ` | ||
namespace A { | ||
declare namespace B { | ||
namespace C {} | ||
} | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
messageId: 'moduleSyntaxIsPreferred', | ||
line: 2, | ||
column: 1, | ||
}, | ||
], | ||
options: [{ allowDeclarations: true }], | ||
}, | ||
{ | ||
code: ` | ||
namespace A { | ||
export declare namespace B { | ||
namespace C {} | ||
} | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
messageId: 'moduleSyntaxIsPreferred', | ||
line: 2, | ||
column: 1, | ||
}, | ||
], | ||
options: [{ allowDeclarations: true }], | ||
}, | ||
{ | ||
code: ` | ||
namespace A { | ||
export declare namespace B { | ||
declare namespace C {} | ||
} | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
messageId: 'moduleSyntaxIsPreferred', | ||
line: 2, | ||
column: 1, | ||
}, | ||
], | ||
options: [{ allowDeclarations: true }], | ||
}, | ||
{ | ||
code: ` | ||
namespace A { | ||
export declare namespace B { | ||
export declare namespace C {} | ||
} | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
messageId: 'moduleSyntaxIsPreferred', | ||
line: 2, | ||
column: 1, | ||
}, | ||
], | ||
options: [{ allowDeclarations: true }], | ||
}, | ||
{ | ||
code: ` | ||
namespace A { | ||
declare namespace B { | ||
export declare namespace C {} | ||
} | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
messageId: 'moduleSyntaxIsPreferred', | ||
line: 2, | ||
column: 1, | ||
}, | ||
], | ||
options: [{ allowDeclarations: true }], | ||
}, | ||
{ | ||
code: ` | ||
namespace A { | ||
export namespace B { | ||
export declare namespace C {} | ||
} | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
messageId: 'moduleSyntaxIsPreferred', | ||
line: 2, | ||
column: 1, | ||
}, | ||
{ | ||
messageId: 'moduleSyntaxIsPreferred', | ||
line: 3, | ||
column: 10, | ||
}, | ||
], | ||
options: [{ allowDeclarations: true }], | ||
}, | ||
{ | ||
code: ` | ||
export namespace A { | ||
namespace B { | ||
declare namespace C {} | ||
} | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
messageId: 'moduleSyntaxIsPreferred', | ||
line: 2, | ||
column: 8, | ||
}, | ||
{ | ||
messageId: 'moduleSyntaxIsPreferred', | ||
line: 3, | ||
column: 3, | ||
}, | ||
], | ||
options: [{ allowDeclarations: true }], | ||
}, | ||
{ | ||
code: ` | ||
export namespace A { | ||
namespace B { | ||
export declare namespace C {} | ||
} | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
messageId: 'moduleSyntaxIsPreferred', | ||
line: 2, | ||
column: 8, | ||
}, | ||
{ | ||
messageId: 'moduleSyntaxIsPreferred', | ||
line: 3, | ||
column: 3, | ||
}, | ||
], | ||
options: [{ allowDeclarations: true }], | ||
}, | ||
{ | ||
code: ` | ||
export namespace A { | ||
declare namespace B { | ||
namespace C {} | ||
} | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
messageId: 'moduleSyntaxIsPreferred', | ||
line: 2, | ||
column: 8, | ||
}, | ||
], | ||
options: [{ allowDeclarations: true }], | ||
}, | ||
{ | ||
code: ` | ||
export namespace A { | ||
export declare namespace B { | ||
namespace C {} | ||
} | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
messageId: 'moduleSyntaxIsPreferred', | ||
line: 2, | ||
column: 8, | ||
}, | ||
], | ||
options: [{ allowDeclarations: true }], | ||
}, | ||
{ | ||
code: ` | ||
export namespace A { | ||
export declare namespace B { | ||
declare namespace C {} | ||
} | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
messageId: 'moduleSyntaxIsPreferred', | ||
line: 2, | ||
column: 8, | ||
}, | ||
], | ||
options: [{ allowDeclarations: true }], | ||
}, | ||
{ | ||
code: ` | ||
export namespace A { | ||
export declare namespace B { | ||
export declare namespace C {} | ||
} | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
messageId: 'moduleSyntaxIsPreferred', | ||
line: 2, | ||
column: 8, | ||
}, | ||
], | ||
options: [{ allowDeclarations: true }], | ||
}, | ||
{ | ||
code: ` | ||
export namespace A { | ||
declare namespace B { | ||
export declare namespace C {} | ||
} | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
messageId: 'moduleSyntaxIsPreferred', | ||
line: 2, | ||
column: 8, | ||
}, | ||
], | ||
options: [{ allowDeclarations: true }], | ||
}, | ||
{ | ||
code: ` | ||
export namespace A { | ||
export namespace B { | ||
export declare namespace C {} | ||
} | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
messageId: 'moduleSyntaxIsPreferred', | ||
line: 2, | ||
column: 8, | ||
}, | ||
{ | ||
messageId: 'moduleSyntaxIsPreferred', | ||
line: 3, | ||
column: 10, | ||
}, | ||
], | ||
options: [{ allowDeclarations: true }], | ||
}, | ||
], | ||
}); |