diff --git a/docs/_data/rules.json b/docs/_data/rules.json index e67982e42a4..311d7c1e058 100644 --- a/docs/_data/rules.json +++ b/docs/_data/rules.json @@ -208,18 +208,6 @@ ], "type": "functionality" }, - { - "ruleName": "label-undefined", - "description": "Checks that labels are defined before usage.", - "descriptionDetails": "This rule is now implemented in the TypeScript compiler and does not need to be used.", - "rationale": "Using `break` or `continue` to go to an out-of-scope label is an error in JS.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality" - }, { "ruleName": "linebreak-style", "description": "Enforces a consistent linebreak style.", @@ -1312,4 +1300,4 @@ ], "type": "style" } -] \ No newline at end of file +] diff --git a/docs/rules/label-undefined/index.html b/docs/rules/label-undefined/index.html deleted file mode 100644 index 4876b9c2486..00000000000 --- a/docs/rules/label-undefined/index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -ruleName: label-undefined -description: Checks that labels are defined before usage. -descriptionDetails: This rule is now implemented in the TypeScript compiler and does not need to be used. -rationale: Using `break` or `continue` to go to an out-of-scope label is an error in JS. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -optionsJSON: 'null' -layout: rule -title: 'Rule: label-undefined' ---- \ No newline at end of file diff --git a/src/configs/recommended.ts b/src/configs/recommended.ts index d0195bd59da..99b52e95cb7 100644 --- a/src/configs/recommended.ts +++ b/src/configs/recommended.ts @@ -32,7 +32,6 @@ export const rules = { "interface-name": [true, "always-prefix"], "jsdoc-format": true, "label-position": true, - "label-undefined": true, "max-line-length": [true, 120], "member-access": true, "member-ordering": [true, diff --git a/src/rules/labelUndefinedRule.ts b/src/rules/labelUndefinedRule.ts deleted file mode 100644 index 54df05d9c33..00000000000 --- a/src/rules/labelUndefinedRule.ts +++ /dev/null @@ -1,75 +0,0 @@ -/** - * @license - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * 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. - */ - -import * as ts from "typescript"; - -import * as Lint from "../lint"; - -export class Rule extends Lint.Rules.AbstractRule { - /* tslint:disable:object-literal-sort-keys */ - public static metadata: Lint.IRuleMetadata = { - ruleName: "label-undefined", - description: "Checks that labels are defined before usage.", - descriptionDetails: "This rule is now implemented in the TypeScript compiler and does not need to be used.", - rationale: "Using `break` or `continue` to go to an out-of-scope label is an error in JS.", - optionsDescription: "Not configurable.", - options: null, - optionExamples: ["true"], - type: "functionality", - }; - /* tslint:enable:object-literal-sort-keys */ - - public static FAILURE_STRING = "undefined label: '"; - - public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { - return this.applyWithWalker(new LabelUndefinedWalker(sourceFile, this.getOptions())); - } -} - -class LabelUndefinedWalker extends Lint.ScopeAwareRuleWalker<{[key: string]: any}> { - public createScope(): {[key: string]: any} { - return {}; - } - - public visitLabeledStatement(node: ts.LabeledStatement) { - const label = node.label.text; - const currentScope = this.getCurrentScope(); - - currentScope[label] = true; - super.visitLabeledStatement(node); - } - - public visitBreakStatement(node: ts.BreakOrContinueStatement) { - this.validateLabelAt(node.label, node.getStart(), node.getChildAt(0).getWidth()); - super.visitBreakStatement(node); - } - - public visitContinueStatement(node: ts.BreakOrContinueStatement) { - this.validateLabelAt(node.label, node.getStart(), node.getChildAt(0).getWidth()); - super.visitContinueStatement(node); - } - - private validateLabelAt(label: ts.Identifier, position: number, width: number) { - const currentScope = this.getCurrentScope(); - - if (label != null && !currentScope[label.text]) { - const failureString = Rule.FAILURE_STRING + label.text + "'"; - const failure = this.createFailure(position, width, failureString); - this.addFailure(failure); - } - } -} diff --git a/src/tsconfig.json b/src/tsconfig.json index 55607a2a7c7..5a55ca1ce33 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -90,7 +90,6 @@ "rules/interfaceNameRule.ts", "rules/jsdocFormatRule.ts", "rules/labelPositionRule.ts", - "rules/labelUndefinedRule.ts", "rules/linebreakStyleRule.ts", "rules/maxFileLineCountRule.ts", "rules/maxLineLengthRule.ts", diff --git a/test/rules/label-undefined/test.ts.lint b/test/rules/label-undefined/test.ts.lint deleted file mode 100644 index d9988de8916..00000000000 --- a/test/rules/label-undefined/test.ts.lint +++ /dev/null @@ -1,55 +0,0 @@ -// invalid code - -function f() { - lab3: - for (var i = 0; i < 10; ++i) { - break lab1; - ~~~~~ [undefined label: 'lab1'] - } -} - -var x = function() { - lab4: - while (i < 10) { - continue lab2; - ~~~~~~~~ [undefined label: 'lab2'] - } -}; - -var y = () => { - lab3: - while (i < 10) { - continue lab3; - } - - (function() { - lab2: - switch (j) { - case 1: - break lab3; - ~~~~~ [undefined label: 'lab3'] - } - })(); -}; - -var z = x => { - lab1: - do { - x++; - continue lab4; - ~~~~~~~~ [undefined label: 'lab4'] - } while (x < 10); -}; - -// valid code - -lab5: -for (var i = 0; i < 10; ++i) { - var w = () => { - lab2: - while (i < 10) { - continue lab2; - } - }; - break lab5; -} diff --git a/test/rules/label-undefined/tslint.json b/test/rules/label-undefined/tslint.json deleted file mode 100644 index 74a9a3d5886..00000000000 --- a/test/rules/label-undefined/tslint.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "rules": { - "label-undefined": true - } -} diff --git a/test/tsconfig.json b/test/tsconfig.json index 4d8f1f8a7a9..d64527e9e25 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -85,7 +85,6 @@ "../src/rules/interfaceNameRule.ts", "../src/rules/jsdocFormatRule.ts", "../src/rules/labelPositionRule.ts", - "../src/rules/labelUndefinedRule.ts", "../src/rules/linebreakStyleRule.ts", "../src/rules/maxFileLineCountRule.ts", "../src/rules/maxLineLengthRule.ts",