From da603e67735db03493615e1f81794a9ffdef4c62 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Sun, 15 Jan 2017 09:40:43 -0800 Subject: [PATCH 01/13] no-magic-numbers: Make condition lazy (don't call `.getText()` for every number literal in the file) (#2042) --- docs/_data/rules.json | 5 +-- docs/rules/whitespace/index.html | 5 ++- src/rules/noMagicNumbersRule.ts | 31 ++++++++++--------- .../no-magic-numbers/custom/test.ts.lint | 1 + 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/docs/_data/rules.json b/docs/_data/rules.json index bdf69bd6a6b..ddea1801436 100644 --- a/docs/_data/rules.json +++ b/docs/_data/rules.json @@ -1720,7 +1720,7 @@ "ruleName": "whitespace", "description": "Enforces whitespace style conventions.", "rationale": "Helps maintain a readable, consistent style in your codebase.", - "optionsDescription": "\nSeven arguments may be optionally provided:\n\n* `\"check-branch\"` checks branching statements (`if`/`else`/`for`/`while`) are followed by whitespace.\n* `\"check-decl\"`checks that variable declarations have whitespace around the equals token.\n* `\"check-operator\"` checks for whitespace around operator tokens.\n* `\"check-module\"` checks for whitespace in import & export statements.\n* `\"check-separator\"` checks for whitespace after separator tokens (`,`/`;`).\n* `\"check-type\"` checks for whitespace before a variable type specification.\n* `\"check-typecast\"` checks for whitespace between a typecast and its target.", + "optionsDescription": "\nSeven arguments may be optionally provided:\n\n* `\"check-branch\"` checks branching statements (`if`/`else`/`for`/`while`) are followed by whitespace.\n* `\"check-decl\"`checks that variable declarations have whitespace around the equals token.\n* `\"check-operator\"` checks for whitespace around operator tokens.\n* `\"check-module\"` checks for whitespace in import & export statements.\n* `\"check-separator\"` checks for whitespace after separator tokens (`,`/`;`).\n* `\"check-type\"` checks for whitespace before a variable type specification.\n* `\"check-typecast\"` checks for whitespace between a typecast and its target.\n* `\"check-preblock\"` checks for whitespace before the opening brace of a block", "options": { "type": "array", "items": { @@ -1732,7 +1732,8 @@ "check-module", "check-separator", "check-type", - "check-typecast" + "check-typecast", + "check-preblock" ] }, "minLength": 0, diff --git a/docs/rules/whitespace/index.html b/docs/rules/whitespace/index.html index 259fd6a8e02..97d6f7bfb29 100644 --- a/docs/rules/whitespace/index.html +++ b/docs/rules/whitespace/index.html @@ -13,6 +13,7 @@ * `"check-separator"` checks for whitespace after separator tokens (`,`/`;`). * `"check-type"` checks for whitespace before a variable type specification. * `"check-typecast"` checks for whitespace between a typecast and its target. + * `"check-preblock"` checks for whitespace before the opening brace of a block options: type: array items: @@ -25,6 +26,7 @@ - check-separator - check-type - check-typecast + - check-preblock minLength: 0 maxLength: 7 optionExamples: @@ -45,7 +47,8 @@ "check-module", "check-separator", "check-type", - "check-typecast" + "check-typecast", + "check-preblock" ] }, "minLength": 0, diff --git a/src/rules/noMagicNumbersRule.ts b/src/rules/noMagicNumbersRule.ts index 4e61383c052..bfc37e2fad5 100644 --- a/src/rules/noMagicNumbersRule.ts +++ b/src/rules/noMagicNumbersRule.ts @@ -68,7 +68,7 @@ export class Rule extends Lint.Rules.AbstractRule { } class NoMagicNumbersWalker extends Lint.RuleWalker { - // lookup object for allowed magic numbers + // allowed magic numbers private allowed: Set; constructor(sourceFile: ts.SourceFile, options: IOptions) { super(sourceFile, options); @@ -79,25 +79,28 @@ class NoMagicNumbersWalker extends Lint.RuleWalker { } public visitNode(node: ts.Node) { - if (node.kind === ts.SyntaxKind.NumericLiteral || this.isNegativeNumericExpression(node)) { - const isAllowedNode = Rule.ALLOWED_NODES.has(node.parent!.kind); - const isAllowedNumber = this.allowed.has(node.getText()); - if (!isAllowedNode && !isAllowedNumber) { + const num = getLiteralNumber(node); + if (num !== undefined) { + if (!Rule.ALLOWED_NODES.has(node.parent!.kind) && !this.allowed.has(num)) { this.addFailureAtNode(node, Rule.FAILURE_STRING); } } else { super.visitNode(node); } } +} - /** - * Checks if a node is an negative unary expression with on a numeric operand. - */ - private isNegativeNumericExpression(node: ts.Node): boolean { - if (node.kind !== ts.SyntaxKind.PrefixUnaryExpression) { - return false; - } - const unaryNode = (node as ts.PrefixUnaryExpression); - return unaryNode.operator === ts.SyntaxKind.MinusToken && unaryNode.operand.kind === ts.SyntaxKind.NumericLiteral; +/** If node is a number literal, return a string representation of that number. */ +function getLiteralNumber(node: ts.Node): string | undefined { + if (node.kind === ts.SyntaxKind.NumericLiteral) { + return (node as ts.NumericLiteral).text; + } + if (node.kind !== ts.SyntaxKind.PrefixUnaryExpression) { + return undefined; + } + const { operator, operand } = node as ts.PrefixUnaryExpression; + if (operator === ts.SyntaxKind.MinusToken && operand.kind === ts.SyntaxKind.NumericLiteral) { + return "-" + (operand as ts.NumericLiteral).text; } + return undefined; } diff --git a/test/rules/no-magic-numbers/custom/test.ts.lint b/test/rules/no-magic-numbers/custom/test.ts.lint index 3f5aa7ddc36..f164c29de8d 100644 --- a/test/rules/no-magic-numbers/custom/test.ts.lint +++ b/test/rules/no-magic-numbers/custom/test.ts.lint @@ -1,5 +1,6 @@ console.log(1337); console.log(-1337); +console.log(- 1337); console.log(1337.7); console.log(1338); ~~~~ ['magic numbers' are not allowed] From fe104728ff4c3138823aba4fbae6f8b0e48485ca Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Sun, 15 Jan 2017 19:11:09 -0800 Subject: [PATCH 02/13] Use native string repeat (#2048) --- src/test/lines.ts | 12 +++++------- src/test/utils.ts | 19 ------------------- test/rule-tester/utilsTests.ts | 28 ---------------------------- 3 files changed, 5 insertions(+), 54 deletions(-) delete mode 100644 src/test/utils.ts delete mode 100644 test/rule-tester/utilsTests.ts diff --git a/src/test/lines.ts b/src/test/lines.ts index 09faafaab06..0f9aeae6422 100644 --- a/src/test/lines.ts +++ b/src/test/lines.ts @@ -14,8 +14,6 @@ * limitations under the License. */ -import {replicateStr} from "./utils"; - // Use classes here instead of interfaces because we want runtime type data export class Line { } export class CodeLine extends Line { constructor(public contents: string) { super(); } } @@ -27,7 +25,7 @@ export class EndErrorLine extends ErrorLine { constructor(startCol: number, public endCol: number, public message: string) { super(startCol); } } -// example matches (between the quotes): +// example matches (between the quotes): // " ~~~~~~~~" const multilineErrorRegex = /^\s*(~+|~nil)$/; // " ~~~~~~~~~ [some error message]" @@ -80,7 +78,7 @@ export function printLine(line: Line, code?: string): string | null { throw new Error("Must supply argument for code parameter when line is an ErrorLine"); } - const leadingSpaces = replicateStr(" ", line.startCol); + const leadingSpaces = " ".repeat(line.startCol); if (line instanceof MultilineErrorLine) { // special case for when the line of code is simply a newline. // use "~nil" to indicate the error continues on that line @@ -88,11 +86,11 @@ export function printLine(line: Line, code?: string): string | null { return ZERO_LENGTH_ERROR; } - const tildes = replicateStr("~", code.length - leadingSpaces.length); + const tildes = "~".repeat(code.length - leadingSpaces.length); return `${leadingSpaces}${tildes}`; } else if (line instanceof EndErrorLine) { - let tildes = replicateStr("~", line.endCol - line.startCol); - let endSpaces = replicateStr(" ", code.length - line.endCol); + let tildes = "~".repeat(line.endCol - line.startCol); + let endSpaces = " ".repeat(code.length - line.endCol); if (tildes.length === 0) { tildes = ZERO_LENGTH_ERROR; // because we add "~nil" we need four less spaces than normal at the end diff --git a/src/test/utils.ts b/src/test/utils.ts deleted file mode 100644 index a7caec955fc..00000000000 --- a/src/test/utils.ts +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2016 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. - */ - -export function replicateStr(str: string, numTimes: number) { - return Array(numTimes + 1).join(str); -} diff --git a/test/rule-tester/utilsTests.ts b/test/rule-tester/utilsTests.ts deleted file mode 100644 index e283a1f8b31..00000000000 --- a/test/rule-tester/utilsTests.ts +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2016 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 utils from "../../src/test/utils"; - -describe("Rule Test Utils", () => { - describe("replicateStr", () => { - it("should duplicate strings correctly", () => { - assert.strictEqual("xxxxx", utils.replicateStr("x", 5)); - assert.strictEqual("", utils.replicateStr("abc", 0)); - assert.strictEqual("abcabcabc", utils.replicateStr("abc", 3)); - assert.strictEqual("one", utils.replicateStr("one", 1)); - }); - }); -}); From a8fbbe24852ee8e9d18e7660847233129e31ffc9 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Mon, 16 Jan 2017 17:15:46 +0100 Subject: [PATCH 03/13] Introduce alternative to SkippableTokenAwareRuleWalker and scanAllTokens (#2036) Scanning the whole source file is very fragile, because the grammar is not context free. You had to skip certain ranges, that were known to cause trouble. For example regex literals or template expressions. This approach is also very fragile, as it didn't cover all cases and has to adopt new grammar as the language adds it. The new function hands the scanning and parsing off to the parser and only iterates over the tokens of all AST nodes. Skipping ranges is no longer necessary. Also added deprecation comment to scanAllTokens. --- src/enableDisableRules.ts | 39 ++-- src/language/utils.ts | 167 ++++++++++++++++++ src/rules/commentFormatRule.ts | 19 +- src/rules/jsdocFormatRule.ts | 19 +- src/rules/noTrailingWhitespaceRule.ts | 22 +-- src/rules/whitespaceRule.ts | 35 +--- .../_integration/enable-disable/test.tsx.lint | 69 ++++++++ test/rules/_integration/react/test.tsx.lint | 8 +- test/rules/comment-format/lower/test.tsx.lint | 12 ++ test/rules/whitespace/all/test.ts.fix | 6 + test/rules/whitespace/all/test.ts.lint | 13 ++ 11 files changed, 306 insertions(+), 103 deletions(-) create mode 100644 test/rules/_integration/enable-disable/test.tsx.lint create mode 100644 test/rules/comment-format/lower/test.tsx.lint diff --git a/src/enableDisableRules.ts b/src/enableDisableRules.ts index 04a5d3d2924..6c819f7ff44 100644 --- a/src/enableDisableRules.ts +++ b/src/enableDisableRules.ts @@ -19,11 +19,11 @@ import * as ts from "typescript"; import {AbstractRule} from "./language/rule/abstractRule"; import {IOptions} from "./language/rule/rule"; -import {scanAllTokens} from "./language/utils"; -import {SkippableTokenAwareRuleWalker} from "./language/walker/skippableTokenAwareRuleWalker"; +import {forEachComment, TokenPosition} from "./language/utils"; +import {RuleWalker} from "./language/walker/ruleWalker"; import {IEnableDisablePosition} from "./ruleLoader"; -export class EnableDisableRulesWalker extends SkippableTokenAwareRuleWalker { +export class EnableDisableRulesWalker extends RuleWalker { public enableDisableRuleMap: {[rulename: string]: IEnableDisablePosition[]} = {}; constructor(sourceFile: ts.SourceFile, options: IOptions, rules: {[name: string]: any}) { @@ -42,25 +42,8 @@ export class EnableDisableRulesWalker extends SkippableTokenAwareRuleWalker { } public visitSourceFile(node: ts.SourceFile) { - super.visitSourceFile(node); - const scan = ts.createScanner(ts.ScriptTarget.ES5, false, ts.LanguageVariant.Standard, node.text); - - scanAllTokens(scan, (scanner: ts.Scanner) => { - const startPos = scanner.getStartPos(); - const skip = this.getSkipEndFromStart(startPos); - if (skip !== undefined) { - // tokens to skip are places where the scanner gets confused about what the token is, without the proper context - // (specifically, regex, identifiers, and templates). So skip those tokens. - scanner.setTextPos(skip); - return; - } - - if (scanner.getToken() === ts.SyntaxKind.MultiLineCommentTrivia || - scanner.getToken() === ts.SyntaxKind.SingleLineCommentTrivia) { - const commentText = scanner.getTokenText(); - const startPosition = scanner.getTokenPos(); - this.handlePossibleTslintSwitch(commentText, startPosition, node, scanner); - } + forEachComment(node, (fullText, _kind, pos) => { + return this.handlePossibleTslintSwitch(fullText.substring(pos.tokenStart, pos.end), node, pos); }); } @@ -97,7 +80,7 @@ export class EnableDisableRulesWalker extends SkippableTokenAwareRuleWalker { return ruleStateMap[ruleStateMap.length - 1].isEnabled; } - private handlePossibleTslintSwitch(commentText: string, startingPosition: number, node: ts.SourceFile, scanner: ts.Scanner) { + private handlePossibleTslintSwitch(commentText: string, node: ts.SourceFile, pos: TokenPosition) { // regex is: start of string followed by "/*" or "//" followed by any amount of whitespace followed by "tslint:" if (commentText.match(/^(\/\*|\/\/)\s*tslint:/)) { const commentTextParts = commentText.split(":"); @@ -150,18 +133,18 @@ export class EnableDisableRulesWalker extends SkippableTokenAwareRuleWalker { if (isCurrentLine) { // start at the beginning of the current line - start = this.getStartOfLinePosition(node, startingPosition); + start = this.getStartOfLinePosition(node, pos.tokenStart); // end at the beginning of the next line - end = scanner.getTextPos() + 1; + end = pos.end + 1; } else if (isNextLine) { // start at the current position - start = startingPosition; + start = pos.tokenStart; // end at the beginning of the line following the next line - end = this.getStartOfLinePosition(node, startingPosition, 2); + end = this.getStartOfLinePosition(node, pos.tokenStart, 2); } else { // disable rule for the rest of the file // start at the current position, but skip end position - start = startingPosition; + start = pos.tokenStart; end = undefined; } diff --git a/src/language/utils.ts b/src/language/utils.ts index b79bff5b45f..5a2d23ff54c 100644 --- a/src/language/utils.ts +++ b/src/language/utils.ts @@ -61,6 +61,7 @@ export function doesIntersect(failure: RuleFailure, disabledIntervals: IDisabled }); } +/** @deprecated use forEachToken instead */ export function scanAllTokens(scanner: ts.Scanner, callback: (s: ts.Scanner) => void) { let lastStartPos = -1; while (scanner.scan() !== ts.SyntaxKind.EndOfFileToken) { @@ -237,3 +238,169 @@ export function isBlockScopeBoundary(node: ts.Node): boolean { && (node.parent.kind === ts.SyntaxKind.TryStatement || node.parent.kind === ts.SyntaxKind.IfStatement); } + +export interface TokenPosition { + /** The start of the token including all trivia before it */ + fullStart: number; + /** The start of the token */ + tokenStart: number; + /** The end of the token */ + end: number; +} +export type ForEachTokenCallback = (fullText: string, kind: ts.SyntaxKind, pos: TokenPosition, parent: ts.Node) => void; +export type ForEachCommentCallback = (fullText: string, kind: ts.SyntaxKind, pos: TokenPosition) => void; +export type FilterCallback = (node: ts.Node) => boolean; + +/** + * Iterate over all tokens of `node` + * + * @description JsDoc comments are treated like regular comments and only visited if `skipTrivia` === false. + * + * @param node The node whose tokens should be visited + * @param skipTrivia If set to false all trivia preceeding `node` or any of its children is included + * @param cb Is called for every token of `node`. It gets the full text of the SourceFile and the position of the token within that text. + * @param filter If provided, will be called for every Node and Token found. If it returns false `cb` will not be called for this subtree. + */ +export function forEachToken(node: ts.Node, skipTrivia: boolean, cb: ForEachTokenCallback, filter?: FilterCallback) { + // this function will most likely be called with SourceFile anyways, so there is no need for an additional parameter + const sourceFile = node.getSourceFile(); + const fullText = sourceFile.text; + const iterateFn = filter === undefined ? iterateChildren : iterateWithFilter; + const handleTrivia = skipTrivia ? undefined : createTriviaHandler(sourceFile, cb); + + iterateFn(node); + + // this function is used to save the if condition for the common case where no filter is provided + function iterateWithFilter(child: ts.Node): void { + if (filter!(child)) { + return iterateChildren(child); + } + } + + function iterateChildren(child: ts.Node): void { + if (child.kind < ts.SyntaxKind.FirstNode) { + // we found a token, tokens have no children, stop recursing here + return callback(child); + } + /* Exclude everything contained in JsDoc, it will be handled with the other trivia anyway. + * When we would handle JsDoc tokens like regular ones, we would scan some trivia multiple times. + * Even worse, we would scan for trivia inside the JsDoc comment, which yields unexpected results.*/ + if (child.kind !== ts.SyntaxKind.JSDocComment) { + // recurse into Node's children to find tokens + return child.getChildren(sourceFile).forEach(iterateFn); + } + } + + function callback(token: ts.Node) { + const tokenStart = token.getStart(sourceFile); + if (!skipTrivia && tokenStart !== token.pos) { + // we only have to handle trivia before each token, because there is nothing after EndOfFileToken + handleTrivia!(token.pos, tokenStart, token); + } + return cb(fullText, token.kind, {tokenStart, fullStart: token.pos, end: token.end}, token.parent!); + } +} + +function createTriviaHandler(sourceFile: ts.SourceFile, cb: ForEachTokenCallback) { + const fullText = sourceFile.text; + const scanner = ts.createScanner(sourceFile.languageVersion, false, sourceFile.languageVariant, fullText); + /** + * Scan the specified range to get all trivia tokens. + * This includes trailing trivia of the last token and the leading trivia of the current token + */ + function handleTrivia(start: number, end: number, token: ts.Node) { + const parent = token.parent!; + // prevent false positives by not scanning inside JsxText + if (!canHaveLeadingTrivia(token.kind, parent)) { + return; + } + scanner.setTextPos(start); + let position: number; + // we only get here if start !== end, so we can scan at least one time + do { + const kind = scanner.scan(); + position = scanner.getTextPos(); + cb(fullText, kind, {tokenStart: scanner.getTokenPos(), end: position, fullStart: start}, parent); + } while (position < end); + } + + return handleTrivia; +} + +/** Iterate over all comments owned by `node` or its children */ +export function forEachComment(node: ts.Node, cb: ForEachCommentCallback) { + /* Visit all tokens and skip trivia. + Comment ranges between tokens are parsed without the need of a scanner. + forEachToken also does intentionally not pay attention to the correct comment ownership of nodes as it always + scans all trivia before each token, which could include trailing comments of the previous token. + Comment onwership is done right in this function*/ + return forEachToken(node, true, (fullText, tokenKind, pos, parent) => { + // don't search for comments inside JsxText + if (canHaveLeadingTrivia(tokenKind, parent)) { + // Comments before the first token (pos.fullStart === 0) are all considered leading comments, so no need for special treatment + ts.forEachLeadingCommentRange(fullText, pos.fullStart, commentCallback); + } + if (canHaveTrailingTrivia(tokenKind, parent)) { + ts.forEachTrailingCommentRange(fullText, pos.end, commentCallback); + } + function commentCallback(tokenStart: number, end: number, kind: ts.SyntaxKind) { + cb(fullText, kind, {tokenStart, end, fullStart: pos.fullStart}); + } + }); +} + +/** Exclude leading positions that would lead to scanning for trivia inside JsxText */ +function canHaveLeadingTrivia(tokenKind: ts.SyntaxKind, parent: ts.Node): boolean { + if (tokenKind === ts.SyntaxKind.JsxText) { + return false; // there is no trivia before JsxText + } + if (tokenKind === ts.SyntaxKind.OpenBraceToken) { + // before a JsxExpression inside a JsxElement's body can only be other JsxChild, but no trivia + return parent.kind !== ts.SyntaxKind.JsxExpression || parent.parent!.kind !== ts.SyntaxKind.JsxElement; + } + if (tokenKind === ts.SyntaxKind.LessThanToken) { + if (parent.kind === ts.SyntaxKind.JsxClosingElement) { + return false; // would be inside the element body + } + if (parent.kind === ts.SyntaxKind.JsxOpeningElement || parent.kind === ts.SyntaxKind.JsxSelfClosingElement) { + // there can only be leading trivia if we are at the end of the top level element + return parent.parent!.parent!.kind !== ts.SyntaxKind.JsxElement; + } + } + return true; +} + +/** Exclude trailing positions that would lead to scanning for trivia inside JsxText */ +function canHaveTrailingTrivia(tokenKind: ts.SyntaxKind, parent: ts.Node): boolean { + if (tokenKind === ts.SyntaxKind.JsxText) { + return false; // there is no trivia after JsxText + } + if (tokenKind === ts.SyntaxKind.CloseBraceToken) { + // after a JsxExpression inside a JsxElement's body can only be other JsxChild, but no trivia + return parent.kind !== ts.SyntaxKind.JsxExpression || parent.parent!.kind !== ts.SyntaxKind.JsxElement; + } + if (tokenKind === ts.SyntaxKind.GreaterThanToken) { + if (parent.kind === ts.SyntaxKind.JsxOpeningElement) { + return false; // would be inside the element + } + if (parent.kind === ts.SyntaxKind.JsxClosingElement || parent.kind === ts.SyntaxKind.JsxSelfClosingElement) { + // there can only be trailing trivia if we are at the end of the top level element + return parent.parent!.parent!.kind !== ts.SyntaxKind.JsxElement; + } + } + return true; +} + +/** + * Checks if there are any comments between `position` and the next non-trivia token + * + * @param text The text to scan + * @param position The position inside `text` where to start scanning. Make sure that this is a valid start position. + * This value is typically obtained from `node.getFullStart()` or `node.getEnd()` + */ +export function hasCommentAfterPosition(text: string, position: number): boolean { + const cb = () => true; + return ts.forEachTrailingCommentRange(text, position, cb) || + ts.forEachLeadingCommentRange(text, position, cb) || + false; // return boolean instead of undefined if no comment is found +} diff --git a/src/rules/commentFormatRule.ts b/src/rules/commentFormatRule.ts index 199083d966a..688728b03ec 100644 --- a/src/rules/commentFormatRule.ts +++ b/src/rules/commentFormatRule.ts @@ -106,7 +106,7 @@ export class Rule extends Lint.Rules.AbstractRule { } } -class CommentWalker extends Lint.SkippableTokenAwareRuleWalker { +class CommentWalker extends Lint.RuleWalker { private exceptionsRegExp: ExceptionsRegExp; private failureIgnorePart: string = ""; @@ -117,19 +117,10 @@ class CommentWalker extends Lint.SkippableTokenAwareRuleWalker { } public visitSourceFile(node: ts.SourceFile) { - super.visitSourceFile(node); - Lint.scanAllTokens(ts.createScanner(ts.ScriptTarget.ES5, false, ts.LanguageVariant.Standard, node.text), (scanner: ts.Scanner) => { - const skip = this.getSkipEndFromStart(scanner.getStartPos()); - if (skip !== undefined) { - // tokens to skip are places where the scanner gets confused about what the token is, without the proper context - // (specifically, regex, identifiers, and templates). So skip those tokens. - scanner.setTextPos(skip); - return; - } - - if (scanner.getToken() === ts.SyntaxKind.SingleLineCommentTrivia) { - const commentText = scanner.getTokenText(); - const startPosition = scanner.getTokenPos() + 2; + Lint.forEachComment(node, (fullText, kind, pos) => { + if (kind === ts.SyntaxKind.SingleLineCommentTrivia) { + const commentText = fullText.substring(pos.tokenStart, pos.end); + const startPosition = pos.tokenStart + 2; const width = commentText.length - 2; if (this.hasOption(OPTION_SPACE)) { if (!startsWithSpace(commentText)) { diff --git a/src/rules/jsdocFormatRule.ts b/src/rules/jsdocFormatRule.ts index 5322276b1ab..f6c9b0ebe24 100644 --- a/src/rules/jsdocFormatRule.ts +++ b/src/rules/jsdocFormatRule.ts @@ -48,22 +48,11 @@ export class Rule extends Lint.Rules.AbstractRule { } } -class JsdocWalker extends Lint.SkippableTokenAwareRuleWalker { +class JsdocWalker extends Lint.RuleWalker { public visitSourceFile(node: ts.SourceFile) { - super.visitSourceFile(node); - Lint.scanAllTokens(ts.createScanner(ts.ScriptTarget.ES5, false, ts.LanguageVariant.Standard, node.text), (scanner: ts.Scanner) => { - const skip = this.getSkipEndFromStart(scanner.getStartPos()); - if (skip !== undefined) { - // tokens to skip are places where the scanner gets confused about what the token is, without the proper context - // (specifically, regex, identifiers, and templates). So skip those tokens. - scanner.setTextPos(skip); - return; - } - - if (scanner.getToken() === ts.SyntaxKind.MultiLineCommentTrivia) { - const commentText = scanner.getTokenText(); - const startPosition = scanner.getTokenPos(); - this.findFailuresForJsdocComment(commentText, startPosition); + Lint.forEachComment(node, (fullText, kind, pos) => { + if (kind === ts.SyntaxKind.MultiLineCommentTrivia) { + this.findFailuresForJsdocComment(fullText.substring(pos.tokenStart, pos.end), pos.tokenStart); } }); } diff --git a/src/rules/noTrailingWhitespaceRule.ts b/src/rules/noTrailingWhitespaceRule.ts index ddc15ef3e70..ca5a52985c7 100644 --- a/src/rules/noTrailingWhitespaceRule.ts +++ b/src/rules/noTrailingWhitespaceRule.ts @@ -40,29 +40,19 @@ export class Rule extends Lint.Rules.AbstractRule { } } -class NoTrailingWhitespaceWalker extends Lint.SkippableTokenAwareRuleWalker { +class NoTrailingWhitespaceWalker extends Lint.RuleWalker { public visitSourceFile(node: ts.SourceFile) { - super.visitSourceFile(node); let lastSeenWasWhitespace = false; let lastSeenWhitespacePosition = 0; - Lint.scanAllTokens(ts.createScanner(ts.ScriptTarget.ES5, false, ts.LanguageVariant.Standard, node.text), (scanner: ts.Scanner) => { - const skip = this.getSkipEndFromStart(scanner.getStartPos()); - if (skip !== undefined) { - // tokens to skip are places where the scanner gets confused about what the token is, without the proper context - // (specifically, regex, identifiers, and templates). So skip those tokens. - scanner.setTextPos(skip); - lastSeenWasWhitespace = false; - return; - } - - if (scanner.getToken() === ts.SyntaxKind.NewLineTrivia) { + Lint.forEachToken(node, false, (_text, kind, pos) => { + if (kind === ts.SyntaxKind.NewLineTrivia) { if (lastSeenWasWhitespace) { - this.addFailureFromStartToEnd(lastSeenWhitespacePosition, scanner.getStartPos(), Rule.FAILURE_STRING); + this.addFailureFromStartToEnd(lastSeenWhitespacePosition, pos.tokenStart, Rule.FAILURE_STRING); } lastSeenWasWhitespace = false; - } else if (scanner.getToken() === ts.SyntaxKind.WhitespaceTrivia) { + } else if (kind === ts.SyntaxKind.WhitespaceTrivia) { lastSeenWasWhitespace = true; - lastSeenWhitespacePosition = scanner.getStartPos(); + lastSeenWhitespacePosition = pos.tokenStart; } else { lastSeenWasWhitespace = false; } diff --git a/src/rules/whitespaceRule.ts b/src/rules/whitespaceRule.ts index 2dd286ceeb1..da72b04eb22 100644 --- a/src/rules/whitespaceRule.ts +++ b/src/rules/whitespaceRule.ts @@ -35,7 +35,7 @@ export class Rule extends Lint.Rules.AbstractRule { description: "Enforces whitespace style conventions.", rationale: "Helps maintain a readable, consistent style in your codebase.", optionsDescription: Lint.Utils.dedent` - Seven arguments may be optionally provided: + Eight arguments may be optionally provided: * \`"check-branch"\` checks branching statements (\`if\`/\`else\`/\`for\`/\`while\`) are followed by whitespace. * \`"check-decl"\`checks that variable declarations have whitespace around the equals token. @@ -68,7 +68,7 @@ export class Rule extends Lint.Rules.AbstractRule { } } -class WhitespaceWalker extends Lint.SkippableTokenAwareRuleWalker { +class WhitespaceWalker extends Lint.RuleWalker { private scanner: ts.Scanner; constructor(sourceFile: ts.SourceFile, options: Lint.IOptions) { @@ -80,27 +80,14 @@ class WhitespaceWalker extends Lint.SkippableTokenAwareRuleWalker { super.visitSourceFile(node); let prevTokenShouldBeFollowedByWhitespace = false; - this.scanner.setTextPos(0); - - Lint.scanAllTokens(this.scanner, (scanner: ts.Scanner) => { - const startPos = scanner.getStartPos(); - const tokenKind = scanner.getToken(); - + Lint.forEachToken(node, false, (_text, tokenKind, pos, parent) => { if (tokenKind === ts.SyntaxKind.WhitespaceTrivia || tokenKind === ts.SyntaxKind.NewLineTrivia) { prevTokenShouldBeFollowedByWhitespace = false; + return; } else if (prevTokenShouldBeFollowedByWhitespace) { - this.addMissingWhitespaceErrorAt(startPos); + this.addMissingWhitespaceErrorAt(pos.tokenStart); prevTokenShouldBeFollowedByWhitespace = false; } - - const skip = this.getSkipEndFromStart(startPos); - if (skip !== undefined) { - // tokens to skip are places where the scanner gets confused about what the token is, without the proper context - // (specifically, regex, identifiers, and templates). So skip those tokens. - scanner.setTextPos(skip); - return; - } - // check for trailing space after the given tokens switch (tokenKind) { case ts.SyntaxKind.CatchKeyword: @@ -120,7 +107,7 @@ class WhitespaceWalker extends Lint.SkippableTokenAwareRuleWalker { } break; case ts.SyntaxKind.EqualsToken: - if (this.hasOption(OPTION_DECL)) { + if (this.hasOption(OPTION_DECL) && parent.kind !== ts.SyntaxKind.JsxAttribute) { prevTokenShouldBeFollowedByWhitespace = true; } break; @@ -219,16 +206,6 @@ class WhitespaceWalker extends Lint.SkippableTokenAwareRuleWalker { super.visitImportEqualsDeclaration(node); } - public visitJsxElement(node: ts.JsxElement) { - this.addTokenToSkipFromNode(node); - super.visitJsxElement(node); - } - - public visitJsxSelfClosingElement(node: ts.JsxSelfClosingElement) { - this.addTokenToSkipFromNode(node); - super.visitJsxSelfClosingElement(node); - } - public visitTypeAssertionExpression(node: ts.TypeAssertion) { if (this.hasOption(OPTION_TYPECAST)) { const position = node.expression.getFullStart(); diff --git a/test/rules/_integration/enable-disable/test.tsx.lint b/test/rules/_integration/enable-disable/test.tsx.lint new file mode 100644 index 00000000000..e6bab97957b --- /dev/null +++ b/test/rules/_integration/enable-disable/test.tsx.lint @@ -0,0 +1,69 @@ +const span = ( + + /* tslint:disable */ + { + x + 'test' + ~~~~~~ [' should be "] + } + text + +); + +const span = ( + + // tslint:disable-next-line + {x + 'test'} + ~~~~~~ [' should be "] + text + +); + +const span = ( + + {x + 'comment is ignored with text'} // tslint:disable-line + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [' should be "] + works with text + +); + +const span = ( + + {x + 'comment is ignored without text'} // tslint:disable-line + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [' should be "] + +); + +const span = ( + + /* tslint:disable */ {x + 'ignores comments before element if not root'} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [' should be "] + +); + +const span = ( + + {x + 'ignores comments after element if not root'} /* tslint:disable-line */ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [' should be "] + +); + +const span = ( + /* tslint:disable-next-line */ + {x + 'ignores trailing comments of root element'} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [' should be "] + +); + +const span = ( + + {{x + 'works for comments inside JsxExpression'} /* tslint:disable-line */} + +); + +const span = ( + + {/* tslint:disable-next-line */} + {x + 'works for comment-only expressions'} + text + +); diff --git a/test/rules/_integration/react/test.tsx.lint b/test/rules/_integration/react/test.tsx.lint index 74101c98b3e..cd7b705f2b2 100644 --- a/test/rules/_integration/react/test.tsx.lint +++ b/test/rules/_integration/react/test.tsx.lint @@ -25,7 +25,13 @@ export class FooComponent extends React.Component { public render() { return ( -
this.onClick()}> +
this.onClick()} class={true===false?"foo":"bar"}> + ~ [missing whitespace] + ~ [missing whitespace] + ~ [missing whitespace] + ~ [missing whitespace] + ~ [missing whitespace] + ~ [missing whitespace] {this.state.bar.map((s) => {s})}
diff --git a/test/rules/comment-format/lower/test.tsx.lint b/test/rules/comment-format/lower/test.tsx.lint new file mode 100644 index 00000000000..7a7e5388409 --- /dev/null +++ b/test/rules/comment-format/lower/test.tsx.lint @@ -0,0 +1,12 @@ +const a = ( + + https://github.com/ { + //invalid comment + ~~~~~~~~~~~~~~~ [space] + content + }, text + +); + + +[space]: comment must start with a space \ No newline at end of file diff --git a/test/rules/whitespace/all/test.ts.fix b/test/rules/whitespace/all/test.ts.fix index 091a21af295..43c7c581fbd 100644 --- a/test/rules/whitespace/all/test.ts.fix +++ b/test/rules/whitespace/all/test.ts.fix @@ -53,6 +53,12 @@ var test = `
Date: Mon, 16 Jan 2017 17:17:56 +0100 Subject: [PATCH 04/13] Rewrite importBlacklistRule (#1975) --- src/rules/importBlacklistRule.ts | 68 ++++++++++-------------- test/rules/import-blacklist/test.js.lint | 3 ++ test/rules/import-blacklist/test.ts.lint | 6 +++ 3 files changed, 38 insertions(+), 39 deletions(-) diff --git a/src/rules/importBlacklistRule.ts b/src/rules/importBlacklistRule.ts index 7c6dfd53c34..73350c779cf 100644 --- a/src/rules/importBlacklistRule.ts +++ b/src/rules/importBlacklistRule.ts @@ -49,62 +49,52 @@ export class Rule extends Lint.Rules.AbstractRule { } public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { - const options = this.getOptions(); - return this.applyWithWalker( - new NoRequireFullLibraryWalker(sourceFile, options, options.ruleArguments), - ); + return this.applyWithWalker(new ImportBlacklistWalker(sourceFile, this.getOptions())); } } -class NoRequireFullLibraryWalker extends Lint.RuleWalker { - private blacklist: string[]; - constructor(sourceFile: ts.SourceFile, options: Lint.IOptions, blacklist: string[]) { - super(sourceFile, options); - this.blacklist = blacklist; - } - +class ImportBlacklistWalker extends Lint.RuleWalker { public visitCallExpression(node: ts.CallExpression) { - if ( - node.expression.getText() === "require" && - node.arguments && - node.arguments[0] && - this.isModuleBlacklisted(node.arguments[0].getText()) - ) { - this.reportFailure(node.arguments[0]); + if (node.expression.kind === ts.SyntaxKind.Identifier && + (node.expression as ts.Identifier).text === "require" && + node.arguments !== undefined && + node.arguments.length === 1) { + + this.checkForBannedImport(node.arguments[0]); } super.visitCallExpression(node); } public visitImportEqualsDeclaration(node: ts.ImportEqualsDeclaration) { - const moduleReference = node.moduleReference as ts.ExternalModuleReference; - // If it's an import require and not an import alias - if (moduleReference.expression) { - if (this.isModuleBlacklisted(moduleReference.expression.getText())) { - this.reportFailure(moduleReference.expression); - } + if (isExternalModuleReference(node.moduleReference) && + node.moduleReference.expression !== undefined) { + // If it's an import require and not an import alias + this.checkForBannedImport(node.moduleReference.expression); } super.visitImportEqualsDeclaration(node); } public visitImportDeclaration(node: ts.ImportDeclaration) { - if (this.isModuleBlacklisted(node.moduleSpecifier.getText())) { - this.reportFailure(node.moduleSpecifier); - } + this.checkForBannedImport(node.moduleSpecifier); super.visitImportDeclaration(node); } - private isModuleBlacklisted(text: string): boolean { - return this.blacklist.some((entry) => { - return text.substring(1, text.length - 1) === entry; - }); + private checkForBannedImport(expression: ts.Expression) { + if (isStringLiteral(expression) && this.hasOption(expression.text)) { + this.addFailureFromStartToEnd( + expression.getStart(this.getSourceFile()) + 1, + expression.getEnd() - 1, + Rule.FAILURE_STRING, + ); + } } +} - private reportFailure(node: ts.Expression): void { - this.addFailureAt( - // take quotes into account - node.getStart() + 1, - node.getWidth() - 2, - Rule.FAILURE_STRING, - ); - } +function isStringLiteral(node: ts.Node): node is ts.LiteralExpression { + return node.kind === ts.SyntaxKind.StringLiteral || + node.kind === ts.SyntaxKind.NoSubstitutionTemplateLiteral; +} + +function isExternalModuleReference(node: ts.ModuleReference): node is ts.ExternalModuleReference { + return node.kind === ts.SyntaxKind.ExternalModuleReference; } diff --git a/test/rules/import-blacklist/test.js.lint b/test/rules/import-blacklist/test.js.lint index 2c155eb4bb3..6cfd234fd76 100644 --- a/test/rules/import-blacklist/test.js.lint +++ b/test/rules/import-blacklist/test.js.lint @@ -4,4 +4,7 @@ const forOwn = require('lodash').forOwn; ~~~~~~ [0] const forOwn = require('lodash/forOwn'); +// non-static imports cannot be checked +const _ = require(lodash); + [0]: This import is blacklisted, import a submodule instead diff --git a/test/rules/import-blacklist/test.ts.lint b/test/rules/import-blacklist/test.ts.lint index 25bac38c85c..2a2be028fd4 100644 --- a/test/rules/import-blacklist/test.ts.lint +++ b/test/rules/import-blacklist/test.ts.lint @@ -6,4 +6,10 @@ import forOwn = require('lodash'); ~~~~~~ [0] import forOwn = require('lodash/forOwn'); +// non-static imports cannot be checked +import {Observable} from rxjs; +import forOwn = require(lodash); + +import * as notBlacklisted from "not-blacklisted"; + [0]: This import is blacklisted, import a submodule instead From 441b2e58f8e990b8f330f609264c3a22cb998df4 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 16 Jan 2017 08:26:18 -0800 Subject: [PATCH 05/13] Add `misused-new` rule (#1963) --- docs/_data/rules.json | 11 +++ .../rules/no-interface-constructor/index.html | 14 ++++ docs/rules/no-misused-new/index.html | 13 +++ src/rules/noMisusedNewRule.ts | 81 +++++++++++++++++++ test/rules/no-misused-new/test.ts.lint | 32 ++++++++ test/rules/no-misused-new/tslint.json | 5 ++ 6 files changed, 156 insertions(+) create mode 100644 docs/rules/no-interface-constructor/index.html create mode 100644 docs/rules/no-misused-new/index.html create mode 100644 src/rules/noMisusedNewRule.ts create mode 100644 test/rules/no-misused-new/test.ts.lint create mode 100644 test/rules/no-misused-new/tslint.json diff --git a/docs/_data/rules.json b/docs/_data/rules.json index ddea1801436..89ca336a49d 100644 --- a/docs/_data/rules.json +++ b/docs/_data/rules.json @@ -838,6 +838,17 @@ "type": "maintainability", "typescriptOnly": true }, + { + "ruleName": "no-misused-new", + "description": "Warns on apparent attempts to define constructors for interfaces or `new` for classes.", + "optionsDescription": "Not configurable.", + "options": null, + "optionExamples": [ + "true" + ], + "type": "functionality", + "typescriptOnly": true + }, { "ruleName": "no-namespace", "description": "Disallows use of internal `module`s and `namespace`s.", diff --git a/docs/rules/no-interface-constructor/index.html b/docs/rules/no-interface-constructor/index.html new file mode 100644 index 00000000000..b2f5778f784 --- /dev/null +++ b/docs/rules/no-interface-constructor/index.html @@ -0,0 +1,14 @@ +--- +ruleName: no-interface-constructor +description: Warns on apparent attempts to define constructors for interfaces. +rationale: '`interface I { new(): I }` declares a type where for `x: I`, `new x()` is also of type `I`.' +optionsDescription: Not configurable. +options: null +optionExamples: + - 'true' +type: functionality +typescriptOnly: true +layout: rule +title: 'Rule: no-interface-constructor' +optionsJSON: 'null' +--- \ No newline at end of file diff --git a/docs/rules/no-misused-new/index.html b/docs/rules/no-misused-new/index.html new file mode 100644 index 00000000000..771e8ed5754 --- /dev/null +++ b/docs/rules/no-misused-new/index.html @@ -0,0 +1,13 @@ +--- +ruleName: no-misused-new +description: Warns on apparent attempts to define constructors for interfaces or `new` for classes. +optionsDescription: Not configurable. +options: null +optionExamples: + - 'true' +type: functionality +typescriptOnly: true +layout: rule +title: 'Rule: no-misused-new' +optionsJSON: 'null' +--- \ No newline at end of file diff --git a/src/rules/noMisusedNewRule.ts b/src/rules/noMisusedNewRule.ts new file mode 100644 index 00000000000..e5bdad0f269 --- /dev/null +++ b/src/rules/noMisusedNewRule.ts @@ -0,0 +1,81 @@ +/** + * @license + * Copyright 2017 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 "../index"; + +export class Rule extends Lint.Rules.AbstractRule { + /* tslint:disable:object-literal-sort-keys */ + public static metadata: Lint.IRuleMetadata = { + ruleName: "no-misused-new", + description: "Warns on apparent attempts to define constructors for interfaces or `new` for classes.", + optionsDescription: "Not configurable.", + options: null, + optionExamples: ["true"], + type: "functionality", + typescriptOnly: true, + }; + /* tslint:enable:object-literal-sort-keys */ + + public static FAILURE_STRING_INTERFACE = "Interfaces cannot be constructed, only classes. Did you mean `declare class`?"; + public static FAILURE_STRING_CLASS = '`new` in a class is a method named "new". Did you mean `constructor`?'; + + public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { + return this.applyWithWalker(new Walker(sourceFile, this.getOptions())); + } +} + +class Walker extends Lint.RuleWalker { + public visitMethodSignature(node: ts.MethodSignature) { + if (nameIs(node.name, "constructor")) { + this.addFailureAtNode(node, Rule.FAILURE_STRING_INTERFACE); + } + } + + public visitMethodDeclaration(node: ts.MethodDeclaration) { + if (node.body === undefined && nameIs(node.name, "new") && + returnTypeMatchesParent(node.parent as ts.ClassLikeDeclaration, node)) { + this.addFailureAtNode(node, Rule.FAILURE_STRING_CLASS); + } + } + + public visitConstructSignature(node: ts.ConstructSignatureDeclaration) { + if (returnTypeMatchesParent(node.parent as ts.InterfaceDeclaration, node)) { + this.addFailureAtNode(node, Rule.FAILURE_STRING_INTERFACE); + } + } +} + +function nameIs(name: ts.PropertyName, text: string): boolean { + return name.kind === ts.SyntaxKind.Identifier && name.text === text; +} + +function returnTypeMatchesParent(parent: { name?: ts.Identifier }, decl: ts.SignatureDeclaration): boolean { + if (parent.name === undefined) { + return false; + } + + const name = parent.name.text; + const type = decl.type; + if (type === undefined || type.kind !== ts.SyntaxKind.TypeReference) { + return false; + } + + const typeName = (type as ts.TypeReferenceNode).typeName; + return typeName.kind === ts.SyntaxKind.Identifier && (typeName as ts.Identifier).text === name; +} diff --git a/test/rules/no-misused-new/test.ts.lint b/test/rules/no-misused-new/test.ts.lint new file mode 100644 index 00000000000..f1ed5ca1120 --- /dev/null +++ b/test/rules/no-misused-new/test.ts.lint @@ -0,0 +1,32 @@ +interface I { + new(): I; + ~~~~~~~~~ [0] + // OK if return type is not the interface. + new(): {}; + constructor(): void; + ~~~~~~~~~~~~~~~~~~~~ [0] +} + +// Works for generic type. +interface G { + new(): G; + ~~~~~~~~~~~~~~~ [0] +} + +type T = { + // `new` OK in type literal (we don't know the type name) + new(): T; + // `constructor` still flagged. + constructor(): void; + ~~~~~~~~~~~~~~~~~~~~ [0] +} + +class C { + new(): C; + ~~~~~~~~~ [1] + // OK if there's a body + new() {} +} + +[0]: Interfaces cannot be constructed, only classes. Did you mean `declare class`? +[1]: `new` in a class is a method named "new". Did you mean `constructor`? diff --git a/test/rules/no-misused-new/tslint.json b/test/rules/no-misused-new/tslint.json new file mode 100644 index 00000000000..87f36324069 --- /dev/null +++ b/test/rules/no-misused-new/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-misused-new": true + } +} From 141002081c7b3ab78637397a449d4772dfad7549 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 16 Jan 2017 08:26:52 -0800 Subject: [PATCH 06/13] Add `no-unnecessary-qualifier` rule (#2008) --- docs/_data/rules.json | 13 ++ .../rules/no-unnecessary-qualifier/index.html | 15 ++ src/language/utils.ts | 23 +-- src/rules/arrowReturnShorthandRule.ts | 10 +- src/rules/noUnnecessaryQualifierRule.ts | 142 ++++++++++++++++++ src/rules/unifiedSignaturesRule.ts | 8 +- src/utils.ts | 7 + test/rules/no-unnecessary-qualifier/b.ts | 1 + .../test-global.ts.fix | 5 + .../test-global.ts.lint | 6 + .../no-unnecessary-qualifier/test.ts.fix | 41 +++++ .../no-unnecessary-qualifier/test.ts.lint | 54 +++++++ .../no-unnecessary-qualifier/tsconfig.json | 5 + .../no-unnecessary-qualifier/tslint.json | 8 + 14 files changed, 314 insertions(+), 24 deletions(-) create mode 100644 docs/rules/no-unnecessary-qualifier/index.html create mode 100644 src/rules/noUnnecessaryQualifierRule.ts create mode 100644 test/rules/no-unnecessary-qualifier/b.ts create mode 100644 test/rules/no-unnecessary-qualifier/test-global.ts.fix create mode 100644 test/rules/no-unnecessary-qualifier/test-global.ts.lint create mode 100644 test/rules/no-unnecessary-qualifier/test.ts.fix create mode 100644 test/rules/no-unnecessary-qualifier/test.ts.lint create mode 100644 test/rules/no-unnecessary-qualifier/tsconfig.json create mode 100644 test/rules/no-unnecessary-qualifier/tslint.json diff --git a/docs/_data/rules.json b/docs/_data/rules.json index 89ca336a49d..c8e76a99a14 100644 --- a/docs/_data/rules.json +++ b/docs/_data/rules.json @@ -979,6 +979,19 @@ "type": "maintainability", "typescriptOnly": false }, + { + "ruleName": "no-unnecessary-qualifier", + "description": "Warns when a namespace qualifier (`A.x`) is unnecessary.", + "hasFix": true, + "optionsDescription": "Not configurable.", + "options": null, + "optionExamples": [ + "true" + ], + "type": "style", + "typescriptOnly": true, + "requiresTypeInfo": true + }, { "ruleName": "no-unsafe-finally", "description": "\nDisallows control flow statements, such as `return`, `continue`,\n`break` and `throws` in finally blocks.", diff --git a/docs/rules/no-unnecessary-qualifier/index.html b/docs/rules/no-unnecessary-qualifier/index.html new file mode 100644 index 00000000000..342ca422939 --- /dev/null +++ b/docs/rules/no-unnecessary-qualifier/index.html @@ -0,0 +1,15 @@ +--- +ruleName: no-unnecessary-qualifier +description: Warns when a namespace qualifier (`A.x`) is unnecessary. +hasFix: true +optionsDescription: Not configurable. +options: null +optionExamples: + - 'true' +type: style +typescriptOnly: true +requiresTypeInfo: true +layout: rule +title: 'Rule: no-unnecessary-qualifier' +optionsJSON: 'null' +--- \ No newline at end of file diff --git a/src/language/utils.ts b/src/language/utils.ts index 5a2d23ff54c..151a35db694 100644 --- a/src/language/utils.ts +++ b/src/language/utils.ts @@ -147,36 +147,40 @@ export function isAssignment(node: ts.Node) { * Bitwise check for node flags. */ export function isNodeFlagSet(node: ts.Node, flagToCheck: ts.NodeFlags): boolean { - /* tslint:disable:no-bitwise */ + // tslint:disable-next-line:no-bitwise return (node.flags & flagToCheck) !== 0; - /* tslint:enable:no-bitwise */ } /** * Bitwise check for combined node flags. */ export function isCombinedNodeFlagSet(node: ts.Node, flagToCheck: ts.NodeFlags): boolean { - /* tslint:disable:no-bitwise */ + // tslint:disable-next-line:no-bitwise return (ts.getCombinedNodeFlags(node) & flagToCheck) !== 0; - /* tslint:enable:no-bitwise */ } /** * Bitwise check for combined modifier flags. */ export function isCombinedModifierFlagSet(node: ts.Node, flagToCheck: ts.ModifierFlags): boolean { - /* tslint:disable:no-bitwise */ + // tslint:disable-next-line:no-bitwise return (ts.getCombinedModifierFlags(node) & flagToCheck) !== 0; - /* tslint:enable:no-bitwise */ } /** * Bitwise check for type flags. */ export function isTypeFlagSet(type: ts.Type, flagToCheck: ts.TypeFlags): boolean { - /* tslint:disable:no-bitwise */ + // tslint:disable-next-line:no-bitwise return (type.flags & flagToCheck) !== 0; - /* tslint:enable:no-bitwise */ +} + +/** + * Bitwise check for symbol flags. + */ +export function isSymbolFlagSet(symbol: ts.Symbol, flagToCheck: ts.SymbolFlags): boolean { + // tslint:disable-next-line:no-bitwise + return (symbol.flags & flagToCheck) !== 0; } /** @@ -184,9 +188,8 @@ export function isTypeFlagSet(type: ts.Type, flagToCheck: ts.TypeFlags): boolean * Does not work with TypeScript 2.0.x */ export function isObjectFlagSet(objectType: ts.ObjectType, flagToCheck: ts.ObjectFlags): boolean { - /* tslint:disable:no-bitwise */ + // tslint:disable-next-line:no-bitwise return (objectType.objectFlags & flagToCheck) !== 0; - /* tslint:enable:no-bitwise */ } /** diff --git a/src/rules/arrowReturnShorthandRule.ts b/src/rules/arrowReturnShorthandRule.ts index 58bb7e869d6..4a765d5fe25 100644 --- a/src/rules/arrowReturnShorthandRule.ts +++ b/src/rules/arrowReturnShorthandRule.ts @@ -85,11 +85,11 @@ class Walker extends Lint.RuleWalker { this.appendText(expr.getEnd(), ")"), ] : []), // " {" - deleteFromTo(arrow.end, openBrace.end), + this.deleteFromTo(arrow.end, openBrace.end), // "return " - deleteFromTo(statement.getStart(), expr.getStart()), + this.deleteFromTo(statement.getStart(), expr.getStart()), // " }" (may include semicolon) - deleteFromTo(expr.end, closeBrace.end), + this.deleteFromTo(expr.end, closeBrace.end), ); function hasComments(node: ts.Node): boolean { @@ -104,7 +104,3 @@ function getSimpleReturnExpression(block: ts.Block): ts.Expression | undefined { ? (block.statements[0] as ts.ReturnStatement).expression : undefined; } - -function deleteFromTo(start: number, end: number): Lint.Replacement { - return new Lint.Replacement(start, end - start, ""); -} diff --git a/src/rules/noUnnecessaryQualifierRule.ts b/src/rules/noUnnecessaryQualifierRule.ts new file mode 100644 index 00000000000..d2c1e5c7bcb --- /dev/null +++ b/src/rules/noUnnecessaryQualifierRule.ts @@ -0,0 +1,142 @@ +/** + * @license + * Copyright 2017 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 "../index"; +import { arraysAreEqual } from "../utils"; + +export class Rule extends Lint.Rules.TypedRule { + /* tslint:disable:object-literal-sort-keys */ + public static metadata: Lint.IRuleMetadata = { + ruleName: "no-unnecessary-qualifier", + description: "Warns when a namespace qualifier (`A.x`) is unnecessary.", + hasFix: true, + optionsDescription: "Not configurable.", + options: null, + optionExamples: ["true"], + type: "style", + typescriptOnly: true, + requiresTypeInfo: true, + }; + /* tslint:enable:object-literal-sort-keys */ + + public static FAILURE_STRING(name: string) { + return `Qualifier is unnecessary since '${name}' is in scope.`; + } + + public applyWithProgram(sourceFile: ts.SourceFile, langSvc: ts.LanguageService): Lint.RuleFailure[] { + return this.applyWithWalker(new Walker(sourceFile, this.getOptions(), langSvc.getProgram())); + } +} + +class Walker extends Lint.ProgramAwareRuleWalker { + private namespacesInScope: Array = []; + + public visitModuleDeclaration(node: ts.ModuleDeclaration) { + this.namespacesInScope.push(node); + super.visitModuleDeclaration(node); + this.namespacesInScope.pop(); + } + + public visitEnumDeclaration(node: ts.EnumDeclaration) { + this.namespacesInScope.push(node); + super.visitEnumDeclaration(node); + this.namespacesInScope.pop(); + } + + public visitNode(node: ts.Node) { + switch (node.kind) { + case ts.SyntaxKind.QualifiedName: + const { left, right } = node as ts.QualifiedName; + this.visitNamespaceAccess(node, left, right); + break; + case ts.SyntaxKind.PropertyAccessExpression: + const { expression, name } = node as ts.PropertyAccessExpression; + if (isEntityNameExpression(expression)) { + this.visitNamespaceAccess(node, expression, name); + break; + } + // fall through + default: + super.visitNode(node); + } + } + + private visitNamespaceAccess(node: ts.Node, qualifier: ts.EntityNameOrEntityNameExpression, name: ts.Identifier) { + if (this.qualifierIsUnnecessary(qualifier, name)) { + const fix = this.createFix(this.deleteFromTo(qualifier.getStart(), name.getStart())); + this.addFailureAtNode(qualifier, Rule.FAILURE_STRING(qualifier.getText()), fix); + } else { + // Only look for nested qualifier errors if we didn't already fail on the outer qualifier. + super.visitNode(node); + } + } + + private qualifierIsUnnecessary(qualifier: ts.EntityNameOrEntityNameExpression, name: ts.Identifier): boolean { + const namespaceSymbol = this.symbolAtLocation(qualifier); + if (namespaceSymbol === undefined || !this.symbolIsNamespaceInScope(namespaceSymbol)) { + return false; + } + + const accessedSymbol = this.symbolAtLocation(name); + if (accessedSymbol === undefined) { + return false; + } + + // If the symbol in scope is different, the qualifier is necessary. + const fromScope = this.getSymbolInScope(qualifier, accessedSymbol.flags, name.text); + return fromScope === undefined || symbolsAreEqual(fromScope, accessedSymbol); + } + + private getSymbolInScope(node: ts.Node, flags: ts.SymbolFlags, name: string): ts.Symbol | undefined { + // TODO:PERF `getSymbolsInScope` gets a long list. Is there a better way? + const scope = this.getTypeChecker().getSymbolsInScope(node, flags); + return scope.find((scopeSymbol) => scopeSymbol.name === name); + } + + private symbolAtLocation(node: ts.Node): ts.Symbol | undefined { + return this.getTypeChecker().getSymbolAtLocation(node); + } + + private symbolIsNamespaceInScope(symbol: ts.Symbol): boolean { + if (symbol.getDeclarations().some((decl) => this.namespacesInScope.some((ns) => nodesAreEqual(ns, decl)))) { + return true; + } + const alias = this.tryGetAliasedSymbol(symbol); + return alias !== undefined && this.symbolIsNamespaceInScope(alias); + } + + private tryGetAliasedSymbol(symbol: ts.Symbol): ts.Symbol | undefined { + return Lint.isSymbolFlagSet(symbol, ts.SymbolFlags.Alias) ? this.getTypeChecker().getAliasedSymbol(symbol) : undefined; + } +} + +function isEntityNameExpression(expr: ts.Expression): expr is ts.EntityNameExpression { + return expr.kind === ts.SyntaxKind.Identifier || + expr.kind === ts.SyntaxKind.PropertyAccessExpression && isEntityNameExpression((expr as ts.PropertyAccessExpression).expression); +} + +// TODO: Should just be `===`. See https://github.com/palantir/tslint/issues/1969 +function nodesAreEqual(a: ts.Node, b: ts.Node) { + return a.pos === b.pos; +} + +// Only needed in global files. Likely due to https://github.com/palantir/tslint/issues/1969. See `test.global.ts.lint`. +function symbolsAreEqual(a: ts.Symbol, b: ts.Symbol): boolean { + return arraysAreEqual(a.declarations, b.declarations, nodesAreEqual); +} diff --git a/src/rules/unifiedSignaturesRule.ts b/src/rules/unifiedSignaturesRule.ts index 5d8c8a36ede..8d844604ddf 100644 --- a/src/rules/unifiedSignaturesRule.ts +++ b/src/rules/unifiedSignaturesRule.ts @@ -18,6 +18,7 @@ import * as ts from "typescript"; import * as Lint from "../index"; +import { arraysAreEqual, Equal } from "../utils"; import { getOverloadKey, isSignatureDeclaration } from "./adjacentOverloadSignaturesRule"; @@ -202,9 +203,6 @@ type GetOverload = (node: T) => { signature: ts.SignatureDeclaration, key: st */ type IsTypeParameter = (typeName: string) => boolean; -/** Return true if both parameters are equal. */ -type Equal = (a: T, b: T) => boolean; - /** Given type parameters, returns a function to test whether a type is one of those parameters. */ function getIsTypeParameter(typeParameters?: ts.TypeParameterDeclaration[]): IsTypeParameter { if (!typeParameters) { @@ -297,7 +295,3 @@ function forEachPair(values: T[], action: (a: T, b: T) => void): void { } } } - -function arraysAreEqual(a: T[] | undefined, b: T[] | undefined, eq: Equal): boolean { - return a === b || !!a && !!b && a.length === b.length && a.every((x, idx) => eq(x, b[idx])); -} diff --git a/src/utils.ts b/src/utils.ts index d0643016314..82479f6366b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -107,3 +107,10 @@ export function stripComments(content: string): string { export function escapeRegExp(re: string): string { return re.replace(/[.+*?|^$[\]{}()\\]/g, "\\$&"); } + +/** Return true if both parameters are equal. */ +export type Equal = (a: T, b: T) => boolean; + +export function arraysAreEqual(a: T[] | undefined, b: T[] | undefined, eq: Equal): boolean { + return a === b || !!a && !!b && a.length === b.length && a.every((x, idx) => eq(x, b[idx])); +} diff --git a/test/rules/no-unnecessary-qualifier/b.ts b/test/rules/no-unnecessary-qualifier/b.ts new file mode 100644 index 00000000000..a87fbc00e59 --- /dev/null +++ b/test/rules/no-unnecessary-qualifier/b.ts @@ -0,0 +1 @@ +export type T = number; \ No newline at end of file diff --git a/test/rules/no-unnecessary-qualifier/test-global.ts.fix b/test/rules/no-unnecessary-qualifier/test-global.ts.fix new file mode 100644 index 00000000000..6db27bd8f6a --- /dev/null +++ b/test/rules/no-unnecessary-qualifier/test-global.ts.fix @@ -0,0 +1,5 @@ +// We need `symbolsAreEqual` in global files. +namespace N { + export type T = number; + export const x: T = 0; +} diff --git a/test/rules/no-unnecessary-qualifier/test-global.ts.lint b/test/rules/no-unnecessary-qualifier/test-global.ts.lint new file mode 100644 index 00000000000..2901f62a880 --- /dev/null +++ b/test/rules/no-unnecessary-qualifier/test-global.ts.lint @@ -0,0 +1,6 @@ +// We need `symbolsAreEqual` in global files. +namespace N { + export type T = number; + export const x: N.T = 0; + ~ [Qualifier is unnecessary since 'N' is in scope.] +} diff --git a/test/rules/no-unnecessary-qualifier/test.ts.fix b/test/rules/no-unnecessary-qualifier/test.ts.fix new file mode 100644 index 00000000000..cd80a83a502 --- /dev/null +++ b/test/rules/no-unnecessary-qualifier/test.ts.fix @@ -0,0 +1,41 @@ +namespace N { + export type T = number; + export const x: T = 0; + + export namespace M { + export type U = T; + export const y: U = 0; + export const z: U = 0; + export const a = x; + export const b = y; + export const c = z; + } +} + +namespace A.B.C1 { + export const D = 7; +} + +namespace A.B.C2 { + const copy = C1.D; +} + +import * as B from "./b"; +declare module "./b" { + const x: T; +} + +namespace X { + export type T = number; + namespace Y { + type T = string; + // This qualifier *is* necessary since 'X.T' is shadowed. + const x: X.T = 0; + } +} + +enum E { + A, + B = A +} + diff --git a/test/rules/no-unnecessary-qualifier/test.ts.lint b/test/rules/no-unnecessary-qualifier/test.ts.lint new file mode 100644 index 00000000000..6e7b2b4cca0 --- /dev/null +++ b/test/rules/no-unnecessary-qualifier/test.ts.lint @@ -0,0 +1,54 @@ +namespace N { + export type T = number; + export const x: N.T = 0; + ~ [N] + + export namespace M { + export type U = N.T; + ~ [N] + export const y: M.U = 0; + ~ [M] + export const z: N.M.U = 0; + ~~~ [NM] + export const a = N.x; + ~ [N] + export const b = M.y; + ~ [M] + export const c = N.M.z; + ~~~ [NM] + } +} + +namespace A.B.C1 { + export const D = 7; +} + +namespace A.B.C2 { + const copy = A.B.C1.D; + ~~~ [Qualifier is unnecessary since 'A.B' is in scope.] +} + +import * as B from "./b"; +declare module "./b" { + const x: B.T; + ~ [Qualifier is unnecessary since 'B' is in scope.] +} + +namespace X { + export type T = number; + namespace Y { + type T = string; + // This qualifier *is* necessary since 'X.T' is shadowed. + const x: X.T = 0; + } +} + +enum E { + A, + B = E.A + ~ [Qualifier is unnecessary since 'E' is in scope.] +} + +[N]: Qualifier is unnecessary since 'N' is in scope. +[M]: Qualifier is unnecessary since 'M' is in scope. +[NM]: Qualifier is unnecessary since 'N.M' is in scope. diff --git a/test/rules/no-unnecessary-qualifier/tsconfig.json b/test/rules/no-unnecessary-qualifier/tsconfig.json new file mode 100644 index 00000000000..db953a729b9 --- /dev/null +++ b/test/rules/no-unnecessary-qualifier/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "declaration": true + } +} \ No newline at end of file diff --git a/test/rules/no-unnecessary-qualifier/tslint.json b/test/rules/no-unnecessary-qualifier/tslint.json new file mode 100644 index 00000000000..2945858d5e7 --- /dev/null +++ b/test/rules/no-unnecessary-qualifier/tslint.json @@ -0,0 +1,8 @@ +{ + "linterOptions": { + "typeCheck": true + }, + "rules": { + "no-unnecessary-qualifier": true + } +} \ No newline at end of file From 15ed0fe89ff29a8396ab32d5ff9d654515ef1453 Mon Sep 17 00:00:00 2001 From: Romke van der Meulen Date: Tue, 17 Jan 2017 04:14:02 +0100 Subject: [PATCH 07/13] README: fix code example so that it type checks (#2050) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ca0c5aa6ded..70b6bbd648d 100644 --- a/README.md +++ b/README.md @@ -247,7 +247,7 @@ const files = Linter.getFileNames(program); const results = files.map(file => { const fileContents = program.getSourceFile(file).getFullText(); const linter = new Linter(file, fileContents, options, program); - return result.lint(); + return linter.lint(); }); ``` From d0322f4663180402d86422c634987b2e1e2890cb Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Wed, 18 Jan 2017 17:02:37 +0100 Subject: [PATCH 08/13] Ensure backwards compatibility of #2036 (#2055) This commit can be reverted once tslint drops support for typescript 2.0.10 Fixes #2054 --- docs/_data/rules.json | 2 +- docs/rules/whitespace/index.html | 2 +- src/language/utils.ts | 28 ++++++++++++++++++---------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/docs/_data/rules.json b/docs/_data/rules.json index c8e76a99a14..44c43320380 100644 --- a/docs/_data/rules.json +++ b/docs/_data/rules.json @@ -1744,7 +1744,7 @@ "ruleName": "whitespace", "description": "Enforces whitespace style conventions.", "rationale": "Helps maintain a readable, consistent style in your codebase.", - "optionsDescription": "\nSeven arguments may be optionally provided:\n\n* `\"check-branch\"` checks branching statements (`if`/`else`/`for`/`while`) are followed by whitespace.\n* `\"check-decl\"`checks that variable declarations have whitespace around the equals token.\n* `\"check-operator\"` checks for whitespace around operator tokens.\n* `\"check-module\"` checks for whitespace in import & export statements.\n* `\"check-separator\"` checks for whitespace after separator tokens (`,`/`;`).\n* `\"check-type\"` checks for whitespace before a variable type specification.\n* `\"check-typecast\"` checks for whitespace between a typecast and its target.\n* `\"check-preblock\"` checks for whitespace before the opening brace of a block", + "optionsDescription": "\nEight arguments may be optionally provided:\n\n* `\"check-branch\"` checks branching statements (`if`/`else`/`for`/`while`) are followed by whitespace.\n* `\"check-decl\"`checks that variable declarations have whitespace around the equals token.\n* `\"check-operator\"` checks for whitespace around operator tokens.\n* `\"check-module\"` checks for whitespace in import & export statements.\n* `\"check-separator\"` checks for whitespace after separator tokens (`,`/`;`).\n* `\"check-type\"` checks for whitespace before a variable type specification.\n* `\"check-typecast\"` checks for whitespace between a typecast and its target.\n* `\"check-preblock\"` checks for whitespace before the opening brace of a block", "options": { "type": "array", "items": { diff --git a/docs/rules/whitespace/index.html b/docs/rules/whitespace/index.html index 97d6f7bfb29..c3f685c206a 100644 --- a/docs/rules/whitespace/index.html +++ b/docs/rules/whitespace/index.html @@ -4,7 +4,7 @@ rationale: 'Helps maintain a readable, consistent style in your codebase.' optionsDescription: |- - Seven arguments may be optionally provided: + Eight arguments may be optionally provided: * `"check-branch"` checks branching statements (`if`/`else`/`for`/`while`) are followed by whitespace. * `"check-decl"`checks that variable declarations have whitespace around the equals token. diff --git a/src/language/utils.ts b/src/language/utils.ts index 151a35db694..f9d31bec4c0 100644 --- a/src/language/utils.ts +++ b/src/language/utils.ts @@ -281,7 +281,10 @@ export function forEachToken(node: ts.Node, skipTrivia: boolean, cb: ForEachToke } function iterateChildren(child: ts.Node): void { - if (child.kind < ts.SyntaxKind.FirstNode) { + if (child.kind < ts.SyntaxKind.FirstNode || + // for backwards compatibility to typescript 2.0.10 + // JsxText was no Token, but a Node in that version + child.kind === ts.SyntaxKind.JsxText) { // we found a token, tokens have no children, stop recursing here return callback(child); } @@ -341,13 +344,20 @@ export function forEachComment(node: ts.Node, cb: ForEachCommentCallback) { // don't search for comments inside JsxText if (canHaveLeadingTrivia(tokenKind, parent)) { // Comments before the first token (pos.fullStart === 0) are all considered leading comments, so no need for special treatment - ts.forEachLeadingCommentRange(fullText, pos.fullStart, commentCallback); + const comments = ts.getLeadingCommentRanges(fullText, pos.fullStart); + if (comments !== undefined) { + for (const comment of comments) { + cb(fullText, comment.kind, {fullStart: pos.fullStart, tokenStart: comment.pos, end: comment.end}); + } + } } if (canHaveTrailingTrivia(tokenKind, parent)) { - ts.forEachTrailingCommentRange(fullText, pos.end, commentCallback); - } - function commentCallback(tokenStart: number, end: number, kind: ts.SyntaxKind) { - cb(fullText, kind, {tokenStart, end, fullStart: pos.fullStart}); + const comments = ts.getTrailingCommentRanges(fullText, pos.end); + if (comments !== undefined) { + for (const comment of comments) { + cb(fullText, comment.kind, {fullStart: pos.fullStart, tokenStart: comment.pos, end: comment.end}); + } + } } }); } @@ -402,8 +412,6 @@ function canHaveTrailingTrivia(tokenKind: ts.SyntaxKind, parent: ts.Node): boole * This value is typically obtained from `node.getFullStart()` or `node.getEnd()` */ export function hasCommentAfterPosition(text: string, position: number): boolean { - const cb = () => true; - return ts.forEachTrailingCommentRange(text, position, cb) || - ts.forEachLeadingCommentRange(text, position, cb) || - false; // return boolean instead of undefined if no comment is found + return ts.getTrailingCommentRanges(text, position) !== undefined || + ts.getTrailingCommentRanges(text, position) !== undefined; } From c795a3d2de2a5ef0c1f4787f770480c38437747c Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Wed, 18 Jan 2017 11:08:17 -0500 Subject: [PATCH 09/13] Add test to circleci for environments with typescript@2.0.10 (#2034) --- circle.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/circle.yml b/circle.yml index 1387283aaff..4b2d8cf7528 100644 --- a/circle.yml +++ b/circle.yml @@ -4,10 +4,11 @@ general: - gh-pages dependencies: pre: - - case $CIRCLE_NODE_INDEX in 0) nvm use 4.2 ;; 1) nvm use 5.7 ;; 2) nvm use 6.1 ;; esac + - case $CIRCLE_NODE_INDEX in 0) nvm use 4.2 ;; 1) nvm use 5.7 ;; [2-3]) nvm use 6.1 ;; esac test: override: - - npm run verify + - case $CIRCLE_NODE_INDEX in [0-2]) npm run verify ;; 3) npm run clean && npm run compile && npm i typescript@2.0.10 && npm run test ;; esac: + parallel: true deployment: npm-latest: # match semver tag (e.g. 3.12.7) From 3a6d35b533652daf41cb4217c72c3601e52b5d15 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Wed, 18 Jan 2017 13:47:34 -0500 Subject: [PATCH 10/13] gitignore rules.json (#2069) --- .gitignore | 2 + docs/_data/rules.json | 1772 ----------------------------------------- 2 files changed, 2 insertions(+), 1772 deletions(-) delete mode 100644 docs/_data/rules.json diff --git a/.gitignore b/.gitignore index 7b4feb5fd1c..66385e0bbbb 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ typings/.basedir.ts # vim swap files *.swo *.swp + +docs/_data/rules.json diff --git a/docs/_data/rules.json b/docs/_data/rules.json deleted file mode 100644 index 44c43320380..00000000000 --- a/docs/_data/rules.json +++ /dev/null @@ -1,1772 +0,0 @@ -[ - { - "ruleName": "adjacent-overload-signatures", - "description": "Enforces function overloads to be consecutive.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "rationale": "Improves readability and organization by grouping naturally related items together.", - "type": "typescript", - "typescriptOnly": true - }, - { - "ruleName": "align", - "description": "Enforces vertical alignment.", - "rationale": "Helps maintain a readable, consistent style in your codebase.", - "optionsDescription": "\nThree arguments may be optionally provided:\n\n* `\"parameters\"` checks alignment of function parameters.\n* `\"arguments\"` checks alignment of function call arguments.\n* `\"statements\"` checks alignment of statements.", - "options": { - "type": "array", - "items": { - "type": "string", - "enum": [ - "arguments", - "parameters", - "statements" - ] - }, - "minLength": 1, - "maxLength": 3 - }, - "optionExamples": [ - "[true, \"parameters\", \"statements\"]" - ], - "type": "style", - "typescriptOnly": false - }, - { - "ruleName": "array-type", - "description": "Requires using either 'T[]' or 'Array' for arrays.", - "hasFix": true, - "optionsDescription": "\nOne of the following arguments must be provided:\n\n* `\"array\"` enforces use of `T[]` for all types T.\n* `\"generic\"` enforces use of `Array` for all types T.\n* `\"array-simple\"` enforces use of `T[]` if `T` is a simple type (primitive or type reference).", - "options": { - "type": "string", - "enum": [ - "array", - "generic", - "array-simple" - ] - }, - "optionExamples": [ - "[true, \"array\"]", - "[true, \"generic\"]", - "[true, \"array-simple\"]" - ], - "type": "style", - "typescriptOnly": true - }, - { - "ruleName": "arrow-parens", - "description": "Requires parentheses around the parameters of arrow function definitions.", - "hasFix": true, - "rationale": "Maintains stylistic consistency with other arrow function definitions.", - "optionsDescription": "\nIf `ban-single-arg-parens` is specified, then arrow functions with one parameter\nmust not have parentheses if removing them is allowed by TypeScript.", - "options": { - "type": "string", - "enum": [ - "ban-single-arg-parens" - ] - }, - "optionExamples": [ - "true", - "[true, \"ban-single-arg-parens\"]" - ], - "type": "style", - "typescriptOnly": false - }, - { - "ruleName": "arrow-return-shorthand", - "description": "Suggests to convert `() => { return x; }` to `() => x`.", - "hasFix": true, - "optionsDescription": "\nIf `multiline` is specified, then this will warn even if the function spans multiple lines.", - "options": { - "type": "string", - "enum": [ - "multiline" - ] - }, - "optionExamples": [ - "[true]", - "[true, \"multiline\"]" - ], - "type": "style", - "typescriptOnly": false - }, - { - "ruleName": "ban", - "description": "Bans the use of specific functions or global methods.", - "optionsDescription": "\nA list of `['object', 'method', 'optional explanation here']` or `['globalMethod']` which ban `object.method()`\nor respectively `globalMethod()`.", - "options": { - "type": "list", - "listType": { - "type": "array", - "items": { - "type": "string" - }, - "minLength": 1, - "maxLength": 3 - } - }, - "optionExamples": [ - "[true, [\"someGlobalMethod\"], [\"someObject\", \"someFunction\"],\n [\"someObject\", \"otherFunction\", \"Optional explanation\"]]" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "callable-types", - "description": "An interface or literal type with just a call signature can be written as a function type.", - "rationale": "style", - "optionsDescription": "Not configurable.", - "options": null, - "type": "style", - "typescriptOnly": true - }, - { - "ruleName": "class-name", - "description": "Enforces PascalCased class and interface names.", - "rationale": "Makes it easy to differentitate classes from regular variables at a glance.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "style", - "typescriptOnly": false - }, - { - "ruleName": "comment-format", - "description": "Enforces formatting rules for single-line comments.", - "rationale": "Helps maintain a consistent, readable style in your codebase.", - "optionsDescription": "\nThree arguments may be optionally provided:\n\n* `\"check-space\"` requires that all single-line comments must begin with a space, as in `// comment`\n * note that comments starting with `///` are also allowed, for things such as `///`\n* `\"check-lowercase\"` requires that the first non-whitespace character of a comment must be lowercase, if applicable.\n* `\"check-uppercase\"` requires that the first non-whitespace character of a comment must be uppercase, if applicable.\n\nExceptions to `\"check-lowercase\"` or `\"check-uppercase\"` can be managed with object that may be passed as last argument.\n\nOne of two options can be provided in this object:\n \n * `\"ignoreWords\"` - array of strings - words that will be ignored at the beginning of the comment.\n * `\"ignorePattern\"` - string - RegExp pattern that will be ignored at the beginning of the comment.\n", - "options": { - "type": "array", - "items": { - "anyOf": [ - { - "type": "string", - "enum": [ - "check-space", - "check-lowercase", - "check-uppercase" - ] - }, - { - "type": "object", - "properties": { - "ignoreWords": { - "type": "array", - "items": { - "type": "string" - } - }, - "ignorePattern": { - "type": "string" - } - }, - "minProperties": 1, - "maxProperties": 1 - } - ] - }, - "minLength": 1, - "maxLength": 4 - }, - "optionExamples": [ - "[true, \"check-space\", \"check-uppercase\"]", - "[true, \"check-lowercase\", {\"ignoreWords\": [\"TODO\", \"HACK\"]}]", - "[true, \"check-lowercase\", {\"ignorePattern\": \"STD\\w{2,3}\\b\"}]" - ], - "type": "style", - "typescriptOnly": false - }, - { - "ruleName": "completed-docs", - "description": "Enforces documentation for important items be filled out.", - "optionsDescription": "\nEither `true` to enable for all, or any of\n`[\"classes\", \"functions\", \"methods\", \"properties\"]\nto choose individual ones.`", - "options": { - "type": "array", - "items": { - "type": "string", - "enum": [ - "classes", - "functions", - "methods", - "properties" - ] - } - }, - "optionExamples": [ - "true", - "[true, \"classes\", \"functions\"]" - ], - "type": "style", - "typescriptOnly": false - }, - { - "ruleName": "curly", - "description": "Enforces braces for `if`/`for`/`do`/`while` statements.", - "rationale": "\n```ts\nif (foo === bar)\n foo++;\n bar++;\n```\n\nIn the code above, the author almost certainly meant for both `foo++` and `bar++`\nto be executed only if `foo === bar`. However, he forgot braces and `bar++` will be executed\nno matter what. This rule could prevent such a mistake.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "cyclomatic-complexity", - "description": "Enforces a threshold of cyclomatic complexity.", - "descriptionDetails": "\nCyclomatic complexity is assessed for each function of any type. A starting value of 20\nis assigned and this value is then incremented for every statement which can branch the\ncontrol flow within the function. The following statements and expressions contribute\nto cyclomatic complexity:\n* `catch`\n* `if` and `? :`\n* `||` and `&&` due to short-circuit evaluation\n* `for`, `for in` and `for of` loops\n* `while` and `do while` loops", - "rationale": "\nCyclomatic complexity is a code metric which indicates the level of complexity in a\nfunction. High cyclomatic complexity indicates confusing code which may be prone to\nerrors or difficult to modify.", - "optionsDescription": "\nAn optional upper limit for cyclomatic complexity can be specified. If no limit option\nis provided a default value of $(Rule.DEFAULT_THRESHOLD) will be used.", - "options": { - "type": "number", - "minimum": "$(Rule.MINIMUM_THRESHOLD)" - }, - "optionExamples": [ - "true", - "[true, 20]" - ], - "type": "maintainability", - "typescriptOnly": false - }, - { - "ruleName": "eofline", - "description": "Ensures the file ends with a newline.", - "rationale": "It is a [standard convention](http://stackoverflow.com/q/729692/3124288) to end files with a newline.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "maintainability", - "typescriptOnly": false - }, - { - "ruleName": "file-header", - "description": "Enforces a certain header comment for all files, matched by a regular expression.", - "optionsDescription": "Regular expression to match the header.", - "options": { - "type": "string" - }, - "optionExamples": [ - "[true, \"Copyright \\\\d{4}\"]" - ], - "type": "style", - "typescriptOnly": false - }, - { - "ruleName": "forin", - "description": "Requires a `for ... in` statement to be filtered with an `if` statement.", - "rationale": "\n```ts\nfor (let key in someObject) {\n if (someObject.hasOwnProperty(key)) {\n // code here\n }\n}\n```\nPrevents accidental interation over properties inherited from an object's prototype.\nSee [MDN's `for...in`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in)\ndocumentation for more information about `for...in` loops.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "import-blacklist", - "description": "\nDisallows importing the specified modules directly via `import` and `require`.\nInstead only sub modules may be imported from that module.", - "rationale": "\nSome libraries allow importing their submodules instead of the entire module.\nThis is good practise as it avoids loading unused modules.", - "optionsDescription": "A list of blacklisted modules.", - "options": { - "type": "array", - "items": { - "type": "string" - }, - "minLength": 1 - }, - "optionExamples": [ - "true", - "[true, \"rxjs\", \"lodash\"]" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "import-spacing", - "description": "Ensures proper spacing between import statement keywords", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "style", - "typescriptOnly": false - }, - { - "ruleName": "indent", - "description": "Enforces indentation with tabs or spaces.", - "rationale": "\nUsing only one of tabs or spaces for indentation leads to more consistent editor behavior,\ncleaner diffs in version control, and easier programatic manipulation.", - "optionsDescription": "\nOne of the following arguments must be provided:\n\n* `\"spaces\"` enforces consistent spaces.\n* `\"tabs\"` enforces consistent tabs.", - "options": { - "type": "string", - "enum": [ - "tabs", - "spaces" - ] - }, - "optionExamples": [ - "[true, \"spaces\"]" - ], - "type": "maintainability", - "typescriptOnly": false - }, - { - "ruleName": "interface-name", - "description": "Requires interface names to begin with a capital 'I'", - "rationale": "Makes it easy to differentitate interfaces from regular classes at a glance.", - "optionsDescription": "\nOne of the following two options must be provided:\n\n* `\"always-prefix\"` requires interface names to start with an \"I\"\n* `\"never-prefix\"` requires interface names to not have an \"I\" prefix", - "options": { - "type": "string", - "enum": [ - "always-prefix", - "never-prefix" - ] - }, - "optionExamples": [ - "[true, \"always-prefix\"]", - "[true, \"never-prefix\"]" - ], - "type": "style", - "typescriptOnly": true - }, - { - "ruleName": "interface-over-type-literal", - "description": "Prefer an interface declaration over a type literal (`type T = { ... }`)", - "rationale": "style", - "optionsDescription": "Not configurable.", - "options": null, - "type": "style", - "typescriptOnly": true - }, - { - "ruleName": "jsdoc-format", - "description": "Enforces basic format rules for JSDoc comments.", - "descriptionDetails": "\nThe following rules are enforced for JSDoc comments (comments starting with `/**`):\n\n* each line contains an asterisk and asterisks must be aligned\n* each asterisk must be followed by either a space or a newline (except for the first and the last)\n* the only characters before the asterisk on each line must be whitespace characters\n* one line comments must start with `/** ` and end with `*/`", - "rationale": "Helps maintain a consistent, readable style for JSDoc comments.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "style", - "typescriptOnly": false - }, - { - "ruleName": "label-position", - "description": "Only allows labels in sensible locations.", - "descriptionDetails": "This rule only allows labels to be on `do/for/while/switch` statements.", - "rationale": "\nLabels in JavaScript only can be used in conjunction with `break` or `continue`,\nconstructs meant to be used for loop flow control. While you can theoretically use\nlabels on any block statement in JS, it is considered poor code structure to do so.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "linebreak-style", - "description": "Enforces a consistent linebreak style.", - "optionsDescription": "\nOne of the following options must be provided:\n\n* `\"LF\"` requires LF (`\\n`) linebreaks\n* `\"CRLF\"` requires CRLF (`\\r\\n`) linebreaks", - "options": { - "type": "string", - "enum": [ - "LF", - "CRLF" - ] - }, - "optionExamples": [ - "[true, \"LF\"]", - "[true, \"CRLF\"]" - ], - "type": "maintainability", - "typescriptOnly": false - }, - { - "ruleName": "max-classes-per-file", - "description": "\nA file may not contain more than the specified number of classes", - "rationale": "\nEnsures that files have a single responsibility so that that classes each exist in their own files", - "optionsDescription": "\nThe one required argument is an integer indicating the maximum number of classes that can appear in a file.", - "options": { - "type": "array", - "items": [ - { - "type": "number", - "minimum": 1 - } - ], - "additionalItems": false, - "minLength": 1, - "maxLength": 2 - }, - "optionExamples": [ - "[true, 1]", - "[true, 5]" - ], - "type": "maintainability", - "typescriptOnly": false - }, - { - "ruleName": "max-file-line-count", - "description": "Requires files to remain under a certain number of lines", - "rationale": "\nLimiting the number of lines allowed in a file allows files to remain small, \nsingle purpose, and maintainable.", - "optionsDescription": "An integer indicating the maximum number of lines.", - "options": { - "type": "number", - "minimum": "1" - }, - "optionExamples": [ - "[true, 300]" - ], - "type": "maintainability", - "typescriptOnly": false - }, - { - "ruleName": "max-line-length", - "description": "Requires lines to be under a certain max length.", - "rationale": "\nLimiting the length of a line of code improves code readability.\nIt also makes comparing code side-by-side easier and improves compatibility with\nvarious editors, IDEs, and diff viewers.", - "optionsDescription": "An integer indicating the max length of lines.", - "options": { - "type": "number", - "minimum": "1" - }, - "optionExamples": [ - "[true, 120]" - ], - "type": "maintainability", - "typescriptOnly": false - }, - { - "ruleName": "member-access", - "description": "Requires explicit visibility declarations for class members.", - "rationale": "Explicit visibility declarations can make code more readable and accessible for those new to TS.", - "optionsDescription": "\nTwo arguments may be optionally provided:\n\n* `\"check-accessor\"` enforces explicit visibility on get/set accessors (can only be public)\n* `\"check-constructor\"` enforces explicit visibility on constructors (can only be public)", - "options": { - "type": "array", - "items": { - "type": "string", - "enum": [ - "check-accessor", - "check-constructor" - ] - }, - "minLength": 0, - "maxLength": 2 - }, - "optionExamples": [ - "true", - "[true, \"check-accessor\"]" - ], - "type": "typescript", - "typescriptOnly": true - }, - { - "ruleName": "member-ordering", - "description": "Enforces member ordering.", - "rationale": "A consistent ordering for class members can make classes easier to read, navigate, and edit.", - "optionsDescription": "\nOne argument, which is an object, must be provided. It should contain an `order` property.\nThe `order` property should have a value of one of the following strings:\n\n* `fields-first`\n* `statics-first`\n* `instance-sandwich`\n\nAlternatively, the value for `order` maybe be an array consisting of the following strings:\n\n* `public-static-field`\n* `protected-static-field`\n* `private-static-field`\n* `public-instance-field`\n* `protected-instance-field`\n* `private-instance-field`\n* `constructor`\n* `public-static-method`\n* `protected-static-method`\n* `private-static-method`\n* `public-instance-method`\n* `protected-instance-method`\n* `private-instance-method`\n\nThis is useful if one of the preset orders does not meet your needs.", - "options": { - "type": "object", - "properties": { - "order": { - "oneOf": [ - { - "type": "string", - "enum": [ - "fields-first", - "statics-first", - "instance-sandwich" - ] - }, - { - "type": "array", - "items": { - "type": "string", - "enum": [ - "public-static-field", - "public-static-method", - "protected-static-field", - "protected-static-method", - "private-static-field", - "private-static-method", - "public-instance-field", - "protected-instance-field", - "private-instance-field", - "constructor", - "public-instance-method", - "protected-instance-method", - "private-instance-method" - ] - }, - "maxLength": 13 - } - ] - } - }, - "additionalProperties": false - }, - "optionExamples": [ - "[true, { \"order\": \"fields-first\" }]" - ], - "type": "typescript", - "typescriptOnly": true - }, - { - "ruleName": "new-parens", - "description": "Requires parentheses when invoking a constructor via the `new` keyword.", - "rationale": "Maintains stylistic consistency with other function calls.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "style", - "typescriptOnly": false - }, - { - "ruleName": "no-angle-bracket-type-assertion", - "description": "Requires the use of `as Type` for type assertions instead of ``.", - "hasFix": true, - "rationale": "\nBoth formats of type assertions have the same effect, but only `as` type assertions\nwork in `.tsx` files. This rule ensures that you have a consistent type assertion style\nacross your codebase.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "style", - "typescriptOnly": true - }, - { - "ruleName": "no-any", - "description": "Diallows usages of `any` as a type declaration.", - "rationale": "Using `any` as a type declaration nullifies the compile-time benefits of the type system.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "typescript", - "typescriptOnly": true - }, - { - "ruleName": "no-arg", - "description": "Disallows use of `arguments.callee`.", - "rationale": "\nUsing `arguments.callee` makes various performance optimizations impossible.\nSee [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments/callee)\nfor more details on why to avoid `arguments.callee`.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "no-bitwise", - "description": "Disallows bitwise operators.", - "descriptionDetails": "\nSpecifically, the following bitwise operators are banned:\n`&`, `&=`, `|`, `|=`,\n`^`, `^=`, `<<`, `<<=`,\n`>>`, `>>=`, `>>>`, `>>>=`, and `~`.\nThis rule does not ban the use of `&` and `|` for intersection and union types.", - "rationale": "\nBitwise operators are often typos - for example `bool1 & bool2` instead of `bool1 && bool2`.\nThey also can be an indicator of overly clever code which decreases maintainability.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "no-boolean-literal-compare", - "description": "Warns on comparison to a boolean literal, as in `x === true`.", - "hasFix": true, - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "style", - "typescriptOnly": true, - "requiresTypeInfo": true - }, - { - "ruleName": "no-conditional-assignment", - "description": "Disallows any type of assignment in conditionals.", - "descriptionDetails": "This applies to `do-while`, `for`, `if`, and `while` statements.", - "rationale": "\nAssignments in conditionals are often typos:\nfor example `if (var1 = var2)` instead of `if (var1 == var2)`.\nThey also can be an indicator of overly clever code which decreases maintainability.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "no-consecutive-blank-lines", - "description": "Disallows one or more blank lines in a row.", - "rationale": "Helps maintain a readable style in your codebase.", - "optionsDescription": "\nAn optional number of maximum allowed sequential blanks can be specified. If no value\nis provided, a default of $(Rule.DEFAULT_ALLOWED_BLANKS) will be used.", - "options": { - "type": "number", - "minimum": "$(Rule.MINIMUM_ALLOWED_BLANKS)" - }, - "optionExamples": [ - "true", - "[true, 2]" - ], - "type": "style", - "typescriptOnly": false - }, - { - "ruleName": "no-console", - "description": "Bans the use of specified `console` methods.", - "rationale": "In general, `console` methods aren't appropriate for production code.", - "optionsDescription": "A list of method names to ban.", - "options": { - "type": "array", - "items": { - "type": "string" - } - }, - "optionExamples": [ - "[true, \"log\", \"error\"]" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "no-construct", - "description": "Disallows access to the constructors of `String`, `Number`, and `Boolean`.", - "descriptionDetails": "Disallows constructor use such as `new Number(foo)` but does not disallow `Number(foo)`.", - "rationale": "\nThere is little reason to use `String`, `Number`, or `Boolean` as constructors.\nIn almost all cases, the regular function-call version is more appropriate.\n[More details](http://stackoverflow.com/q/4719320/3124288) are available on StackOverflow.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "no-debugger", - "description": "Disallows `debugger` statements.", - "rationale": "In general, `debugger` statements aren't appropriate for production code.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "no-default-export", - "description": "Disallows default exports in ES6-style modules.", - "descriptionDetails": "Use named exports instead.", - "rationale": "\nNamed imports/exports [promote clarity](https://github.com/palantir/tslint/issues/1182#issue-151780453).\nIn addition, current tooling differs on the correct way to handle default imports/exports.\nAvoiding them all together can help avoid tooling bugs and conflicts.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "maintainability", - "typescriptOnly": false - }, - { - "ruleName": "no-duplicate-variable", - "description": "Disallows duplicate variable declarations in the same block scope.", - "descriptionDetails": "\nThis rule is only useful when using the `var` keyword -\nthe compiler will detect redeclarations of `let` and `const` variables.", - "rationale": "\nA variable can be reassigned if necessary -\nthere's no good reason to have a duplicate variable declaration.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "no-empty-interface", - "description": "Forbids empty interfaces.", - "rationale": "An empty interface is equivalent to its supertype (or `{}`).", - "optionsDescription": "Not configurable.", - "options": null, - "type": "typescript", - "typescriptOnly": true - }, - { - "ruleName": "no-empty", - "description": "Disallows empty blocks.", - "descriptionDetails": "Blocks with a comment inside are not considered empty.", - "rationale": "Empty blocks are often indicators of missing code.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "no-eval", - "description": "Disallows `eval` function invocations.", - "rationale": "\n`eval()` is dangerous as it allows arbitrary code execution with full privileges. There are\n[alternatives](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval)\nfor most of the use cases for `eval()`.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "no-for-in-array", - "description": "Disallows iterating over an array with a for-in loop.", - "descriptionDetails": "\nA for-in loop (`for (var k in o)`) iterates over the properties of an Object.\n\nWhile it is legal to use for-in loops with array types, it is not common.\nfor-in will iterate over the indices of the array as strings, omitting any \"holes\" in\nthe array.\n\nMore common is to use for-of, which iterates over the values of an array.\nIf you want to iterate over the indices, alternatives include:\n\narray.forEach((value, index) => { ... });\nfor (const [index, value] of array.entries()) { ... }\nfor (let i = 0; i < array.length; i++) { ... }\n", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "requiresTypeInfo": true, - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "no-inferrable-types", - "description": "Disallows explicit type declarations for variables or parameters initialized to a number, string, or boolean.", - "rationale": "Explicit types where they can be easily infered by the compiler make code more verbose.", - "optionsDescription": "\nOne argument may be optionally provided:\n\n* `ignore-params` allows specifying an inferrable type annotation for function params.\nThis can be useful when combining with the `typedef` rule.", - "options": { - "type": "array", - "items": { - "type": "string", - "enum": [ - "ignore-params" - ] - }, - "minLength": 0, - "maxLength": 1 - }, - "optionExamples": [ - "true", - "[true, \"ignore-params\"]" - ], - "type": "typescript", - "typescriptOnly": true - }, - { - "ruleName": "no-inferred-empty-object-type", - "description": "Disallow type inference of {} (empty object type) at function and constructor call sites", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": true, - "requiresTypeInfo": true - }, - { - "ruleName": "no-internal-module", - "description": "Disallows internal `module`", - "rationale": "Using `module` leads to a confusion of concepts with external modules. Use the newer `namespace` keyword instead.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "typescript", - "typescriptOnly": true - }, - { - "ruleName": "no-invalid-this", - "description": "Disallows using the `this` keyword outside of classes.", - "rationale": "See [the rule's author's rationale here.](https://github.com/palantir/tslint/pull/1105#issue-147549402)", - "optionsDescription": "\nOne argument may be optionally provided:\n\n* `check-function-in-method` disallows using the `this` keyword in functions within class methods.", - "options": { - "type": "array", - "items": { - "type": "string", - "enum": [ - "check-function-in-method" - ] - }, - "minLength": 0, - "maxLength": 1 - }, - "optionExamples": [ - "true", - "[true, \"check-function-in-method\"]" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "no-magic-numbers", - "description": "\nDisallows the use constant number values outside of variable assignments.\nWhen no list of allowed values is specified, -1, 0 and 1 are allowed by default.", - "rationale": "\nMagic numbers should be avoided as they often lack documentation, forcing\nthem to be stored in variables gives them implicit documentation.", - "optionsDescription": "A list of allowed numbers.", - "options": { - "type": "array", - "items": { - "type": "number" - }, - "minLength": 1 - }, - "optionExamples": [ - "true", - "[true, 1, 2, 3]" - ], - "type": "typescript", - "typescriptOnly": false - }, - { - "ruleName": "no-mergeable-namespace", - "description": "Disallows mergeable namespaces in the same file.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "maintainability", - "typescriptOnly": true - }, - { - "ruleName": "no-misused-new", - "description": "Warns on apparent attempts to define constructors for interfaces or `new` for classes.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": true - }, - { - "ruleName": "no-namespace", - "description": "Disallows use of internal `module`s and `namespace`s.", - "descriptionDetails": "This rule still allows the use of `declare module ... {}`", - "rationale": "\nES6-style external modules are the standard way to modularize code.\nUsing `module {}` and `namespace {}` are outdated ways to organize TypeScript code.", - "optionsDescription": "\nOne argument may be optionally provided:\n\n* `allow-declarations` allows `declare namespace ... {}` to describe external APIs.", - "options": { - "type": "array", - "items": { - "type": "string", - "enum": [ - "allow-declarations" - ] - }, - "minLength": 0, - "maxLength": 1 - }, - "optionExamples": [ - "true", - "[true, \"allow-declarations\"]" - ], - "type": "typescript", - "typescriptOnly": true - }, - { - "ruleName": "no-null-keyword", - "description": "Disallows use of the `null` keyword literal.", - "rationale": "\nInstead of having the dual concepts of `null` and`undefined` in a codebase,\nthis rule ensures that only `undefined` is used.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "no-parameter-properties", - "description": "Disallows parameter properties in class constructors.", - "rationale": "\nParameter properties can be confusing to those new to TS as they are less explicit\nthan other ways of declaring and initializing class members.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "style", - "typescriptOnly": true - }, - { - "ruleName": "no-reference", - "description": "Disallows `/// ` imports (use ES6-style imports instead).", - "rationale": "\nUsing `/// ` comments to load other files is outdated.\nUse ES6-style imports to reference other files.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "typescript", - "typescriptOnly": false - }, - { - "ruleName": "no-require-imports", - "description": "Disallows invocation of `require()`.", - "rationale": "Prefer the newer ES6-style imports over `require()`.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "maintainability", - "typescriptOnly": false - }, - { - "ruleName": "no-shadowed-variable", - "description": "Disallows shadowing variable declarations.", - "rationale": "Shadowing a variable masks access to it and obscures to what value an identifier actually refers.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "no-string-literal", - "description": "Disallows object access via string literals.", - "rationale": "Encourages using strongly-typed property access.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "no-string-throw", - "description": "Flags throwing plain strings or concatenations of strings because only Errors produce proper stack traces.", - "hasFix": true, - "options": null, - "optionsDescription": "Not configurable.", - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "no-switch-case-fall-through", - "description": "Disallows falling through case statements.", - "descriptionDetails": "\nFor example, the following is not allowed:\n\n```ts\nswitch(foo) {\n case 1:\n someFunc(foo);\n case 2:\n someOtherFunc(foo);\n}\n```\n\nHowever, fall through is allowed when case statements are consecutive or\na magic `/* falls through */` comment is present. The following is valid:\n\n```ts\nswitch(foo) {\n case 1:\n someFunc(foo);\n /* falls through */\n case 2:\n case 3:\n someOtherFunc(foo);\n}\n```", - "rationale": "Fall though in switch statements is often unintentional and a bug.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "no-trailing-whitespace", - "description": "Disallows trailing whitespace at the end of a line.", - "rationale": "Keeps version control diffs clean as it prevents accidental whitespace from being committed.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "maintainability", - "typescriptOnly": false - }, - { - "ruleName": "no-unnecessary-qualifier", - "description": "Warns when a namespace qualifier (`A.x`) is unnecessary.", - "hasFix": true, - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "style", - "typescriptOnly": true, - "requiresTypeInfo": true - }, - { - "ruleName": "no-unsafe-finally", - "description": "\nDisallows control flow statements, such as `return`, `continue`,\n`break` and `throws` in finally blocks.", - "descriptionDetails": "", - "rationale": "\nWhen used inside `finally` blocks, control flow statements,\nsuch as `return`, `continue`, `break` and `throws`\noverride any other control flow statements in the same try/catch scope.\nThis is confusing and unexpected behavior.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "no-unused-expression", - "description": "Disallows unused expression statements.", - "descriptionDetails": "\nUnused expressions are expression statements which are not assignments or function calls\n(and thus usually no-ops).", - "rationale": "\nDetects potential errors where an assignment or function call was intended.", - "optionsDescription": "\nOne argument may be optionally provided:\n\n* `allow-fast-null-checks` allows to use logical operators to perform fast null checks and perform\nmethod or function calls for side effects (e.g. `e && e.preventDefault()`).", - "options": { - "type": "array", - "items": { - "type": "string", - "enum": [ - "allow-fast-null-checks" - ] - }, - "minLength": 0, - "maxLength": 1 - }, - "optionExamples": [ - "true", - "[true, \"allow-fast-null-checks\"]" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "no-unused-new", - "description": "Disallows unused 'new' expression statements.", - "descriptionDetails": "\nUnused 'new' expressions indicate that a constructor is being invoked solely for its side effects.", - "rationale": "\nDetects constructs such as `new SomeClass()`, where a constructor is used solely for its side effects, which is considered\npoor style.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "no-unused-variable", - "deprecationMessage": "Use the tsc compiler options --noUnusedParameters and --noUnusedLocals instead.", - "description": "Disallows unused imports, variables, functions and private class members.", - "hasFix": true, - "optionsDescription": "\nThree optional arguments may be optionally provided:\n\n* `\"check-parameters\"` disallows unused function and constructor parameters.\n * NOTE: this option is experimental and does not work with classes\n that use abstract method declarations, among other things.\n* `\"react\"` relaxes the rule for a namespace import named `React`\n(from either the module `\"react\"` or `\"react/addons\"`).\nAny JSX expression in the file will be treated as a usage of `React`\n(because it expands to `React.createElement `).\n* `{\"ignore-pattern\": \"pattern\"}` where pattern is a case-sensitive regexp.\nVariable names that match the pattern will be ignored.", - "options": { - "type": "array", - "items": { - "oneOf": [ - { - "type": "string", - "enum": [ - "check-parameters", - "react" - ] - }, - { - "type": "object", - "properties": { - "ignore-pattern": { - "type": "string" - } - }, - "additionalProperties": false - } - ] - }, - "minLength": 0, - "maxLength": 3 - }, - "optionExamples": [ - "[true, \"react\"]", - "[true, {\"ignore-pattern\": \"^_\"}]" - ], - "type": "functionality", - "typescriptOnly": true - }, - { - "ruleName": "no-use-before-declare", - "description": "Disallows usage of variables before their declaration.", - "descriptionDetails": "\nThis rule is primarily useful when using the `var` keyword -\nthe compiler will detect if a `let` and `const` variable is used before it is declared.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "no-var-keyword", - "description": "Disallows usage of the `var` keyword.", - "descriptionDetails": "Use `let` or `const` instead.", - "hasFix": true, - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "no-var-requires", - "description": "Disallows the use of require statements except in import statements.", - "descriptionDetails": "\nIn other words, the use of forms such as `var module = require(\"module\")` are banned.\nInstead use ES6 style imports or `import foo = require('foo')` imports.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "typescript", - "typescriptOnly": true - }, - { - "ruleName": "no-void-expression", - "description": "Requires expressions of type `void` to appear in statement position.", - "optionsDescription": "Not configurable.", - "options": null, - "requiresTypeInfo": true, - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "object-literal-key-quotes", - "description": "Enforces consistent object literal property quote style.", - "descriptionDetails": "\nObject literal property names can be defined in two ways: using literals or using strings.\nFor example, these two objects are equivalent:\n\nvar object1 = {\n property: true\n};\n\nvar object2 = {\n \"property\": true\n};\n\nIn many cases, it doesn’t matter if you choose to use an identifier instead of a string\nor vice-versa. Even so, you might decide to enforce a consistent style in your code.\n\nThis rules lets you enforce consistent quoting of property names. Either they should always\nbe quoted (default behavior) or quoted only as needed (\"as-needed\").", - "hasFix": true, - "optionsDescription": "\nPossible settings are:\n\n* `\"always\"`: Property names should always be quoted. (This is the default.)\n* `\"as-needed\"`: Only property names which require quotes may be quoted (e.g. those with spaces in them).\n* `\"consistent\"`: Property names should either all be quoted or unquoted.\n* `\"consistent-as-needed\"`: If any property name requires quotes, then all properties must be quoted. Otherwise, no\nproperty names may be quoted.\n\nFor ES6, computed property names (`{[name]: value}`) and methods (`{foo() {}}`) never need\nto be quoted.", - "options": { - "type": "string", - "enum": [ - "always", - "as-needed", - "consistent", - "consistent-as-needed" - ] - }, - "optionExamples": [ - "[true, \"as-needed\"]", - "[true, \"always\"]" - ], - "type": "style", - "typescriptOnly": false - }, - { - "ruleName": "object-literal-shorthand", - "description": "Enforces use of ES6 object literal shorthand when possible.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "style", - "typescriptOnly": false - }, - { - "ruleName": "object-literal-sort-keys", - "description": "Requires keys in object literals to be sorted alphabetically", - "rationale": "Useful in preventing merge conflicts", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "maintainability", - "typescriptOnly": false - }, - { - "ruleName": "one-line", - "description": "Requires the specified tokens to be on the same line as the expression preceding them.", - "optionsDescription": "\nFive arguments may be optionally provided:\n\n* `\"check-catch\"` checks that `catch` is on the same line as the closing brace for `try`.\n* `\"check-finally\"` checks that `finally` is on the same line as the closing brace for `catch`.\n* `\"check-else\"` checks that `else` is on the same line as the closing brace for `if`.\n* `\"check-open-brace\"` checks that an open brace falls on the same line as its preceding expression.\n* `\"check-whitespace\"` checks preceding whitespace for the specified tokens.", - "options": { - "type": "array", - "items": { - "type": "string", - "enum": [ - "check-catch", - "check-finally", - "check-else", - "check-open-brace", - "check-whitespace" - ] - }, - "minLength": 0, - "maxLength": 5 - }, - "optionExamples": [ - "[true, \"check-catch\", \"check-finally\", \"check-else\"]" - ], - "type": "style", - "typescriptOnly": false - }, - { - "ruleName": "one-variable-per-declaration", - "description": "Disallows multiple variable definitions in the same declaration statement.", - "optionsDescription": "\nOne argument may be optionally provided:\n\n* `ignore-for-loop` allows multiple variable definitions in a for loop declaration.", - "options": { - "type": "array", - "items": { - "type": "string", - "enum": [ - "ignore-for-loop" - ] - }, - "minLength": 0, - "maxLength": 1 - }, - "optionExamples": [ - "true", - "[true, \"ignore-for-loop\"]" - ], - "type": "style", - "typescriptOnly": false - }, - { - "ruleName": "only-arrow-functions", - "description": "Disallows traditional (non-arrow) function expressions.", - "rationale": "Traditional functions don't bind lexical scope, which can lead to unexpected behavior when accessing 'this'.", - "optionsDescription": "\nTwo arguments may be optionally provided:\n\n* `\"allow-declarations\"` allows standalone function declarations.\n* `\"allow-named-functions\"` allows the expression `function foo() {}` but not `function() {}`.\n ", - "options": { - "type": "array", - "items": { - "type": "string", - "enum": [ - "allow-declarations", - "allow-named-functions" - ] - }, - "minLength": 0, - "maxLength": 1 - }, - "optionExamples": [ - "true", - "[true, \"allow-declarations\", \"allow-named-functions\"]" - ], - "type": "typescript", - "typescriptOnly": false - }, - { - "ruleName": "ordered-imports", - "description": "Requires that import statements be alphabetized.", - "descriptionDetails": "\nEnforce a consistent ordering for ES6 imports:\n- Named imports must be alphabetized (i.e. \"import {A, B, C} from \"foo\";\")\n - The exact ordering can be controlled by the named-imports-order option.\n - \"longName as name\" imports are ordered by \"longName\".\n- Import sources must be alphabetized within groups, i.e.:\n import * as foo from \"a\";\n import * as bar from \"b\";\n- Groups of imports are delineated by blank lines. You can use these to group imports\n however you like, e.g. by first- vs. third-party or thematically.", - "hasFix": true, - "optionsDescription": "\nYou may set the `\"import-sources-order\"` option to control the ordering of source\nimports (the `\"foo\"` in `import {A, B, C} from \"foo\"`).\n\nPossible values for `\"import-sources-order\"` are:\n\n* `\"case-insensitive'`: Correct order is `\"Bar\"`, `\"baz\"`, `\"Foo\"`. (This is the default.)\n* `\"lowercase-first\"`: Correct order is `\"baz\"`, `\"Bar\"`, `\"Foo\"`.\n* `\"lowercase-last\"`: Correct order is `\"Bar\"`, `\"Foo\"`, `\"baz\"`.\n* `\"any\"`: Allow any order.\n\nYou may set the `\"named-imports-order\"` option to control the ordering of named\nimports (the `{A, B, C}` in `import {A, B, C} from \"foo\"`).\n\nPossible values for `\"named-imports-order\"` are:\n\n* `\"case-insensitive'`: Correct order is `{A, b, C}`. (This is the default.)\n* `\"lowercase-first\"`: Correct order is `{b, A, C}`.\n* `\"lowercase-last\"`: Correct order is `{A, C, b}`.\n* `\"any\"`: Allow any order.\n\n ", - "options": { - "type": "object", - "properties": { - "import-sources-order": { - "type": "string", - "enum": [ - "case-insensitive", - "lowercase-first", - "lowercase-last", - "any" - ] - }, - "named-imports-order": { - "type": "string", - "enum": [ - "case-insensitive", - "lowercase-first", - "lowercase-last", - "any" - ] - } - }, - "additionalProperties": false - }, - "optionExamples": [ - "true", - "[true, {\"import-sources-order\": \"lowercase-last\", \"named-imports-order\": \"lowercase-first\"}]" - ], - "type": "style", - "typescriptOnly": false - }, - { - "ruleName": "prefer-const", - "description": "Requires that variable declarations use `const` instead of `let` if possible.", - "descriptionDetails": "\nIf a variable is only assigned to once when it is declared, it should be declared using 'const'", - "hasFix": true, - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "maintainability", - "typescriptOnly": false - }, - { - "ruleName": "prefer-for-of", - "description": "Recommends a 'for-of' loop over a standard 'for' loop if the index is only used to access the array being iterated.", - "rationale": "A for(... of ...) loop is easier to implement and read when the index is not needed.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "typescript", - "typescriptOnly": false - }, - { - "ruleName": "prefer-method-signature", - "description": "Prefer `foo(): void` over `foo: () => void` in interfaces and types.", - "hasFix": true, - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "style", - "typescriptOnly": false - }, - { - "ruleName": "promise-function-async", - "description": "Requires any function or method that returns a promise to be marked async.", - "rationale": "\nEnsures that each function is only capable of 1) returning a rejected promise, or 2)\nthrowing an Error object. In contrast, non-`async` `Promise`-returning functions\nare technically capable of either. This practice removes a requirement for consuming\ncode to handle both cases.\n ", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "typescript", - "typescriptOnly": false, - "requiresTypeInfo": true - }, - { - "ruleName": "quotemark", - "description": "Requires single or double quotes for string literals.", - "hasFix": true, - "optionsDescription": "\nFive arguments may be optionally provided:\n\n* `\"single\"` enforces single quotes.\n* `\"double\"` enforces double quotes.\n* `\"jsx-single\"` enforces single quotes for JSX attributes.\n* `\"jsx-double\"` enforces double quotes for JSX attributes.\n* `\"avoid-escape\"` allows you to use the \"other\" quotemark in cases where escaping would normally be required.\nFor example, `[true, \"double\", \"avoid-escape\"]` would not report a failure on the string literal `'Hello \"World\"'`.", - "options": { - "type": "array", - "items": { - "type": "string", - "enum": [ - "single", - "double", - "jsx-single", - "jsx-double", - "avoid-escape" - ] - }, - "minLength": 0, - "maxLength": 5 - }, - "optionExamples": [ - "[true, \"single\", \"avoid-escape\"]", - "[true, \"single\", \"jsx-double\"]" - ], - "type": "style", - "typescriptOnly": false - }, - { - "ruleName": "radix", - "description": "Requires the radix parameter to be specified when calling `parseInt`.", - "rationale": "\nFrom [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt):\n> Always specify this parameter to eliminate reader confusion and to guarantee predictable behavior.\n> Different implementations produce different results when a radix is not specified, usually defaulting the value to 10.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "restrict-plus-operands", - "description": "When adding two variables, operands must both be of type number or of type string.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false, - "requiresTypeInfo": true - }, - { - "ruleName": "semicolon", - "description": "Enforces consistent semicolon usage at the end of every statement.", - "hasFix": true, - "optionsDescription": "\nOne of the following arguments must be provided:\n\n* `\"always\"` enforces semicolons at the end of every statement.\n* `\"never\"` disallows semicolons at the end of every statement except for when they are necessary.\n\nThe following arguments may be optionaly provided:\n\n* `\"ignore-interfaces\"` skips checking semicolons at the end of interface members.\n* `\"ignore-bound-class-methods\"` skips checking semicolons at the end of bound class methods.", - "options": { - "type": "array", - "items": [ - { - "type": "string", - "enum": [ - "always", - "never" - ] - }, - { - "type": "string", - "enum": [ - "ignore-interfaces" - ] - } - ], - "additionalItems": false - }, - "optionExamples": [ - "[true, \"always\"]", - "[true, \"never\"]", - "[true, \"always\", \"ignore-interfaces\"]", - "[true, \"always\", \"ignore-bound-class-methods\"]" - ], - "type": "style", - "typescriptOnly": false - }, - { - "description": "Require or disallow a space before function parenthesis", - "hasFix": true, - "optionExamples": [ - "true", - "[true, \"always\"]", - "[true, \"never\"]", - "[true, {\"anonymous\": \"always\", \"named\": \"never\", \"asyncArrow\": \"always\"}]" - ], - "options": { - "properties": { - "anonymous": { - "enum": [ - "always", - "never" - ], - "type": "string" - }, - "asyncArrow": { - "enum": [ - "always", - "never" - ], - "type": "string" - }, - "constructor": { - "enum": [ - "always", - "never" - ], - "type": "string" - }, - "method": { - "enum": [ - "always", - "never" - ], - "type": "string" - }, - "named": { - "enum": [ - "always", - "never" - ], - "type": "string" - } - }, - "type": "object" - }, - "optionsDescription": "\nOne argument which is an object which may contain the keys `anonymous`, `named`, and `asyncArrow`\nThese should be set to either `\"always\"` or `\"never\"`.\n\n* `\"anonymous\"` checks before the opening paren in anonymous functions\n* `\"named\"` checks before the opening paren in named functions\n* `\"asyncArrow\"` checks before the opening paren in async arrow functions\n* `\"method\"` checks before the opening paren in class methods\n* `\"constructor\"` checks before the opening paren in class constructors\n ", - "ruleName": "space-before-function-paren", - "type": "style", - "typescriptOnly": false - }, - { - "ruleName": "strict-boolean-expressions", - "description": "Usage of && or || operators should be with boolean operands and\nexpressions in If, Do, While and For statements should be of type boolean", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": true, - "requiresTypeInfo": true - }, - { - "ruleName": "switch-default", - "description": "Require a `default` case in all `switch` statements.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "trailing-comma", - "description": "\nRequires or disallows trailing commas in array and object literals, destructuring assignments, function and tuple typings,\nnamed imports and function parameters.", - "hasFix": true, - "optionsDescription": "\nOne argument which is an object with the keys `multiline` and `singleline`.\nBoth should be set to either `\"always\"` or `\"never\"`.\n\n* `\"multiline\"` checks multi-line object literals.\n* `\"singleline\"` checks single-line object literals.\n\nA array is considered \"multiline\" if its closing bracket is on a line\nafter the last array element. The same general logic is followed for\nobject literals, function and tuple typings, named import statements\nand function parameters.", - "options": { - "type": "object", - "properties": { - "multiline": { - "type": "string", - "enum": [ - "always", - "never" - ] - }, - "singleline": { - "type": "string", - "enum": [ - "always", - "never" - ] - } - }, - "additionalProperties": false - }, - "optionExamples": [ - "[true, {\"multiline\": \"always\", \"singleline\": \"never\"}]" - ], - "type": "maintainability", - "typescriptOnly": false - }, - { - "ruleName": "triple-equals", - "description": "Requires `===` and `!==` in place of `==` and `!=`.", - "optionsDescription": "\nTwo arguments may be optionally provided:\n\n* `\"allow-null-check\"` allows `==` and `!=` when comparing to `null`.\n* `\"allow-undefined-check\"` allows `==` and `!=` when comparing to `undefined`.", - "options": { - "type": "array", - "items": { - "type": "string", - "enum": [ - "allow-null-check", - "allow-undefined-check" - ] - }, - "minLength": 0, - "maxLength": 2 - }, - "optionExamples": [ - "true", - "[true, \"allow-null-check\"]", - "[true, \"allow-undefined-check\"]" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "typedef", - "description": "Requires type definitions to exist.", - "optionsDescription": "\nSeven arguments may be optionally provided:\n\n* `\"call-signature\"` checks return type of functions.\n* `\"arrow-call-signature\"` checks return type of arrow functions.\n* `\"parameter\"` checks type specifier of function parameters for non-arrow functions.\n* `\"arrow-parameter\"` checks type specifier of function parameters for arrow functions.\n* `\"property-declaration\"` checks return types of interface properties.\n* `\"variable-declaration\"` checks variable declarations.\n* `\"member-variable-declaration\"` checks member variable declarations.", - "options": { - "type": "array", - "items": { - "type": "string", - "enum": [ - "call-signature", - "arrow-call-signature", - "parameter", - "arrow-parameter", - "property-declaration", - "variable-declaration", - "member-variable-declaration" - ] - }, - "minLength": 0, - "maxLength": 7 - }, - "optionExamples": [ - "[true, \"call-signature\", \"parameter\", \"member-variable-declaration\"]" - ], - "type": "typescript", - "typescriptOnly": true - }, - { - "ruleName": "typedef-whitespace", - "description": "Requires or disallows whitespace for type definitions.", - "descriptionDetails": "Determines if a space is required or not before the colon in a type specifier.", - "optionsDescription": "\nTwo arguments which are both objects.\nThe first argument specifies how much space should be to the _left_ of a typedef colon.\nThe second argument specifies how much space should be to the _right_ of a typedef colon.\nEach key should have a value of `\"space\"` or `\"nospace\"`.\nPossible keys are:\n\n* `\"call-signature\"` checks return type of functions.\n* `\"index-signature\"` checks index type specifier of indexers.\n* `\"parameter\"` checks function parameters.\n* `\"property-declaration\"` checks object property declarations.\n* `\"variable-declaration\"` checks variable declaration.", - "options": { - "type": "array", - "items": [ - { - "type": "object", - "properties": { - "call-signature": { - "type": "string", - "enum": [ - "nospace", - "onespace", - "space" - ] - }, - "index-signature": { - "type": "string", - "enum": [ - "nospace", - "onespace", - "space" - ] - }, - "parameter": { - "type": "string", - "enum": [ - "nospace", - "onespace", - "space" - ] - }, - "property-declaration": { - "type": "string", - "enum": [ - "nospace", - "onespace", - "space" - ] - }, - "variable-declaration": { - "type": "string", - "enum": [ - "nospace", - "onespace", - "space" - ] - } - }, - "additionalProperties": false - }, - { - "type": "object", - "properties": { - "call-signature": { - "type": "string", - "enum": [ - "nospace", - "onespace", - "space" - ] - }, - "index-signature": { - "type": "string", - "enum": [ - "nospace", - "onespace", - "space" - ] - }, - "parameter": { - "type": "string", - "enum": [ - "nospace", - "onespace", - "space" - ] - }, - "property-declaration": { - "type": "string", - "enum": [ - "nospace", - "onespace", - "space" - ] - }, - "variable-declaration": { - "type": "string", - "enum": [ - "nospace", - "onespace", - "space" - ] - } - }, - "additionalProperties": false - } - ], - "additionalItems": false - }, - "optionExamples": [ - "\n[\n true,\n {\n \"call-signature\": \"nospace\",\n \"index-signature\": \"nospace\",\n \"parameter\": \"nospace\",\n \"property-declaration\": \"nospace\",\n \"variable-declaration\": \"nospace\"\n },\n {\n \"call-signature\": \"onespace\",\n \"index-signature\": \"onespace\",\n \"parameter\": \"onespace\",\n \"property-declaration\": \"onespace\",\n \"variable-declaration\": \"onespace\"\n }\n]" - ], - "type": "typescript", - "typescriptOnly": true - }, - { - "ruleName": "typeof-compare", - "description": "Makes sure result of `typeof` is compared to correct string values", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "unified-signatures", - "description": "Warns for any two overloads that could be unified into one by using a union or an optional/rest parameter.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "typescript", - "typescriptOnly": true - }, - { - "ruleName": "use-isnan", - "description": "Enforces use of the `isNaN()` function to check for NaN references instead of a comparison to the `NaN` constant.", - "rationale": "\nSince `NaN !== NaN`, comparisons with regular operators will produce unexpected results.\nSo, instead of `if (myVar === NaN)`, do `if (isNaN(myVar))`.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false - }, - { - "ruleName": "variable-name", - "description": "Checks variable names for various errors.", - "optionsDescription": "\nFive arguments may be optionally provided:\n\n* `\"check-format\"`: allows only camelCased or UPPER_CASED variable names\n * `\"allow-leading-underscore\"` allows underscores at the beginning (only has an effect if \"check-format\" specified)\n * `\"allow-trailing-underscore\"` allows underscores at the end. (only has an effect if \"check-format\" specified)\n * `\"allow-pascal-case\"` allows PascalCase in addtion to camelCase.\n* `\"ban-keywords\"`: disallows the use of certain TypeScript keywords (`any`, `Number`, `number`, `String`,\n`string`, `Boolean`, `boolean`, `undefined`) as variable or parameter names.", - "options": { - "type": "array", - "items": { - "type": "string", - "enum": [ - "check-format", - "allow-leading-underscore", - "allow-trailing-underscore", - "allow-pascal-case", - "ban-keywords" - ] - }, - "minLength": 0, - "maxLength": 5 - }, - "optionExamples": [ - "[true, \"ban-keywords\", \"check-format\", \"allow-leading-underscore\"]" - ], - "type": "style", - "typescriptOnly": false - }, - { - "ruleName": "whitespace", - "description": "Enforces whitespace style conventions.", - "rationale": "Helps maintain a readable, consistent style in your codebase.", - "optionsDescription": "\nEight arguments may be optionally provided:\n\n* `\"check-branch\"` checks branching statements (`if`/`else`/`for`/`while`) are followed by whitespace.\n* `\"check-decl\"`checks that variable declarations have whitespace around the equals token.\n* `\"check-operator\"` checks for whitespace around operator tokens.\n* `\"check-module\"` checks for whitespace in import & export statements.\n* `\"check-separator\"` checks for whitespace after separator tokens (`,`/`;`).\n* `\"check-type\"` checks for whitespace before a variable type specification.\n* `\"check-typecast\"` checks for whitespace between a typecast and its target.\n* `\"check-preblock\"` checks for whitespace before the opening brace of a block", - "options": { - "type": "array", - "items": { - "type": "string", - "enum": [ - "check-branch", - "check-decl", - "check-operator", - "check-module", - "check-separator", - "check-type", - "check-typecast", - "check-preblock" - ] - }, - "minLength": 0, - "maxLength": 7 - }, - "optionExamples": [ - "[true, \"check-branch\", \"check-operator\", \"check-typecast\"]" - ], - "type": "style", - "typescriptOnly": false - } -] \ No newline at end of file From 3664812e38f542e9cae5a2d6698b3d09dc9b8da3 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Wed, 18 Jan 2017 15:28:08 -0500 Subject: [PATCH 11/13] Ignore .html files in docs/rules (#2071) --- .gitignore | 1 + .../adjacent-overload-signatures/index.html | 14 -- docs/rules/align/index.html | 42 ----- docs/rules/array-type/index.html | 35 ---- docs/rules/arrow-parens/index.html | 28 --- docs/rules/arrow-return-shorthand/index.html | 26 --- docs/rules/ban/index.html | 36 ---- docs/rules/callable-types/index.html | 12 -- docs/rules/class-name/index.html | 14 -- docs/rules/comment-format/index.html | 83 --------- docs/rules/completed-docs/index.html | 38 ----- docs/rules/curly/index.html | 24 --- docs/rules/cyclomatic-complexity/index.html | 39 ----- docs/rules/eofline/index.html | 14 -- docs/rules/file-header/index.html | 17 -- docs/rules/forin/index.html | 25 --- docs/rules/import-blacklist/index.html | 32 ---- docs/rules/import-spacing/index.html | 13 -- docs/rules/indent/index.html | 33 ---- docs/rules/index.html | 22 --- docs/rules/interface-name/index.html | 31 ---- .../interface-over-type-literal/index.html | 12 -- docs/rules/jsdoc-format/index.html | 22 --- docs/rules/label-position/index.html | 19 --- docs/rules/linebreak-style/index.html | 30 ---- docs/rules/max-classes-per-file/index.html | 40 ----- docs/rules/max-file-line-count/index.html | 23 --- docs/rules/max-line-length/index.html | 24 --- docs/rules/member-access/index.html | 40 ----- docs/rules/member-ordering/index.html | 107 ------------ docs/rules/new-parens/index.html | 14 -- .../index.html | 19 --- docs/rules/no-any/index.html | 14 -- docs/rules/no-arg/index.html | 18 -- docs/rules/no-bitwise/index.html | 24 --- docs/rules/no-boolean-compare/index.html | 14 -- .../no-boolean-literal-compare/index.html | 15 -- .../no-conditional-assignment/index.html | 19 --- .../no-consecutive-blank-lines/index.html | 24 --- docs/rules/no-console/index.html | 23 --- docs/rules/no-construct/index.html | 19 --- docs/rules/no-debugger/index.html | 14 -- docs/rules/no-default-export/index.html | 19 --- docs/rules/no-duplicate-variable/index.html | 21 --- docs/rules/no-empty-interface/index.html | 12 -- docs/rules/no-empty/index.html | 15 -- docs/rules/no-eval/index.html | 18 -- docs/rules/no-for-in-array/index.html | 28 --- docs/rules/no-inferrable-types/index.html | 38 ----- .../no-inferred-empty-object-type/index.html | 14 -- .../rules/no-interface-constructor/index.html | 14 -- docs/rules/no-internal-module/index.html | 14 -- docs/rules/no-invalid-this/index.html | 37 ---- docs/rules/no-magic-numbers/index.html | 32 ---- docs/rules/no-mergeable-namespace/index.html | 13 -- docs/rules/no-misused-new/index.html | 13 -- docs/rules/no-namespace/index.html | 41 ----- docs/rules/no-null-keyword/index.html | 17 -- docs/rules/no-parameter-properties/index.html | 17 -- docs/rules/no-reference/index.html | 17 -- docs/rules/no-require-imports/index.html | 14 -- docs/rules/no-shadowed-variable/index.html | 14 -- docs/rules/no-string-literal/index.html | 14 -- docs/rules/no-string-throw/index.html | 12 -- .../no-switch-case-fall-through/index.html | 40 ----- docs/rules/no-trailing-whitespace/index.html | 14 -- .../rules/no-unnecessary-qualifier/index.html | 15 -- docs/rules/no-unreachable/index.html | 13 -- docs/rules/no-unsafe-finally/index.html | 23 --- docs/rules/no-unused-expression/index.html | 44 ----- docs/rules/no-unused-new/index.html | 20 --- docs/rules/no-unused-variable/index.html | 67 -------- docs/rules/no-use-before-declare/index.html | 17 -- docs/rules/no-var-keyword/index.html | 15 -- docs/rules/no-var-requires/index.html | 17 -- docs/rules/no-void-expression/index.html | 12 -- .../object-literal-key-quotes/index.html | 59 ------- .../rules/object-literal-shorthand/index.html | 13 -- .../rules/object-literal-sort-keys/index.html | 14 -- docs/rules/one-line/index.html | 47 ----- .../one-variable-per-declaration/index.html | 36 ---- docs/rules/only-arrow-functions/index.html | 41 ----- docs/rules/ordered-imports/index.html | 89 ---------- .../prefer-arrow-shorthand-return/index.html | 14 -- docs/rules/prefer-const/index.html | 17 -- docs/rules/prefer-for-of/index.html | 14 -- docs/rules/prefer-method-signature/index.html | 14 -- docs/rules/promise-function-async/index.html | 21 --- docs/rules/quotemark/index.html | 50 ------ docs/rules/radix/index.html | 18 -- docs/rules/restrict-plus-operands/index.html | 14 -- docs/rules/semicolon/index.html | 56 ------ .../space-before-function-paren/index.html | 78 --------- .../strict-boolean-expressions/index.html | 16 -- docs/rules/switch-default/index.html | 13 -- docs/rules/trailing-comma/index.html | 61 ------- docs/rules/triple-equals/index.html | 40 ----- docs/rules/typedef-whitespace/index.html | 160 ------------------ docs/rules/typedef/index.html | 53 ------ docs/rules/typeof-compare/index.html | 13 -- docs/rules/unified-signatures/index.html | 13 -- docs/rules/use-isnan/index.html | 17 -- docs/rules/variable-name/index.html | 48 ------ docs/rules/whitespace/index.html | 57 ------- 104 files changed, 1 insertion(+), 2929 deletions(-) delete mode 100644 docs/rules/adjacent-overload-signatures/index.html delete mode 100644 docs/rules/align/index.html delete mode 100644 docs/rules/array-type/index.html delete mode 100644 docs/rules/arrow-parens/index.html delete mode 100644 docs/rules/arrow-return-shorthand/index.html delete mode 100644 docs/rules/ban/index.html delete mode 100644 docs/rules/callable-types/index.html delete mode 100644 docs/rules/class-name/index.html delete mode 100644 docs/rules/comment-format/index.html delete mode 100644 docs/rules/completed-docs/index.html delete mode 100644 docs/rules/curly/index.html delete mode 100644 docs/rules/cyclomatic-complexity/index.html delete mode 100644 docs/rules/eofline/index.html delete mode 100644 docs/rules/file-header/index.html delete mode 100644 docs/rules/forin/index.html delete mode 100644 docs/rules/import-blacklist/index.html delete mode 100644 docs/rules/import-spacing/index.html delete mode 100644 docs/rules/indent/index.html delete mode 100644 docs/rules/index.html delete mode 100644 docs/rules/interface-name/index.html delete mode 100644 docs/rules/interface-over-type-literal/index.html delete mode 100644 docs/rules/jsdoc-format/index.html delete mode 100644 docs/rules/label-position/index.html delete mode 100644 docs/rules/linebreak-style/index.html delete mode 100644 docs/rules/max-classes-per-file/index.html delete mode 100644 docs/rules/max-file-line-count/index.html delete mode 100644 docs/rules/max-line-length/index.html delete mode 100644 docs/rules/member-access/index.html delete mode 100644 docs/rules/member-ordering/index.html delete mode 100644 docs/rules/new-parens/index.html delete mode 100644 docs/rules/no-angle-bracket-type-assertion/index.html delete mode 100644 docs/rules/no-any/index.html delete mode 100644 docs/rules/no-arg/index.html delete mode 100644 docs/rules/no-bitwise/index.html delete mode 100644 docs/rules/no-boolean-compare/index.html delete mode 100644 docs/rules/no-boolean-literal-compare/index.html delete mode 100644 docs/rules/no-conditional-assignment/index.html delete mode 100644 docs/rules/no-consecutive-blank-lines/index.html delete mode 100644 docs/rules/no-console/index.html delete mode 100644 docs/rules/no-construct/index.html delete mode 100644 docs/rules/no-debugger/index.html delete mode 100644 docs/rules/no-default-export/index.html delete mode 100644 docs/rules/no-duplicate-variable/index.html delete mode 100644 docs/rules/no-empty-interface/index.html delete mode 100644 docs/rules/no-empty/index.html delete mode 100644 docs/rules/no-eval/index.html delete mode 100644 docs/rules/no-for-in-array/index.html delete mode 100644 docs/rules/no-inferrable-types/index.html delete mode 100644 docs/rules/no-inferred-empty-object-type/index.html delete mode 100644 docs/rules/no-interface-constructor/index.html delete mode 100644 docs/rules/no-internal-module/index.html delete mode 100644 docs/rules/no-invalid-this/index.html delete mode 100644 docs/rules/no-magic-numbers/index.html delete mode 100644 docs/rules/no-mergeable-namespace/index.html delete mode 100644 docs/rules/no-misused-new/index.html delete mode 100644 docs/rules/no-namespace/index.html delete mode 100644 docs/rules/no-null-keyword/index.html delete mode 100644 docs/rules/no-parameter-properties/index.html delete mode 100644 docs/rules/no-reference/index.html delete mode 100644 docs/rules/no-require-imports/index.html delete mode 100644 docs/rules/no-shadowed-variable/index.html delete mode 100644 docs/rules/no-string-literal/index.html delete mode 100644 docs/rules/no-string-throw/index.html delete mode 100644 docs/rules/no-switch-case-fall-through/index.html delete mode 100644 docs/rules/no-trailing-whitespace/index.html delete mode 100644 docs/rules/no-unnecessary-qualifier/index.html delete mode 100644 docs/rules/no-unreachable/index.html delete mode 100644 docs/rules/no-unsafe-finally/index.html delete mode 100644 docs/rules/no-unused-expression/index.html delete mode 100644 docs/rules/no-unused-new/index.html delete mode 100644 docs/rules/no-unused-variable/index.html delete mode 100644 docs/rules/no-use-before-declare/index.html delete mode 100644 docs/rules/no-var-keyword/index.html delete mode 100644 docs/rules/no-var-requires/index.html delete mode 100644 docs/rules/no-void-expression/index.html delete mode 100644 docs/rules/object-literal-key-quotes/index.html delete mode 100644 docs/rules/object-literal-shorthand/index.html delete mode 100644 docs/rules/object-literal-sort-keys/index.html delete mode 100644 docs/rules/one-line/index.html delete mode 100644 docs/rules/one-variable-per-declaration/index.html delete mode 100644 docs/rules/only-arrow-functions/index.html delete mode 100644 docs/rules/ordered-imports/index.html delete mode 100644 docs/rules/prefer-arrow-shorthand-return/index.html delete mode 100644 docs/rules/prefer-const/index.html delete mode 100644 docs/rules/prefer-for-of/index.html delete mode 100644 docs/rules/prefer-method-signature/index.html delete mode 100644 docs/rules/promise-function-async/index.html delete mode 100644 docs/rules/quotemark/index.html delete mode 100644 docs/rules/radix/index.html delete mode 100644 docs/rules/restrict-plus-operands/index.html delete mode 100644 docs/rules/semicolon/index.html delete mode 100644 docs/rules/space-before-function-paren/index.html delete mode 100644 docs/rules/strict-boolean-expressions/index.html delete mode 100644 docs/rules/switch-default/index.html delete mode 100644 docs/rules/trailing-comma/index.html delete mode 100644 docs/rules/triple-equals/index.html delete mode 100644 docs/rules/typedef-whitespace/index.html delete mode 100644 docs/rules/typedef/index.html delete mode 100644 docs/rules/typeof-compare/index.html delete mode 100644 docs/rules/unified-signatures/index.html delete mode 100644 docs/rules/use-isnan/index.html delete mode 100644 docs/rules/variable-name/index.html delete mode 100644 docs/rules/whitespace/index.html diff --git a/.gitignore b/.gitignore index 66385e0bbbb..ec83b7c5002 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ typings/.basedir.ts *.swp docs/_data/rules.json +docs/rules/ diff --git a/docs/rules/adjacent-overload-signatures/index.html b/docs/rules/adjacent-overload-signatures/index.html deleted file mode 100644 index 3506700140c..00000000000 --- a/docs/rules/adjacent-overload-signatures/index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -ruleName: adjacent-overload-signatures -description: Enforces function overloads to be consecutive. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -rationale: Improves readability and organization by grouping naturally related items together. -type: typescript -typescriptOnly: true -layout: rule -title: 'Rule: adjacent-overload-signatures' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/align/index.html b/docs/rules/align/index.html deleted file mode 100644 index f42a1421e39..00000000000 --- a/docs/rules/align/index.html +++ /dev/null @@ -1,42 +0,0 @@ ---- -ruleName: align -description: Enforces vertical alignment. -rationale: 'Helps maintain a readable, consistent style in your codebase.' -optionsDescription: |- - - Three arguments may be optionally provided: - - * `"parameters"` checks alignment of function parameters. - * `"arguments"` checks alignment of function call arguments. - * `"statements"` checks alignment of statements. -options: - type: array - items: - type: string - enum: - - arguments - - parameters - - statements - minLength: 1 - maxLength: 3 -optionExamples: - - '[true, "parameters", "statements"]' -type: style -typescriptOnly: false -layout: rule -title: 'Rule: align' -optionsJSON: |- - { - "type": "array", - "items": { - "type": "string", - "enum": [ - "arguments", - "parameters", - "statements" - ] - }, - "minLength": 1, - "maxLength": 3 - } ---- \ No newline at end of file diff --git a/docs/rules/array-type/index.html b/docs/rules/array-type/index.html deleted file mode 100644 index 029dfaa19a4..00000000000 --- a/docs/rules/array-type/index.html +++ /dev/null @@ -1,35 +0,0 @@ ---- -ruleName: array-type -description: 'Requires using either ''T[]'' or ''Array'' for arrays.' -hasFix: true -optionsDescription: |- - - One of the following arguments must be provided: - - * `"array"` enforces use of `T[]` for all types T. - * `"generic"` enforces use of `Array` for all types T. - * `"array-simple"` enforces use of `T[]` if `T` is a simple type (primitive or type reference). -options: - type: string - enum: - - array - - generic - - array-simple -optionExamples: - - '[true, "array"]' - - '[true, "generic"]' - - '[true, "array-simple"]' -type: style -typescriptOnly: true -layout: rule -title: 'Rule: array-type' -optionsJSON: |- - { - "type": "string", - "enum": [ - "array", - "generic", - "array-simple" - ] - } ---- \ No newline at end of file diff --git a/docs/rules/arrow-parens/index.html b/docs/rules/arrow-parens/index.html deleted file mode 100644 index d6bec9d8a20..00000000000 --- a/docs/rules/arrow-parens/index.html +++ /dev/null @@ -1,28 +0,0 @@ ---- -ruleName: arrow-parens -description: Requires parentheses around the parameters of arrow function definitions. -hasFix: true -rationale: Maintains stylistic consistency with other arrow function definitions. -optionsDescription: |- - - If `ban-single-arg-parens` is specified, then arrow functions with one parameter - must not have parentheses if removing them is allowed by TypeScript. -options: - type: string - enum: - - ban-single-arg-parens -optionExamples: - - 'true' - - '[true, "ban-single-arg-parens"]' -type: style -typescriptOnly: false -layout: rule -title: 'Rule: arrow-parens' -optionsJSON: |- - { - "type": "string", - "enum": [ - "ban-single-arg-parens" - ] - } ---- \ No newline at end of file diff --git a/docs/rules/arrow-return-shorthand/index.html b/docs/rules/arrow-return-shorthand/index.html deleted file mode 100644 index 69ca43199ca..00000000000 --- a/docs/rules/arrow-return-shorthand/index.html +++ /dev/null @@ -1,26 +0,0 @@ ---- -ruleName: arrow-return-shorthand -description: 'Suggests to convert `() => { return x; }` to `() => x`.' -hasFix: true -optionsDescription: |- - - If `multiline` is specified, then this will warn even if the function spans multiple lines. -options: - type: string - enum: - - multiline -optionExamples: - - '[true]' - - '[true, "multiline"]' -type: style -typescriptOnly: false -layout: rule -title: 'Rule: arrow-return-shorthand' -optionsJSON: |- - { - "type": "string", - "enum": [ - "multiline" - ] - } ---- \ No newline at end of file diff --git a/docs/rules/ban/index.html b/docs/rules/ban/index.html deleted file mode 100644 index 8d301eea4dc..00000000000 --- a/docs/rules/ban/index.html +++ /dev/null @@ -1,36 +0,0 @@ ---- -ruleName: ban -description: Bans the use of specific functions or global methods. -optionsDescription: |- - - A list of `['object', 'method', 'optional explanation here']` or `['globalMethod']` which ban `object.method()` - or respectively `globalMethod()`. -options: - type: list - listType: - type: array - items: - type: string - minLength: 1 - maxLength: 3 -optionExamples: - - |- - [true, ["someGlobalMethod"], ["someObject", "someFunction"], - ["someObject", "otherFunction", "Optional explanation"]] -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: ban' -optionsJSON: |- - { - "type": "list", - "listType": { - "type": "array", - "items": { - "type": "string" - }, - "minLength": 1, - "maxLength": 3 - } - } ---- \ No newline at end of file diff --git a/docs/rules/callable-types/index.html b/docs/rules/callable-types/index.html deleted file mode 100644 index 4c65f626683..00000000000 --- a/docs/rules/callable-types/index.html +++ /dev/null @@ -1,12 +0,0 @@ ---- -ruleName: callable-types -description: An interface or literal type with just a call signature can be written as a function type. -rationale: style -optionsDescription: Not configurable. -options: null -type: style -typescriptOnly: true -layout: rule -title: 'Rule: callable-types' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/class-name/index.html b/docs/rules/class-name/index.html deleted file mode 100644 index 0ae19d6e8be..00000000000 --- a/docs/rules/class-name/index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -ruleName: class-name -description: Enforces PascalCased class and interface names. -rationale: Makes it easy to differentitate classes from regular variables at a glance. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: style -typescriptOnly: false -layout: rule -title: 'Rule: class-name' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/comment-format/index.html b/docs/rules/comment-format/index.html deleted file mode 100644 index 65450916bb9..00000000000 --- a/docs/rules/comment-format/index.html +++ /dev/null @@ -1,83 +0,0 @@ ---- -ruleName: comment-format -description: Enforces formatting rules for single-line comments. -rationale: 'Helps maintain a consistent, readable style in your codebase.' -optionsDescription: | - - Three arguments may be optionally provided: - - * `"check-space"` requires that all single-line comments must begin with a space, as in `// comment` - * note that comments starting with `///` are also allowed, for things such as `///` - * `"check-lowercase"` requires that the first non-whitespace character of a comment must be lowercase, if applicable. - * `"check-uppercase"` requires that the first non-whitespace character of a comment must be uppercase, if applicable. - - Exceptions to `"check-lowercase"` or `"check-uppercase"` can be managed with object that may be passed as last argument. - - One of two options can be provided in this object: - - * `"ignoreWords"` - array of strings - words that will be ignored at the beginning of the comment. - * `"ignorePattern"` - string - RegExp pattern that will be ignored at the beginning of the comment. -options: - type: array - items: - anyOf: - - type: string - enum: - - check-space - - check-lowercase - - check-uppercase - - type: object - properties: - ignoreWords: - type: array - items: - type: string - ignorePattern: - type: string - minProperties: 1 - maxProperties: 1 - minLength: 1 - maxLength: 4 -optionExamples: - - '[true, "check-space", "check-uppercase"]' - - '[true, "check-lowercase", {"ignoreWords": ["TODO", "HACK"]}]' - - '[true, "check-lowercase", {"ignorePattern": "STD\w{2,3}\b"}]' -type: style -typescriptOnly: false -layout: rule -title: 'Rule: comment-format' -optionsJSON: |- - { - "type": "array", - "items": { - "anyOf": [ - { - "type": "string", - "enum": [ - "check-space", - "check-lowercase", - "check-uppercase" - ] - }, - { - "type": "object", - "properties": { - "ignoreWords": { - "type": "array", - "items": { - "type": "string" - } - }, - "ignorePattern": { - "type": "string" - } - }, - "minProperties": 1, - "maxProperties": 1 - } - ] - }, - "minLength": 1, - "maxLength": 4 - } ---- \ No newline at end of file diff --git a/docs/rules/completed-docs/index.html b/docs/rules/completed-docs/index.html deleted file mode 100644 index 0ea545d71e5..00000000000 --- a/docs/rules/completed-docs/index.html +++ /dev/null @@ -1,38 +0,0 @@ ---- -ruleName: completed-docs -description: Enforces documentation for important items be filled out. -optionsDescription: |- - - Either `true` to enable for all, or any of - `["classes", "functions", "methods", "properties"] - to choose individual ones.` -options: - type: array - items: - type: string - enum: - - classes - - functions - - methods - - properties -optionExamples: - - 'true' - - '[true, "classes", "functions"]' -type: style -typescriptOnly: false -layout: rule -title: 'Rule: completed-docs' -optionsJSON: |- - { - "type": "array", - "items": { - "type": "string", - "enum": [ - "classes", - "functions", - "methods", - "properties" - ] - } - } ---- \ No newline at end of file diff --git a/docs/rules/curly/index.html b/docs/rules/curly/index.html deleted file mode 100644 index 5e9075da7fe..00000000000 --- a/docs/rules/curly/index.html +++ /dev/null @@ -1,24 +0,0 @@ ---- -ruleName: curly -description: Enforces braces for `if`/`for`/`do`/`while` statements. -rationale: |- - - ```ts - if (foo === bar) - foo++; - bar++; - ``` - - In the code above, the author almost certainly meant for both `foo++` and `bar++` - to be executed only if `foo === bar`. However, he forgot braces and `bar++` will be executed - no matter what. This rule could prevent such a mistake. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: curly' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/cyclomatic-complexity/index.html b/docs/rules/cyclomatic-complexity/index.html deleted file mode 100644 index 12ba0162133..00000000000 --- a/docs/rules/cyclomatic-complexity/index.html +++ /dev/null @@ -1,39 +0,0 @@ ---- -ruleName: cyclomatic-complexity -description: Enforces a threshold of cyclomatic complexity. -descriptionDetails: |- - - Cyclomatic complexity is assessed for each function of any type. A starting value of 20 - is assigned and this value is then incremented for every statement which can branch the - control flow within the function. The following statements and expressions contribute - to cyclomatic complexity: - * `catch` - * `if` and `? :` - * `||` and `&&` due to short-circuit evaluation - * `for`, `for in` and `for of` loops - * `while` and `do while` loops -rationale: |- - - Cyclomatic complexity is a code metric which indicates the level of complexity in a - function. High cyclomatic complexity indicates confusing code which may be prone to - errors or difficult to modify. -optionsDescription: |- - - An optional upper limit for cyclomatic complexity can be specified. If no limit option - is provided a default value of $(Rule.DEFAULT_THRESHOLD) will be used. -options: - type: number - minimum: $(Rule.MINIMUM_THRESHOLD) -optionExamples: - - 'true' - - '[true, 20]' -type: maintainability -typescriptOnly: false -layout: rule -title: 'Rule: cyclomatic-complexity' -optionsJSON: |- - { - "type": "number", - "minimum": "$(Rule.MINIMUM_THRESHOLD)" - } ---- \ No newline at end of file diff --git a/docs/rules/eofline/index.html b/docs/rules/eofline/index.html deleted file mode 100644 index 985298840d8..00000000000 --- a/docs/rules/eofline/index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -ruleName: eofline -description: Ensures the file ends with a newline. -rationale: 'It is a [standard convention](http://stackoverflow.com/q/729692/3124288) to end files with a newline.' -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: maintainability -typescriptOnly: false -layout: rule -title: 'Rule: eofline' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/file-header/index.html b/docs/rules/file-header/index.html deleted file mode 100644 index 7cc981b6bb8..00000000000 --- a/docs/rules/file-header/index.html +++ /dev/null @@ -1,17 +0,0 @@ ---- -ruleName: file-header -description: 'Enforces a certain header comment for all files, matched by a regular expression.' -optionsDescription: Regular expression to match the header. -options: - type: string -optionExamples: - - '[true, "Copyright \\d{4}"]' -type: style -typescriptOnly: false -layout: rule -title: 'Rule: file-header' -optionsJSON: |- - { - "type": "string" - } ---- \ No newline at end of file diff --git a/docs/rules/forin/index.html b/docs/rules/forin/index.html deleted file mode 100644 index e41a69c1068..00000000000 --- a/docs/rules/forin/index.html +++ /dev/null @@ -1,25 +0,0 @@ ---- -ruleName: forin -description: Requires a `for ... in` statement to be filtered with an `if` statement. -rationale: |- - - ```ts - for (let key in someObject) { - if (someObject.hasOwnProperty(key)) { - // code here - } - } - ``` - Prevents accidental interation over properties inherited from an object's prototype. - See [MDN's `for...in`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in) - documentation for more information about `for...in` loops. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: forin' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/import-blacklist/index.html b/docs/rules/import-blacklist/index.html deleted file mode 100644 index 41ec9639819..00000000000 --- a/docs/rules/import-blacklist/index.html +++ /dev/null @@ -1,32 +0,0 @@ ---- -ruleName: import-blacklist -description: |- - - Disallows importing the specified modules directly via `import` and `require`. - Instead only sub modules may be imported from that module. -rationale: |- - - Some libraries allow importing their submodules instead of the entire module. - This is good practise as it avoids loading unused modules. -optionsDescription: A list of blacklisted modules. -options: - type: array - items: - type: string - minLength: 1 -optionExamples: - - 'true' - - '[true, "rxjs", "lodash"]' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: import-blacklist' -optionsJSON: |- - { - "type": "array", - "items": { - "type": "string" - }, - "minLength": 1 - } ---- \ No newline at end of file diff --git a/docs/rules/import-spacing/index.html b/docs/rules/import-spacing/index.html deleted file mode 100644 index a95c212b9c2..00000000000 --- a/docs/rules/import-spacing/index.html +++ /dev/null @@ -1,13 +0,0 @@ ---- -ruleName: import-spacing -description: Ensures proper spacing between import statement keywords -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: style -typescriptOnly: false -layout: rule -title: 'Rule: import-spacing' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/indent/index.html b/docs/rules/indent/index.html deleted file mode 100644 index 28d55c314b5..00000000000 --- a/docs/rules/indent/index.html +++ /dev/null @@ -1,33 +0,0 @@ ---- -ruleName: indent -description: Enforces indentation with tabs or spaces. -rationale: |- - - Using only one of tabs or spaces for indentation leads to more consistent editor behavior, - cleaner diffs in version control, and easier programatic manipulation. -optionsDescription: |- - - One of the following arguments must be provided: - - * `"spaces"` enforces consistent spaces. - * `"tabs"` enforces consistent tabs. -options: - type: string - enum: - - tabs - - spaces -optionExamples: - - '[true, "spaces"]' -type: maintainability -typescriptOnly: false -layout: rule -title: 'Rule: indent' -optionsJSON: |- - { - "type": "string", - "enum": [ - "tabs", - "spaces" - ] - } ---- \ No newline at end of file diff --git a/docs/rules/index.html b/docs/rules/index.html deleted file mode 100644 index 537271b7ba2..00000000000 --- a/docs/rules/index.html +++ /dev/null @@ -1,22 +0,0 @@ ---- -layout: page -title: Rules -permalink: /rules/ -menu: main -order: 2 ---- -

TypeScript Specific

-

These rules find errors related to TypeScript features:

-{% include rule_list.html ruleType="typescript" %} - -

Functionality

-

These rules catch common errors in JS programming or otherwise confusing constructs that are prone to producing bugs:

-{% include rule_list.html ruleType="functionality" %} - -

Maintainability

-

These rules make code maintenance easier:

-{% include rule_list.html ruleType="maintainability" %} - -

Style

-

These rules enforce consistent style across your codebase:

-{% include rule_list.html ruleType="style" %} diff --git a/docs/rules/interface-name/index.html b/docs/rules/interface-name/index.html deleted file mode 100644 index 91375f2a0ec..00000000000 --- a/docs/rules/interface-name/index.html +++ /dev/null @@ -1,31 +0,0 @@ ---- -ruleName: interface-name -description: Requires interface names to begin with a capital 'I' -rationale: Makes it easy to differentitate interfaces from regular classes at a glance. -optionsDescription: |- - - One of the following two options must be provided: - - * `"always-prefix"` requires interface names to start with an "I" - * `"never-prefix"` requires interface names to not have an "I" prefix -options: - type: string - enum: - - always-prefix - - never-prefix -optionExamples: - - '[true, "always-prefix"]' - - '[true, "never-prefix"]' -type: style -typescriptOnly: true -layout: rule -title: 'Rule: interface-name' -optionsJSON: |- - { - "type": "string", - "enum": [ - "always-prefix", - "never-prefix" - ] - } ---- \ No newline at end of file diff --git a/docs/rules/interface-over-type-literal/index.html b/docs/rules/interface-over-type-literal/index.html deleted file mode 100644 index 3f89916e141..00000000000 --- a/docs/rules/interface-over-type-literal/index.html +++ /dev/null @@ -1,12 +0,0 @@ ---- -ruleName: interface-over-type-literal -description: 'Prefer an interface declaration over a type literal (`type T = { ... }`)' -rationale: style -optionsDescription: Not configurable. -options: null -type: style -typescriptOnly: true -layout: rule -title: 'Rule: interface-over-type-literal' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/jsdoc-format/index.html b/docs/rules/jsdoc-format/index.html deleted file mode 100644 index 269ceab1b0a..00000000000 --- a/docs/rules/jsdoc-format/index.html +++ /dev/null @@ -1,22 +0,0 @@ ---- -ruleName: jsdoc-format -description: Enforces basic format rules for JSDoc comments. -descriptionDetails: |- - - The following rules are enforced for JSDoc comments (comments starting with `/**`): - - * each line contains an asterisk and asterisks must be aligned - * each asterisk must be followed by either a space or a newline (except for the first and the last) - * the only characters before the asterisk on each line must be whitespace characters - * one line comments must start with `/** ` and end with `*/` -rationale: 'Helps maintain a consistent, readable style for JSDoc comments.' -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: style -typescriptOnly: false -layout: rule -title: 'Rule: jsdoc-format' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/label-position/index.html b/docs/rules/label-position/index.html deleted file mode 100644 index d82ae64eab8..00000000000 --- a/docs/rules/label-position/index.html +++ /dev/null @@ -1,19 +0,0 @@ ---- -ruleName: label-position -description: Only allows labels in sensible locations. -descriptionDetails: This rule only allows labels to be on `do/for/while/switch` statements. -rationale: |- - - Labels in JavaScript only can be used in conjunction with `break` or `continue`, - constructs meant to be used for loop flow control. While you can theoretically use - labels on any block statement in JS, it is considered poor code structure to do so. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: label-position' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/linebreak-style/index.html b/docs/rules/linebreak-style/index.html deleted file mode 100644 index 363c990858e..00000000000 --- a/docs/rules/linebreak-style/index.html +++ /dev/null @@ -1,30 +0,0 @@ ---- -ruleName: linebreak-style -description: Enforces a consistent linebreak style. -optionsDescription: |- - - One of the following options must be provided: - - * `"LF"` requires LF (`\n`) linebreaks - * `"CRLF"` requires CRLF (`\r\n`) linebreaks -options: - type: string - enum: - - LF - - CRLF -optionExamples: - - '[true, "LF"]' - - '[true, "CRLF"]' -type: maintainability -typescriptOnly: false -layout: rule -title: 'Rule: linebreak-style' -optionsJSON: |- - { - "type": "string", - "enum": [ - "LF", - "CRLF" - ] - } ---- \ No newline at end of file diff --git a/docs/rules/max-classes-per-file/index.html b/docs/rules/max-classes-per-file/index.html deleted file mode 100644 index 985d4d6824a..00000000000 --- a/docs/rules/max-classes-per-file/index.html +++ /dev/null @@ -1,40 +0,0 @@ ---- -ruleName: max-classes-per-file -description: |- - - A file may not contain more than the specified number of classes -rationale: |- - - Ensures that files have a single responsibility so that that classes each exist in their own files -optionsDescription: |- - - The one required argument is an integer indicating the maximum number of classes that can appear in a file. -options: - type: array - items: - - type: number - minimum: 1 - additionalItems: false - minLength: 1 - maxLength: 2 -optionExamples: - - '[true, 1]' - - '[true, 5]' -type: maintainability -typescriptOnly: false -layout: rule -title: 'Rule: max-classes-per-file' -optionsJSON: |- - { - "type": "array", - "items": [ - { - "type": "number", - "minimum": 1 - } - ], - "additionalItems": false, - "minLength": 1, - "maxLength": 2 - } ---- \ No newline at end of file diff --git a/docs/rules/max-file-line-count/index.html b/docs/rules/max-file-line-count/index.html deleted file mode 100644 index 88556799827..00000000000 --- a/docs/rules/max-file-line-count/index.html +++ /dev/null @@ -1,23 +0,0 @@ ---- -ruleName: max-file-line-count -description: Requires files to remain under a certain number of lines -rationale: |- - - Limiting the number of lines allowed in a file allows files to remain small, - single purpose, and maintainable. -optionsDescription: An integer indicating the maximum number of lines. -options: - type: number - minimum: '1' -optionExamples: - - '[true, 300]' -type: maintainability -typescriptOnly: false -layout: rule -title: 'Rule: max-file-line-count' -optionsJSON: |- - { - "type": "number", - "minimum": "1" - } ---- \ No newline at end of file diff --git a/docs/rules/max-line-length/index.html b/docs/rules/max-line-length/index.html deleted file mode 100644 index fdd451fce6a..00000000000 --- a/docs/rules/max-line-length/index.html +++ /dev/null @@ -1,24 +0,0 @@ ---- -ruleName: max-line-length -description: Requires lines to be under a certain max length. -rationale: |- - - Limiting the length of a line of code improves code readability. - It also makes comparing code side-by-side easier and improves compatibility with - various editors, IDEs, and diff viewers. -optionsDescription: An integer indicating the max length of lines. -options: - type: number - minimum: '1' -optionExamples: - - '[true, 120]' -type: maintainability -typescriptOnly: false -layout: rule -title: 'Rule: max-line-length' -optionsJSON: |- - { - "type": "number", - "minimum": "1" - } ---- \ No newline at end of file diff --git a/docs/rules/member-access/index.html b/docs/rules/member-access/index.html deleted file mode 100644 index ae5c4991013..00000000000 --- a/docs/rules/member-access/index.html +++ /dev/null @@ -1,40 +0,0 @@ ---- -ruleName: member-access -description: Requires explicit visibility declarations for class members. -rationale: Explicit visibility declarations can make code more readable and accessible for those new to TS. -optionsDescription: |- - - Two arguments may be optionally provided: - - * `"check-accessor"` enforces explicit visibility on get/set accessors (can only be public) - * `"check-constructor"` enforces explicit visibility on constructors (can only be public) -options: - type: array - items: - type: string - enum: - - check-accessor - - check-constructor - minLength: 0 - maxLength: 2 -optionExamples: - - 'true' - - '[true, "check-accessor"]' -type: typescript -typescriptOnly: true -layout: rule -title: 'Rule: member-access' -optionsJSON: |- - { - "type": "array", - "items": { - "type": "string", - "enum": [ - "check-accessor", - "check-constructor" - ] - }, - "minLength": 0, - "maxLength": 2 - } ---- \ No newline at end of file diff --git a/docs/rules/member-ordering/index.html b/docs/rules/member-ordering/index.html deleted file mode 100644 index 295ced8cb52..00000000000 --- a/docs/rules/member-ordering/index.html +++ /dev/null @@ -1,107 +0,0 @@ ---- -ruleName: member-ordering -description: Enforces member ordering. -rationale: 'A consistent ordering for class members can make classes easier to read, navigate, and edit.' -optionsDescription: |- - - One argument, which is an object, must be provided. It should contain an `order` property. - The `order` property should have a value of one of the following strings: - - * `fields-first` - * `statics-first` - * `instance-sandwich` - - Alternatively, the value for `order` maybe be an array consisting of the following strings: - - * `public-static-field` - * `protected-static-field` - * `private-static-field` - * `public-instance-field` - * `protected-instance-field` - * `private-instance-field` - * `constructor` - * `public-static-method` - * `protected-static-method` - * `private-static-method` - * `public-instance-method` - * `protected-instance-method` - * `private-instance-method` - - This is useful if one of the preset orders does not meet your needs. -options: - type: object - properties: - order: - oneOf: - - type: string - enum: - - fields-first - - statics-first - - instance-sandwich - - type: array - items: - type: string - enum: - - public-static-field - - public-static-method - - protected-static-field - - protected-static-method - - private-static-field - - private-static-method - - public-instance-field - - protected-instance-field - - private-instance-field - - constructor - - public-instance-method - - protected-instance-method - - private-instance-method - maxLength: 13 - additionalProperties: false -optionExamples: - - '[true, { "order": "fields-first" }]' -type: typescript -typescriptOnly: true -layout: rule -title: 'Rule: member-ordering' -optionsJSON: |- - { - "type": "object", - "properties": { - "order": { - "oneOf": [ - { - "type": "string", - "enum": [ - "fields-first", - "statics-first", - "instance-sandwich" - ] - }, - { - "type": "array", - "items": { - "type": "string", - "enum": [ - "public-static-field", - "public-static-method", - "protected-static-field", - "protected-static-method", - "private-static-field", - "private-static-method", - "public-instance-field", - "protected-instance-field", - "private-instance-field", - "constructor", - "public-instance-method", - "protected-instance-method", - "private-instance-method" - ] - }, - "maxLength": 13 - } - ] - } - }, - "additionalProperties": false - } ---- \ No newline at end of file diff --git a/docs/rules/new-parens/index.html b/docs/rules/new-parens/index.html deleted file mode 100644 index 58aa3916f69..00000000000 --- a/docs/rules/new-parens/index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -ruleName: new-parens -description: Requires parentheses when invoking a constructor via the `new` keyword. -rationale: Maintains stylistic consistency with other function calls. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: style -typescriptOnly: false -layout: rule -title: 'Rule: new-parens' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-angle-bracket-type-assertion/index.html b/docs/rules/no-angle-bracket-type-assertion/index.html deleted file mode 100644 index bb441ed52bd..00000000000 --- a/docs/rules/no-angle-bracket-type-assertion/index.html +++ /dev/null @@ -1,19 +0,0 @@ ---- -ruleName: no-angle-bracket-type-assertion -description: Requires the use of `as Type` for type assertions instead of ``. -hasFix: true -rationale: |- - - Both formats of type assertions have the same effect, but only `as` type assertions - work in `.tsx` files. This rule ensures that you have a consistent type assertion style - across your codebase. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: style -typescriptOnly: true -layout: rule -title: 'Rule: no-angle-bracket-type-assertion' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-any/index.html b/docs/rules/no-any/index.html deleted file mode 100644 index 9e96a7e560a..00000000000 --- a/docs/rules/no-any/index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -ruleName: no-any -description: Diallows usages of `any` as a type declaration. -rationale: Using `any` as a type declaration nullifies the compile-time benefits of the type system. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: typescript -typescriptOnly: true -layout: rule -title: 'Rule: no-any' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-arg/index.html b/docs/rules/no-arg/index.html deleted file mode 100644 index a49b3401ff5..00000000000 --- a/docs/rules/no-arg/index.html +++ /dev/null @@ -1,18 +0,0 @@ ---- -ruleName: no-arg -description: Disallows use of `arguments.callee`. -rationale: |- - - Using `arguments.callee` makes various performance optimizations impossible. - See [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments/callee) - for more details on why to avoid `arguments.callee`. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: no-arg' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-bitwise/index.html b/docs/rules/no-bitwise/index.html deleted file mode 100644 index 9c83ca93d89..00000000000 --- a/docs/rules/no-bitwise/index.html +++ /dev/null @@ -1,24 +0,0 @@ ---- -ruleName: no-bitwise -description: Disallows bitwise operators. -descriptionDetails: |- - - Specifically, the following bitwise operators are banned: - `&`, `&=`, `|`, `|=`, - `^`, `^=`, `<<`, `<<=`, - `>>`, `>>=`, `>>>`, `>>>=`, and `~`. - This rule does not ban the use of `&` and `|` for intersection and union types. -rationale: |- - - Bitwise operators are often typos - for example `bool1 & bool2` instead of `bool1 && bool2`. - They also can be an indicator of overly clever code which decreases maintainability. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: no-bitwise' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-boolean-compare/index.html b/docs/rules/no-boolean-compare/index.html deleted file mode 100644 index 1c1a89423b2..00000000000 --- a/docs/rules/no-boolean-compare/index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -ruleName: no-boolean-compare -description: 'Warns on comparison to a boolean literal, as in `x === true`.' -hasFix: true -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: style -typescriptOnly: true -layout: rule -title: 'Rule: no-boolean-compare' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-boolean-literal-compare/index.html b/docs/rules/no-boolean-literal-compare/index.html deleted file mode 100644 index 74860ef768f..00000000000 --- a/docs/rules/no-boolean-literal-compare/index.html +++ /dev/null @@ -1,15 +0,0 @@ ---- -ruleName: no-boolean-literal-compare -description: 'Warns on comparison to a boolean literal, as in `x === true`.' -hasFix: true -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: style -typescriptOnly: true -requiresTypeInfo: true -layout: rule -title: 'Rule: no-boolean-literal-compare' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-conditional-assignment/index.html b/docs/rules/no-conditional-assignment/index.html deleted file mode 100644 index b7bdc4041ef..00000000000 --- a/docs/rules/no-conditional-assignment/index.html +++ /dev/null @@ -1,19 +0,0 @@ ---- -ruleName: no-conditional-assignment -description: Disallows any type of assignment in conditionals. -descriptionDetails: 'This applies to `do-while`, `for`, `if`, and `while` statements.' -rationale: |- - - Assignments in conditionals are often typos: - for example `if (var1 = var2)` instead of `if (var1 == var2)`. - They also can be an indicator of overly clever code which decreases maintainability. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: no-conditional-assignment' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-consecutive-blank-lines/index.html b/docs/rules/no-consecutive-blank-lines/index.html deleted file mode 100644 index 180294b281f..00000000000 --- a/docs/rules/no-consecutive-blank-lines/index.html +++ /dev/null @@ -1,24 +0,0 @@ ---- -ruleName: no-consecutive-blank-lines -description: Disallows one or more blank lines in a row. -rationale: Helps maintain a readable style in your codebase. -optionsDescription: |- - - An optional number of maximum allowed sequential blanks can be specified. If no value - is provided, a default of $(Rule.DEFAULT_ALLOWED_BLANKS) will be used. -options: - type: number - minimum: $(Rule.MINIMUM_ALLOWED_BLANKS) -optionExamples: - - 'true' - - '[true, 2]' -type: style -typescriptOnly: false -layout: rule -title: 'Rule: no-consecutive-blank-lines' -optionsJSON: |- - { - "type": "number", - "minimum": "$(Rule.MINIMUM_ALLOWED_BLANKS)" - } ---- \ No newline at end of file diff --git a/docs/rules/no-console/index.html b/docs/rules/no-console/index.html deleted file mode 100644 index 3a04d5c29f2..00000000000 --- a/docs/rules/no-console/index.html +++ /dev/null @@ -1,23 +0,0 @@ ---- -ruleName: no-console -description: Bans the use of specified `console` methods. -rationale: 'In general, `console` methods aren''t appropriate for production code.' -optionsDescription: A list of method names to ban. -options: - type: array - items: - type: string -optionExamples: - - '[true, "log", "error"]' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: no-console' -optionsJSON: |- - { - "type": "array", - "items": { - "type": "string" - } - } ---- \ No newline at end of file diff --git a/docs/rules/no-construct/index.html b/docs/rules/no-construct/index.html deleted file mode 100644 index d7f937db798..00000000000 --- a/docs/rules/no-construct/index.html +++ /dev/null @@ -1,19 +0,0 @@ ---- -ruleName: no-construct -description: 'Disallows access to the constructors of `String`, `Number`, and `Boolean`.' -descriptionDetails: Disallows constructor use such as `new Number(foo)` but does not disallow `Number(foo)`. -rationale: |- - - There is little reason to use `String`, `Number`, or `Boolean` as constructors. - In almost all cases, the regular function-call version is more appropriate. - [More details](http://stackoverflow.com/q/4719320/3124288) are available on StackOverflow. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: no-construct' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-debugger/index.html b/docs/rules/no-debugger/index.html deleted file mode 100644 index a3133012e5f..00000000000 --- a/docs/rules/no-debugger/index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -ruleName: no-debugger -description: Disallows `debugger` statements. -rationale: 'In general, `debugger` statements aren''t appropriate for production code.' -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: no-debugger' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-default-export/index.html b/docs/rules/no-default-export/index.html deleted file mode 100644 index 8e7a279a2a7..00000000000 --- a/docs/rules/no-default-export/index.html +++ /dev/null @@ -1,19 +0,0 @@ ---- -ruleName: no-default-export -description: Disallows default exports in ES6-style modules. -descriptionDetails: Use named exports instead. -rationale: |- - - Named imports/exports [promote clarity](https://github.com/palantir/tslint/issues/1182#issue-151780453). - In addition, current tooling differs on the correct way to handle default imports/exports. - Avoiding them all together can help avoid tooling bugs and conflicts. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: maintainability -typescriptOnly: false -layout: rule -title: 'Rule: no-default-export' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-duplicate-variable/index.html b/docs/rules/no-duplicate-variable/index.html deleted file mode 100644 index 3dee824d2ce..00000000000 --- a/docs/rules/no-duplicate-variable/index.html +++ /dev/null @@ -1,21 +0,0 @@ ---- -ruleName: no-duplicate-variable -description: Disallows duplicate variable declarations in the same block scope. -descriptionDetails: |- - - This rule is only useful when using the `var` keyword - - the compiler will detect redeclarations of `let` and `const` variables. -rationale: |- - - A variable can be reassigned if necessary - - there's no good reason to have a duplicate variable declaration. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: no-duplicate-variable' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-empty-interface/index.html b/docs/rules/no-empty-interface/index.html deleted file mode 100644 index cd2fcfec4f6..00000000000 --- a/docs/rules/no-empty-interface/index.html +++ /dev/null @@ -1,12 +0,0 @@ ---- -ruleName: no-empty-interface -description: Forbids empty interfaces. -rationale: 'An empty interface is equivalent to its supertype (or `{}`).' -optionsDescription: Not configurable. -options: null -type: typescript -typescriptOnly: true -layout: rule -title: 'Rule: no-empty-interface' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-empty/index.html b/docs/rules/no-empty/index.html deleted file mode 100644 index 5fe4cc64ff0..00000000000 --- a/docs/rules/no-empty/index.html +++ /dev/null @@ -1,15 +0,0 @@ ---- -ruleName: no-empty -description: Disallows empty blocks. -descriptionDetails: Blocks with a comment inside are not considered empty. -rationale: Empty blocks are often indicators of missing code. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: no-empty' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-eval/index.html b/docs/rules/no-eval/index.html deleted file mode 100644 index 63f08fba017..00000000000 --- a/docs/rules/no-eval/index.html +++ /dev/null @@ -1,18 +0,0 @@ ---- -ruleName: no-eval -description: Disallows `eval` function invocations. -rationale: |- - - `eval()` is dangerous as it allows arbitrary code execution with full privileges. There are - [alternatives](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) - for most of the use cases for `eval()`. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: no-eval' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-for-in-array/index.html b/docs/rules/no-for-in-array/index.html deleted file mode 100644 index 781e895234f..00000000000 --- a/docs/rules/no-for-in-array/index.html +++ /dev/null @@ -1,28 +0,0 @@ ---- -ruleName: no-for-in-array -description: Disallows iterating over an array with a for-in loop. -descriptionDetails: | - - A for-in loop (`for (var k in o)`) iterates over the properties of an Object. - - While it is legal to use for-in loops with array types, it is not common. - for-in will iterate over the indices of the array as strings, omitting any "holes" in - the array. - - More common is to use for-of, which iterates over the values of an array. - If you want to iterate over the indices, alternatives include: - - array.forEach((value, index) => { ... }); - for (const [index, value] of array.entries()) { ... } - for (let i = 0; i < array.length; i++) { ... } -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -requiresTypeInfo: true -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: no-for-in-array' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-inferrable-types/index.html b/docs/rules/no-inferrable-types/index.html deleted file mode 100644 index 4518dc603e5..00000000000 --- a/docs/rules/no-inferrable-types/index.html +++ /dev/null @@ -1,38 +0,0 @@ ---- -ruleName: no-inferrable-types -description: 'Disallows explicit type declarations for variables or parameters initialized to a number, string, or boolean.' -rationale: Explicit types where they can be easily infered by the compiler make code more verbose. -optionsDescription: |- - - One argument may be optionally provided: - - * `ignore-params` allows specifying an inferrable type annotation for function params. - This can be useful when combining with the `typedef` rule. -options: - type: array - items: - type: string - enum: - - ignore-params - minLength: 0 - maxLength: 1 -optionExamples: - - 'true' - - '[true, "ignore-params"]' -type: typescript -typescriptOnly: true -layout: rule -title: 'Rule: no-inferrable-types' -optionsJSON: |- - { - "type": "array", - "items": { - "type": "string", - "enum": [ - "ignore-params" - ] - }, - "minLength": 0, - "maxLength": 1 - } ---- \ No newline at end of file diff --git a/docs/rules/no-inferred-empty-object-type/index.html b/docs/rules/no-inferred-empty-object-type/index.html deleted file mode 100644 index aa2a9c3f558..00000000000 --- a/docs/rules/no-inferred-empty-object-type/index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -ruleName: no-inferred-empty-object-type -description: 'Disallow type inference of {} (empty object type) at function and constructor call sites' -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: true -requiresTypeInfo: true -layout: rule -title: 'Rule: no-inferred-empty-object-type' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-interface-constructor/index.html b/docs/rules/no-interface-constructor/index.html deleted file mode 100644 index b2f5778f784..00000000000 --- a/docs/rules/no-interface-constructor/index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -ruleName: no-interface-constructor -description: Warns on apparent attempts to define constructors for interfaces. -rationale: '`interface I { new(): I }` declares a type where for `x: I`, `new x()` is also of type `I`.' -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: true -layout: rule -title: 'Rule: no-interface-constructor' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-internal-module/index.html b/docs/rules/no-internal-module/index.html deleted file mode 100644 index 5092d8ef529..00000000000 --- a/docs/rules/no-internal-module/index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -ruleName: no-internal-module -description: Disallows internal `module` -rationale: Using `module` leads to a confusion of concepts with external modules. Use the newer `namespace` keyword instead. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: typescript -typescriptOnly: true -layout: rule -title: 'Rule: no-internal-module' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-invalid-this/index.html b/docs/rules/no-invalid-this/index.html deleted file mode 100644 index fb2d3d34ed2..00000000000 --- a/docs/rules/no-invalid-this/index.html +++ /dev/null @@ -1,37 +0,0 @@ ---- -ruleName: no-invalid-this -description: Disallows using the `this` keyword outside of classes. -rationale: 'See [the rule''s author''s rationale here.](https://github.com/palantir/tslint/pull/1105#issue-147549402)' -optionsDescription: |- - - One argument may be optionally provided: - - * `check-function-in-method` disallows using the `this` keyword in functions within class methods. -options: - type: array - items: - type: string - enum: - - check-function-in-method - minLength: 0 - maxLength: 1 -optionExamples: - - 'true' - - '[true, "check-function-in-method"]' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: no-invalid-this' -optionsJSON: |- - { - "type": "array", - "items": { - "type": "string", - "enum": [ - "check-function-in-method" - ] - }, - "minLength": 0, - "maxLength": 1 - } ---- \ No newline at end of file diff --git a/docs/rules/no-magic-numbers/index.html b/docs/rules/no-magic-numbers/index.html deleted file mode 100644 index 3ebe8bc3ed0..00000000000 --- a/docs/rules/no-magic-numbers/index.html +++ /dev/null @@ -1,32 +0,0 @@ ---- -ruleName: no-magic-numbers -description: |- - - Disallows the use constant number values outside of variable assignments. - When no list of allowed values is specified, -1, 0 and 1 are allowed by default. -rationale: |- - - Magic numbers should be avoided as they often lack documentation, forcing - them to be stored in variables gives them implicit documentation. -optionsDescription: A list of allowed numbers. -options: - type: array - items: - type: number - minLength: 1 -optionExamples: - - 'true' - - '[true, 1, 2, 3]' -type: typescript -typescriptOnly: false -layout: rule -title: 'Rule: no-magic-numbers' -optionsJSON: |- - { - "type": "array", - "items": { - "type": "number" - }, - "minLength": 1 - } ---- \ No newline at end of file diff --git a/docs/rules/no-mergeable-namespace/index.html b/docs/rules/no-mergeable-namespace/index.html deleted file mode 100644 index ca24c662893..00000000000 --- a/docs/rules/no-mergeable-namespace/index.html +++ /dev/null @@ -1,13 +0,0 @@ ---- -ruleName: no-mergeable-namespace -description: Disallows mergeable namespaces in the same file. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: maintainability -typescriptOnly: true -layout: rule -title: 'Rule: no-mergeable-namespace' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-misused-new/index.html b/docs/rules/no-misused-new/index.html deleted file mode 100644 index 771e8ed5754..00000000000 --- a/docs/rules/no-misused-new/index.html +++ /dev/null @@ -1,13 +0,0 @@ ---- -ruleName: no-misused-new -description: Warns on apparent attempts to define constructors for interfaces or `new` for classes. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: true -layout: rule -title: 'Rule: no-misused-new' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-namespace/index.html b/docs/rules/no-namespace/index.html deleted file mode 100644 index d29ecbf5262..00000000000 --- a/docs/rules/no-namespace/index.html +++ /dev/null @@ -1,41 +0,0 @@ ---- -ruleName: no-namespace -description: Disallows use of internal `module`s and `namespace`s. -descriptionDetails: 'This rule still allows the use of `declare module ... {}`' -rationale: |- - - ES6-style external modules are the standard way to modularize code. - Using `module {}` and `namespace {}` are outdated ways to organize TypeScript code. -optionsDescription: |- - - One argument may be optionally provided: - - * `allow-declarations` allows `declare namespace ... {}` to describe external APIs. -options: - type: array - items: - type: string - enum: - - allow-declarations - minLength: 0 - maxLength: 1 -optionExamples: - - 'true' - - '[true, "allow-declarations"]' -type: typescript -typescriptOnly: true -layout: rule -title: 'Rule: no-namespace' -optionsJSON: |- - { - "type": "array", - "items": { - "type": "string", - "enum": [ - "allow-declarations" - ] - }, - "minLength": 0, - "maxLength": 1 - } ---- \ No newline at end of file diff --git a/docs/rules/no-null-keyword/index.html b/docs/rules/no-null-keyword/index.html deleted file mode 100644 index c4c46d69f8d..00000000000 --- a/docs/rules/no-null-keyword/index.html +++ /dev/null @@ -1,17 +0,0 @@ ---- -ruleName: no-null-keyword -description: Disallows use of the `null` keyword literal. -rationale: |- - - Instead of having the dual concepts of `null` and`undefined` in a codebase, - this rule ensures that only `undefined` is used. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: no-null-keyword' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-parameter-properties/index.html b/docs/rules/no-parameter-properties/index.html deleted file mode 100644 index bac7fbb8f6e..00000000000 --- a/docs/rules/no-parameter-properties/index.html +++ /dev/null @@ -1,17 +0,0 @@ ---- -ruleName: no-parameter-properties -description: Disallows parameter properties in class constructors. -rationale: |- - - Parameter properties can be confusing to those new to TS as they are less explicit - than other ways of declaring and initializing class members. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: style -typescriptOnly: true -layout: rule -title: 'Rule: no-parameter-properties' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-reference/index.html b/docs/rules/no-reference/index.html deleted file mode 100644 index 85ff055965e..00000000000 --- a/docs/rules/no-reference/index.html +++ /dev/null @@ -1,17 +0,0 @@ ---- -ruleName: no-reference -description: Disallows `/// ` imports (use ES6-style imports instead). -rationale: |- - - Using `/// ` comments to load other files is outdated. - Use ES6-style imports to reference other files. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: typescript -typescriptOnly: false -layout: rule -title: 'Rule: no-reference' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-require-imports/index.html b/docs/rules/no-require-imports/index.html deleted file mode 100644 index 0791ef11775..00000000000 --- a/docs/rules/no-require-imports/index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -ruleName: no-require-imports -description: Disallows invocation of `require()`. -rationale: Prefer the newer ES6-style imports over `require()`. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: maintainability -typescriptOnly: false -layout: rule -title: 'Rule: no-require-imports' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-shadowed-variable/index.html b/docs/rules/no-shadowed-variable/index.html deleted file mode 100644 index c9b41de6420..00000000000 --- a/docs/rules/no-shadowed-variable/index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -ruleName: no-shadowed-variable -description: Disallows shadowing variable declarations. -rationale: Shadowing a variable masks access to it and obscures to what value an identifier actually refers. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: no-shadowed-variable' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-string-literal/index.html b/docs/rules/no-string-literal/index.html deleted file mode 100644 index c4472e65b53..00000000000 --- a/docs/rules/no-string-literal/index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -ruleName: no-string-literal -description: Disallows object access via string literals. -rationale: Encourages using strongly-typed property access. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: no-string-literal' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-string-throw/index.html b/docs/rules/no-string-throw/index.html deleted file mode 100644 index de7259b8141..00000000000 --- a/docs/rules/no-string-throw/index.html +++ /dev/null @@ -1,12 +0,0 @@ ---- -ruleName: no-string-throw -description: Flags throwing plain strings or concatenations of strings because only Errors produce proper stack traces. -hasFix: true -options: null -optionsDescription: Not configurable. -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: no-string-throw' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-switch-case-fall-through/index.html b/docs/rules/no-switch-case-fall-through/index.html deleted file mode 100644 index e6ff8459f6d..00000000000 --- a/docs/rules/no-switch-case-fall-through/index.html +++ /dev/null @@ -1,40 +0,0 @@ ---- -ruleName: no-switch-case-fall-through -description: Disallows falling through case statements. -descriptionDetails: |- - - For example, the following is not allowed: - - ```ts - switch(foo) { - case 1: - someFunc(foo); - case 2: - someOtherFunc(foo); - } - ``` - - However, fall through is allowed when case statements are consecutive or - a magic `/* falls through */` comment is present. The following is valid: - - ```ts - switch(foo) { - case 1: - someFunc(foo); - /* falls through */ - case 2: - case 3: - someOtherFunc(foo); - } - ``` -rationale: Fall though in switch statements is often unintentional and a bug. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: no-switch-case-fall-through' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-trailing-whitespace/index.html b/docs/rules/no-trailing-whitespace/index.html deleted file mode 100644 index eef2dc69bf4..00000000000 --- a/docs/rules/no-trailing-whitespace/index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -ruleName: no-trailing-whitespace -description: Disallows trailing whitespace at the end of a line. -rationale: Keeps version control diffs clean as it prevents accidental whitespace from being committed. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: maintainability -typescriptOnly: false -layout: rule -title: 'Rule: no-trailing-whitespace' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-unnecessary-qualifier/index.html b/docs/rules/no-unnecessary-qualifier/index.html deleted file mode 100644 index 342ca422939..00000000000 --- a/docs/rules/no-unnecessary-qualifier/index.html +++ /dev/null @@ -1,15 +0,0 @@ ---- -ruleName: no-unnecessary-qualifier -description: Warns when a namespace qualifier (`A.x`) is unnecessary. -hasFix: true -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: style -typescriptOnly: true -requiresTypeInfo: true -layout: rule -title: 'Rule: no-unnecessary-qualifier' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-unreachable/index.html b/docs/rules/no-unreachable/index.html deleted file mode 100644 index f660c7e3198..00000000000 --- a/docs/rules/no-unreachable/index.html +++ /dev/null @@ -1,13 +0,0 @@ ---- -ruleName: no-unreachable -description: 'Disallows unreachable code after `break`, `catch`, `throw`, and `return` statements.' -rationale: Unreachable code is often indication of a logic error. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -optionsJSON: 'null' -layout: rule -title: 'Rule: no-unreachable' ---- \ No newline at end of file diff --git a/docs/rules/no-unsafe-finally/index.html b/docs/rules/no-unsafe-finally/index.html deleted file mode 100644 index 1d6e46900c8..00000000000 --- a/docs/rules/no-unsafe-finally/index.html +++ /dev/null @@ -1,23 +0,0 @@ ---- -ruleName: no-unsafe-finally -description: |- - - Disallows control flow statements, such as `return`, `continue`, - `break` and `throws` in finally blocks. -descriptionDetails: '' -rationale: |- - - When used inside `finally` blocks, control flow statements, - such as `return`, `continue`, `break` and `throws` - override any other control flow statements in the same try/catch scope. - This is confusing and unexpected behavior. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: no-unsafe-finally' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-unused-expression/index.html b/docs/rules/no-unused-expression/index.html deleted file mode 100644 index 6856223df77..00000000000 --- a/docs/rules/no-unused-expression/index.html +++ /dev/null @@ -1,44 +0,0 @@ ---- -ruleName: no-unused-expression -description: Disallows unused expression statements. -descriptionDetails: |- - - Unused expressions are expression statements which are not assignments or function calls - (and thus usually no-ops). -rationale: |- - - Detects potential errors where an assignment or function call was intended. -optionsDescription: |- - - One argument may be optionally provided: - - * `allow-fast-null-checks` allows to use logical operators to perform fast null checks and perform - method or function calls for side effects (e.g. `e && e.preventDefault()`). -options: - type: array - items: - type: string - enum: - - allow-fast-null-checks - minLength: 0 - maxLength: 1 -optionExamples: - - 'true' - - '[true, "allow-fast-null-checks"]' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: no-unused-expression' -optionsJSON: |- - { - "type": "array", - "items": { - "type": "string", - "enum": [ - "allow-fast-null-checks" - ] - }, - "minLength": 0, - "maxLength": 1 - } ---- \ No newline at end of file diff --git a/docs/rules/no-unused-new/index.html b/docs/rules/no-unused-new/index.html deleted file mode 100644 index 4508b8fb8c6..00000000000 --- a/docs/rules/no-unused-new/index.html +++ /dev/null @@ -1,20 +0,0 @@ ---- -ruleName: no-unused-new -description: Disallows unused 'new' expression statements. -descriptionDetails: |- - - Unused 'new' expressions indicate that a constructor is being invoked solely for its side effects. -rationale: |- - - Detects constructs such as `new SomeClass()`, where a constructor is used solely for its side effects, which is considered - poor style. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: no-unused-new' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-unused-variable/index.html b/docs/rules/no-unused-variable/index.html deleted file mode 100644 index 8d68ff2ebcd..00000000000 --- a/docs/rules/no-unused-variable/index.html +++ /dev/null @@ -1,67 +0,0 @@ ---- -ruleName: no-unused-variable -deprecationMessage: Use the tsc compiler options --noUnusedParameters and --noUnusedLocals instead. -description: 'Disallows unused imports, variables, functions and private class members.' -hasFix: true -optionsDescription: |- - - Three optional arguments may be optionally provided: - - * `"check-parameters"` disallows unused function and constructor parameters. - * NOTE: this option is experimental and does not work with classes - that use abstract method declarations, among other things. - * `"react"` relaxes the rule for a namespace import named `React` - (from either the module `"react"` or `"react/addons"`). - Any JSX expression in the file will be treated as a usage of `React` - (because it expands to `React.createElement `). - * `{"ignore-pattern": "pattern"}` where pattern is a case-sensitive regexp. - Variable names that match the pattern will be ignored. -options: - type: array - items: - oneOf: - - type: string - enum: - - check-parameters - - react - - type: object - properties: - ignore-pattern: - type: string - additionalProperties: false - minLength: 0 - maxLength: 3 -optionExamples: - - '[true, "react"]' - - '[true, {"ignore-pattern": "^_"}]' -type: functionality -typescriptOnly: true -layout: rule -title: 'Rule: no-unused-variable' -optionsJSON: |- - { - "type": "array", - "items": { - "oneOf": [ - { - "type": "string", - "enum": [ - "check-parameters", - "react" - ] - }, - { - "type": "object", - "properties": { - "ignore-pattern": { - "type": "string" - } - }, - "additionalProperties": false - } - ] - }, - "minLength": 0, - "maxLength": 3 - } ---- \ No newline at end of file diff --git a/docs/rules/no-use-before-declare/index.html b/docs/rules/no-use-before-declare/index.html deleted file mode 100644 index d2c24056758..00000000000 --- a/docs/rules/no-use-before-declare/index.html +++ /dev/null @@ -1,17 +0,0 @@ ---- -ruleName: no-use-before-declare -description: Disallows usage of variables before their declaration. -descriptionDetails: |- - - This rule is primarily useful when using the `var` keyword - - the compiler will detect if a `let` and `const` variable is used before it is declared. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: no-use-before-declare' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-var-keyword/index.html b/docs/rules/no-var-keyword/index.html deleted file mode 100644 index 88b9b544610..00000000000 --- a/docs/rules/no-var-keyword/index.html +++ /dev/null @@ -1,15 +0,0 @@ ---- -ruleName: no-var-keyword -description: Disallows usage of the `var` keyword. -descriptionDetails: Use `let` or `const` instead. -hasFix: true -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: no-var-keyword' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-var-requires/index.html b/docs/rules/no-var-requires/index.html deleted file mode 100644 index ecbbca8fe5a..00000000000 --- a/docs/rules/no-var-requires/index.html +++ /dev/null @@ -1,17 +0,0 @@ ---- -ruleName: no-var-requires -description: Disallows the use of require statements except in import statements. -descriptionDetails: |- - - In other words, the use of forms such as `var module = require("module")` are banned. - Instead use ES6 style imports or `import foo = require('foo')` imports. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: typescript -typescriptOnly: true -layout: rule -title: 'Rule: no-var-requires' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/no-void-expression/index.html b/docs/rules/no-void-expression/index.html deleted file mode 100644 index 6722b9d77a0..00000000000 --- a/docs/rules/no-void-expression/index.html +++ /dev/null @@ -1,12 +0,0 @@ ---- -ruleName: no-void-expression -description: Requires expressions of type `void` to appear in statement position. -optionsDescription: Not configurable. -options: null -requiresTypeInfo: true -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: no-void-expression' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/object-literal-key-quotes/index.html b/docs/rules/object-literal-key-quotes/index.html deleted file mode 100644 index 7f39682b16f..00000000000 --- a/docs/rules/object-literal-key-quotes/index.html +++ /dev/null @@ -1,59 +0,0 @@ ---- -ruleName: object-literal-key-quotes -description: Enforces consistent object literal property quote style. -descriptionDetails: |- - - Object literal property names can be defined in two ways: using literals or using strings. - For example, these two objects are equivalent: - - var object1 = { - property: true - }; - - var object2 = { - "property": true - }; - - In many cases, it doesn’t matter if you choose to use an identifier instead of a string - or vice-versa. Even so, you might decide to enforce a consistent style in your code. - - This rules lets you enforce consistent quoting of property names. Either they should always - be quoted (default behavior) or quoted only as needed ("as-needed"). -hasFix: true -optionsDescription: |- - - Possible settings are: - - * `"always"`: Property names should always be quoted. (This is the default.) - * `"as-needed"`: Only property names which require quotes may be quoted (e.g. those with spaces in them). - * `"consistent"`: Property names should either all be quoted or unquoted. - * `"consistent-as-needed"`: If any property name requires quotes, then all properties must be quoted. Otherwise, no - property names may be quoted. - - For ES6, computed property names (`{[name]: value}`) and methods (`{foo() {}}`) never need - to be quoted. -options: - type: string - enum: - - always - - as-needed - - consistent - - consistent-as-needed -optionExamples: - - '[true, "as-needed"]' - - '[true, "always"]' -type: style -typescriptOnly: false -layout: rule -title: 'Rule: object-literal-key-quotes' -optionsJSON: |- - { - "type": "string", - "enum": [ - "always", - "as-needed", - "consistent", - "consistent-as-needed" - ] - } ---- \ No newline at end of file diff --git a/docs/rules/object-literal-shorthand/index.html b/docs/rules/object-literal-shorthand/index.html deleted file mode 100644 index 1a6ca8708e8..00000000000 --- a/docs/rules/object-literal-shorthand/index.html +++ /dev/null @@ -1,13 +0,0 @@ ---- -ruleName: object-literal-shorthand -description: Enforces use of ES6 object literal shorthand when possible. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: style -typescriptOnly: false -layout: rule -title: 'Rule: object-literal-shorthand' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/object-literal-sort-keys/index.html b/docs/rules/object-literal-sort-keys/index.html deleted file mode 100644 index 44dcc1850e8..00000000000 --- a/docs/rules/object-literal-sort-keys/index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -ruleName: object-literal-sort-keys -description: Requires keys in object literals to be sorted alphabetically -rationale: Useful in preventing merge conflicts -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: maintainability -typescriptOnly: false -layout: rule -title: 'Rule: object-literal-sort-keys' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/one-line/index.html b/docs/rules/one-line/index.html deleted file mode 100644 index 646e89b8d56..00000000000 --- a/docs/rules/one-line/index.html +++ /dev/null @@ -1,47 +0,0 @@ ---- -ruleName: one-line -description: Requires the specified tokens to be on the same line as the expression preceding them. -optionsDescription: |- - - Five arguments may be optionally provided: - - * `"check-catch"` checks that `catch` is on the same line as the closing brace for `try`. - * `"check-finally"` checks that `finally` is on the same line as the closing brace for `catch`. - * `"check-else"` checks that `else` is on the same line as the closing brace for `if`. - * `"check-open-brace"` checks that an open brace falls on the same line as its preceding expression. - * `"check-whitespace"` checks preceding whitespace for the specified tokens. -options: - type: array - items: - type: string - enum: - - check-catch - - check-finally - - check-else - - check-open-brace - - check-whitespace - minLength: 0 - maxLength: 5 -optionExamples: - - '[true, "check-catch", "check-finally", "check-else"]' -type: style -typescriptOnly: false -layout: rule -title: 'Rule: one-line' -optionsJSON: |- - { - "type": "array", - "items": { - "type": "string", - "enum": [ - "check-catch", - "check-finally", - "check-else", - "check-open-brace", - "check-whitespace" - ] - }, - "minLength": 0, - "maxLength": 5 - } ---- \ No newline at end of file diff --git a/docs/rules/one-variable-per-declaration/index.html b/docs/rules/one-variable-per-declaration/index.html deleted file mode 100644 index 327b8b59f65..00000000000 --- a/docs/rules/one-variable-per-declaration/index.html +++ /dev/null @@ -1,36 +0,0 @@ ---- -ruleName: one-variable-per-declaration -description: Disallows multiple variable definitions in the same declaration statement. -optionsDescription: |- - - One argument may be optionally provided: - - * `ignore-for-loop` allows multiple variable definitions in a for loop declaration. -options: - type: array - items: - type: string - enum: - - ignore-for-loop - minLength: 0 - maxLength: 1 -optionExamples: - - 'true' - - '[true, "ignore-for-loop"]' -type: style -typescriptOnly: false -layout: rule -title: 'Rule: one-variable-per-declaration' -optionsJSON: |- - { - "type": "array", - "items": { - "type": "string", - "enum": [ - "ignore-for-loop" - ] - }, - "minLength": 0, - "maxLength": 1 - } ---- \ No newline at end of file diff --git a/docs/rules/only-arrow-functions/index.html b/docs/rules/only-arrow-functions/index.html deleted file mode 100644 index bff41cac593..00000000000 --- a/docs/rules/only-arrow-functions/index.html +++ /dev/null @@ -1,41 +0,0 @@ ---- -ruleName: only-arrow-functions -description: Disallows traditional (non-arrow) function expressions. -rationale: 'Traditional functions don''t bind lexical scope, which can lead to unexpected behavior when accessing ''this''.' -optionsDescription: |- - - Two arguments may be optionally provided: - - * `"allow-declarations"` allows standalone function declarations. - * `"allow-named-functions"` allows the expression `function foo() {}` but not `function() {}`. - -options: - type: array - items: - type: string - enum: - - allow-declarations - - allow-named-functions - minLength: 0 - maxLength: 1 -optionExamples: - - 'true' - - '[true, "allow-declarations", "allow-named-functions"]' -type: typescript -typescriptOnly: false -layout: rule -title: 'Rule: only-arrow-functions' -optionsJSON: |- - { - "type": "array", - "items": { - "type": "string", - "enum": [ - "allow-declarations", - "allow-named-functions" - ] - }, - "minLength": 0, - "maxLength": 1 - } ---- \ No newline at end of file diff --git a/docs/rules/ordered-imports/index.html b/docs/rules/ordered-imports/index.html deleted file mode 100644 index 607a5097967..00000000000 --- a/docs/rules/ordered-imports/index.html +++ /dev/null @@ -1,89 +0,0 @@ ---- -ruleName: ordered-imports -description: Requires that import statements be alphabetized. -descriptionDetails: |- - - Enforce a consistent ordering for ES6 imports: - - Named imports must be alphabetized (i.e. "import {A, B, C} from "foo";") - - The exact ordering can be controlled by the named-imports-order option. - - "longName as name" imports are ordered by "longName". - - Import sources must be alphabetized within groups, i.e.: - import * as foo from "a"; - import * as bar from "b"; - - Groups of imports are delineated by blank lines. You can use these to group imports - however you like, e.g. by first- vs. third-party or thematically. -hasFix: true -optionsDescription: |- - - You may set the `"import-sources-order"` option to control the ordering of source - imports (the `"foo"` in `import {A, B, C} from "foo"`). - - Possible values for `"import-sources-order"` are: - - * `"case-insensitive'`: Correct order is `"Bar"`, `"baz"`, `"Foo"`. (This is the default.) - * `"lowercase-first"`: Correct order is `"baz"`, `"Bar"`, `"Foo"`. - * `"lowercase-last"`: Correct order is `"Bar"`, `"Foo"`, `"baz"`. - * `"any"`: Allow any order. - - You may set the `"named-imports-order"` option to control the ordering of named - imports (the `{A, B, C}` in `import {A, B, C} from "foo"`). - - Possible values for `"named-imports-order"` are: - - * `"case-insensitive'`: Correct order is `{A, b, C}`. (This is the default.) - * `"lowercase-first"`: Correct order is `{b, A, C}`. - * `"lowercase-last"`: Correct order is `{A, C, b}`. - * `"any"`: Allow any order. - - -options: - type: object - properties: - import-sources-order: - type: string - enum: - - case-insensitive - - lowercase-first - - lowercase-last - - any - named-imports-order: - type: string - enum: - - case-insensitive - - lowercase-first - - lowercase-last - - any - additionalProperties: false -optionExamples: - - 'true' - - '[true, {"import-sources-order": "lowercase-last", "named-imports-order": "lowercase-first"}]' -type: style -typescriptOnly: false -layout: rule -title: 'Rule: ordered-imports' -optionsJSON: |- - { - "type": "object", - "properties": { - "import-sources-order": { - "type": "string", - "enum": [ - "case-insensitive", - "lowercase-first", - "lowercase-last", - "any" - ] - }, - "named-imports-order": { - "type": "string", - "enum": [ - "case-insensitive", - "lowercase-first", - "lowercase-last", - "any" - ] - } - }, - "additionalProperties": false - } ---- \ No newline at end of file diff --git a/docs/rules/prefer-arrow-shorthand-return/index.html b/docs/rules/prefer-arrow-shorthand-return/index.html deleted file mode 100644 index 615e5a844da..00000000000 --- a/docs/rules/prefer-arrow-shorthand-return/index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -ruleName: prefer-arrow-shorthand-return -description: 'Suggests to convert `() => { return x; }` to `() => x`.' -optionsDescription: Not configurable. -options: null -optionExamples: - - '[true]' - - '[true, "multiline"]' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: prefer-arrow-shorthand-return' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/prefer-const/index.html b/docs/rules/prefer-const/index.html deleted file mode 100644 index 6ff68747269..00000000000 --- a/docs/rules/prefer-const/index.html +++ /dev/null @@ -1,17 +0,0 @@ ---- -ruleName: prefer-const -description: Requires that variable declarations use `const` instead of `let` if possible. -descriptionDetails: |- - - If a variable is only assigned to once when it is declared, it should be declared using 'const' -hasFix: true -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: maintainability -typescriptOnly: false -layout: rule -title: 'Rule: prefer-const' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/prefer-for-of/index.html b/docs/rules/prefer-for-of/index.html deleted file mode 100644 index 182c695e16f..00000000000 --- a/docs/rules/prefer-for-of/index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -ruleName: prefer-for-of -description: Recommends a 'for-of' loop over a standard 'for' loop if the index is only used to access the array being iterated. -rationale: A for(... of ...) loop is easier to implement and read when the index is not needed. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: typescript -typescriptOnly: false -layout: rule -title: 'Rule: prefer-for-of' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/prefer-method-signature/index.html b/docs/rules/prefer-method-signature/index.html deleted file mode 100644 index c5b89e93be1..00000000000 --- a/docs/rules/prefer-method-signature/index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -ruleName: prefer-method-signature -description: 'Prefer `foo(): void` over `foo: () => void` in interfaces and types.' -hasFix: true -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: style -typescriptOnly: false -layout: rule -title: 'Rule: prefer-method-signature' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/promise-function-async/index.html b/docs/rules/promise-function-async/index.html deleted file mode 100644 index 2da06dd6f4a..00000000000 --- a/docs/rules/promise-function-async/index.html +++ /dev/null @@ -1,21 +0,0 @@ ---- -ruleName: promise-function-async -description: Requires any function or method that returns a promise to be marked async. -rationale: |- - - Ensures that each function is only capable of 1) returning a rejected promise, or 2) - throwing an Error object. In contrast, non-`async` `Promise`-returning functions - are technically capable of either. This practice removes a requirement for consuming - code to handle both cases. - -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: typescript -typescriptOnly: false -requiresTypeInfo: true -layout: rule -title: 'Rule: promise-function-async' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/quotemark/index.html b/docs/rules/quotemark/index.html deleted file mode 100644 index c3c295f2d8e..00000000000 --- a/docs/rules/quotemark/index.html +++ /dev/null @@ -1,50 +0,0 @@ ---- -ruleName: quotemark -description: Requires single or double quotes for string literals. -hasFix: true -optionsDescription: |- - - Five arguments may be optionally provided: - - * `"single"` enforces single quotes. - * `"double"` enforces double quotes. - * `"jsx-single"` enforces single quotes for JSX attributes. - * `"jsx-double"` enforces double quotes for JSX attributes. - * `"avoid-escape"` allows you to use the "other" quotemark in cases where escaping would normally be required. - For example, `[true, "double", "avoid-escape"]` would not report a failure on the string literal `'Hello "World"'`. -options: - type: array - items: - type: string - enum: - - single - - double - - jsx-single - - jsx-double - - avoid-escape - minLength: 0 - maxLength: 5 -optionExamples: - - '[true, "single", "avoid-escape"]' - - '[true, "single", "jsx-double"]' -type: style -typescriptOnly: false -layout: rule -title: 'Rule: quotemark' -optionsJSON: |- - { - "type": "array", - "items": { - "type": "string", - "enum": [ - "single", - "double", - "jsx-single", - "jsx-double", - "avoid-escape" - ] - }, - "minLength": 0, - "maxLength": 5 - } ---- \ No newline at end of file diff --git a/docs/rules/radix/index.html b/docs/rules/radix/index.html deleted file mode 100644 index b3af9ac6b9d..00000000000 --- a/docs/rules/radix/index.html +++ /dev/null @@ -1,18 +0,0 @@ ---- -ruleName: radix -description: Requires the radix parameter to be specified when calling `parseInt`. -rationale: |- - - From [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt): - > Always specify this parameter to eliminate reader confusion and to guarantee predictable behavior. - > Different implementations produce different results when a radix is not specified, usually defaulting the value to 10. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: radix' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/restrict-plus-operands/index.html b/docs/rules/restrict-plus-operands/index.html deleted file mode 100644 index 1a20bb14ee8..00000000000 --- a/docs/rules/restrict-plus-operands/index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -ruleName: restrict-plus-operands -description: 'When adding two variables, operands must both be of type number or of type string.' -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: false -requiresTypeInfo: true -layout: rule -title: 'Rule: restrict-plus-operands' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/semicolon/index.html b/docs/rules/semicolon/index.html deleted file mode 100644 index e42fd34fcf6..00000000000 --- a/docs/rules/semicolon/index.html +++ /dev/null @@ -1,56 +0,0 @@ ---- -ruleName: semicolon -description: Enforces consistent semicolon usage at the end of every statement. -hasFix: true -optionsDescription: |- - - One of the following arguments must be provided: - - * `"always"` enforces semicolons at the end of every statement. - * `"never"` disallows semicolons at the end of every statement except for when they are necessary. - - The following arguments may be optionaly provided: - - * `"ignore-interfaces"` skips checking semicolons at the end of interface members. - * `"ignore-bound-class-methods"` skips checking semicolons at the end of bound class methods. -options: - type: array - items: - - type: string - enum: - - always - - never - - type: string - enum: - - ignore-interfaces - additionalItems: false -optionExamples: - - '[true, "always"]' - - '[true, "never"]' - - '[true, "always", "ignore-interfaces"]' - - '[true, "always", "ignore-bound-class-methods"]' -type: style -typescriptOnly: false -layout: rule -title: 'Rule: semicolon' -optionsJSON: |- - { - "type": "array", - "items": [ - { - "type": "string", - "enum": [ - "always", - "never" - ] - }, - { - "type": "string", - "enum": [ - "ignore-interfaces" - ] - } - ], - "additionalItems": false - } ---- \ No newline at end of file diff --git a/docs/rules/space-before-function-paren/index.html b/docs/rules/space-before-function-paren/index.html deleted file mode 100644 index e9a200d58ee..00000000000 --- a/docs/rules/space-before-function-paren/index.html +++ /dev/null @@ -1,78 +0,0 @@ ---- -description: Require or disallow a space before function parenthesis -hasFix: true -optionExamples: - - 'true' - - '[true, "always"]' - - '[true, "never"]' - - '[true, {"anonymous": "always", "named": "never", "asyncArrow": "always"}]' -options: - properties: - anonymous: &ref_0 - enum: - - always - - never - type: string - asyncArrow: *ref_0 - constructor: *ref_0 - method: *ref_0 - named: *ref_0 - type: object -optionsDescription: |- - - One argument which is an object which may contain the keys `anonymous`, `named`, and `asyncArrow` - These should be set to either `"always"` or `"never"`. - - * `"anonymous"` checks before the opening paren in anonymous functions - * `"named"` checks before the opening paren in named functions - * `"asyncArrow"` checks before the opening paren in async arrow functions - * `"method"` checks before the opening paren in class methods - * `"constructor"` checks before the opening paren in class constructors - -ruleName: space-before-function-paren -type: style -typescriptOnly: false -layout: rule -title: 'Rule: space-before-function-paren' -optionsJSON: |- - { - "properties": { - "anonymous": { - "enum": [ - "always", - "never" - ], - "type": "string" - }, - "asyncArrow": { - "enum": [ - "always", - "never" - ], - "type": "string" - }, - "constructor": { - "enum": [ - "always", - "never" - ], - "type": "string" - }, - "method": { - "enum": [ - "always", - "never" - ], - "type": "string" - }, - "named": { - "enum": [ - "always", - "never" - ], - "type": "string" - } - }, - "type": "object" - } ---- \ No newline at end of file diff --git a/docs/rules/strict-boolean-expressions/index.html b/docs/rules/strict-boolean-expressions/index.html deleted file mode 100644 index a3bf5cbd61c..00000000000 --- a/docs/rules/strict-boolean-expressions/index.html +++ /dev/null @@ -1,16 +0,0 @@ ---- -ruleName: strict-boolean-expressions -description: |- - Usage of && or || operators should be with boolean operands and - expressions in If, Do, While and For statements should be of type boolean -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: true -requiresTypeInfo: true -layout: rule -title: 'Rule: strict-boolean-expressions' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/switch-default/index.html b/docs/rules/switch-default/index.html deleted file mode 100644 index 4bfa95371fa..00000000000 --- a/docs/rules/switch-default/index.html +++ /dev/null @@ -1,13 +0,0 @@ ---- -ruleName: switch-default -description: Require a `default` case in all `switch` statements. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: switch-default' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/trailing-comma/index.html b/docs/rules/trailing-comma/index.html deleted file mode 100644 index d41f07af51b..00000000000 --- a/docs/rules/trailing-comma/index.html +++ /dev/null @@ -1,61 +0,0 @@ ---- -ruleName: trailing-comma -description: |- - - Requires or disallows trailing commas in array and object literals, destructuring assignments, function and tuple typings, - named imports and function parameters. -hasFix: true -optionsDescription: |- - - One argument which is an object with the keys `multiline` and `singleline`. - Both should be set to either `"always"` or `"never"`. - - * `"multiline"` checks multi-line object literals. - * `"singleline"` checks single-line object literals. - - A array is considered "multiline" if its closing bracket is on a line - after the last array element. The same general logic is followed for - object literals, function and tuple typings, named import statements - and function parameters. -options: - type: object - properties: - multiline: - type: string - enum: - - always - - never - singleline: - type: string - enum: - - always - - never - additionalProperties: false -optionExamples: - - '[true, {"multiline": "always", "singleline": "never"}]' -type: maintainability -typescriptOnly: false -layout: rule -title: 'Rule: trailing-comma' -optionsJSON: |- - { - "type": "object", - "properties": { - "multiline": { - "type": "string", - "enum": [ - "always", - "never" - ] - }, - "singleline": { - "type": "string", - "enum": [ - "always", - "never" - ] - } - }, - "additionalProperties": false - } ---- \ No newline at end of file diff --git a/docs/rules/triple-equals/index.html b/docs/rules/triple-equals/index.html deleted file mode 100644 index 1fdfe98e5b8..00000000000 --- a/docs/rules/triple-equals/index.html +++ /dev/null @@ -1,40 +0,0 @@ ---- -ruleName: triple-equals -description: Requires `===` and `!==` in place of `==` and `!=`. -optionsDescription: |- - - Two arguments may be optionally provided: - - * `"allow-null-check"` allows `==` and `!=` when comparing to `null`. - * `"allow-undefined-check"` allows `==` and `!=` when comparing to `undefined`. -options: - type: array - items: - type: string - enum: - - allow-null-check - - allow-undefined-check - minLength: 0 - maxLength: 2 -optionExamples: - - 'true' - - '[true, "allow-null-check"]' - - '[true, "allow-undefined-check"]' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: triple-equals' -optionsJSON: |- - { - "type": "array", - "items": { - "type": "string", - "enum": [ - "allow-null-check", - "allow-undefined-check" - ] - }, - "minLength": 0, - "maxLength": 2 - } ---- \ No newline at end of file diff --git a/docs/rules/typedef-whitespace/index.html b/docs/rules/typedef-whitespace/index.html deleted file mode 100644 index 8fcd3b63087..00000000000 --- a/docs/rules/typedef-whitespace/index.html +++ /dev/null @@ -1,160 +0,0 @@ ---- -ruleName: typedef-whitespace -description: Requires or disallows whitespace for type definitions. -descriptionDetails: Determines if a space is required or not before the colon in a type specifier. -optionsDescription: |- - - Two arguments which are both objects. - The first argument specifies how much space should be to the _left_ of a typedef colon. - The second argument specifies how much space should be to the _right_ of a typedef colon. - Each key should have a value of `"space"` or `"nospace"`. - Possible keys are: - - * `"call-signature"` checks return type of functions. - * `"index-signature"` checks index type specifier of indexers. - * `"parameter"` checks function parameters. - * `"property-declaration"` checks object property declarations. - * `"variable-declaration"` checks variable declaration. -options: - type: array - items: - - &ref_1 - type: object - properties: - call-signature: &ref_0 - type: string - enum: - - nospace - - onespace - - space - index-signature: *ref_0 - parameter: *ref_0 - property-declaration: *ref_0 - variable-declaration: *ref_0 - additionalProperties: false - - *ref_1 - additionalItems: false -optionExamples: - - |- - - [ - true, - { - "call-signature": "nospace", - "index-signature": "nospace", - "parameter": "nospace", - "property-declaration": "nospace", - "variable-declaration": "nospace" - }, - { - "call-signature": "onespace", - "index-signature": "onespace", - "parameter": "onespace", - "property-declaration": "onespace", - "variable-declaration": "onespace" - } - ] -type: typescript -typescriptOnly: true -layout: rule -title: 'Rule: typedef-whitespace' -optionsJSON: |- - { - "type": "array", - "items": [ - { - "type": "object", - "properties": { - "call-signature": { - "type": "string", - "enum": [ - "nospace", - "onespace", - "space" - ] - }, - "index-signature": { - "type": "string", - "enum": [ - "nospace", - "onespace", - "space" - ] - }, - "parameter": { - "type": "string", - "enum": [ - "nospace", - "onespace", - "space" - ] - }, - "property-declaration": { - "type": "string", - "enum": [ - "nospace", - "onespace", - "space" - ] - }, - "variable-declaration": { - "type": "string", - "enum": [ - "nospace", - "onespace", - "space" - ] - } - }, - "additionalProperties": false - }, - { - "type": "object", - "properties": { - "call-signature": { - "type": "string", - "enum": [ - "nospace", - "onespace", - "space" - ] - }, - "index-signature": { - "type": "string", - "enum": [ - "nospace", - "onespace", - "space" - ] - }, - "parameter": { - "type": "string", - "enum": [ - "nospace", - "onespace", - "space" - ] - }, - "property-declaration": { - "type": "string", - "enum": [ - "nospace", - "onespace", - "space" - ] - }, - "variable-declaration": { - "type": "string", - "enum": [ - "nospace", - "onespace", - "space" - ] - } - }, - "additionalProperties": false - } - ], - "additionalItems": false - } ---- \ No newline at end of file diff --git a/docs/rules/typedef/index.html b/docs/rules/typedef/index.html deleted file mode 100644 index 67ca7f977f2..00000000000 --- a/docs/rules/typedef/index.html +++ /dev/null @@ -1,53 +0,0 @@ ---- -ruleName: typedef -description: Requires type definitions to exist. -optionsDescription: |- - - Seven arguments may be optionally provided: - - * `"call-signature"` checks return type of functions. - * `"arrow-call-signature"` checks return type of arrow functions. - * `"parameter"` checks type specifier of function parameters for non-arrow functions. - * `"arrow-parameter"` checks type specifier of function parameters for arrow functions. - * `"property-declaration"` checks return types of interface properties. - * `"variable-declaration"` checks variable declarations. - * `"member-variable-declaration"` checks member variable declarations. -options: - type: array - items: - type: string - enum: - - call-signature - - arrow-call-signature - - parameter - - arrow-parameter - - property-declaration - - variable-declaration - - member-variable-declaration - minLength: 0 - maxLength: 7 -optionExamples: - - '[true, "call-signature", "parameter", "member-variable-declaration"]' -type: typescript -typescriptOnly: true -layout: rule -title: 'Rule: typedef' -optionsJSON: |- - { - "type": "array", - "items": { - "type": "string", - "enum": [ - "call-signature", - "arrow-call-signature", - "parameter", - "arrow-parameter", - "property-declaration", - "variable-declaration", - "member-variable-declaration" - ] - }, - "minLength": 0, - "maxLength": 7 - } ---- \ No newline at end of file diff --git a/docs/rules/typeof-compare/index.html b/docs/rules/typeof-compare/index.html deleted file mode 100644 index a879dcc2679..00000000000 --- a/docs/rules/typeof-compare/index.html +++ /dev/null @@ -1,13 +0,0 @@ ---- -ruleName: typeof-compare -description: Makes sure result of `typeof` is compared to correct string values -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: typeof-compare' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/unified-signatures/index.html b/docs/rules/unified-signatures/index.html deleted file mode 100644 index 39e0a1c7eea..00000000000 --- a/docs/rules/unified-signatures/index.html +++ /dev/null @@ -1,13 +0,0 @@ ---- -ruleName: unified-signatures -description: Warns for any two overloads that could be unified into one by using a union or an optional/rest parameter. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: typescript -typescriptOnly: true -layout: rule -title: 'Rule: unified-signatures' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/use-isnan/index.html b/docs/rules/use-isnan/index.html deleted file mode 100644 index 848ec439738..00000000000 --- a/docs/rules/use-isnan/index.html +++ /dev/null @@ -1,17 +0,0 @@ ---- -ruleName: use-isnan -description: Enforces use of the `isNaN()` function to check for NaN references instead of a comparison to the `NaN` constant. -rationale: |- - - Since `NaN !== NaN`, comparisons with regular operators will produce unexpected results. - So, instead of `if (myVar === NaN)`, do `if (isNaN(myVar))`. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -typescriptOnly: false -layout: rule -title: 'Rule: use-isnan' -optionsJSON: 'null' ---- \ No newline at end of file diff --git a/docs/rules/variable-name/index.html b/docs/rules/variable-name/index.html deleted file mode 100644 index 0808782623f..00000000000 --- a/docs/rules/variable-name/index.html +++ /dev/null @@ -1,48 +0,0 @@ ---- -ruleName: variable-name -description: Checks variable names for various errors. -optionsDescription: |- - - Five arguments may be optionally provided: - - * `"check-format"`: allows only camelCased or UPPER_CASED variable names - * `"allow-leading-underscore"` allows underscores at the beginning (only has an effect if "check-format" specified) - * `"allow-trailing-underscore"` allows underscores at the end. (only has an effect if "check-format" specified) - * `"allow-pascal-case"` allows PascalCase in addtion to camelCase. - * `"ban-keywords"`: disallows the use of certain TypeScript keywords (`any`, `Number`, `number`, `String`, - `string`, `Boolean`, `boolean`, `undefined`) as variable or parameter names. -options: - type: array - items: - type: string - enum: - - check-format - - allow-leading-underscore - - allow-trailing-underscore - - allow-pascal-case - - ban-keywords - minLength: 0 - maxLength: 5 -optionExamples: - - '[true, "ban-keywords", "check-format", "allow-leading-underscore"]' -type: style -typescriptOnly: false -layout: rule -title: 'Rule: variable-name' -optionsJSON: |- - { - "type": "array", - "items": { - "type": "string", - "enum": [ - "check-format", - "allow-leading-underscore", - "allow-trailing-underscore", - "allow-pascal-case", - "ban-keywords" - ] - }, - "minLength": 0, - "maxLength": 5 - } ---- \ No newline at end of file diff --git a/docs/rules/whitespace/index.html b/docs/rules/whitespace/index.html deleted file mode 100644 index c3f685c206a..00000000000 --- a/docs/rules/whitespace/index.html +++ /dev/null @@ -1,57 +0,0 @@ ---- -ruleName: whitespace -description: Enforces whitespace style conventions. -rationale: 'Helps maintain a readable, consistent style in your codebase.' -optionsDescription: |- - - Eight arguments may be optionally provided: - - * `"check-branch"` checks branching statements (`if`/`else`/`for`/`while`) are followed by whitespace. - * `"check-decl"`checks that variable declarations have whitespace around the equals token. - * `"check-operator"` checks for whitespace around operator tokens. - * `"check-module"` checks for whitespace in import & export statements. - * `"check-separator"` checks for whitespace after separator tokens (`,`/`;`). - * `"check-type"` checks for whitespace before a variable type specification. - * `"check-typecast"` checks for whitespace between a typecast and its target. - * `"check-preblock"` checks for whitespace before the opening brace of a block -options: - type: array - items: - type: string - enum: - - check-branch - - check-decl - - check-operator - - check-module - - check-separator - - check-type - - check-typecast - - check-preblock - minLength: 0 - maxLength: 7 -optionExamples: - - '[true, "check-branch", "check-operator", "check-typecast"]' -type: style -typescriptOnly: false -layout: rule -title: 'Rule: whitespace' -optionsJSON: |- - { - "type": "array", - "items": { - "type": "string", - "enum": [ - "check-branch", - "check-decl", - "check-operator", - "check-module", - "check-separator", - "check-type", - "check-typecast", - "check-preblock" - ] - }, - "minLength": 0, - "maxLength": 7 - } ---- \ No newline at end of file From d119274af72f1f53e1621c1023db6520617057a3 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Wed, 18 Jan 2017 15:51:32 -0500 Subject: [PATCH 12/13] Fix buildDocs to create directory (#2072) --- scripts/buildDocs.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/buildDocs.ts b/scripts/buildDocs.ts index 937928927b5..3333be4b698 100644 --- a/scripts/buildDocs.ts +++ b/scripts/buildDocs.ts @@ -132,6 +132,9 @@ function buildSingleModuleDocumentation(documentation: IDocumentation, modulePat // Ensure a directory exists and write the module's file. const moduleName = (metadata as any)[documentation.nameMetadataKey]; const fileDirectory = path.join(documentation.subDirectory, moduleName); + if (!fs.existsSync(documentation.subDirectory)) { + fs.mkdirSync(documentation.subDirectory); + } if (!fs.existsSync(fileDirectory)) { fs.mkdirSync(fileDirectory); } From b6171dd731effe4bcc5308a2279901ae6ec11122 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Wed, 18 Jan 2017 22:29:06 +0100 Subject: [PATCH 13/13] Allow empty interfaces with 2 or more parent (#2070) Fixes: #2065 --- src/rules/noEmptyInterfaceRule.ts | 7 +++++-- test/rules/no-empty-interface/test.ts.lint | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/rules/noEmptyInterfaceRule.ts b/src/rules/noEmptyInterfaceRule.ts index 844ee5611b9..fe29e91b491 100644 --- a/src/rules/noEmptyInterfaceRule.ts +++ b/src/rules/noEmptyInterfaceRule.ts @@ -42,9 +42,12 @@ export class Rule extends Lint.Rules.AbstractRule { class Walker extends Lint.RuleWalker { public visitInterfaceDeclaration(node: ts.InterfaceDeclaration) { - if (node.members.length === 0) { + if (node.members.length === 0 && + (node.heritageClauses === undefined || + node.heritageClauses[0].types === undefined || + // allow interfaces that extend 2 or more interfaces + node.heritageClauses[0].types!.length < 2)) { this.addFailureAtNode(node.name, node.heritageClauses ? Rule.FAILURE_STRING_FOR_EXTENDS : Rule.FAILURE_STRING); } - super.visitInterfaceDeclaration(node); } } diff --git a/test/rules/no-empty-interface/test.ts.lint b/test/rules/no-empty-interface/test.ts.lint index 3fb5872674c..b60398d65c8 100644 --- a/test/rules/no-empty-interface/test.ts.lint +++ b/test/rules/no-empty-interface/test.ts.lint @@ -5,3 +5,8 @@ interface J extends I { } ~ [An interface declaring no members is equivalent to its supertype.] interface K { x: number; } + +interface L extends J, K {} // extending more than one interface is ok, as it can be used instead of intersection types + +interface M extends {} // don't crash on empty extends list + ~ [An interface declaring no members is equivalent to its supertype.]