diff --git a/linter-4.2/src/TypeScriptLinter.ts b/linter-4.2/src/TypeScriptLinter.ts index dafd72b8f1d912efe1952a629542784df6e0aaaa..a2247c08aba914c71eaef2a50cbf8a8773a26c77 100644 --- a/linter-4.2/src/TypeScriptLinter.ts +++ b/linter-4.2/src/TypeScriptLinter.ts @@ -1064,6 +1064,7 @@ export class TypeScriptLinter { private handleModuleDeclaration(node: ts.Node) { let tsModuleDecl = node as ts.ModuleDeclaration; + this.countDeclarationsWithDuplicateName( this.tsTypeChecker.getSymbolAtLocation(tsModuleDecl.name), tsModuleDecl @@ -1092,7 +1093,10 @@ export class TypeScriptLinter { } } } - } else if (this.tsUtils.hasModifier(tsModifiers, ts.SyntaxKind.DeclareKeyword)) { + } + + if (!(tsModuleDecl.flags & ts.NodeFlags.Namespace) && + this.tsUtils.hasModifier(tsModifiers, ts.SyntaxKind.DeclareKeyword)) { this.incrementCounters(tsModuleDecl, FaultID.ShorthandAmbientModuleDecl); } diff --git a/linter-4.2/test/ambient_module.ts b/linter-4.2/test/ambient_module.ts index 80f9520da57d3c3b848a56ec1ffd4f30dafb52e7..cd1b67be356798700d967f59038ad6b1c807937a 100644 --- a/linter-4.2/test/ambient_module.ts +++ b/linter-4.2/test/ambient_module.ts @@ -28,3 +28,11 @@ declare module 'json!*' { } declare module 'library/*'; + +declare module 'abc' { + export function f(): void; +} + +declare namespace abc2 { + export function f(): void; +} diff --git a/linter-4.2/test/ambient_module.ts.relax.json b/linter-4.2/test/ambient_module.ts.relax.json index 384f229b6a77a435e2e5cca141f03663b178c2c5..a02ca7fc8935464e83947500d0dfc1e6558752dd 100644 --- a/linter-4.2/test/ambient_module.ts.relax.json +++ b/linter-4.2/test/ambient_module.ts.relax.json @@ -17,42 +17,79 @@ { "line": 16, "column": 1, - "problem": "ShorthandAmbientModuleDecl" + "problem": "ShorthandAmbientModuleDecl", + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" }, { "line": 22, "column": 3, - "problem": "NonDeclarationInNamespace" + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" }, { "line": 20, "column": 1, - "problem": "WildcardsInModuleName" + "problem": "ShorthandAmbientModuleDecl", + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" + }, + { + "line": 20, + "column": 1, + "problem": "WildcardsInModuleName", + "suggest": "", + "rule": "Wildcards in module names are not supported (arkts-no-module-wildcards)" }, { "line": 27, "column": 3, - "problem": "NonDeclarationInNamespace" + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" }, { "line": 25, "column": 1, - "problem": "WildcardsInModuleName" + "problem": "ShorthandAmbientModuleDecl", + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" + }, + { + "line": 25, + "column": 1, + "problem": "WildcardsInModuleName", + "suggest": "", + "rule": "Wildcards in module names are not supported (arkts-no-module-wildcards)" }, { "line": 26, "column": 16, - "problem": "AnyType" + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, { "line": 30, "column": 1, - "problem": "ShorthandAmbientModuleDecl" + "problem": "ShorthandAmbientModuleDecl", + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" }, { "line": 30, "column": 1, - "problem": "WildcardsInModuleName" + "problem": "WildcardsInModuleName", + "suggest": "", + "rule": "Wildcards in module names are not supported (arkts-no-module-wildcards)" + }, + { + "line": 32, + "column": 1, + "problem": "ShorthandAmbientModuleDecl", + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" } ] } \ No newline at end of file diff --git a/linter-4.2/test/ambient_module.ts.strict.json b/linter-4.2/test/ambient_module.ts.strict.json index 384f229b6a77a435e2e5cca141f03663b178c2c5..a02ca7fc8935464e83947500d0dfc1e6558752dd 100644 --- a/linter-4.2/test/ambient_module.ts.strict.json +++ b/linter-4.2/test/ambient_module.ts.strict.json @@ -17,42 +17,79 @@ { "line": 16, "column": 1, - "problem": "ShorthandAmbientModuleDecl" + "problem": "ShorthandAmbientModuleDecl", + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" }, { "line": 22, "column": 3, - "problem": "NonDeclarationInNamespace" + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" }, { "line": 20, "column": 1, - "problem": "WildcardsInModuleName" + "problem": "ShorthandAmbientModuleDecl", + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" + }, + { + "line": 20, + "column": 1, + "problem": "WildcardsInModuleName", + "suggest": "", + "rule": "Wildcards in module names are not supported (arkts-no-module-wildcards)" }, { "line": 27, "column": 3, - "problem": "NonDeclarationInNamespace" + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" }, { "line": 25, "column": 1, - "problem": "WildcardsInModuleName" + "problem": "ShorthandAmbientModuleDecl", + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" + }, + { + "line": 25, + "column": 1, + "problem": "WildcardsInModuleName", + "suggest": "", + "rule": "Wildcards in module names are not supported (arkts-no-module-wildcards)" }, { "line": 26, "column": 16, - "problem": "AnyType" + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, { "line": 30, "column": 1, - "problem": "ShorthandAmbientModuleDecl" + "problem": "ShorthandAmbientModuleDecl", + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" }, { "line": 30, "column": 1, - "problem": "WildcardsInModuleName" + "problem": "WildcardsInModuleName", + "suggest": "", + "rule": "Wildcards in module names are not supported (arkts-no-module-wildcards)" + }, + { + "line": 32, + "column": 1, + "problem": "ShorthandAmbientModuleDecl", + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" } ] } \ No newline at end of file diff --git a/linter/src/TypeScriptLinter.ts b/linter/src/TypeScriptLinter.ts index ad41b9016a5ce6acea2da9cfcd8f57ef8630e71a..f5ee6bd7f159424e10586dc182e6f949a0b7fcb4 100644 --- a/linter/src/TypeScriptLinter.ts +++ b/linter/src/TypeScriptLinter.ts @@ -1033,10 +1033,12 @@ export class TypeScriptLinter { private handleModuleDeclaration(node: ts.Node) { let tsModuleDecl = node as ts.ModuleDeclaration; + this.countDeclarationsWithDuplicateName( this.tsTypeChecker.getSymbolAtLocation(tsModuleDecl.name), tsModuleDecl ); + let tsModuleBody = tsModuleDecl.body; let tsModifiers = ts.getModifiers(tsModuleDecl); if (tsModuleBody) { @@ -1060,9 +1062,13 @@ export class TypeScriptLinter { } } } - } else if (this.tsUtils.hasModifier(tsModifiers, ts.SyntaxKind.DeclareKeyword)) { + } + + if (!(tsModuleDecl.flags & ts.NodeFlags.Namespace) && + this.tsUtils.hasModifier(tsModifiers, ts.SyntaxKind.DeclareKeyword)) { this.incrementCounters(tsModuleDecl, FaultID.ShorthandAmbientModuleDecl); } + if (ts.isStringLiteral(tsModuleDecl.name) && tsModuleDecl.name.text.includes('*')) this.incrementCounters(tsModuleDecl, FaultID.WildcardsInModuleName); } diff --git a/linter/test/ambient_module.ts b/linter/test/ambient_module.ts index 80f9520da57d3c3b848a56ec1ffd4f30dafb52e7..cd1b67be356798700d967f59038ad6b1c807937a 100644 --- a/linter/test/ambient_module.ts +++ b/linter/test/ambient_module.ts @@ -28,3 +28,11 @@ declare module 'json!*' { } declare module 'library/*'; + +declare module 'abc' { + export function f(): void; +} + +declare namespace abc2 { + export function f(): void; +} diff --git a/linter/test/ambient_module.ts.relax.json b/linter/test/ambient_module.ts.relax.json index 384f229b6a77a435e2e5cca141f03663b178c2c5..a02ca7fc8935464e83947500d0dfc1e6558752dd 100755 --- a/linter/test/ambient_module.ts.relax.json +++ b/linter/test/ambient_module.ts.relax.json @@ -17,42 +17,79 @@ { "line": 16, "column": 1, - "problem": "ShorthandAmbientModuleDecl" + "problem": "ShorthandAmbientModuleDecl", + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" }, { "line": 22, "column": 3, - "problem": "NonDeclarationInNamespace" + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" }, { "line": 20, "column": 1, - "problem": "WildcardsInModuleName" + "problem": "ShorthandAmbientModuleDecl", + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" + }, + { + "line": 20, + "column": 1, + "problem": "WildcardsInModuleName", + "suggest": "", + "rule": "Wildcards in module names are not supported (arkts-no-module-wildcards)" }, { "line": 27, "column": 3, - "problem": "NonDeclarationInNamespace" + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" }, { "line": 25, "column": 1, - "problem": "WildcardsInModuleName" + "problem": "ShorthandAmbientModuleDecl", + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" + }, + { + "line": 25, + "column": 1, + "problem": "WildcardsInModuleName", + "suggest": "", + "rule": "Wildcards in module names are not supported (arkts-no-module-wildcards)" }, { "line": 26, "column": 16, - "problem": "AnyType" + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, { "line": 30, "column": 1, - "problem": "ShorthandAmbientModuleDecl" + "problem": "ShorthandAmbientModuleDecl", + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" }, { "line": 30, "column": 1, - "problem": "WildcardsInModuleName" + "problem": "WildcardsInModuleName", + "suggest": "", + "rule": "Wildcards in module names are not supported (arkts-no-module-wildcards)" + }, + { + "line": 32, + "column": 1, + "problem": "ShorthandAmbientModuleDecl", + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" } ] } \ No newline at end of file diff --git a/linter/test/ambient_module.ts.strict.json b/linter/test/ambient_module.ts.strict.json index 384f229b6a77a435e2e5cca141f03663b178c2c5..a02ca7fc8935464e83947500d0dfc1e6558752dd 100755 --- a/linter/test/ambient_module.ts.strict.json +++ b/linter/test/ambient_module.ts.strict.json @@ -17,42 +17,79 @@ { "line": 16, "column": 1, - "problem": "ShorthandAmbientModuleDecl" + "problem": "ShorthandAmbientModuleDecl", + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" }, { "line": 22, "column": 3, - "problem": "NonDeclarationInNamespace" + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" }, { "line": 20, "column": 1, - "problem": "WildcardsInModuleName" + "problem": "ShorthandAmbientModuleDecl", + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" + }, + { + "line": 20, + "column": 1, + "problem": "WildcardsInModuleName", + "suggest": "", + "rule": "Wildcards in module names are not supported (arkts-no-module-wildcards)" }, { "line": 27, "column": 3, - "problem": "NonDeclarationInNamespace" + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" }, { "line": 25, "column": 1, - "problem": "WildcardsInModuleName" + "problem": "ShorthandAmbientModuleDecl", + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" + }, + { + "line": 25, + "column": 1, + "problem": "WildcardsInModuleName", + "suggest": "", + "rule": "Wildcards in module names are not supported (arkts-no-module-wildcards)" }, { "line": 26, "column": 16, - "problem": "AnyType" + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, { "line": 30, "column": 1, - "problem": "ShorthandAmbientModuleDecl" + "problem": "ShorthandAmbientModuleDecl", + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" }, { "line": 30, "column": 1, - "problem": "WildcardsInModuleName" + "problem": "WildcardsInModuleName", + "suggest": "", + "rule": "Wildcards in module names are not supported (arkts-no-module-wildcards)" + }, + { + "line": 32, + "column": 1, + "problem": "ShorthandAmbientModuleDecl", + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" } ] } \ No newline at end of file