Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
Fix false positive from no-internal-module on global augmentation
Browse files Browse the repository at this point in the history
Fixes #1069
  • Loading branch information
Jason Killian committed Apr 8, 2016
1 parent 0a7539a commit cc431f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/rules/noInternalModuleRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
Expand Down Expand Up @@ -39,7 +38,8 @@ class NoInternalModuleWalker extends Lint.RuleWalker {
// for external modules, node.name.kind will be a LiteralExpression instead of Identifier
return !Lint.isNodeFlagSet(node, ts.NodeFlags.Namespace)
&& !isNestedDeclaration(node)
&& node.name.kind === ts.SyntaxKind.Identifier;
&& node.name.kind === ts.SyntaxKind.Identifier
&& !isGlobalAugmentation(node);
}
}

Expand All @@ -49,3 +49,9 @@ function isNestedDeclaration(node: ts.ModuleDeclaration) {
// nodes
return node.name.pos === node.pos;
}

function isGlobalAugmentation(node: ts.ModuleDeclaration) {
// augmenting global uses a sepcial syntax that is allowed
// see https://github.com/Microsoft/TypeScript/pull/6213
return node.name.kind === ts.SyntaxKind.Identifier && node.name.text === "global";
}
3 changes: 3 additions & 0 deletions test/rules/no-internal-module/test.ts.lint
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
namespace foo {
}

// valid, special syntax for augmenting global
declare global { }

module bar {
~~~~~~~~~~~~
}
Expand Down

0 comments on commit cc431f8

Please sign in to comment.