From efaa980ea609821178dca45a50538e482abafcdb Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Thu, 17 Dec 2015 18:09:29 -0500 Subject: [PATCH 01/30] New testing system prototype Allows tests for rules to be written in a more visual manner. Works in this commit! However, major code cleanup needed. --- Gruntfile.js | 4 +- package.json | 2 + test/ruleTestRunner.ts | 95 +++++++++++ test/ruleTestRunner/lines.ts | 64 ++++++++ test/ruleTestRunner/parse.ts | 133 +++++++++++++++ test/ruleTestRunner/types.ts | 47 ++++++ test/ruleTestRunner/utils.ts | 29 ++++ test/ruleTestRunnerTests/linesTests.ts | 35 ++++ test/ruleTestRunnerTests/parseTests.ts | 56 +++++++ test/ruleTestRunnerTests/testData.ts | 94 +++++++++++ test/ruleTestRunnerTests/utilsTests.ts | 30 ++++ .../align-arguments/test.ts.linttest | 152 ++++++++++++++++++ test/ruleTests/align-arguments/tslint.json | 5 + .../align-parameters/test.ts.linttest | 38 +++++ test/ruleTests/align-parameters/tslint.json | 5 + .../align-statements/test.ts.linttest | 151 +++++++++++++++++ test/ruleTests/align-statements/tslint.json | 5 + test/ruleTests/ban/test.ts.linttest | 4 + test/ruleTests/ban/tslint.json | 5 + test/tsconfig.json | 13 ++ test/tsd.json | 6 + test/typings/colors/colors.d.ts | 123 ++++++++++++++ test/typings/diff/diff.d.ts | 59 +++++++ 23 files changed, 1153 insertions(+), 2 deletions(-) create mode 100644 test/ruleTestRunner.ts create mode 100644 test/ruleTestRunner/lines.ts create mode 100644 test/ruleTestRunner/parse.ts create mode 100644 test/ruleTestRunner/types.ts create mode 100644 test/ruleTestRunner/utils.ts create mode 100644 test/ruleTestRunnerTests/linesTests.ts create mode 100644 test/ruleTestRunnerTests/parseTests.ts create mode 100644 test/ruleTestRunnerTests/testData.ts create mode 100644 test/ruleTestRunnerTests/utilsTests.ts create mode 100644 test/ruleTests/align-arguments/test.ts.linttest create mode 100644 test/ruleTests/align-arguments/tslint.json create mode 100644 test/ruleTests/align-parameters/test.ts.linttest create mode 100644 test/ruleTests/align-parameters/tslint.json create mode 100644 test/ruleTests/align-statements/test.ts.linttest create mode 100644 test/ruleTests/align-statements/tslint.json create mode 100644 test/ruleTests/ban/test.ts.linttest create mode 100644 test/ruleTests/ban/tslint.json create mode 100644 test/typings/colors/colors.d.ts create mode 100644 test/typings/diff/diff.d.ts diff --git a/Gruntfile.js b/Gruntfile.js index e18be1c6371..f5bc9a85a98 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -22,13 +22,13 @@ module.exports = function (grunt) { options: { reporter: "spec" }, - src: ["build/test/**/*.js"] + src: ["build/test/**/*Tests.js", "build/test/assert.js", "build/test/lint.js"] } }, run: { test: { - cmd: "./test/check-bin.sh" + exec: "./test/check-bin.sh && node ./build/test/ruleTestRunner.js" } }, diff --git a/package.json b/package.json index 420eb2f3aed..c4666467cd7 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,8 @@ }, "devDependencies": { "chai": "^3.0.0", + "colors": "^1.1.2", + "diff": "^2.2.1", "grunt": "^0.4.5", "grunt-cli": "^0.1.9", "grunt-contrib-clean": "^0.6.0", diff --git a/test/ruleTestRunner.ts b/test/ruleTestRunner.ts new file mode 100644 index 00000000000..89c399619a5 --- /dev/null +++ b/test/ruleTestRunner.ts @@ -0,0 +1,95 @@ +/* + * 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 diff from "diff"; +import * as colors from "colors"; +import * as fs from "fs"; +import * as glob from "glob"; +import * as path from "path"; + +import * as Linter from "../src/tslint"; +import * as parse from "./ruleTestRunner/parse"; +import {LintError} from "./ruleTestRunner/types"; + +console.log(); +console.log(colors.underline("Testing Lint Rules:")); + +const EXTENSION = ".linttest"; +// needed to get colors to show up when passing through Grunt +(colors as any).enabled = true; + +const testDirectories = glob.sync("test/ruleTests/*"); +for (const testDirectory of testDirectories) { + const filesToLint = glob.sync(path.join(testDirectory, `**/*${EXTENSION}`)); + const configuration = JSON.parse(fs.readFileSync(path.join(testDirectory, "tslint.json"), "utf8")); + for (const fileToLint of filesToLint) { + process.stdout.write(`${fileToLint}:`); + const baseFilename = path.basename(fileToLint, ".linttest"); + const fileData = fs.readFileSync(fileToLint, "utf8"); + const fileDataWithoutMarkup = parse.removeErrorMarkup(fileData); + const errorsFromMarkup = parse.parseErrorsFromMarkup(fileData); + + const options = { + configuration, + formatter: "prose", + formattersDirectory: "", + rulesDirectory: "", + }; + + const linter = new Linter(baseFilename, fileDataWithoutMarkup, options); + const errorsFromLinter: LintError[] = linter.lint().failures.map((failure) => { + const startCol = failure.getStartPosition().getLineAndCharacter().character + 1; + const startLine = failure.getStartPosition().getLineAndCharacter().line + 1; + const endCol = failure.getEndPosition().getLineAndCharacter().character + 1; + const endLine = failure.getEndPosition().getLineAndCharacter().line + 1; + + return { + endPos: { col: endCol, line: endLine }, + message: failure.getFailure(), + startPos: { col: startCol, line: startLine }, + }; + }); + + const markupFromMarkup = parse.createMarkupFromErrors(fileDataWithoutMarkup, errorsFromMarkup); + const markupFromLinter = parse.createMarkupFromErrors(fileDataWithoutMarkup, errorsFromLinter); + + const diffResults = diff.diffLines(markupFromMarkup, markupFromLinter); + const didTestPass = !diffResults.some((diff) => diff.added || diff.removed); + + if (didTestPass) { + console.log(colors.green(" Passed")); + } else { + console.log(colors.red(" Failed!")); + console.log(colors.red("Expected (from .linttest file)")); + console.log(colors.green("Actual (from TSLint)")); + + for (const diffResult of diffResults) { + let text: string; + if (diffResult.added) { + text = colors.green(diffResult.value); + } else if (diffResult.removed) { + text = colors.red(diffResult.value); + } else { + text = colors.gray(diffResult.value); + } + process.stdout.write(text); + } + } + + } + } + +process.exit(0); diff --git a/test/ruleTestRunner/lines.ts b/test/ruleTestRunner/lines.ts new file mode 100644 index 00000000000..1994ab908be --- /dev/null +++ b/test/ruleTestRunner/lines.ts @@ -0,0 +1,64 @@ +/* + * 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 {strMult} from "./utils"; + +// Use classes here instead of interfaces because we want runtime type data +export class CodeLine { + constructor(public contents: string) { } +} +export class MultilineErrorLine { + constructor(public startCol: number) { } +} +export class EndErrorLine { + constructor(public startCol: number, public endCol: number, public message: string) { } +} +export type ErrorLine = MultilineErrorLine | EndErrorLine; +export type Line = CodeLine | ErrorLine; + +const multilineErrorRegex = /^\s*~+$/; +const endErrorRegex = /^\s*~+\s*\[([\w ]+)\]\s*$/; + +export function classifyLine(line: string): Line { + let matches: RegExpMatchArray; + /* tslint:disable:no-conditional-assignment */ + if (line.match(multilineErrorRegex)) { + // 1-based indexing for line and column numbers + const startErrorCol = line.indexOf("~") + 1; + return new MultilineErrorLine(startErrorCol); + } else if (matches = line.match(endErrorRegex)) { + const startErrorCol = line.indexOf("~") + 1; + // exclusive endpoint + const endErrorCol = line.lastIndexOf("~") + 2; + const [, message] = matches; + return new EndErrorLine(startErrorCol, endErrorCol, message); + } else { + return new CodeLine(line); + } + /* tslint:enable:no-conditional-assignment */ +} + +export function createErrorString(code: string, errorLine: ErrorLine) { + const startSpaces = strMult(" ", errorLine.startCol - 1); + if (errorLine instanceof MultilineErrorLine) { + const tildes = strMult("~", code.length - startSpaces.length); + return `${startSpaces}${tildes}`; + } else if (errorLine instanceof EndErrorLine) { + const tildes = strMult("~", errorLine.endCol - errorLine.startCol); + const endSpaces = strMult(" ", code.length - errorLine.endCol + 1); + return `${startSpaces}${tildes}${endSpaces} [${errorLine.message}]`; + } +} diff --git a/test/ruleTestRunner/parse.ts b/test/ruleTestRunner/parse.ts new file mode 100644 index 00000000000..b976327ccb1 --- /dev/null +++ b/test/ruleTestRunner/parse.ts @@ -0,0 +1,133 @@ +/* + * 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 {LintError, errorComparator, lintSyntaxError} from "./types"; +import {ErrorLine, CodeLine, MultilineErrorLine, EndErrorLine, classifyLine, createErrorString} from "./lines"; + +export function removeErrorMarkup(text: string): string { + const textLines = text.split("\n"); + const lines = textLines.map(classifyLine); + const codeLines = lines.filter((line) => (line instanceof CodeLine)).map((line) => (line).contents); + return codeLines.join("\n"); +} + +/* tslint:disable:object-literal-sort-keys */ +export function parseErrorsFromMarkup(text: string): LintError[] { + const textLines = text.split("\n"); + const lines = textLines.map(classifyLine); + + if (lines.length > 0 && !(lines[0] instanceof CodeLine)) { + throw lintSyntaxError("Cannot start a lint file with an error mark line."); + } + + // map each line of code to the error markings beneath it + let lineIndex = -1; + const lineErrorMap: ErrorLine[][] = []; + for (const line of lines) { + if (line instanceof CodeLine) { + lineIndex++; + lineErrorMap[lineIndex] = []; + } else { + lineErrorMap[lineIndex].push(line); + } + } + + const lintErrors: LintError[] = []; + + // for each line of code... + for (let lineNo = 1; lineNo <= lineErrorMap.length; ++lineNo) { + const errorLines = lineErrorMap[lineNo - 1]; + + // for each error marking on that line... + while (errorLines.length > 0) { + const errorLine = errorLines.shift(); + const errorStartPos = { line: lineNo, col: errorLine.startCol }; + + // if the error starts and ends on this line, add it now to list of errors + if (errorLine instanceof EndErrorLine) { + lintErrors.push({ + startPos: errorStartPos, + endPos: { line: lineNo, col: errorLine.endCol }, + message: errorLine.message + }); + + // if the error is the start of a multiline error + } else if (errorLine instanceof MultilineErrorLine) { + // keep going until we get to the end of the multiline error + for (let endLineNo = lineNo + 1; ; ++endLineNo) { + if (endLineNo > lineErrorMap.length + || lineErrorMap[endLineNo - 1].length === 0 + || lineErrorMap[endLineNo - 1][0].startCol !== 1) { + throw lintSyntaxError( + `Error mark starting at ${errorStartPos.line}:${errorStartPos.col} does not end correctly.` + ); + } else { + const nextErrorLine = lineErrorMap[endLineNo - 1].shift(); + + // if end of multiline error, add it it list of errors + if (nextErrorLine instanceof EndErrorLine) { + lintErrors.push({ + startPos: errorStartPos, + endPos: { line: endLineNo, col: nextErrorLine.endCol }, + message: nextErrorLine.message + }); + break; + } + } + } + } + } + } + + // sort errors by startPos then endPos + lintErrors.sort(errorComparator); + + return lintErrors; +} + +export function createMarkupFromErrors(code: string, lintErrors: LintError[]) { + // theoretically, lint errors should be already sorted, but just to play it safe... + lintErrors.sort(errorComparator); + + const codeLines = code.split("\n"); + const lineErrorMap: ErrorLine[][] = codeLines.map(() => []); + for (const error of lintErrors) { + const {startPos, endPos, message} = error; + if (startPos.line === endPos.line) { // single line error + lineErrorMap[startPos.line - 1].push(new EndErrorLine( + startPos.col, + endPos.col, + message + )); + } else { // multiline error + lineErrorMap[startPos.line - 1].push(new MultilineErrorLine(startPos.col)); + for (let lineNo = startPos.line; lineNo < endPos.line - 1; ++lineNo) { + lineErrorMap[lineNo].push(new MultilineErrorLine(1)); + } + lineErrorMap[endPos.line - 1].push(new EndErrorLine(1, endPos.col, message)); + } + } + + let resultLines: string[] = []; + codeLines.forEach((codeLine, i) => { + resultLines.push(codeLine); + for (let errorLine of lineErrorMap[i]) { + resultLines.push(createErrorString(codeLine, errorLine)); + } + }); + return resultLines.join("\n"); +} +/* tslint:enable:object-literal-sort-keys */ diff --git a/test/ruleTestRunner/types.ts b/test/ruleTestRunner/types.ts new file mode 100644 index 00000000000..0aca220ed97 --- /dev/null +++ b/test/ruleTestRunner/types.ts @@ -0,0 +1,47 @@ +/* + * 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 interface PositionInFile { + line: number; + col: number; +} + +export interface LintError { + startPos: PositionInFile; + endPos?: PositionInFile; + message: string; +} + +export interface LintFile { + contents: string; + lintErrors: LintError[]; +} + +export function errorComparator(err1: LintError, err2: LintError) { + if (err1.startPos.line !== err2.startPos.line) { + return err1.startPos.line - err2.startPos.line; + } else if (err1.startPos.col !== err2.startPos.col) { + return err1.startPos.col - err2.startPos.col; + } else if (err1.endPos.line !== err2.endPos.line) { + return err1.endPos.line - err2.endPos.line; + } else { + return err1.endPos.col - err2.endPos.col; + } +} + +export function lintSyntaxError(message: string) { + return new Error(`Lint File Syntax Error: ${message}`); +} diff --git a/test/ruleTestRunner/utils.ts b/test/ruleTestRunner/utils.ts new file mode 100644 index 00000000000..ce8d5c8d6d6 --- /dev/null +++ b/test/ruleTestRunner/utils.ts @@ -0,0 +1,29 @@ +/* + * 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 tempCwd(newCwd: string, callback: () => void) { + const oldCwd = process.cwd(); + process.chdir(newCwd); + try { + callback(); + } finally { + process.chdir(oldCwd); + } +} + +export function strMult(str: string, numTimes: number) { + return Array(numTimes + 1).join(str); +} diff --git a/test/ruleTestRunnerTests/linesTests.ts b/test/ruleTestRunnerTests/linesTests.ts new file mode 100644 index 00000000000..031142a33e2 --- /dev/null +++ b/test/ruleTestRunnerTests/linesTests.ts @@ -0,0 +1,35 @@ +/* + * 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 lines from "../ruleTestRunner/lines"; + +describe("Rule Test Runner", () => { + describe("lines", () => { + describe("::createErrorString", () => { + it("should correctly create strings", () => { + const code1 = "this is a line of code"; + const errorMarkup1 = " ~~~~~~~~~~~~~~~~~~~~"; + const errorLine1 = new lines.MultilineErrorLine(3); + assert.equal(lines.createErrorString(code1, errorLine1), errorMarkup1); + + const code2 = "another line of code here"; + const errorMarkup2 = "~~~~~~~~~~~~~~~~~~~~~~~~~ [foo]"; + const errorLine2 = new lines.EndErrorLine(1, code2.length + 1, "foo"); + assert.equal(lines.createErrorString(code2, errorLine2), errorMarkup2); + }); + }); + }); +}); diff --git a/test/ruleTestRunnerTests/parseTests.ts b/test/ruleTestRunnerTests/parseTests.ts new file mode 100644 index 00000000000..40cfce1553f --- /dev/null +++ b/test/ruleTestRunnerTests/parseTests.ts @@ -0,0 +1,56 @@ +/* + * 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 testData from "./testData"; +import * as parse from "../ruleTestRunner/parse"; + +describe("Rule Test Runner", () => { + describe("parse", () => { + describe("::removeErrorMarkup", () => { + it("should return the contents of a regular string unchanged", () => { + assert.equal(parse.removeErrorMarkup(testData.lintStr1), testData.codeStr1); + }); + + it("should remove a single-line error markup correctly", () => { + assert.equal(parse.removeErrorMarkup(testData.lintStr2), testData.codeStr2); + }); + + it("should remove a mix of error markup correctly", () => { + assert.equal(parse.removeErrorMarkup(testData.lintStr3), testData.codeStr3); + }); + }); + + describe("::parseErrors", () => { + it("should return no errors from a regular string", () => { + assert.deepEqual(parse.parseErrorsFromMarkup(testData.lintStr1), testData.resultErrs1); + }); + + it("should find a single-line error correctly", () => { + assert.deepEqual(parse.parseErrorsFromMarkup(testData.lintStr2), testData.resultErrs2); + }); + + it("should find a mix of errors correctly", () => { + assert.deepEqual(parse.parseErrorsFromMarkup(testData.lintStr3), testData.resultErrs3); + }); + }); + + describe("::createMarkupFromErrors", () => { + it("should generate correct markup", () => { + assert.equal(parse.createMarkupFromErrors(testData.codeStr5, testData.resultErrs5), testData.lintStr5); + }); + }); + }); +}); diff --git a/test/ruleTestRunnerTests/testData.ts b/test/ruleTestRunnerTests/testData.ts new file mode 100644 index 00000000000..3cc53a3f60e --- /dev/null +++ b/test/ruleTestRunnerTests/testData.ts @@ -0,0 +1,94 @@ +/* + * 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 {LintError} from "../ruleTestRunner/types"; + +/* tslint:disable:object-literal-sort-keys */ + +export const lintStr1 = ` +Yay some file contents +That have ~~ in it in the middle +And some brackets too [brackets are here] +~~~ And even lines that start with [tildes] +`; +export const codeStr1 = lintStr1; +export const resultErrs1: LintError[] = []; + + +export const lintStr2 = ` +A file with an error +~~~~~ [error] +`; +export const codeStr2 = ` +A file with an error +`; +export const resultErrs2: LintError[] = [ + { startPos: { line: 2, col: 1 }, endPos: { line: 2, col: 6 }, message: "error" } +]; + + +export const lintStr3 = ` +A file with lots of errors +~~~~~ [error] + ~~~~~~~~~~~~~ [error2] + ~~~~~~~~~~~~~~~~~~~~~~~ + Some more code goes here +~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + And more code here +~~~~~~~~~~~~ [multiline error1] +~~~~~~~~~~~~~~~~~~~~~ + ~ [error3] + Final code here +~~ [multiline error2] +`; + +export const codeStr3 = ` +A file with lots of errors + Some more code goes here + And more code here + Final code here +`; +export const resultErrs3: LintError[] = [ + { startPos: { line: 2, col: 1 }, endPos: { line: 2, col: 6 }, message: "error" }, + { startPos: { line: 2, col: 4 }, endPos: { line: 4, col: 13 }, message: "multiline error1" }, + { startPos: { line: 2, col: 5 }, endPos: { line: 2, col: 18 }, message: "error2" }, + { startPos: { line: 3, col: 1 }, endPos: { line: 5, col: 3 }, message: "multiline error2" }, + { startPos: { line: 4, col: 7 }, endPos: { line: 4, col: 8 }, message: "error3" } +]; + +export const lintStr4 = ""; +export const codeStr4 = ""; +export const resultErrs4: LintError[] = []; + +// this is a ideally formatted lint string, errors ordered by start position, +// error messages one space after end of line of code above +export const lintStr5 = ` +someObject.someProperty.doSomething(); + ~~~~~~~~~~~~~ [unsafe access] + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +someVar <- someObject.crazyMethod(arg1, arg2, arg3); +~~~~~~~ [another error] +`; +export const codeStr5 = ` +someObject.someProperty.doSomething(); +someVar <- someObject.crazyMethod(arg1, arg2, arg3); +`; +export const resultErrs5: LintError[] = [ + { startPos: { line: 2, col: 11 }, endPos: { line: 2, col: 24 }, message: "unsafe access" }, + { startPos: { line: 2, col: 13 }, endPos: { line: 3, col: 8 }, message: "another error" } +]; +/* tslint:enable:object-literal-sort-keys */ diff --git a/test/ruleTestRunnerTests/utilsTests.ts b/test/ruleTestRunnerTests/utilsTests.ts new file mode 100644 index 00000000000..b366cfacf9c --- /dev/null +++ b/test/ruleTestRunnerTests/utilsTests.ts @@ -0,0 +1,30 @@ +/* + * 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 "../ruleTestRunner/utils"; + +describe("Rule Test Runner", () => { + describe("utils", () => { + describe("::strMult", () => { + it("should duplicate strings correctly", () => { + assert.equal("xxxxx", utils.strMult("x", 5)); + assert.equal("", utils.strMult("abc", 0)); + assert.equal("abcabcabc", utils.strMult("abc", 3)); + assert.equal("one", utils.strMult("one", 1)); + }); + }); + }); +}); diff --git a/test/ruleTests/align-arguments/test.ts.linttest b/test/ruleTests/align-arguments/test.ts.linttest new file mode 100644 index 00000000000..0202a35c2fd --- /dev/null +++ b/test/ruleTests/align-arguments/test.ts.linttest @@ -0,0 +1,152 @@ +function invalidParametersAlignment1(a: number, +b: number) { + var i = 0; +} + +function invalidParametersAlignment2(a: number, b: number, +c: number) { + var i = 0; +} + +function invalidParametersAlignment3(a: number, + b: number, + c: number) { + var i = 0; +} + +class C1 { + invalidParametersAlignment(a: number, + b: number) + { + } +} + +class InvalidAlignmentInConstructor { + constructor(a: number, + str: string) + { + } +} + +var invalidParametersAlignment4 = function(xxx: foo, + yyy: bar) { return true; } + +function validParametersAlignment1(a: number, b: number) { + var i = 0; +} + +function validParametersAlignment2(a: number, b: number, + c: number) { + var i = 0; +} + +function validParametersAlignment3(a: number, + b: number, + c: number) { + var i = 0; +} + +function validParametersAlignment4( + a: number, + b: number, + c: number) { + var i = 0; +} + +var validParametersAlignment6 = function(xxx: foo, + yyy: bar) { return true; } + +/////// + +function invalidArgumentsAlignment1() +{ + f(10, + 'abcd', 0); + ~~~~~~ [arguments are not aligned] +} + +function invalidArgumentsAlignment2() +{ + f(10, + 'abcd', + 0); + ~ [arguments are not aligned] + +} + +class Foo { + constructor(a: number, + str: string) + { + } +} + +var invalidConstructorArgsAlignment = new foo(10, + "abcd"); + ~~~~~~ [arguments are not aligned] + +function validArgumentsAlignment1() +{ + f(101, 'xyz', 'abc'); +} + +function validArgumentsAlignment2() +{ + f(1, + 2, + 3, + 4); +} + +function validArgumentsAlignment3() +{ + f( + 1, + 2, + 3, + 4); +} + +function validArgumentsAlignment3() +{ + f(1, 2, + 3, 4); +} + +//////// + +function invalidStatementsAlignment1() +{ + var i = 0; + var j = 0; + var k = 1; +} + +function invalidStatementsAlignment1() +{ + var i = 0; + { + var j = 0; + var k = 1; + } +} + +function validStatementsAlignment1() +{ + var i = 0; + var j = 0; + var k = 1; +} + +function validStatementsAlignment2() +{ + var i = 0; + { + var j = 0; + var k = 1; + } +} + +function shouldntCrash() { + let f = new Foo; +} diff --git a/test/ruleTests/align-arguments/tslint.json b/test/ruleTests/align-arguments/tslint.json new file mode 100644 index 00000000000..642cc953dcf --- /dev/null +++ b/test/ruleTests/align-arguments/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "align": [true, "arguments"] + } +} diff --git a/test/ruleTests/align-parameters/test.ts.linttest b/test/ruleTests/align-parameters/test.ts.linttest new file mode 100644 index 00000000000..6eeeae1e99c --- /dev/null +++ b/test/ruleTests/align-parameters/test.ts.linttest @@ -0,0 +1,38 @@ +function invalidParametersAlignment1(a: number, +b: number) { +~~~~~~~~~ [parameters are not aligned] + var i = 0; +} + +function invalidParametersAlignment2(a: number, b: number, +c: number) { +~~~~~~~~~ [parameters are not aligned] + var i = 0; +} + +function invalidParametersAlignment3(a: number, + b: number, + ~~~~~~~~~ [parameters are not aligned] + c: number) { + var i = 0; +} + +class C1 { + invalidParametersAlignment(a: number, + b: number) + ~~~~~~~~~ [parameters are not aligned] + { + } +} + +class InvalidAlignmentInConstructor { + constructor(a: number, + str: string) + ~~~~~~~~~~~ [parameters are not aligned] + { + } +} + +var invalidParametersAlignment4 = function(xxx: foo, + yyy: bar) { return true; } + ~~~~~~~~ [parameters are not aligned] diff --git a/test/ruleTests/align-parameters/tslint.json b/test/ruleTests/align-parameters/tslint.json new file mode 100644 index 00000000000..b9360403062 --- /dev/null +++ b/test/ruleTests/align-parameters/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "align": [true, "parameters"] + } +} diff --git a/test/ruleTests/align-statements/test.ts.linttest b/test/ruleTests/align-statements/test.ts.linttest new file mode 100644 index 00000000000..5581bc3c60e --- /dev/null +++ b/test/ruleTests/align-statements/test.ts.linttest @@ -0,0 +1,151 @@ +function invalidParametersAlignment1(a: number, +b: number) { + var i = 0; +} + +function invalidParametersAlignment2(a: number, b: number, +c: number) { + var i = 0; +} + +function invalidParametersAlignment3(a: number, + b: number, + c: number) { + var i = 0; +} + +class C1 { + invalidParametersAlignment(a: number, + b: number) + { + } +} + +class InvalidAlignmentInConstructor { + constructor(a: number, + str: string) + { + } +} + +var invalidParametersAlignment4 = function(xxx: foo, + yyy: bar) { return true; } + +function validParametersAlignment1(a: number, b: number) { + var i = 0; +} + +function validParametersAlignment2(a: number, b: number, + c: number) { + var i = 0; +} + +function validParametersAlignment3(a: number, + b: number, + c: number) { + var i = 0; +} + +function validParametersAlignment4( + a: number, + b: number, + c: number) { + var i = 0; +} + +var validParametersAlignment6 = function(xxx: foo, + yyy: bar) { return true; } + + +/////// + +function invalidArgumentsAlignment1() +{ + f(10, + 'abcd', 0); +} + +function invalidArgumentsAlignment2() +{ + f(10, + 'abcd', + 0); +} + +class Foo { + constructor(a: number, + str: string) + { + } +} + +var invalidConstructorArgsAlignment = new foo(10, + "abcd"); + +function validArgumentsAlignment1() +{ + f(101, 'xyz', 'abc'); +} + +function validArgumentsAlignment2() +{ + f(1, + 2, + 3, + 4); +} + +function validArgumentsAlignment3() +{ + f( + 1, + 2, + 3, + 4); +} + +function validArgumentsAlignment3() +{ + f(1, 2, + 3, 4); +} + +//////// + +function invalidStatementsAlignment1() +{ + var i = 0; + var j = 0; + var k = 1; + ~~~~~~~~~~ [statements are not aligned] +} + +function invalidStatementsAlignment1() +{ + var i = 0; + { + var j = 0; + var k = 1; + ~~~~~~~~~~ [statements are not aligned] + } +} + +function validStatementsAlignment1() +{ + var i = 0; + var j = 0; + var k = 1; +} + +function validStatementsAlignment2() +{ + var i = 0; + { + var j = 0; + var k = 1; + } +} + +function shouldntCrash() { + let f = new Foo; +} diff --git a/test/ruleTests/align-statements/tslint.json b/test/ruleTests/align-statements/tslint.json new file mode 100644 index 00000000000..3bd25ec81d8 --- /dev/null +++ b/test/ruleTests/align-statements/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "align": [true, "statements"] + } +} diff --git a/test/ruleTests/ban/test.ts.linttest b/test/ruleTests/ban/test.ts.linttest new file mode 100644 index 00000000000..d8a1a5a89f5 --- /dev/null +++ b/test/ruleTests/ban/test.ts.linttest @@ -0,0 +1,4 @@ +console.time(); +window.toString(); + ~~~~~~~~~~~~~ [wrong error message] +console.log(); diff --git a/test/ruleTests/ban/tslint.json b/test/ruleTests/ban/tslint.json new file mode 100644 index 00000000000..37d2e217daf --- /dev/null +++ b/test/ruleTests/ban/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "ban": [true, ["window", "toString"]] + } +} diff --git a/test/tsconfig.json b/test/tsconfig.json index 888131b0575..78be81a96a5 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -15,6 +15,8 @@ "./typings/**/*.d.ts", "../src/**/*.ts", "./*.ts", + "./ruleTestRunner/*.ts", + "./ruleTestRunnerTests/*.ts", "./rules/*.ts", "./formatters/*.ts" ], @@ -27,6 +29,8 @@ "../typings/underscore.string/underscore.string.d.ts", "../typings/underscore/underscore.d.ts", "typings/chai/chai.d.ts", + "typings/colors/colors.d.ts", + "typings/diff/diff.d.ts", "typings/mocha/mocha.d.ts", "../src/configuration.ts", "../src/enableDisableRules.ts", @@ -113,8 +117,17 @@ "lint.ts", "ruleDisableEnableTests.ts", "ruleLoaderTests.ts", + "ruleTestRunner.ts", "tsxTests.ts", "utils.ts", + "ruleTestRunner/lines.ts", + "ruleTestRunner/parse.ts", + "ruleTestRunner/types.ts", + "ruleTestRunner/utils.ts", + "ruleTestRunnerTests/linesTests.ts", + "ruleTestRunnerTests/parseTests.ts", + "ruleTestRunnerTests/testData.ts", + "ruleTestRunnerTests/utilsTests.ts", "rules/alignRuleTests.ts", "rules/banRuleTests.ts", "rules/classNameRuleTests.ts", diff --git a/test/tsd.json b/test/tsd.json index 7266793fd1c..2ef63f7467b 100644 --- a/test/tsd.json +++ b/test/tsd.json @@ -9,6 +9,12 @@ }, "mocha/mocha.d.ts": { "commit": "aadd63ecae3feb76ea2d4be80511e266b5c2c4a7" + }, + "colors/colors.d.ts": { + "commit": "78ba6e41543e5ababbd1dda19797601be3c1f304" + }, + "diff/diff.d.ts": { + "commit": "78ba6e41543e5ababbd1dda19797601be3c1f304" } } } diff --git a/test/typings/colors/colors.d.ts b/test/typings/colors/colors.d.ts new file mode 100644 index 00000000000..5aa28553a39 --- /dev/null +++ b/test/typings/colors/colors.d.ts @@ -0,0 +1,123 @@ +// Type definitions for Colors.js 0.6.0-1 +// Project: https://github.com/Marak/colors.js +// Definitions by: Bart van der Schoor +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "colors" { + interface Color { + (text: string): string; + + black: Color; + red: Color; + green: Color; + yellow: Color; + blue: Color; + magenta: Color; + cyan: Color; + white: Color; + gray: Color; + grey: Color; + + bgBlack: Color; + bgRed: Color; + bgGreen: Color; + bgYellow: Color; + bgBlue: Color; + bgMagenta: Color; + bgCyan: Color; + bgWhite: Color; + + reset: Color; + bold: Color; + dim: Color; + italic: Color; + underline: Color; + inverse: Color; + hidden: Color; + strikethrough: Color; + + rainbow: Color; + zebra: Color; + america: Color; + trap: Color; + random: Color; + } + + module e { + export function setTheme(theme:any): void; + + export var black: Color; + export var red: Color; + export var green: Color; + export var yellow: Color; + export var blue: Color; + export var magenta: Color; + export var cyan: Color; + export var white: Color; + export var gray: Color; + export var grey: Color; + + export var bgBlack: Color; + export var bgRed: Color; + export var bgGreen: Color; + export var bgYellow: Color; + export var bgBlue: Color; + export var bgMagenta: Color; + export var bgCyan: Color; + export var bgWhite: Color; + + export var reset: Color; + export var bold: Color; + export var dim: Color; + export var italic: Color; + export var underline: Color; + export var inverse: Color; + export var hidden: Color; + export var strikethrough: Color; + + export var rainbow: Color; + export var zebra: Color; + export var america: Color; + export var trap: Color; + export var random: Color; + } + + export = e; +} + +interface String { + black: string; + red: string; + green: string; + yellow: string; + blue: string; + magenta: string; + cyan: string; + white: string; + gray: string; + grey: string; + + bgBlack: string; + bgRed: string; + bgGreen: string; + bgYellow: string; + bgBlue: string; + bgMagenta: string; + bgCyan: string; + bgWhite: string; + + reset: string; + bold: string; + dim: string; + italic: string; + underline: string; + inverse: string; + hidden: string; + strikethrough: string; + + rainbow: string; + zebra: string; + america: string; + trap: string; + random: string; +} diff --git a/test/typings/diff/diff.d.ts b/test/typings/diff/diff.d.ts new file mode 100644 index 00000000000..f5c2cc48f83 --- /dev/null +++ b/test/typings/diff/diff.d.ts @@ -0,0 +1,59 @@ +// Type definitions for diff +// Project: https://github.com/kpdecker/jsdiff +// Definitions by: vvakame +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module JsDiff { + interface IDiffResult { + value: string; + added?: boolean; + removed?: boolean; + } + + interface IBestPath { + newPos: number; + componenets: IDiffResult[]; + } + + class Diff { + ignoreWhitespace:boolean; + + constructor(ignoreWhitespace?:boolean); + + diff(oldString:string, newString:string):IDiffResult[]; + + pushComponent(components:IDiffResult[], value:string, added:boolean, removed:boolean):void; + + extractCommon(basePath:IBestPath, newString:string, oldString:string, diagonalPath:number):number; + + equals(left:string, right:string):boolean; + + join(left:string, right:string):string; + + tokenize(value:string):any; // return types are string or string[] + } + + function diffChars(oldStr:string, newStr:string):IDiffResult[]; + + function diffWords(oldStr:string, newStr:string):IDiffResult[]; + + function diffWordsWithSpace(oldStr:string, newStr:string):IDiffResult[]; + + function diffJson(oldObj: Object, newObj: Object): IDiffResult[]; + + function diffLines(oldStr:string, newStr:string):IDiffResult[]; + + function diffCss(oldStr:string, newStr:string):IDiffResult[]; + + function createPatch(fileName:string, oldStr:string, newStr:string, oldHeader:string, newHeader:string):string; + + function applyPatch(oldStr:string, uniDiff:string):string; + + function convertChangesToXML(changes:IDiffResult[]):string; + + function convertChangesToDMP(changes:IDiffResult[]):{0: number; 1:string;}[]; +} + +declare module "diff" { + export = JsDiff; +} From b92d1611080780a767401a08c0027b17153cd28f Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Fri, 18 Dec 2015 11:44:31 -0500 Subject: [PATCH 02/30] Switch to 0-based indexing for line and col numbers since that's how TSLint does stuff --- test/ruleTestRunner.ts | 29 +++++++++++++++++--------- test/ruleTestRunner/lines.ts | 10 ++++----- test/ruleTestRunner/parse.ts | 25 +++++++++++----------- test/ruleTestRunnerTests/linesTests.ts | 4 ++-- test/ruleTestRunnerTests/testData.ts | 16 +++++++------- 5 files changed, 46 insertions(+), 38 deletions(-) diff --git a/test/ruleTestRunner.ts b/test/ruleTestRunner.ts index 89c399619a5..8709ebf3e85 100644 --- a/test/ruleTestRunner.ts +++ b/test/ruleTestRunner.ts @@ -24,26 +24,31 @@ import * as Linter from "../src/tslint"; import * as parse from "./ruleTestRunner/parse"; import {LintError} from "./ruleTestRunner/types"; -console.log(); -console.log(colors.underline("Testing Lint Rules:")); - const EXTENSION = ".linttest"; + // needed to get colors to show up when passing through Grunt (colors as any).enabled = true; +console.log(); +console.log(colors.underline("Testing Lint Rules:")); + +let hadTestFailure = false; const testDirectories = glob.sync("test/ruleTests/*"); + for (const testDirectory of testDirectories) { const filesToLint = glob.sync(path.join(testDirectory, `**/*${EXTENSION}`)); - const configuration = JSON.parse(fs.readFileSync(path.join(testDirectory, "tslint.json"), "utf8")); + const tslintConfig = JSON.parse(fs.readFileSync(path.join(testDirectory, "tslint.json"), "utf8")); + for (const fileToLint of filesToLint) { process.stdout.write(`${fileToLint}:`); + const baseFilename = path.basename(fileToLint, ".linttest"); const fileData = fs.readFileSync(fileToLint, "utf8"); const fileDataWithoutMarkup = parse.removeErrorMarkup(fileData); const errorsFromMarkup = parse.parseErrorsFromMarkup(fileData); const options = { - configuration, + configuration: tslintConfig, formatter: "prose", formattersDirectory: "", rulesDirectory: "", @@ -51,10 +56,10 @@ for (const testDirectory of testDirectories) { const linter = new Linter(baseFilename, fileDataWithoutMarkup, options); const errorsFromLinter: LintError[] = linter.lint().failures.map((failure) => { - const startCol = failure.getStartPosition().getLineAndCharacter().character + 1; - const startLine = failure.getStartPosition().getLineAndCharacter().line + 1; - const endCol = failure.getEndPosition().getLineAndCharacter().character + 1; - const endLine = failure.getEndPosition().getLineAndCharacter().line + 1; + const startCol = failure.getStartPosition().getLineAndCharacter().character; + const startLine = failure.getStartPosition().getLineAndCharacter().line; + const endCol = failure.getEndPosition().getLineAndCharacter().character; + const endLine = failure.getEndPosition().getLineAndCharacter().line; return { endPos: { col: endCol, line: endLine }, @@ -76,6 +81,8 @@ for (const testDirectory of testDirectories) { console.log(colors.red("Expected (from .linttest file)")); console.log(colors.green("Actual (from TSLint)")); + hadTestFailure = true; + for (const diffResult of diffResults) { let text: string; if (diffResult.added) { @@ -92,4 +99,6 @@ for (const testDirectory of testDirectories) { } } -process.exit(0); +if (hadTestFailure) { + process.exit(1); +} diff --git a/test/ruleTestRunner/lines.ts b/test/ruleTestRunner/lines.ts index 1994ab908be..4bef33fcfbb 100644 --- a/test/ruleTestRunner/lines.ts +++ b/test/ruleTestRunner/lines.ts @@ -37,12 +37,12 @@ export function classifyLine(line: string): Line { /* tslint:disable:no-conditional-assignment */ if (line.match(multilineErrorRegex)) { // 1-based indexing for line and column numbers - const startErrorCol = line.indexOf("~") + 1; + const startErrorCol = line.indexOf("~"); return new MultilineErrorLine(startErrorCol); } else if (matches = line.match(endErrorRegex)) { - const startErrorCol = line.indexOf("~") + 1; + const startErrorCol = line.indexOf("~"); // exclusive endpoint - const endErrorCol = line.lastIndexOf("~") + 2; + const endErrorCol = line.lastIndexOf("~") + 1; const [, message] = matches; return new EndErrorLine(startErrorCol, endErrorCol, message); } else { @@ -52,13 +52,13 @@ export function classifyLine(line: string): Line { } export function createErrorString(code: string, errorLine: ErrorLine) { - const startSpaces = strMult(" ", errorLine.startCol - 1); + const startSpaces = strMult(" ", errorLine.startCol); if (errorLine instanceof MultilineErrorLine) { const tildes = strMult("~", code.length - startSpaces.length); return `${startSpaces}${tildes}`; } else if (errorLine instanceof EndErrorLine) { const tildes = strMult("~", errorLine.endCol - errorLine.startCol); - const endSpaces = strMult(" ", code.length - errorLine.endCol + 1); + const endSpaces = strMult(" ", code.length - errorLine.endCol); return `${startSpaces}${tildes}${endSpaces} [${errorLine.message}]`; } } diff --git a/test/ruleTestRunner/parse.ts b/test/ruleTestRunner/parse.ts index b976327ccb1..3c763b1eef4 100644 --- a/test/ruleTestRunner/parse.ts +++ b/test/ruleTestRunner/parse.ts @@ -48,8 +48,7 @@ export function parseErrorsFromMarkup(text: string): LintError[] { const lintErrors: LintError[] = []; // for each line of code... - for (let lineNo = 1; lineNo <= lineErrorMap.length; ++lineNo) { - const errorLines = lineErrorMap[lineNo - 1]; + lineErrorMap.forEach((errorLines, lineNo) => { // for each error marking on that line... while (errorLines.length > 0) { @@ -64,18 +63,18 @@ export function parseErrorsFromMarkup(text: string): LintError[] { message: errorLine.message }); - // if the error is the start of a multiline error + // if the error is the start of a multiline error } else if (errorLine instanceof MultilineErrorLine) { // keep going until we get to the end of the multiline error for (let endLineNo = lineNo + 1; ; ++endLineNo) { - if (endLineNo > lineErrorMap.length - || lineErrorMap[endLineNo - 1].length === 0 - || lineErrorMap[endLineNo - 1][0].startCol !== 1) { + if (endLineNo >= lineErrorMap.length + || lineErrorMap[endLineNo].length === 0 + || lineErrorMap[endLineNo][0].startCol !== 0) { throw lintSyntaxError( `Error mark starting at ${errorStartPos.line}:${errorStartPos.col} does not end correctly.` ); } else { - const nextErrorLine = lineErrorMap[endLineNo - 1].shift(); + const nextErrorLine = lineErrorMap[endLineNo].shift(); // if end of multiline error, add it it list of errors if (nextErrorLine instanceof EndErrorLine) { @@ -90,7 +89,7 @@ export function parseErrorsFromMarkup(text: string): LintError[] { } } } - } + }); // sort errors by startPos then endPos lintErrors.sort(errorComparator); @@ -107,17 +106,17 @@ export function createMarkupFromErrors(code: string, lintErrors: LintError[]) { for (const error of lintErrors) { const {startPos, endPos, message} = error; if (startPos.line === endPos.line) { // single line error - lineErrorMap[startPos.line - 1].push(new EndErrorLine( + lineErrorMap[startPos.line].push(new EndErrorLine( startPos.col, endPos.col, message )); } else { // multiline error - lineErrorMap[startPos.line - 1].push(new MultilineErrorLine(startPos.col)); - for (let lineNo = startPos.line; lineNo < endPos.line - 1; ++lineNo) { - lineErrorMap[lineNo].push(new MultilineErrorLine(1)); + lineErrorMap[startPos.line].push(new MultilineErrorLine(startPos.col)); + for (let lineNo = startPos.line + 1; lineNo < endPos.line; ++lineNo) { + lineErrorMap[lineNo].push(new MultilineErrorLine(0)); } - lineErrorMap[endPos.line - 1].push(new EndErrorLine(1, endPos.col, message)); + lineErrorMap[endPos.line].push(new EndErrorLine(0, endPos.col, message)); } } diff --git a/test/ruleTestRunnerTests/linesTests.ts b/test/ruleTestRunnerTests/linesTests.ts index 031142a33e2..8175d105a08 100644 --- a/test/ruleTestRunnerTests/linesTests.ts +++ b/test/ruleTestRunnerTests/linesTests.ts @@ -22,12 +22,12 @@ describe("Rule Test Runner", () => { it("should correctly create strings", () => { const code1 = "this is a line of code"; const errorMarkup1 = " ~~~~~~~~~~~~~~~~~~~~"; - const errorLine1 = new lines.MultilineErrorLine(3); + const errorLine1 = new lines.MultilineErrorLine(2); assert.equal(lines.createErrorString(code1, errorLine1), errorMarkup1); const code2 = "another line of code here"; const errorMarkup2 = "~~~~~~~~~~~~~~~~~~~~~~~~~ [foo]"; - const errorLine2 = new lines.EndErrorLine(1, code2.length + 1, "foo"); + const errorLine2 = new lines.EndErrorLine(0, code2.length, "foo"); assert.equal(lines.createErrorString(code2, errorLine2), errorMarkup2); }); }); diff --git a/test/ruleTestRunnerTests/testData.ts b/test/ruleTestRunnerTests/testData.ts index 3cc53a3f60e..d264b2eb4a8 100644 --- a/test/ruleTestRunnerTests/testData.ts +++ b/test/ruleTestRunnerTests/testData.ts @@ -36,7 +36,7 @@ export const codeStr2 = ` A file with an error `; export const resultErrs2: LintError[] = [ - { startPos: { line: 2, col: 1 }, endPos: { line: 2, col: 6 }, message: "error" } + { startPos: { line: 1, col: 0 }, endPos: { line: 1, col: 5 }, message: "error" } ]; @@ -63,11 +63,11 @@ A file with lots of errors Final code here `; export const resultErrs3: LintError[] = [ - { startPos: { line: 2, col: 1 }, endPos: { line: 2, col: 6 }, message: "error" }, - { startPos: { line: 2, col: 4 }, endPos: { line: 4, col: 13 }, message: "multiline error1" }, - { startPos: { line: 2, col: 5 }, endPos: { line: 2, col: 18 }, message: "error2" }, - { startPos: { line: 3, col: 1 }, endPos: { line: 5, col: 3 }, message: "multiline error2" }, - { startPos: { line: 4, col: 7 }, endPos: { line: 4, col: 8 }, message: "error3" } + { startPos: { line: 1, col: 0 }, endPos: { line: 1, col: 5 }, message: "error" }, + { startPos: { line: 1, col: 3 }, endPos: { line: 3, col: 12 }, message: "multiline error1" }, + { startPos: { line: 1, col: 4 }, endPos: { line: 1, col: 17 }, message: "error2" }, + { startPos: { line: 2, col: 0 }, endPos: { line: 4, col: 2 }, message: "multiline error2" }, + { startPos: { line: 3, col: 6 }, endPos: { line: 3, col: 7 }, message: "error3" } ]; export const lintStr4 = ""; @@ -88,7 +88,7 @@ someObject.someProperty.doSomething(); someVar <- someObject.crazyMethod(arg1, arg2, arg3); `; export const resultErrs5: LintError[] = [ - { startPos: { line: 2, col: 11 }, endPos: { line: 2, col: 24 }, message: "unsafe access" }, - { startPos: { line: 2, col: 13 }, endPos: { line: 3, col: 8 }, message: "another error" } + { startPos: { line: 1, col: 10 }, endPos: { line: 1, col: 23}, message: "unsafe access" }, + { startPos: { line: 1, col: 12 }, endPos: { line: 2, col: 7 }, message: "another error" } ]; /* tslint:enable:object-literal-sort-keys */ From 97083606958f59bc8e73e6dea115cff6cc3e35e6 Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Fri, 18 Dec 2015 15:00:36 -0500 Subject: [PATCH 03/30] Add support for [shortcut]: message notation --- test/ruleTestRunner.ts | 6 +- test/ruleTestRunner/lines.ts | 9 ++- test/ruleTestRunner/parse.ts | 98 +++++++++++++++----------- test/ruleTestRunner/types.ts | 2 + test/ruleTestRunnerTests/linesTests.ts | 4 +- test/ruleTestRunnerTests/parseTests.ts | 16 +++-- test/ruleTestRunnerTests/testData.ts | 19 +++++ test/ruleTestRunnerTests/utilsTests.ts | 8 +-- 8 files changed, 107 insertions(+), 55 deletions(-) diff --git a/test/ruleTestRunner.ts b/test/ruleTestRunner.ts index 8709ebf3e85..6a30d050c4e 100644 --- a/test/ruleTestRunner.ts +++ b/test/ruleTestRunner.ts @@ -22,9 +22,7 @@ import * as path from "path"; import * as Linter from "../src/tslint"; import * as parse from "./ruleTestRunner/parse"; -import {LintError} from "./ruleTestRunner/types"; - -const EXTENSION = ".linttest"; +import {LintError, FILE_EXTENSION} from "./ruleTestRunner/types"; // needed to get colors to show up when passing through Grunt (colors as any).enabled = true; @@ -36,7 +34,7 @@ let hadTestFailure = false; const testDirectories = glob.sync("test/ruleTests/*"); for (const testDirectory of testDirectories) { - const filesToLint = glob.sync(path.join(testDirectory, `**/*${EXTENSION}`)); + const filesToLint = glob.sync(path.join(testDirectory, `**/*${FILE_EXTENSION}`)); const tslintConfig = JSON.parse(fs.readFileSync(path.join(testDirectory, "tslint.json"), "utf8")); for (const fileToLint of filesToLint) { diff --git a/test/ruleTestRunner/lines.ts b/test/ruleTestRunner/lines.ts index 4bef33fcfbb..858a56848f2 100644 --- a/test/ruleTestRunner/lines.ts +++ b/test/ruleTestRunner/lines.ts @@ -26,11 +26,15 @@ export class MultilineErrorLine { export class EndErrorLine { constructor(public startCol: number, public endCol: number, public message: string) { } } +export class MessageSubstitutionLine { + constructor(public key: string, public message: string) { } +} export type ErrorLine = MultilineErrorLine | EndErrorLine; -export type Line = CodeLine | ErrorLine; +export type Line = CodeLine | ErrorLine | MessageSubstitutionLine; const multilineErrorRegex = /^\s*~+$/; const endErrorRegex = /^\s*~+\s*\[([\w ]+)\]\s*$/; +const messageSubstitutionRegex = /^\[(\w+?)]: \s*(.+?)\s*$/; export function classifyLine(line: string): Line { let matches: RegExpMatchArray; @@ -45,6 +49,9 @@ export function classifyLine(line: string): Line { const endErrorCol = line.lastIndexOf("~") + 1; const [, message] = matches; return new EndErrorLine(startErrorCol, endErrorCol, message); + } else if (matches = line.match(messageSubstitutionRegex)) { + const [, key, message] = matches; + return new MessageSubstitutionLine(key, message); } else { return new CodeLine(line); } diff --git a/test/ruleTestRunner/parse.ts b/test/ruleTestRunner/parse.ts index 3c763b1eef4..456c14074df 100644 --- a/test/ruleTestRunner/parse.ts +++ b/test/ruleTestRunner/parse.ts @@ -14,8 +14,8 @@ * limitations under the License. */ -import {LintError, errorComparator, lintSyntaxError} from "./types"; -import {ErrorLine, CodeLine, MultilineErrorLine, EndErrorLine, classifyLine, createErrorString} from "./lines"; +import {LintError, FILE_EXTENSION, errorComparator, lintSyntaxError} from "./types"; +import {ErrorLine, CodeLine, MultilineErrorLine, EndErrorLine, MessageSubstitutionLine, classifyLine, createErrorString} from "./lines"; export function removeErrorMarkup(text: string): string { const textLines = text.split("\n"); @@ -27,61 +27,67 @@ export function removeErrorMarkup(text: string): string { /* tslint:disable:object-literal-sort-keys */ export function parseErrorsFromMarkup(text: string): LintError[] { const textLines = text.split("\n"); - const lines = textLines.map(classifyLine); + const classifiedLines = textLines.map(classifyLine); - if (lines.length > 0 && !(lines[0] instanceof CodeLine)) { - throw lintSyntaxError("Cannot start a lint file with an error mark line."); + if (classifiedLines.length > 0 && !(classifiedLines[0] instanceof CodeLine)) { + throw lintSyntaxError(`Cannot start a ${FILE_EXTENSION} file with an error mark line.`); } - // map each line of code to the error markings beneath it - let lineIndex = -1; - const lineErrorMap: ErrorLine[][] = []; - for (const line of lines) { + const messageSubstitutionLines = classifiedLines.filter((l) => l instanceof MessageSubstitutionLine); + const messageSubstitutions = messageSubstitutionLines.reduce((obj, line) => { + obj[line.key] = line.message; + return obj; + }, {}); + + // map each actual line of code to the error markings beneath it + const errorMarkupForLinesOfCode = classifiedLines.reduce((lineMap, line) => { if (line instanceof CodeLine) { - lineIndex++; - lineErrorMap[lineIndex] = []; + lineMap.push([]); + } else if (line instanceof MessageSubstitutionLine) { + // do nothing, already processed above } else { - lineErrorMap[lineIndex].push(line); + lineMap[lineMap.length - 1].push(line); } - } + return lineMap; + }, ( [])); + const lintErrors: LintError[] = []; // for each line of code... - lineErrorMap.forEach((errorLines, lineNo) => { + errorMarkupForLinesOfCode.forEach((errorMarkupForLineOfCode, lineNo) => { // for each error marking on that line... - while (errorLines.length > 0) { - const errorLine = errorLines.shift(); - const errorStartPos = { line: lineNo, col: errorLine.startCol }; + while (errorMarkupForLineOfCode.length > 0) { + const errorMarkup = errorMarkupForLineOfCode.shift(); + const errorStartPos = { line: lineNo, col: errorMarkup.startCol }; // if the error starts and ends on this line, add it now to list of errors - if (errorLine instanceof EndErrorLine) { + if (errorMarkup instanceof EndErrorLine) { lintErrors.push({ startPos: errorStartPos, - endPos: { line: lineNo, col: errorLine.endCol }, - message: errorLine.message + endPos: { line: lineNo, col: errorMarkup.endCol }, + message: getFullMessage(messageSubstitutions, errorMarkup.message) }); - // if the error is the start of a multiline error - } else if (errorLine instanceof MultilineErrorLine) { + // if the error is the start of a multiline error + } else if (errorMarkup instanceof MultilineErrorLine) { + // keep going until we get to the end of the multiline error - for (let endLineNo = lineNo + 1; ; ++endLineNo) { - if (endLineNo >= lineErrorMap.length - || lineErrorMap[endLineNo].length === 0 - || lineErrorMap[endLineNo][0].startCol !== 0) { + for (let nextLineNo = lineNo + 1; ; ++nextLineNo) { + if (!validErrorMarkupContinuation(errorMarkupForLinesOfCode, nextLineNo)) { throw lintSyntaxError( `Error mark starting at ${errorStartPos.line}:${errorStartPos.col} does not end correctly.` ); } else { - const nextErrorLine = lineErrorMap[endLineNo].shift(); + const nextErrorLine = errorMarkupForLinesOfCode[nextLineNo].shift(); // if end of multiline error, add it it list of errors if (nextErrorLine instanceof EndErrorLine) { lintErrors.push({ startPos: errorStartPos, - endPos: { line: endLineNo, col: nextErrorLine.endCol }, - message: nextErrorLine.message + endPos: { line: nextLineNo, col: nextErrorLine.endCol }, + message: getFullMessage(messageSubstitutions, nextErrorLine.message) }); break; } @@ -102,31 +108,43 @@ export function createMarkupFromErrors(code: string, lintErrors: LintError[]) { lintErrors.sort(errorComparator); const codeLines = code.split("\n"); - const lineErrorMap: ErrorLine[][] = codeLines.map(() => []); + const errorMarkupForLinesOfCode: ErrorLine[][] = codeLines.map(() => []); + for (const error of lintErrors) { const {startPos, endPos, message} = error; + if (startPos.line === endPos.line) { // single line error - lineErrorMap[startPos.line].push(new EndErrorLine( + errorMarkupForLinesOfCode[startPos.line].push(new EndErrorLine( startPos.col, endPos.col, message )); } else { // multiline error - lineErrorMap[startPos.line].push(new MultilineErrorLine(startPos.col)); + errorMarkupForLinesOfCode[startPos.line].push(new MultilineErrorLine(startPos.col)); for (let lineNo = startPos.line + 1; lineNo < endPos.line; ++lineNo) { - lineErrorMap[lineNo].push(new MultilineErrorLine(0)); + errorMarkupForLinesOfCode[lineNo].push(new MultilineErrorLine(0)); } - lineErrorMap[endPos.line].push(new EndErrorLine(0, endPos.col, message)); + errorMarkupForLinesOfCode[endPos.line].push(new EndErrorLine(0, endPos.col, message)); } } - let resultLines: string[] = []; - codeLines.forEach((codeLine, i) => { - resultLines.push(codeLine); - for (let errorLine of lineErrorMap[i]) { - resultLines.push(createErrorString(codeLine, errorLine)); + const resultLines = codeLines.reduce((finalLines, codeLine, i) => { + finalLines.push(codeLine); + for (const errorMarkup of errorMarkupForLinesOfCode[i]) { + finalLines.push(createErrorString(codeLine, errorMarkup)); } - }); + return finalLines; + }, []); return resultLines.join("\n"); } + +function getFullMessage(messageSubstitutions: {[k: string]: string}, message: string) { + return messageSubstitutions[message] || message; +} + +function validErrorMarkupContinuation(errorMarkupForLinesOfCode: ErrorLine[][], lineNo: number) { + return lineNo < errorMarkupForLinesOfCode.length + && errorMarkupForLinesOfCode[lineNo].length !== 0 + && errorMarkupForLinesOfCode[lineNo][0].startCol === 0; +} /* tslint:enable:object-literal-sort-keys */ diff --git a/test/ruleTestRunner/types.ts b/test/ruleTestRunner/types.ts index 0aca220ed97..48f71d7a664 100644 --- a/test/ruleTestRunner/types.ts +++ b/test/ruleTestRunner/types.ts @@ -14,6 +14,8 @@ * limitations under the License. */ +export const FILE_EXTENSION = ".linttest"; + export interface PositionInFile { line: number; col: number; diff --git a/test/ruleTestRunnerTests/linesTests.ts b/test/ruleTestRunnerTests/linesTests.ts index 8175d105a08..c167106ed8b 100644 --- a/test/ruleTestRunnerTests/linesTests.ts +++ b/test/ruleTestRunnerTests/linesTests.ts @@ -23,12 +23,12 @@ describe("Rule Test Runner", () => { const code1 = "this is a line of code"; const errorMarkup1 = " ~~~~~~~~~~~~~~~~~~~~"; const errorLine1 = new lines.MultilineErrorLine(2); - assert.equal(lines.createErrorString(code1, errorLine1), errorMarkup1); + assert.strictEqual(lines.createErrorString(code1, errorLine1), errorMarkup1); const code2 = "another line of code here"; const errorMarkup2 = "~~~~~~~~~~~~~~~~~~~~~~~~~ [foo]"; const errorLine2 = new lines.EndErrorLine(0, code2.length, "foo"); - assert.equal(lines.createErrorString(code2, errorLine2), errorMarkup2); + assert.strictEqual(lines.createErrorString(code2, errorLine2), errorMarkup2); }); }); }); diff --git a/test/ruleTestRunnerTests/parseTests.ts b/test/ruleTestRunnerTests/parseTests.ts index 40cfce1553f..3404a919ac4 100644 --- a/test/ruleTestRunnerTests/parseTests.ts +++ b/test/ruleTestRunnerTests/parseTests.ts @@ -21,15 +21,19 @@ describe("Rule Test Runner", () => { describe("parse", () => { describe("::removeErrorMarkup", () => { it("should return the contents of a regular string unchanged", () => { - assert.equal(parse.removeErrorMarkup(testData.lintStr1), testData.codeStr1); + assert.strictEqual(parse.removeErrorMarkup(testData.lintStr1), testData.codeStr1); }); it("should remove a single-line error markup correctly", () => { - assert.equal(parse.removeErrorMarkup(testData.lintStr2), testData.codeStr2); + assert.strictEqual(parse.removeErrorMarkup(testData.lintStr2), testData.codeStr2); }); it("should remove a mix of error markup correctly", () => { - assert.equal(parse.removeErrorMarkup(testData.lintStr3), testData.codeStr3); + assert.strictEqual(parse.removeErrorMarkup(testData.lintStr3), testData.codeStr3); + }); + + it("should handle message substitutions correctly", () => { + assert.strictEqual(parse.removeErrorMarkup(testData.lintStr6), testData.codeStr6); }); }); @@ -45,11 +49,15 @@ describe("Rule Test Runner", () => { it("should find a mix of errors correctly", () => { assert.deepEqual(parse.parseErrorsFromMarkup(testData.lintStr3), testData.resultErrs3); }); + + it("should handle message substitutions correctly", () => { + assert.deepEqual(parse.parseErrorsFromMarkup(testData.lintStr6), testData.resultErrs6); + }); }); describe("::createMarkupFromErrors", () => { it("should generate correct markup", () => { - assert.equal(parse.createMarkupFromErrors(testData.codeStr5, testData.resultErrs5), testData.lintStr5); + assert.strictEqual(parse.createMarkupFromErrors(testData.codeStr5, testData.resultErrs5), testData.lintStr5); }); }); }); diff --git a/test/ruleTestRunnerTests/testData.ts b/test/ruleTestRunnerTests/testData.ts index d264b2eb4a8..70fbc5054c5 100644 --- a/test/ruleTestRunnerTests/testData.ts +++ b/test/ruleTestRunnerTests/testData.ts @@ -91,4 +91,23 @@ export const resultErrs5: LintError[] = [ { startPos: { line: 1, col: 10 }, endPos: { line: 1, col: 23}, message: "unsafe access" }, { startPos: { line: 1, col: 12 }, endPos: { line: 2, col: 7 }, message: "another error" } ]; + +export const lintStr6 = ` +if (code === lint-error-free) { + ~~~~~~~~~~~~~~~ [err] +} + +[err]: A longer error message I didn't want to type every time! +`; +export const codeStr6 = ` +if (code === lint-error-free) { +} + +`; +export const resultErrs6: LintError[] = [ + { startPos: { line: 1, col: 13 }, endPos: { line: 1, col: 28 }, message: "A longer error message I didn't want to type every time!" }, +]; + + + /* tslint:enable:object-literal-sort-keys */ diff --git a/test/ruleTestRunnerTests/utilsTests.ts b/test/ruleTestRunnerTests/utilsTests.ts index b366cfacf9c..e9356d7ff4d 100644 --- a/test/ruleTestRunnerTests/utilsTests.ts +++ b/test/ruleTestRunnerTests/utilsTests.ts @@ -20,10 +20,10 @@ describe("Rule Test Runner", () => { describe("utils", () => { describe("::strMult", () => { it("should duplicate strings correctly", () => { - assert.equal("xxxxx", utils.strMult("x", 5)); - assert.equal("", utils.strMult("abc", 0)); - assert.equal("abcabcabc", utils.strMult("abc", 3)); - assert.equal("one", utils.strMult("one", 1)); + assert.strictEqual("xxxxx", utils.strMult("x", 5)); + assert.strictEqual("", utils.strMult("abc", 0)); + assert.strictEqual("abcabcabc", utils.strMult("abc", 3)); + assert.strictEqual("one", utils.strMult("one", 1)); }); }); }); From ebf2a1151b36f50e76a93577dde8eddd13e5be18 Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Fri, 18 Dec 2015 15:36:45 -0500 Subject: [PATCH 04/30] Add more tests for rules Fix bug where messages couldn't have punctuation Fix bug where errors wouldn't be sorted with a total ordering (sort by message) --- test/ruleTestRunner/lines.ts | 2 +- test/ruleTestRunner/types.ts | 4 +- test/ruleTestRunnerTests/testData.ts | 4 +- test/ruleTests/ban/test.ts.linttest | 2 +- test/ruleTests/class-name/test.ts.linttest | 17 ++++ test/ruleTests/class-name/tslint.json | 5 ++ .../comment-format-lower/test.ts.linttest | 22 +++++ .../comment-format-lower/tslint.json | 5 ++ .../comment-format-upper/test.ts.linttest | 22 +++++ .../comment-format-upper/tslint.json | 5 ++ test/ruleTests/curly/test.ts.linttest | 81 +++++++++++++++++++ test/ruleTests/curly/tslint.json | 5 ++ 12 files changed, 169 insertions(+), 5 deletions(-) create mode 100644 test/ruleTests/class-name/test.ts.linttest create mode 100644 test/ruleTests/class-name/tslint.json create mode 100644 test/ruleTests/comment-format-lower/test.ts.linttest create mode 100644 test/ruleTests/comment-format-lower/tslint.json create mode 100644 test/ruleTests/comment-format-upper/test.ts.linttest create mode 100644 test/ruleTests/comment-format-upper/tslint.json create mode 100644 test/ruleTests/curly/test.ts.linttest create mode 100644 test/ruleTests/curly/tslint.json diff --git a/test/ruleTestRunner/lines.ts b/test/ruleTestRunner/lines.ts index 858a56848f2..02125d5694f 100644 --- a/test/ruleTestRunner/lines.ts +++ b/test/ruleTestRunner/lines.ts @@ -33,7 +33,7 @@ export type ErrorLine = MultilineErrorLine | EndErrorLine; export type Line = CodeLine | ErrorLine | MessageSubstitutionLine; const multilineErrorRegex = /^\s*~+$/; -const endErrorRegex = /^\s*~+\s*\[([\w ]+)\]\s*$/; +const endErrorRegex = /^\s*~+\s*\[(.+)\]\s*$/; const messageSubstitutionRegex = /^\[(\w+?)]: \s*(.+?)\s*$/; export function classifyLine(line: string): Line { diff --git a/test/ruleTestRunner/types.ts b/test/ruleTestRunner/types.ts index 48f71d7a664..15221ee5703 100644 --- a/test/ruleTestRunner/types.ts +++ b/test/ruleTestRunner/types.ts @@ -39,8 +39,10 @@ export function errorComparator(err1: LintError, err2: LintError) { return err1.startPos.col - err2.startPos.col; } else if (err1.endPos.line !== err2.endPos.line) { return err1.endPos.line - err2.endPos.line; - } else { + } else if (err1.endPos.col !== err2.endPos.col) { return err1.endPos.col - err2.endPos.col; + } else { + return err1.message.localeCompare(err2.message); } } diff --git a/test/ruleTestRunnerTests/testData.ts b/test/ruleTestRunnerTests/testData.ts index 70fbc5054c5..6a10e74bbef 100644 --- a/test/ruleTestRunnerTests/testData.ts +++ b/test/ruleTestRunnerTests/testData.ts @@ -51,7 +51,7 @@ A file with lots of errors And more code here ~~~~~~~~~~~~ [multiline error1] ~~~~~~~~~~~~~~~~~~~~~ - ~ [error3] + ~ [error3: fun] Final code here ~~ [multiline error2] `; @@ -67,7 +67,7 @@ export const resultErrs3: LintError[] = [ { startPos: { line: 1, col: 3 }, endPos: { line: 3, col: 12 }, message: "multiline error1" }, { startPos: { line: 1, col: 4 }, endPos: { line: 1, col: 17 }, message: "error2" }, { startPos: { line: 2, col: 0 }, endPos: { line: 4, col: 2 }, message: "multiline error2" }, - { startPos: { line: 3, col: 6 }, endPos: { line: 3, col: 7 }, message: "error3" } + { startPos: { line: 3, col: 6 }, endPos: { line: 3, col: 7 }, message: "error3: fun" } ]; export const lintStr4 = ""; diff --git a/test/ruleTests/ban/test.ts.linttest b/test/ruleTests/ban/test.ts.linttest index d8a1a5a89f5..f3f3c0f9ccd 100644 --- a/test/ruleTests/ban/test.ts.linttest +++ b/test/ruleTests/ban/test.ts.linttest @@ -1,4 +1,4 @@ console.time(); window.toString(); - ~~~~~~~~~~~~~ [wrong error message] +~~~~~~~~~~~~~~~ [function invocation disallowed: window.toString] console.log(); diff --git a/test/ruleTests/class-name/test.ts.linttest b/test/ruleTests/class-name/test.ts.linttest new file mode 100644 index 00000000000..b186f4d2b9e --- /dev/null +++ b/test/ruleTests/class-name/test.ts.linttest @@ -0,0 +1,17 @@ +class ValidClassName { + +} + +class invalidClassName { + ~~~~~~~~~~~~~~~~ [0] +} + +class Another_Invalid_Class_Name { + ~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] +} + +export default class { + // should not fail +} + +[0]: name must be in pascal case \ No newline at end of file diff --git a/test/ruleTests/class-name/tslint.json b/test/ruleTests/class-name/tslint.json new file mode 100644 index 00000000000..fcaed86a61e --- /dev/null +++ b/test/ruleTests/class-name/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "class-name": true + } +} diff --git a/test/ruleTests/comment-format-lower/test.ts.linttest b/test/ruleTests/comment-format-lower/test.ts.linttest new file mode 100644 index 00000000000..467d630bed5 --- /dev/null +++ b/test/ruleTests/comment-format-lower/test.ts.linttest @@ -0,0 +1,22 @@ +class Clazz { // this comment is correct + /* block comment + * adada + */ + public funcxion() { // This comment has a capital letter starting it + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [lower] + //This comment is on its own line, and starts with a capital _and_ no space + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [lower] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [space] + console.log("test"); //this comment has no space + ~~~~~~~~~~~~~~~~~~~~~~~~~ [space] + } + /// +} + +//#region test +//#endregion + +`${location.protocol}//${location.hostname}` + +[lower]: comment must start with lowercase letter +[space]: comment must start with a space \ No newline at end of file diff --git a/test/ruleTests/comment-format-lower/tslint.json b/test/ruleTests/comment-format-lower/tslint.json new file mode 100644 index 00000000000..b5c3658ef21 --- /dev/null +++ b/test/ruleTests/comment-format-lower/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "comment-format": [true, "check-space", "check-lowercase"] + } +} diff --git a/test/ruleTests/comment-format-upper/test.ts.linttest b/test/ruleTests/comment-format-upper/test.ts.linttest new file mode 100644 index 00000000000..109fcc2eb1e --- /dev/null +++ b/test/ruleTests/comment-format-upper/test.ts.linttest @@ -0,0 +1,22 @@ +class Clazz { // This comment is correct + /* block comment + * adada + */ + public funcxion() { // this comment has a lowercase letter starting it + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [upper] + //this comment is on its own line, and starts with a lowercase _and_ no space + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [upper] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [space] + console.log("test"); //This comment has no space + ~~~~~~~~~~~~~~~~~~~~~~~~~ [space] + } + /// +} + +//#region test +//#endregion + +`${location.protocol}//${location.hostname}` + +[upper]: comment must start with uppercase letter +[space]: comment must start with a space \ No newline at end of file diff --git a/test/ruleTests/comment-format-upper/tslint.json b/test/ruleTests/comment-format-upper/tslint.json new file mode 100644 index 00000000000..acb87406447 --- /dev/null +++ b/test/ruleTests/comment-format-upper/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "comment-format": [true, "check-space", "check-uppercase"] + } +} diff --git a/test/ruleTests/curly/test.ts.linttest b/test/ruleTests/curly/test.ts.linttest new file mode 100644 index 00000000000..54a6099cc81 --- /dev/null +++ b/test/ruleTests/curly/test.ts.linttest @@ -0,0 +1,81 @@ +if (x == 3) { + console.log("x"); +} + +if (y == 4) +{ + console.log("y"); +} + + if (z == 5) // failure + ~~~~~~~~~~~~~~~~~~~~~~ + console.log("z"); +~~~~~~~~~~~~~~~~~~~~~~~~~ [if statements must be braced] + +for (i = 0; i < 1; ++i) { + console.log("i"); +} + +for (j = 0; j < 1; ++j) +{ + console.log("j"); +} + + for (k = 0; k < 1; ++k) // failure + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + console.log("k"); +~~~~~~~~~~~~~~~~~~~~~~~ [for statements must be braced] + +for (k in l) // failure +~~~~~~~~~~~~~~~~~~~~~~~ + console.log("l"); +~~~~~~~~~~~~~~~~~~~~~ [for statements must be braced] + +while (m < 0) { + console.log("q"); +} + +while (n < 0) +{ + console.log("r"); +} + +while (n < 0) // failure +~~~~~~~~~~~~~~~~~~~~~~~~ + console.log("s"); +~~~~~~~~~~~~~~~~~~~~~ [while statements must be braced] + +do { + console.log("m"); +} while (i == 1); + +do +{ + console.log("n"); +} +while (j == 1); + +do // failure +~~~~~~~~~~~~~ + console.log("o"); +~~~~~~~~~~~~~~~~~~~~~ +while (k == 1); +~~~~~~~~~~~~~~~ [do statements must be braced] + +if (true) { + console.log("x"); +} else console.log("y"); // failure + ~~~~~~~~~~~~~~~~~~~~~~ [else statements must be braced] + +if (true) { + console.log("x"); +} else if (true) {console.log("y")}; + +for (let x of [1, 2, 3]) { + console.log(x); +} + +for (let y of [1, 2, 3]) // failure +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + console.log(y); +~~~~~~~~~~~~~~~~~~~ [for statements must be braced] diff --git a/test/ruleTests/curly/tslint.json b/test/ruleTests/curly/tslint.json new file mode 100644 index 00000000000..c0855ef9fd0 --- /dev/null +++ b/test/ruleTests/curly/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "curly": true + } +} From a9d6b615a44675c2da4e28fc628086b389d13138 Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Fri, 18 Dec 2015 15:42:31 -0500 Subject: [PATCH 05/30] Convert tests for no-debugger rule --- .../no-debugger/test.ts.linttest} | 1 + test/ruleTests/no-debugger/tslint.json | 5 ++++ test/rules/noDebuggerRuleTests.ts | 30 ------------------- 3 files changed, 6 insertions(+), 30 deletions(-) rename test/{files/rules/debug.test.ts => ruleTests/no-debugger/test.ts.linttest} (68%) create mode 100644 test/ruleTests/no-debugger/tslint.json delete mode 100644 test/rules/noDebuggerRuleTests.ts diff --git a/test/files/rules/debug.test.ts b/test/ruleTests/no-debugger/test.ts.linttest similarity index 68% rename from test/files/rules/debug.test.ts rename to test/ruleTests/no-debugger/test.ts.linttest index 8aaf7db4fe5..2f022705916 100644 --- a/test/files/rules/debug.test.ts +++ b/test/ruleTests/no-debugger/test.ts.linttest @@ -3,5 +3,6 @@ var testVariable = "debugger"; function testFunction(): number { if (testVariable === "debugger") { debugger; + ~~~~~~~~ [use of debugger statements is disallowed] } } diff --git a/test/ruleTests/no-debugger/tslint.json b/test/ruleTests/no-debugger/tslint.json new file mode 100644 index 00000000000..53e3193c563 --- /dev/null +++ b/test/ruleTests/no-debugger/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-debugger": true + } +} diff --git a/test/rules/noDebuggerRuleTests.ts b/test/rules/noDebuggerRuleTests.ts deleted file mode 100644 index 43903c4cec2..00000000000 --- a/test/rules/noDebuggerRuleTests.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - const NoDebuggerRule = TestUtils.getRule("no-debugger"); - const fileName = "rules/debug.test.ts"; - const failureString = NoDebuggerRule.FAILURE_STRING; - - it("forbids debugger statements", () => { - const actualFailures = TestUtils.applyRuleOnFile(fileName, NoDebuggerRule); - const expectedFailure = TestUtils.createFailure(fileName, [5, 9], [5, 17], failureString); - - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); -}); From a5c10371bbc363b3e2a9fbed8690ed52d965f0a4 Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Fri, 18 Dec 2015 15:56:31 -0500 Subject: [PATCH 06/30] Delete now uneeded test files --- test/files/rules/align.test.ts | 149 ------------------------- test/files/rules/ban.test.ts | 3 - test/files/rules/classname.test.ts | 15 --- test/files/rules/comment-lower.test.ts | 15 --- test/files/rules/comment-upper.test.ts | 15 --- test/files/rules/curly.test.ts | 68 ----------- test/rules/alignRuleTests.ts | 63 ----------- test/rules/banRuleTests.ts | 27 ----- test/rules/classNameRuleTests.ts | 33 ------ test/rules/commentFormatRuleTests.ts | 65 ----------- test/rules/curlyRuleTests.ts | 66 ----------- test/tsconfig.json | 6 - 12 files changed, 525 deletions(-) delete mode 100644 test/files/rules/align.test.ts delete mode 100644 test/files/rules/ban.test.ts delete mode 100644 test/files/rules/classname.test.ts delete mode 100644 test/files/rules/comment-lower.test.ts delete mode 100644 test/files/rules/comment-upper.test.ts delete mode 100644 test/files/rules/curly.test.ts delete mode 100644 test/rules/alignRuleTests.ts delete mode 100644 test/rules/banRuleTests.ts delete mode 100644 test/rules/classNameRuleTests.ts delete mode 100644 test/rules/commentFormatRuleTests.ts delete mode 100644 test/rules/curlyRuleTests.ts diff --git a/test/files/rules/align.test.ts b/test/files/rules/align.test.ts deleted file mode 100644 index 220e6d94550..00000000000 --- a/test/files/rules/align.test.ts +++ /dev/null @@ -1,149 +0,0 @@ -function invalidParametersAlignment1(a: number, -b: number) { - var i = 0; -} - -function invalidParametersAlignment2(a: number, b: number, -c: number) { - var i = 0; -} - -function invalidParametersAlignment3(a: number, - b: number, - c: number) { - var i = 0; -} - -class C1 { - invalidParametersAlignment(a: number, - b: number) - { - } -} - -class InvalidAlignmentInConstructor { - constructor(a: number, - str: string) - { - } -} - -var invalidParametersAlignment4 = function(xxx: foo, - yyy: bar) { return true; } - -function validParametersAlignment1(a: number, b: number) { - var i = 0; -} - -function validParametersAlignment2(a: number, b: number, - c: number) { - var i = 0; -} - -function validParametersAlignment3(a: number, - b: number, - c: number) { - var i = 0; -} - -function validParametersAlignment4( - a: number, - b: number, - c: number) { - var i = 0; -} - -var validParametersAlignment6 = function(xxx: foo, - yyy: bar) { return true; } - - -/////// - -function invalidArgumentsAlignment1() -{ - f(10, - 'abcd', 0); -} - -function invalidArgumentsAlignment2() -{ - f(10, - 'abcd', - 0); -} - -class Foo { - constructor(a: number, - str: string) - { - } -} - -var invalidConstructorArgsAlignment = new foo(10, - "abcd"); - -function validArgumentsAlignment1() -{ - f(101, 'xyz', 'abc'); -} - -function validArgumentsAlignment2() -{ - f(1, - 2, - 3, - 4); -} - -function validArgumentsAlignment3() -{ - f( - 1, - 2, - 3, - 4); -} - -function validArgumentsAlignment3() -{ - f(1, 2, - 3, 4); -} - -//////// - -function invalidStatementsAlignment1() -{ - var i = 0; - var j = 0; - var k = 1; -} - -function invalidStatementsAlignment1() -{ - var i = 0; - { - var j = 0; - var k = 1; - } -} - -function validStatementsAlignment1() -{ - var i = 0; - var j = 0; - var k = 1; -} - -function validStatementsAlignment2() -{ - var i = 0; - { - var j = 0; - var k = 1; - } -} - -function shouldntCrash() { - let f = new Foo; -} diff --git a/test/files/rules/ban.test.ts b/test/files/rules/ban.test.ts deleted file mode 100644 index 881b10c8b99..00000000000 --- a/test/files/rules/ban.test.ts +++ /dev/null @@ -1,3 +0,0 @@ -console.time(); -window.toString(); -console.log(); diff --git a/test/files/rules/classname.test.ts b/test/files/rules/classname.test.ts deleted file mode 100644 index 0a2eae5a0e6..00000000000 --- a/test/files/rules/classname.test.ts +++ /dev/null @@ -1,15 +0,0 @@ -class ValidClassName { - -} - -class invalidClassName { - -} - -class Another_Invalid_Class_Name { - -} - -export default class { - // should not fail -} diff --git a/test/files/rules/comment-lower.test.ts b/test/files/rules/comment-lower.test.ts deleted file mode 100644 index 28a3d402fff..00000000000 --- a/test/files/rules/comment-lower.test.ts +++ /dev/null @@ -1,15 +0,0 @@ -class Clazz { // this comment is correct - /* block comment - * adada - */ - public funcxion() { // This comment has a capital letter starting it - //This comment is on its own line, and starts with a capital _and_ no space - console.log("test"); //this comment has no space - } - /// -} - -//#region test -//#endregion - -`${location.protocol}//${location.hostname}` diff --git a/test/files/rules/comment-upper.test.ts b/test/files/rules/comment-upper.test.ts deleted file mode 100644 index 0a7ba128c18..00000000000 --- a/test/files/rules/comment-upper.test.ts +++ /dev/null @@ -1,15 +0,0 @@ -class Clazz { // This comment is correct - /* block comment - * adada - */ - public funcxion() { // this comment has a lower letter starting it - //this comment is on its own line, and starts with a lower _and_ no space - console.log("test"); //This comment has no space - } - /// -} - -//#region test -//#endregion - -`${location.protocol}//${location.hostname}` diff --git a/test/files/rules/curly.test.ts b/test/files/rules/curly.test.ts deleted file mode 100644 index 472f60dd377..00000000000 --- a/test/files/rules/curly.test.ts +++ /dev/null @@ -1,68 +0,0 @@ -if (x == 3) { - console.log("x"); -} - -if (y == 4) -{ - console.log("y"); -} - - if (z == 5) // failure - console.log("z"); - -for (i = 0; i < 1; ++i) { - console.log("i"); -} - -for (j = 0; j < 1; ++j) -{ - console.log("j"); -} - - for (k = 0; k < 1; ++k) // failure - console.log("k"); - -for (k in l) // failure - console.log("l"); - -while (m < 0) { - console.log("q"); -} - -while (n < 0) -{ - console.log("r"); -} - -while (n < 0) // failure - console.log("s"); - -do { - console.log("m"); -} while (i == 1); - -do -{ - console.log("n"); -} -while (j == 1); - -do // failure - console.log("o"); -while (k == 1); - -if (true) { - console.log("x"); -} else console.log("y"); // failure - - -if (true) { - console.log("x"); -} else if (true) {console.log("y")}; - -for (let x of [1, 2, 3]) { - console.log(x); -} - -for (let y of [1, 2, 3]) // failure - console.log(y); diff --git a/test/rules/alignRuleTests.ts b/test/rules/alignRuleTests.ts deleted file mode 100644 index e8c267d0ddc..00000000000 --- a/test/rules/alignRuleTests.ts +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - const fileName = "rules/align.test.ts"; - const AlignRule = TestUtils.getRule("align"); - - it("ensures that parameters in function signatures are aligned", () => { - const options = [true, AlignRule.PARAMETERS_OPTION]; - const failureString = AlignRule.PARAMETERS_OPTION + AlignRule.FAILURE_STRING_SUFFIX; - const createFailure = TestUtils.createFailuresOnFile(fileName, failureString); - const expectedFailures = [ - createFailure([2, 1], [2, 10]), - createFailure([7, 1], [7, 10]), - createFailure([12, 30], [12, 39]), - createFailure([19, 28], [19, 37]), - createFailure([26, 34], [26, 45]), - createFailure([32, 31], [32, 39]) - ]; - const actualFailures = TestUtils.applyRuleOnFile(fileName, AlignRule, options); - TestUtils.assertFailuresEqual(actualFailures, expectedFailures); - }); - - it("ensures that arguments in function calls are aligned", () => { - const options = [true, AlignRule.ARGUMENTS_OPTION]; - const failureString = AlignRule.ARGUMENTS_OPTION + AlignRule.FAILURE_STRING_SUFFIX; - const createFailure = TestUtils.createFailuresOnFile(fileName, failureString); - const expectedFailures = [ - createFailure([65, 5], [65, 11]), - createFailure([72, 9], [72, 10]), - createFailure([83, 14], [83, 20]) - ]; - const actualFailures = TestUtils.applyRuleOnFile(fileName, AlignRule, options); - TestUtils.assertFailuresEqual(actualFailures, expectedFailures); - }); - - it("ensures that statements at the same nesting level are aligned", () => { - const options = [true, AlignRule.STATEMENTS_OPTION]; - const failureString = AlignRule.STATEMENTS_OPTION + AlignRule.FAILURE_STRING_SUFFIX; - const createFailure = TestUtils.createFailuresOnFile(fileName, failureString); - const expectedFailures = [ - createFailure([119, 6], [119, 16]), - createFailure([127, 8], [127, 18]) - ]; - const actualFailures = TestUtils.applyRuleOnFile(fileName, AlignRule, options); - TestUtils.assertFailuresEqual(actualFailures, expectedFailures); - }); -}); diff --git a/test/rules/banRuleTests.ts b/test/rules/banRuleTests.ts deleted file mode 100644 index 2c4e38a4860..00000000000 --- a/test/rules/banRuleTests.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import {TestUtils} from "../lint"; - -describe("", () => { - const fileName = "rules/ban.test.ts"; - const BanRule = TestUtils.getRule("ban"); - - it("bans access to specified functions", () => { - const dirFailure = TestUtils.createFailuresOnFile(fileName, BanRule.FAILURE_STRING_PART + "window.toString")([2, 1], [2, 16]); - const actualFailures = TestUtils.applyRuleOnFile(fileName, BanRule, [true, ["window", "toString"]]); - TestUtils.assertContainsFailure(actualFailures, dirFailure); - }); -}); diff --git a/test/rules/classNameRuleTests.ts b/test/rules/classNameRuleTests.ts deleted file mode 100644 index 0c616e906a8..00000000000 --- a/test/rules/classNameRuleTests.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - const ClassNameRule = TestUtils.getRule("class-name"); - const fileName = "rules/classname.test.ts"; - - it("ensures class names are always pascal-cased", () => { - const createFailure = TestUtils.createFailuresOnFile(fileName, ClassNameRule.FAILURE_STRING); - const expectedFailures = [ - createFailure([5, 7], [5, 23]), - createFailure([9, 7], [9, 33]) - ]; - const actualFailures = TestUtils.applyRuleOnFile(fileName, ClassNameRule); - - TestUtils.assertFailuresEqual(actualFailures, expectedFailures); - }); -}); diff --git a/test/rules/commentFormatRuleTests.ts b/test/rules/commentFormatRuleTests.ts deleted file mode 100644 index 4c93f860ba4..00000000000 --- a/test/rules/commentFormatRuleTests.ts +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - const CommentFormatRule = TestUtils.getRule("comment-format"); - - it("ensures comments start with a space and a lowercase letter", () => { - const fileName = "rules/comment-lower.test.ts"; - const createLowercaseFailure = TestUtils.createFailuresOnFile(fileName, CommentFormatRule.LOWERCASE_FAILURE); - const createLeadingSpaceFailure = TestUtils.createFailuresOnFile(fileName, CommentFormatRule.LEADING_SPACE_FAILURE); - const expectedFailure1 = createLowercaseFailure([5, 27], [5, 73]); - const expectedFailure2 = createLowercaseFailure([6, 11], [6, 84]); - const expectedFailure3 = createLeadingSpaceFailure([6, 11], [6, 84]); - const expectedFailure4 = createLeadingSpaceFailure([7, 32], [7, 57]); - - const options = [true, - "check-space", - "check-lowercase" - ]; - const actualFailures = TestUtils.applyRuleOnFile(fileName, CommentFormatRule, options); - - TestUtils.assertContainsFailure(actualFailures, expectedFailure1); - TestUtils.assertContainsFailure(actualFailures, expectedFailure2); - TestUtils.assertContainsFailure(actualFailures, expectedFailure3); - TestUtils.assertContainsFailure(actualFailures, expectedFailure4); - assert.lengthOf(actualFailures, 4); - }); - - it("ensures comments start with a space and a uppercase letter", () => { - const fileName = "rules/comment-upper.test.ts"; - const createUppercaseFailure = TestUtils.createFailuresOnFile(fileName, CommentFormatRule.UPPERCASE_FAILURE); - const createLeadingSpaceFailure = TestUtils.createFailuresOnFile(fileName, CommentFormatRule.LEADING_SPACE_FAILURE); - const expectedFailure1 = createUppercaseFailure([5, 27], [5, 73]); - const expectedFailure2 = createUppercaseFailure([6, 11], [6, 84]); - const expectedFailure3 = createLeadingSpaceFailure([6, 11], [6, 84]); - const expectedFailure4 = createLeadingSpaceFailure([7, 32], [7, 57]); - - const options = [true, - "check-space", - "check-uppercase" - ]; - const actualFailures = TestUtils.applyRuleOnFile(fileName, CommentFormatRule, options); - - TestUtils.assertContainsFailure(actualFailures, expectedFailure1); - TestUtils.assertContainsFailure(actualFailures, expectedFailure2); - TestUtils.assertContainsFailure(actualFailures, expectedFailure3); - TestUtils.assertContainsFailure(actualFailures, expectedFailure4); - assert.lengthOf(actualFailures, 4); - }); -}); diff --git a/test/rules/curlyRuleTests.ts b/test/rules/curlyRuleTests.ts deleted file mode 100644 index 0843b7f503d..00000000000 --- a/test/rules/curlyRuleTests.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {RuleFailure, TestUtils} from "../lint"; - -describe("", () => { - const fileName = "rules/curly.test.ts"; - const CurlyRule = TestUtils.getRule("curly"); - let actualFailures: RuleFailure[]; - - before(() => { - actualFailures = TestUtils.applyRuleOnFile(fileName, CurlyRule); - }); - - it("ensures if statements are always braced", () => { - const failureString = CurlyRule.IF_FAILURE_STRING; - const expectedFailure = TestUtils.createFailure(fileName, [10, 5], [11, 26], failureString); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("ensures for statements are always braced", () => { - const failureString = CurlyRule.FOR_FAILURE_STRING; - const expectedFailure1 = TestUtils.createFailure(fileName, [22, 3], [23, 24], failureString); - const expectedFailure2 = TestUtils.createFailure(fileName, [25, 1], [26, 22], failureString); - const expectedFailure3 = TestUtils.createFailure(fileName, [67, 1], [68, 20], failureString); - - TestUtils.assertContainsFailure(actualFailures, expectedFailure1); - TestUtils.assertContainsFailure(actualFailures, expectedFailure2); - TestUtils.assertContainsFailure(actualFailures, expectedFailure3); - }); - - it("ensures while statements are always braced", () => { - const failureString = CurlyRule.WHILE_FAILURE_STRING; - const expectedFailure1 = TestUtils.createFailure(fileName, [37, 1], [38, 22], failureString); - TestUtils.assertContainsFailure(actualFailures, expectedFailure1); - }); - - it("ensures do statements are always braced", () => { - const failureString = CurlyRule.DO_FAILURE_STRING; - const expectedFailure1 = TestUtils.createFailure(fileName, [50, 1], [52, 16], failureString); - TestUtils.assertContainsFailure(actualFailures, expectedFailure1); - }); - - it("ensures else statements are always braced", () => { - const failureString = CurlyRule.ELSE_FAILURE_STRING; - const expectedFailure = TestUtils.createFailure(fileName, [56, 3], [56, 25], failureString); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("does not have false positives", () => { - assert.lengthOf(actualFailures, 7); - }); -}); diff --git a/test/tsconfig.json b/test/tsconfig.json index 78be81a96a5..acf87d7fd1c 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -128,11 +128,6 @@ "ruleTestRunnerTests/parseTests.ts", "ruleTestRunnerTests/testData.ts", "ruleTestRunnerTests/utilsTests.ts", - "rules/alignRuleTests.ts", - "rules/banRuleTests.ts", - "rules/classNameRuleTests.ts", - "rules/commentFormatRuleTests.ts", - "rules/curlyRuleTests.ts", "rules/eofLineRuleTests.ts", "rules/forInRuleTests.ts", "rules/indentRuleTests.ts", @@ -151,7 +146,6 @@ "rules/noConsoleRuleTests.ts", "rules/noConstructRuleTests.ts", "rules/noConstructorVarsRuleTests.ts", - "rules/noDebuggerRuleTests.ts", "rules/noDuplicateKeyRuleTests.ts", "rules/noDuplicateVariableRuleTests.ts", "rules/noEmptyRuleTests.ts", From 3c2420b3f20da0db8eefcf2530da8d0d14680ca1 Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Tue, 22 Dec 2015 00:11:00 -0500 Subject: [PATCH 07/30] convert tests for forin and indent rules --- .../forin/test.ts.linttest} | 11 ++ test/ruleTests/forin/tslint.json | 5 + .../indent-spaces/.test.ts.linttest.swp | Bin 0 -> 12288 bytes .../indent-spaces/test.ts.linttest} | 25 ++++ test/ruleTests/indent-spaces/tslint.json | 5 + .../indent-tabs/test.ts.linttest} | 23 +++ test/ruleTests/indent-tabs/tslint.json | 5 + test/rules/forInRuleTests.ts | 33 ----- test/rules/indentRuleTests.ts | 138 ------------------ 9 files changed, 74 insertions(+), 171 deletions(-) rename test/{files/rules/forin.test.ts => ruleTests/forin/test.ts.linttest} (67%) create mode 100644 test/ruleTests/forin/tslint.json create mode 100644 test/ruleTests/indent-spaces/.test.ts.linttest.swp rename test/{files/rules/indentwith_spaces.test.ts => ruleTests/indent-spaces/test.ts.linttest} (82%) create mode 100644 test/ruleTests/indent-spaces/tslint.json rename test/{files/rules/indentwith_tabs.test.ts => ruleTests/indent-tabs/test.ts.linttest} (85%) create mode 100644 test/ruleTests/indent-tabs/tslint.json delete mode 100644 test/rules/forInRuleTests.ts delete mode 100644 test/rules/indentRuleTests.ts diff --git a/test/files/rules/forin.test.ts b/test/ruleTests/forin/test.ts.linttest similarity index 67% rename from test/files/rules/forin.test.ts rename to test/ruleTests/forin/test.ts.linttest index 49e0345b003..a621922b16b 100644 --- a/test/files/rules/forin.test.ts +++ b/test/ruleTests/forin/test.ts.linttest @@ -1,14 +1,23 @@ function a() { for (var i in obj) { + ~~~~~~~~~~~~~~~~~~~~ console.log("i"); +~~~~~~~~~~~~~~~~~~~~~~~~~ } +~~~~~ [0] for (var j in obj) { + ~~~~~~~~~~~~~~~~~~~~ if (j === 3) { +~~~~~~~~~~~~~~~~~~~~~~ console.log("j"); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ } +~~~~~~~~~ console.log("j"); +~~~~~~~~~~~~~~~~~~~~~~~~~ } +~~~~~ [0] for (var k in obj) { if (obj.hasOwnProperty(k)) { @@ -28,3 +37,5 @@ function a() { console.log("m"); } } + +[0]: for (... in ...) statements must be filtered with an if statement diff --git a/test/ruleTests/forin/tslint.json b/test/ruleTests/forin/tslint.json new file mode 100644 index 00000000000..c7c10b4b899 --- /dev/null +++ b/test/ruleTests/forin/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "forin": true + } +} diff --git a/test/ruleTests/indent-spaces/.test.ts.linttest.swp b/test/ruleTests/indent-spaces/.test.ts.linttest.swp new file mode 100644 index 0000000000000000000000000000000000000000..a0b23738c29feaeb4166472a84d8ee381c76c990 GIT binary patch literal 12288 zcmeI2ONbmr7{@CCC2Nf4p`heat_OGX*qPZ48fQ#IBx)d056Pm$5PD{6GoAEyPr7?{ zqwB60FDh#AK~#K1V|BW_TWJ;0l|YtG>Q<^lM*qaM)3FbbkFQ$HxtBDq>BAb zS66*i_0_+szS(7~oFCq}S>H6UMv)dPb>geN!#BUTUwv@5QoDA$p65EgRCP<4-RjYD zy_?-sW|*so!7fvYqg)($t{>-O6UDi(;h8ODqMYkjjUTU$>Q2RAL)kza4Tz=WyA5IM ztO8bnxfE!`BdgagQbU772NuBD%ar;J zeuh)e?q zgYY^WfPL@~#1O(B@L(A3g)H_8h#bo zUQ(JgnS4sFT-0k?FHTVptxDb|)Rd+()ic?APfZ8aR9fDHZ6UKAb3*Ne;h+q*W73T zE7vKr#_RM@OC7m~dPl>r$oB0^oJ-r(LwC%Hjm}z?RK;_mC~@ufB-b1(8$x`L&gh*D zR#GD!owl6H%!b>}B<7<*m0Pn(@0*+136;xfaa{9LHWjCVsMptT1 z=y2vZ7=9J|M%1pG(mMkqjeX<9H7d>Mfb=?U^iC6Nhm0FmbyP7v?gYAK=y^Q(3>u+E zz6KX~L+", () => { - const ForInRule = TestUtils.getRule("forin"); - const fileName = "rules/forin.test.ts"; - const failureString = ForInRule.FAILURE_STRING; - - it("enforces filtering for the body of a for...in statement", () => { - const expectedFailures = [ - TestUtils.createFailure(fileName, [2, 5], [4, 6], failureString), - TestUtils.createFailure(fileName, [6, 5], [11, 6], failureString) - ]; - const actualFailures = TestUtils.applyRuleOnFile(fileName, ForInRule); - - TestUtils.assertFailuresEqual(actualFailures, expectedFailures); - }); -}); diff --git a/test/rules/indentRuleTests.ts b/test/rules/indentRuleTests.ts deleted file mode 100644 index 3ef5200d860..00000000000 --- a/test/rules/indentRuleTests.ts +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {RuleFailure, TestUtils} from "../lint"; - -describe("", () => { - const IndentRule = TestUtils.getRule("indent"); - const failureStringTabs = IndentRule.FAILURE_STRING_TABS; - const failureStringSpaces = IndentRule.FAILURE_STRING_SPACES; - let actualFailures: RuleFailure[]; - - function expectFailure(failure: RuleFailure) { - TestUtils.assertContainsFailure(actualFailures, failure); - } - - // checks only that the indent character is the specified one, *NOT* the size of the indent - describe("on a tab-indented file", () => { - const fileName = "rules/indentwith_tabs.test.ts"; - - before(() => { - actualFailures = TestUtils.applyRuleOnFile(fileName, IndentRule, [true, "tabs"]); - }); - - it("doesn't fail good code", () => { - assert.lengthOf(actualFailures, 21); - }); - - it("enforces variable indentation", () => { - expectFailure(TestUtils.createFailure(fileName, [61, 1], [61, 5], failureStringTabs)); - expectFailure(TestUtils.createFailure(fileName, [65, 1], [65, 9], failureStringTabs)); - expectFailure(TestUtils.createFailure(fileName, [69, 1], [69, 5], failureStringTabs)); - }); - - it("enforces class method indentation", () => { - expectFailure(TestUtils.createFailure(fileName, [71, 1], [71, 5], failureStringTabs)); - expectFailure(TestUtils.createFailure(fileName, [72, 1], [72, 8], failureStringTabs)); - expectFailure(TestUtils.createFailure(fileName, [73, 1], [73, 5], failureStringTabs)); - }); - - it("enforces object literal indentation", () => { - expectFailure(TestUtils.createFailure(fileName, [77, 1], [77, 5], failureStringTabs)); - }); - - it("enforces enum indentation", () => { - expectFailure(TestUtils.createFailure(fileName, [83, 1], [83, 5], failureStringTabs)); - }); - - it("enforces switch indentation", () => { - expectFailure(TestUtils.createFailure(fileName, [91, 1], [91, 5], failureStringTabs)); - expectFailure(TestUtils.createFailure(fileName, [92, 1], [92, 9], failureStringTabs)); - expectFailure(TestUtils.createFailure(fileName, [93, 1], [93, 9], failureStringTabs)); - expectFailure(TestUtils.createFailure(fileName, [94, 1], [94, 5], failureStringTabs)); - expectFailure(TestUtils.createFailure(fileName, [95, 1], [95, 9], failureStringTabs)); - expectFailure(TestUtils.createFailure(fileName, [96, 1], [96, 9], failureStringTabs)); - }); - - it("enforces control blocks indentation", () => { - expectFailure(TestUtils.createFailure(fileName, [100, 1], [100, 5], failureStringTabs)); - expectFailure(TestUtils.createFailure(fileName, [104, 1], [104, 5], failureStringTabs)); - expectFailure(TestUtils.createFailure(fileName, [108, 1], [108, 5], failureStringTabs)); - expectFailure(TestUtils.createFailure(fileName, [112, 1], [112, 5], failureStringTabs)); - }); - - it("enforces array literal indentation", () => { - expectFailure(TestUtils.createFailure(fileName, [116, 1], [116, 5], failureStringTabs)); - expectFailure(TestUtils.createFailure(fileName, [122, 1], [122, 9], failureStringTabs)); - expectFailure(TestUtils.createFailure(fileName, [124, 1], [124, 5], failureStringTabs)); - }); - }); - - // checks only that the indent character is the specified one, *NOT* the size of the indent - describe("on a space-indented file", () => { - const fileName = "rules/indentwith_spaces.test.ts"; - - before(() => { - actualFailures = TestUtils.applyRuleOnFile(fileName, IndentRule, [true, "spaces"]); - }); - - it("doesn't fail good code", () => { - assert.lengthOf(actualFailures, 21); - }); - - it("enforces variable indentation", () => { - expectFailure(TestUtils.createFailure(fileName, [58, 1], [58, 2], failureStringSpaces)); - expectFailure(TestUtils.createFailure(fileName, [62, 1], [62, 3], failureStringSpaces)); - expectFailure(TestUtils.createFailure(fileName, [66, 1], [66, 2], failureStringSpaces)); - }); - - it("enforces class method indentation", () => { - expectFailure(TestUtils.createFailure(fileName, [68, 1], [68, 2], failureStringSpaces)); - expectFailure(TestUtils.createFailure(fileName, [69, 1], [69, 3], failureStringSpaces)); - expectFailure(TestUtils.createFailure(fileName, [70, 1], [70, 2], failureStringSpaces)); - }); - - it("enforces object literal indentation", () => { - expectFailure(TestUtils.createFailure(fileName, [74, 1], [74, 2], failureStringSpaces)); - }); - - it("enforces enum indentation", () => { - expectFailure(TestUtils.createFailure(fileName, [80, 1], [80, 2], failureStringSpaces)); - }); - - it("enforces switch indentation", () => { - expectFailure(TestUtils.createFailure(fileName, [85, 1], [85, 2], failureStringSpaces)); - expectFailure(TestUtils.createFailure(fileName, [86, 1], [86, 3], failureStringSpaces)); - expectFailure(TestUtils.createFailure(fileName, [87, 1], [87, 3], failureStringSpaces)); - expectFailure(TestUtils.createFailure(fileName, [91, 1], [91, 2], failureStringSpaces)); - expectFailure(TestUtils.createFailure(fileName, [92, 1], [92, 3], failureStringSpaces)); - expectFailure(TestUtils.createFailure(fileName, [93, 1], [93, 3], failureStringSpaces)); - }); - - it("enforces control blocks indentation", () => { - expectFailure(TestUtils.createFailure(fileName, [97, 1], [97, 2], failureStringSpaces)); - expectFailure(TestUtils.createFailure(fileName, [101, 1], [101, 2], failureStringSpaces)); - expectFailure(TestUtils.createFailure(fileName, [105, 1], [105, 2], failureStringSpaces)); - expectFailure(TestUtils.createFailure(fileName, [109, 1], [109, 2], failureStringSpaces)); - }); - - it("enforces array literal indentation", () => { - expectFailure(TestUtils.createFailure(fileName, [113, 1], [113, 2], failureStringSpaces)); - expectFailure(TestUtils.createFailure(fileName, [119, 1], [119, 3], failureStringSpaces)); - expectFailure(TestUtils.createFailure(fileName, [121, 1], [121, 2], failureStringSpaces)); - }); - }); -}); From 520d8b69c63bee1ed679b3204f0ad83bc5e4f6c8 Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Tue, 22 Dec 2015 00:32:29 -0500 Subject: [PATCH 08/30] Convert tests for interface-name rule --- test/files/rules/interfacename.test.ts | 7 ----- .../ruleTests/interface-name/test.ts.linttest | 8 +++++ test/ruleTests/interface-name/tslint.json | 5 +++ test/rules/interfaceNameRuleTests.ts | 31 ------------------- test/tsconfig.json | 3 -- 5 files changed, 13 insertions(+), 41 deletions(-) delete mode 100644 test/files/rules/interfacename.test.ts create mode 100644 test/ruleTests/interface-name/test.ts.linttest create mode 100644 test/ruleTests/interface-name/tslint.json delete mode 100644 test/rules/interfaceNameRuleTests.ts diff --git a/test/files/rules/interfacename.test.ts b/test/files/rules/interfacename.test.ts deleted file mode 100644 index d39d382356e..00000000000 --- a/test/files/rules/interfacename.test.ts +++ /dev/null @@ -1,7 +0,0 @@ -interface IValidInterfaceName { - -} - -interface NotValidInterfaceName { - -} \ No newline at end of file diff --git a/test/ruleTests/interface-name/test.ts.linttest b/test/ruleTests/interface-name/test.ts.linttest new file mode 100644 index 00000000000..62ebefbe877 --- /dev/null +++ b/test/ruleTests/interface-name/test.ts.linttest @@ -0,0 +1,8 @@ +interface IValidInterfaceName { + +} + +interface NotValidInterfaceName { + ~~~~~~~~~~~~~~~~~~~~~ [interface name must be a capitalized I] + +} \ No newline at end of file diff --git a/test/ruleTests/interface-name/tslint.json b/test/ruleTests/interface-name/tslint.json new file mode 100644 index 00000000000..a474c87992a --- /dev/null +++ b/test/ruleTests/interface-name/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "interface-name": true + } +} diff --git a/test/rules/interfaceNameRuleTests.ts b/test/rules/interfaceNameRuleTests.ts deleted file mode 100644 index 942a2ab7d2b..00000000000 --- a/test/rules/interfaceNameRuleTests.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - const InterfaceNameRule = TestUtils.getRule("interface-name"); - const fileName = "rules/interfacename.test.ts"; - - it("ensures interface names always start with a capital I", () => { - const createFailure = TestUtils.createFailuresOnFile(fileName, InterfaceNameRule.FAILURE_STRING); - const expectedFailure1 = createFailure([5, 11], [5, 32]); - const actualFailures = TestUtils.applyRuleOnFile(fileName, InterfaceNameRule); - - TestUtils.assertContainsFailure(actualFailures, expectedFailure1); - assert.lengthOf(actualFailures, 1); - }); -}); diff --git a/test/tsconfig.json b/test/tsconfig.json index acf87d7fd1c..18444f420eb 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -129,9 +129,6 @@ "ruleTestRunnerTests/testData.ts", "ruleTestRunnerTests/utilsTests.ts", "rules/eofLineRuleTests.ts", - "rules/forInRuleTests.ts", - "rules/indentRuleTests.ts", - "rules/interfaceNameRuleTests.ts", "rules/jsdocFormatRuleTests.ts", "rules/labelPositionRuleTests.ts", "rules/labelUndefinedRuleTests.ts", From 308361c2911a394f31e58a2acd1f248b3b156b9b Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Tue, 22 Dec 2015 16:41:32 -0500 Subject: [PATCH 09/30] Convert jsdoc-format, label-position, and label-undefined rule tests --- test/files/rules/label-undefined.test.ts | 51 ------------------- test/files/rules/labelpos.test.ts | 31 ----------- .../jsdoc-format/jsdoc-windows.ts.linttest} | 0 .../jsdoc-format/jsdoc.ts.linttest} | 10 ++++ test/ruleTests/jsdoc-format/tslint.json | 5 ++ test/rules/jsdocFormatRuleTests.ts | 51 ------------------- test/rules/labelPositionRuleTests.ts | 33 ------------ test/rules/labelUndefinedRuleTests.ts | 35 ------------- test/tsconfig.json | 3 -- 9 files changed, 15 insertions(+), 204 deletions(-) delete mode 100644 test/files/rules/label-undefined.test.ts delete mode 100644 test/files/rules/labelpos.test.ts rename test/{files/rules/jsdoc-windows.test.ts => ruleTests/jsdoc-format/jsdoc-windows.ts.linttest} (100%) rename test/{files/rules/jsdoc.test.ts => ruleTests/jsdoc-format/jsdoc.ts.linttest} (81%) create mode 100644 test/ruleTests/jsdoc-format/tslint.json delete mode 100644 test/rules/jsdocFormatRuleTests.ts delete mode 100644 test/rules/labelPositionRuleTests.ts delete mode 100644 test/rules/labelUndefinedRuleTests.ts diff --git a/test/files/rules/label-undefined.test.ts b/test/files/rules/label-undefined.test.ts deleted file mode 100644 index f500dfe3350..00000000000 --- a/test/files/rules/label-undefined.test.ts +++ /dev/null @@ -1,51 +0,0 @@ -// invalid code - -function f() { - lab3: - for (var i = 0; i < 10; ++i) { - break lab1; - } -} - -var x = function() { - lab4: - while (i < 10) { - continue lab2; - } -}; - -var y = () => { - lab3: - while (i < 10) { - continue lab3; - } - - (function() { - lab2: - switch (j) { - case 1: - break lab3; - } - })(); -}; - -var z = x => { - lab1: - do { - x++; - continue lab4; - } while (x < 10); -}; - -// valid code - -lab5: -for (var i = 0; i < 10; ++i) { - var w = () => { - lab2: - while (i < 10) { - continue lab2; - } - }; - break lab5; -} diff --git a/test/files/rules/labelpos.test.ts b/test/files/rules/labelpos.test.ts deleted file mode 100644 index 4eb92216e32..00000000000 --- a/test/files/rules/labelpos.test.ts +++ /dev/null @@ -1,31 +0,0 @@ -var t = function() { - lab1: - var x = 123; - - lab2: - console.log("123"); - - lab3: - for (var i = 0; i < 5; ++i) { - break lab3; - } - - lab4: - do { - break lab4; - } while (i < 10); - - lab5: - while (i < 10) { - lab6: - while (j < 20) { - break lab5; - } - } - - lab7: - switch (i) { - case 0: - break lab7; - } -}; diff --git a/test/files/rules/jsdoc-windows.test.ts b/test/ruleTests/jsdoc-format/jsdoc-windows.ts.linttest similarity index 100% rename from test/files/rules/jsdoc-windows.test.ts rename to test/ruleTests/jsdoc-format/jsdoc-windows.ts.linttest diff --git a/test/files/rules/jsdoc.test.ts b/test/ruleTests/jsdoc-format/jsdoc.ts.linttest similarity index 81% rename from test/files/rules/jsdoc.test.ts rename to test/ruleTests/jsdoc-format/jsdoc.ts.linttest index 0b58fd9f497..52444146974 100644 --- a/test/files/rules/jsdoc.test.ts +++ b/test/ruleTests/jsdoc-format/jsdoc.ts.linttest @@ -26,30 +26,37 @@ I've even got characters where I shouldn't. How fun! * /** * this is also jsdoc *and it has a problem on this line +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [format] */ /** * this jsoc is fine * up until the last line when it isn't */ +~~~~~ [asterisks] /** * this jsdoc has characters where it really should not */ +~~~~~~~ [format] /** * same thing with this one * +~~~~~~ [format] */ /** * what else can go wrong? * oh right this +~~~~~~~~~~~~~~~~~~ [asterisks] */ /**a bad one liner */ + ~~~~~~~~~~~~~~~~~~~~~ [format] /** another bad one liner*/ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ [format] /** */ @@ -67,3 +74,6 @@ function makeHeader(pkg: Package) { `\t */` ].join("\r\n"); } + +[format]: jsdoc is not formatted correctly on this line +[asterisks]: asterisks in jsdoc must be aligned diff --git a/test/ruleTests/jsdoc-format/tslint.json b/test/ruleTests/jsdoc-format/tslint.json new file mode 100644 index 00000000000..02b95774ec7 --- /dev/null +++ b/test/ruleTests/jsdoc-format/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "jsdoc-format": true + } +} diff --git a/test/rules/jsdocFormatRuleTests.ts b/test/rules/jsdocFormatRuleTests.ts deleted file mode 100644 index d904fe2a74c..00000000000 --- a/test/rules/jsdocFormatRuleTests.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - const JsdocFormatRule = TestUtils.getRule("jsdoc-format"); - - it("ensures jsdoc comments have properly lined up asterisks and start with spaces", () => { - const fileName = "rules/jsdoc.test.ts"; - const createFormatFailure = TestUtils.createFailuresOnFile(fileName, JsdocFormatRule.FORMAT_FAILURE_STRING); - const createAlignmentFailure = TestUtils.createFailuresOnFile(fileName, JsdocFormatRule.ALIGNMENT_FAILURE_STRING); - const expectedFailure1 = createFormatFailure([28, 1], [28, 40]); - const expectedFailure2 = createAlignmentFailure([34, 1], [34, 6]); - const expectedFailure3 = createFormatFailure([38, 1], [38, 8]); - const expectedFailure4 = createFormatFailure([42, 1], [42, 7]); - const expectedFailure5 = createAlignmentFailure([47, 1], [47, 19]); - const expectedFailure6 = createFormatFailure([50, 5], [50, 26]); - const expectedFailure7 = createFormatFailure([52, 5], [52, 32]); - - const actualFailures = TestUtils.applyRuleOnFile(fileName, JsdocFormatRule); - - TestUtils.assertContainsFailure(actualFailures, expectedFailure1); - TestUtils.assertContainsFailure(actualFailures, expectedFailure2); - TestUtils.assertContainsFailure(actualFailures, expectedFailure3); - TestUtils.assertContainsFailure(actualFailures, expectedFailure4); - TestUtils.assertContainsFailure(actualFailures, expectedFailure5); - TestUtils.assertContainsFailure(actualFailures, expectedFailure6); - TestUtils.assertContainsFailure(actualFailures, expectedFailure7); - assert.lengthOf(actualFailures, 7); - }); - - it("ensures jsdoc commments can have have windows line endings", () => { - const fileName = "rules/jsdoc-windows.test.ts"; - const actualFailures = TestUtils.applyRuleOnFile(fileName, JsdocFormatRule); - assert.lengthOf(actualFailures, 0); - }); -}); diff --git a/test/rules/labelPositionRuleTests.ts b/test/rules/labelPositionRuleTests.ts deleted file mode 100644 index 65350b7779c..00000000000 --- a/test/rules/labelPositionRuleTests.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {RuleFailure, TestUtils} from "../lint"; - -describe("", () => { - const LabelPositionRule = TestUtils.getRule("label-position"); - const fileName = "rules/labelpos.test.ts"; - - it("enforces that labels are correctly positioned", () => { - const createFailure = TestUtils.createFailuresOnFile(fileName, LabelPositionRule.FAILURE_STRING); - const expectedFailures: RuleFailure[] = [ - createFailure([2, 5], [2, 9]), - createFailure([5, 5], [5, 9]) - ]; - const actualFailures = TestUtils.applyRuleOnFile(fileName, LabelPositionRule); - - TestUtils.assertFailuresEqual(actualFailures, expectedFailures); - }); -}); diff --git a/test/rules/labelUndefinedRuleTests.ts b/test/rules/labelUndefinedRuleTests.ts deleted file mode 100644 index 533a52385eb..00000000000 --- a/test/rules/labelUndefinedRuleTests.ts +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {RuleFailure, TestUtils} from "../lint"; - -describe("", () => { - const LabelUndefinedRule = TestUtils.getRule("label-undefined"); - const fileName = "rules/label-undefined.test.ts"; - const failureString = LabelUndefinedRule.FAILURE_STRING; - - it("forbids the use of undefined labels", () => { - const expectedFailures: RuleFailure[] = [ - TestUtils.createFailure(fileName, [6, 9], [6, 14], failureString + "lab1'"), - TestUtils.createFailure(fileName, [13, 9], [13, 17], failureString + "lab2'"), - TestUtils.createFailure(fileName, [27, 17], [27, 22], failureString + "lab3'"), - TestUtils.createFailure(fileName, [36, 9], [36, 17], failureString + "lab4'") - ]; - const actualFailures = TestUtils.applyRuleOnFile(fileName, LabelUndefinedRule); - - TestUtils.assertFailuresEqual(actualFailures, expectedFailures); - }); -}); diff --git a/test/tsconfig.json b/test/tsconfig.json index 18444f420eb..b2a10467426 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -129,9 +129,6 @@ "ruleTestRunnerTests/testData.ts", "ruleTestRunnerTests/utilsTests.ts", "rules/eofLineRuleTests.ts", - "rules/jsdocFormatRuleTests.ts", - "rules/labelPositionRuleTests.ts", - "rules/labelUndefinedRuleTests.ts", "rules/maxLineLengthRuleTests.ts", "rules/memberAccessRuleTests.ts", "rules/memberOrderingRuleTests.ts", From 99679ce10eab9edaa7e22d177cd7d38d2dc0e5e0 Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Tue, 22 Dec 2015 17:33:16 -0500 Subject: [PATCH 10/30] convert tests for member-access and max-line-length --- .../ruleTests/label-position/test.ts.linttest | 33 ++++++++++ test/ruleTests/label-position/tslint.json | 5 ++ .../label-undefined/test.ts.linttest | 55 ++++++++++++++++ test/ruleTests/label-undefined/tslint.json | 5 ++ .../max-line-length/test.ts.linttest} | 3 +- test/ruleTests/max-line-length/tslint.json | 5 ++ .../member-access-accessor/test.ts.linttest} | 6 +- .../member-access-accessor/tslint.json | 5 ++ .../test.ts.linttest} | 2 + .../member-access-constructor/tslint.json | 5 ++ .../member-access/test.ts.linttest} | 7 +++ test/ruleTests/member-access/tslint.json | 5 ++ test/rules/maxLineLengthRuleTests.ts | 31 --------- test/rules/memberAccessRuleTests.ts | 63 ------------------- test/tsconfig.json | 2 - 15 files changed, 134 insertions(+), 98 deletions(-) create mode 100644 test/ruleTests/label-position/test.ts.linttest create mode 100644 test/ruleTests/label-position/tslint.json create mode 100644 test/ruleTests/label-undefined/test.ts.linttest create mode 100644 test/ruleTests/label-undefined/tslint.json rename test/{files/rules/maxlen.test.ts => ruleTests/max-line-length/test.ts.linttest} (61%) create mode 100644 test/ruleTests/max-line-length/tslint.json rename test/{files/rules/memberaccess-accessor.test.ts => ruleTests/member-access-accessor/test.ts.linttest} (55%) create mode 100644 test/ruleTests/member-access-accessor/tslint.json rename test/{files/rules/memberaccess-constructor.test.ts => ruleTests/member-access-constructor/test.ts.linttest} (52%) create mode 100644 test/ruleTests/member-access-constructor/tslint.json rename test/{files/rules/memberaccess.test.ts => ruleTests/member-access/test.ts.linttest} (71%) create mode 100644 test/ruleTests/member-access/tslint.json delete mode 100644 test/rules/maxLineLengthRuleTests.ts delete mode 100644 test/rules/memberAccessRuleTests.ts diff --git a/test/ruleTests/label-position/test.ts.linttest b/test/ruleTests/label-position/test.ts.linttest new file mode 100644 index 00000000000..07631eb3e9a --- /dev/null +++ b/test/ruleTests/label-position/test.ts.linttest @@ -0,0 +1,33 @@ +var t = function() { + lab1: + ~~~~ [unexpected label on statement] + var x = 123; + + lab2: + ~~~~ [unexpected label on statement] + console.log("123"); + + lab3: + for (var i = 0; i < 5; ++i) { + break lab3; + } + + lab4: + do { + break lab4; + } while (i < 10); + + lab5: + while (i < 10) { + lab6: + while (j < 20) { + break lab5; + } + } + + lab7: + switch (i) { + case 0: + break lab7; + } +}; diff --git a/test/ruleTests/label-position/tslint.json b/test/ruleTests/label-position/tslint.json new file mode 100644 index 00000000000..82a6a0582e6 --- /dev/null +++ b/test/ruleTests/label-position/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "label-position": true + } +} diff --git a/test/ruleTests/label-undefined/test.ts.linttest b/test/ruleTests/label-undefined/test.ts.linttest new file mode 100644 index 00000000000..d9988de8916 --- /dev/null +++ b/test/ruleTests/label-undefined/test.ts.linttest @@ -0,0 +1,55 @@ +// invalid code + +function f() { + lab3: + for (var i = 0; i < 10; ++i) { + break lab1; + ~~~~~ [undefined label: 'lab1'] + } +} + +var x = function() { + lab4: + while (i < 10) { + continue lab2; + ~~~~~~~~ [undefined label: 'lab2'] + } +}; + +var y = () => { + lab3: + while (i < 10) { + continue lab3; + } + + (function() { + lab2: + switch (j) { + case 1: + break lab3; + ~~~~~ [undefined label: 'lab3'] + } + })(); +}; + +var z = x => { + lab1: + do { + x++; + continue lab4; + ~~~~~~~~ [undefined label: 'lab4'] + } while (x < 10); +}; + +// valid code + +lab5: +for (var i = 0; i < 10; ++i) { + var w = () => { + lab2: + while (i < 10) { + continue lab2; + } + }; + break lab5; +} diff --git a/test/ruleTests/label-undefined/tslint.json b/test/ruleTests/label-undefined/tslint.json new file mode 100644 index 00000000000..74a9a3d5886 --- /dev/null +++ b/test/ruleTests/label-undefined/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "label-undefined": true + } +} diff --git a/test/files/rules/maxlen.test.ts b/test/ruleTests/max-line-length/test.ts.linttest similarity index 61% rename from test/files/rules/maxlen.test.ts rename to test/ruleTests/max-line-length/test.ts.linttest index 6f1b5e1aca1..ac3eb4efabf 100644 --- a/test/files/rules/maxlen.test.ts +++ b/test/ruleTests/max-line-length/test.ts.linttest @@ -1,4 +1,5 @@ var simpleName = 1; var complicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicatedName; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [exceeds maximum line length of 140] -var complicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicat; +var complicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicat; diff --git a/test/ruleTests/max-line-length/tslint.json b/test/ruleTests/max-line-length/tslint.json new file mode 100644 index 00000000000..26a149d34a0 --- /dev/null +++ b/test/ruleTests/max-line-length/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "max-line-length": [true, 140] + } +} diff --git a/test/files/rules/memberaccess-accessor.test.ts b/test/ruleTests/member-access-accessor/test.ts.linttest similarity index 55% rename from test/files/rules/memberaccess-accessor.test.ts rename to test/ruleTests/member-access-accessor/test.ts.linttest index f664fa7f324..9fe7c2a6ddf 100644 --- a/test/files/rules/memberaccess-accessor.test.ts +++ b/test/ruleTests/member-access-accessor/test.ts.linttest @@ -1,8 +1,12 @@ class Members { get g() { + ~~~~~~~~~ return 1; +~~~~~~~~~~~~~~~~~ } +~~~~~ [default access modifier on member/method not allowed] set s(o: any) {} + ~~~~~~~~~~~~~~~~ [default access modifier on member/method not allowed] public get publicG() { return 1; @@ -14,4 +18,4 @@ const obj = { get g() { return 1; } -}; +}; \ No newline at end of file diff --git a/test/ruleTests/member-access-accessor/tslint.json b/test/ruleTests/member-access-accessor/tslint.json new file mode 100644 index 00000000000..165c6526ab4 --- /dev/null +++ b/test/ruleTests/member-access-accessor/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "member-access": [true, "check-accessor"] + } +} diff --git a/test/files/rules/memberaccess-constructor.test.ts b/test/ruleTests/member-access-constructor/test.ts.linttest similarity index 52% rename from test/files/rules/memberaccess-constructor.test.ts rename to test/ruleTests/member-access-constructor/test.ts.linttest index 4f20fd4fc2b..454a0af0fe9 100644 --- a/test/files/rules/memberaccess-constructor.test.ts +++ b/test/ruleTests/member-access-constructor/test.ts.linttest @@ -1,6 +1,8 @@ class ContructorsNoAccess { constructor(i: number); + ~~~~~~~~~~~~~~~~~~~~~~~ [default access modifier on member/method not allowed] constructor(o: any) {} + ~~~~~~~~~~~~~~~~~~~~~~ [default access modifier on member/method not allowed] } class ContructorsAccess { diff --git a/test/ruleTests/member-access-constructor/tslint.json b/test/ruleTests/member-access-constructor/tslint.json new file mode 100644 index 00000000000..2166eb52f4f --- /dev/null +++ b/test/ruleTests/member-access-constructor/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "member-access": [true, "check-constructor"] + } +} diff --git a/test/files/rules/memberaccess.test.ts b/test/ruleTests/member-access/test.ts.linttest similarity index 71% rename from test/files/rules/memberaccess.test.ts rename to test/ruleTests/member-access/test.ts.linttest index cff562c6672..bd052623b8d 100644 --- a/test/files/rules/memberaccess.test.ts +++ b/test/ruleTests/member-access/test.ts.linttest @@ -1,5 +1,6 @@ declare class AmbientNoAccess { a(): number; + ~~~~~~~~~~~~ [0] } declare class AmbientAccess { @@ -8,13 +9,16 @@ declare class AmbientAccess { class Members { i: number; + ~~~~~~~~~~ [0] public nPublic: number; protected nProtected: number; private nPrivate: number; noAccess(x: number): number; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] noAccess(o: any): any {} + ~~~~~~~~~~~~~~~~~~~~~~~~ [0] public access(x: number): number; public access(o: any): any {} @@ -27,6 +31,9 @@ const obj = { function main() { class A { i: number; + ~~~~~~~~~~ [0] public n: number; } } + +[0]: default access modifier on member/method not allowed diff --git a/test/ruleTests/member-access/tslint.json b/test/ruleTests/member-access/tslint.json new file mode 100644 index 00000000000..f9c417e0902 --- /dev/null +++ b/test/ruleTests/member-access/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "member-access": true + } +} diff --git a/test/rules/maxLineLengthRuleTests.ts b/test/rules/maxLineLengthRuleTests.ts deleted file mode 100644 index 8651749c795..00000000000 --- a/test/rules/maxLineLengthRuleTests.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - const MaxLineLengthRule = TestUtils.getRule("max-line-length"); - const fileName = "rules/maxlen.test.ts"; - - it("enforces a maximum line length", () => { - const actualFailures = TestUtils.applyRuleOnFile(fileName, MaxLineLengthRule, [true, 140]); - const expectedFailures = [ - TestUtils.createFailure(fileName, [2, 1], [2, 165], MaxLineLengthRule.FAILURE_STRING + "140") - ]; - - TestUtils.assertFailuresEqual(actualFailures, expectedFailures); - }); -}); diff --git a/test/rules/memberAccessRuleTests.ts b/test/rules/memberAccessRuleTests.ts deleted file mode 100644 index 89fbbe2e90f..00000000000 --- a/test/rules/memberAccessRuleTests.ts +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - it("ensures that class properties have access modifiers", () => { - const fileName = "rules/memberaccess.test.ts"; - const expectedFailures = [ - [[2, 5], [2, 17]], - [[10, 5], [10, 15]], - [[16, 5], [16, 33]], - [[17, 5], [17, 29]], - [[29, 9], [29, 19]] - ]; - - assertFailuresInFile(fileName, expectedFailures); - }); - - it("ensures that constructors have access modifiers", () => { - const fileName = "rules/memberaccess-constructor.test.ts"; - const expectedFailures = [ - [[2, 5], [2, 28]], - [[3, 5], [3, 27]] - ]; - const options = [true, "check-constructor"]; - - assertFailuresInFile(fileName, expectedFailures, options); - }); - - it("ensures that accessors have access modifiers", () => { - const fileName = "rules/memberaccess-accessor.test.ts"; - const expectedFailures = [ - [[2, 5], [4, 6]], - [[5, 5], [5, 21]] - ]; - const options = [true, "check-accessor"]; - - assertFailuresInFile(fileName, expectedFailures, options); - }); - - function assertFailuresInFile(fileName: string, expectedFailures: number[][][], options: any[] = [true]) { - const MemberAccessRule = TestUtils.getRule("member-access"); - const createFailure = TestUtils.createFailuresOnFile(fileName, MemberAccessRule.FAILURE_STRING); - const expectedFileFailures = expectedFailures.map(failure => createFailure(failure[0], failure[1])); - - const actualFailures = TestUtils.applyRuleOnFile(fileName, MemberAccessRule, options); - TestUtils.assertFailuresEqual(actualFailures, expectedFileFailures); - } -}); diff --git a/test/tsconfig.json b/test/tsconfig.json index b2a10467426..ec70f68fed8 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -129,8 +129,6 @@ "ruleTestRunnerTests/testData.ts", "ruleTestRunnerTests/utilsTests.ts", "rules/eofLineRuleTests.ts", - "rules/maxLineLengthRuleTests.ts", - "rules/memberAccessRuleTests.ts", "rules/memberOrderingRuleTests.ts", "rules/noAnyRuleTests.ts", "rules/noArgRuleTests.ts", From a7840b3919bcef294066a99a4a8f27ce2cd521a6 Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Tue, 22 Dec 2015 17:58:26 -0500 Subject: [PATCH 11/30] Convert tests for member-ordering rule --- .../rules/memberordering-private.test.ts | 7 -- .../files/rules/memberordering-static.test.ts | 7 -- .../member-ordering-method/test.ts.linttest} | 4 ++ .../member-ordering-method/tslint.json | 5 ++ .../member-ordering-private/test.ts.linttest | 10 +++ .../member-ordering-private/tslint.json | 5 ++ .../member-ordering-static/test.ts.linttest | 10 +++ .../member-ordering-static/tslint.json | 5 ++ test/rules/memberOrderingRuleTests.ts | 67 ------------------- test/tsconfig.json | 1 - 10 files changed, 39 insertions(+), 82 deletions(-) delete mode 100644 test/files/rules/memberordering-private.test.ts delete mode 100644 test/files/rules/memberordering-static.test.ts rename test/{files/rules/memberordering-method.test.ts => ruleTests/member-ordering-method/test.ts.linttest} (56%) create mode 100644 test/ruleTests/member-ordering-method/tslint.json create mode 100644 test/ruleTests/member-ordering-private/test.ts.linttest create mode 100644 test/ruleTests/member-ordering-private/tslint.json create mode 100644 test/ruleTests/member-ordering-static/test.ts.linttest create mode 100644 test/ruleTests/member-ordering-static/tslint.json delete mode 100644 test/rules/memberOrderingRuleTests.ts diff --git a/test/files/rules/memberordering-private.test.ts b/test/files/rules/memberordering-private.test.ts deleted file mode 100644 index fc9b54106aa..00000000000 --- a/test/files/rules/memberordering-private.test.ts +++ /dev/null @@ -1,7 +0,0 @@ -class Foo { - private x: number; - private bar(): any { - var bla: { a: string } = {a: '1'}; - } - y: number; -} diff --git a/test/files/rules/memberordering-static.test.ts b/test/files/rules/memberordering-static.test.ts deleted file mode 100644 index 4d755015446..00000000000 --- a/test/files/rules/memberordering-static.test.ts +++ /dev/null @@ -1,7 +0,0 @@ -class Foo { - x: number; - static y: number; - constructor() { - // nothing to do - } -} diff --git a/test/files/rules/memberordering-method.test.ts b/test/ruleTests/member-ordering-method/test.ts.linttest similarity index 56% rename from test/files/rules/memberordering-method.test.ts rename to test/ruleTests/member-ordering-method/test.ts.linttest index 8359f74d531..f723f73ef38 100644 --- a/test/files/rules/memberordering-method.test.ts +++ b/test/ruleTests/member-ordering-method/test.ts.linttest @@ -10,9 +10,13 @@ interface Baz { interface BarBaz { x(): void; y: number; + ~~~~~~~~~~ [0] } class Foo { x(): void {} y: number; + ~~~~~~~~~~ [0] } + +[0]: Declaration of public instance member variable not allowed to appear after declaration of public instance member function \ No newline at end of file diff --git a/test/ruleTests/member-ordering-method/tslint.json b/test/ruleTests/member-ordering-method/tslint.json new file mode 100644 index 00000000000..9be59dcd531 --- /dev/null +++ b/test/ruleTests/member-ordering-method/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "member-ordering": [true, "variables-before-functions"] + } +} diff --git a/test/ruleTests/member-ordering-private/test.ts.linttest b/test/ruleTests/member-ordering-private/test.ts.linttest new file mode 100644 index 00000000000..24f637796f7 --- /dev/null +++ b/test/ruleTests/member-ordering-private/test.ts.linttest @@ -0,0 +1,10 @@ +class Foo { + private x: number; + private bar(): any { + var bla: { a: string } = {a: '1'}; + } + y: number; + ~~~~~~~~~~ [0] +} + +[0]: Declaration of public instance member variable not allowed to appear after declaration of private instance member function diff --git a/test/ruleTests/member-ordering-private/tslint.json b/test/ruleTests/member-ordering-private/tslint.json new file mode 100644 index 00000000000..9b2be79af85 --- /dev/null +++ b/test/ruleTests/member-ordering-private/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "member-ordering": [true, "public-before-private"] + } +} diff --git a/test/ruleTests/member-ordering-static/test.ts.linttest b/test/ruleTests/member-ordering-static/test.ts.linttest new file mode 100644 index 00000000000..b5396b81a18 --- /dev/null +++ b/test/ruleTests/member-ordering-static/test.ts.linttest @@ -0,0 +1,10 @@ +class Foo { + x: number; + static y: number; + ~~~~~~~~~~~~~~~~~ [0] + constructor() { + // nothing to do + } +} + +[0]: Declaration of public static member variable not allowed to appear after declaration of public instance member variable diff --git a/test/ruleTests/member-ordering-static/tslint.json b/test/ruleTests/member-ordering-static/tslint.json new file mode 100644 index 00000000000..01c8d924d1e --- /dev/null +++ b/test/ruleTests/member-ordering-static/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "member-ordering": [true, "static-before-instance"] + } +} diff --git a/test/rules/memberOrderingRuleTests.ts b/test/rules/memberOrderingRuleTests.ts deleted file mode 100644 index 851bbe1e00f..00000000000 --- a/test/rules/memberOrderingRuleTests.ts +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - it("requires public variables to go before private ones", () => { - const fileName = "rules/memberordering-private.test.ts"; - const MemberOrderingRule = TestUtils.getRule("member-ordering"); - const actualFailures = TestUtils.applyRuleOnFile(fileName, MemberOrderingRule, [ - true, - "public-before-private" - ]); - - TestUtils.assertFailuresEqual(actualFailures, [ - TestUtils.createFailure(fileName, [6, 5], [6, 15], - "Declaration of public instance member variable not allowed " + - "to appear after declaration of private instance member function") - ]); - }); - - it("requires variables to go before methods", () => { - const fileName = "rules/memberordering-method.test.ts"; - const MemberOrderingRule = TestUtils.getRule("member-ordering"); - const actualFailures = TestUtils.applyRuleOnFile(fileName, MemberOrderingRule, [ - true, - "variables-before-functions" - ]); - - TestUtils.assertFailuresEqual(actualFailures, [ - TestUtils.createFailure(fileName, [12, 5], [12, 15], - "Declaration of public instance member variable not allowed " + - "to appear after declaration of public instance member function"), - TestUtils.createFailure(fileName, [17, 5], [17, 15], - "Declaration of public instance member variable not allowed " + - "to appear after declaration of public instance member function"), - ]); - }); - - it("requires static variables to go before instance variables", () => { - const fileName = "rules/memberordering-static.test.ts"; - const MemberOrderingRule = TestUtils.getRule("member-ordering"); - const actualFailures = TestUtils.applyRuleOnFile(fileName, MemberOrderingRule, [ - true, - "static-before-instance" - ]); - - TestUtils.assertFailuresEqual(actualFailures, [ - TestUtils.createFailure(fileName, [3, 5], [3, 22], - "Declaration of public static member variable not allowed " + - "to appear after declaration of public instance member variable") - ]); - }); -}); diff --git a/test/tsconfig.json b/test/tsconfig.json index ec70f68fed8..9ca58d681e4 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -129,7 +129,6 @@ "ruleTestRunnerTests/testData.ts", "ruleTestRunnerTests/utilsTests.ts", "rules/eofLineRuleTests.ts", - "rules/memberOrderingRuleTests.ts", "rules/noAnyRuleTests.ts", "rules/noArgRuleTests.ts", "rules/noBitwiseRuleTests.ts", From ae7d15b88fa289228ec0481fe4fce1249645e7c5 Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Tue, 22 Dec 2015 19:46:55 -0500 Subject: [PATCH 12/30] Convert tests for no-any, no-arg and no-bitwise --- test/files/rules/bitwise.test.ts | 3 - test/files/rules/noany.test.ts | 10 ---- test/ruleTests/no-any/test.ts.linttest | 18 ++++++ test/ruleTests/no-any/tslint.json | 5 ++ .../no-arg/test.ts.linttest} | 1 + test/ruleTests/no-arg/tslint.json | 5 ++ test/ruleTests/no-bitwise/test.ts.linttest | 6 ++ test/ruleTests/no-bitwise/tslint.json | 5 ++ test/rules/noAnyRuleTests.ts | 57 ------------------- test/rules/noArgRuleTests.ts | 30 ---------- test/rules/noBitwiseRuleTests.ts | 34 ----------- test/tsconfig.json | 3 - 12 files changed, 40 insertions(+), 137 deletions(-) delete mode 100644 test/files/rules/bitwise.test.ts delete mode 100644 test/files/rules/noany.test.ts create mode 100644 test/ruleTests/no-any/test.ts.linttest create mode 100644 test/ruleTests/no-any/tslint.json rename test/{files/rules/noarg.test.ts => ruleTests/no-arg/test.ts.linttest} (69%) create mode 100644 test/ruleTests/no-arg/tslint.json create mode 100644 test/ruleTests/no-bitwise/test.ts.linttest create mode 100644 test/ruleTests/no-bitwise/tslint.json delete mode 100644 test/rules/noAnyRuleTests.ts delete mode 100644 test/rules/noArgRuleTests.ts delete mode 100644 test/rules/noBitwiseRuleTests.ts diff --git a/test/files/rules/bitwise.test.ts b/test/files/rules/bitwise.test.ts deleted file mode 100644 index 8b58fe8465b..00000000000 --- a/test/files/rules/bitwise.test.ts +++ /dev/null @@ -1,3 +0,0 @@ -var z = (x || 3) && (y || 4); -var yy = x | 3; -var zz = (z || y) & (x | y); diff --git a/test/files/rules/noany.test.ts b/test/files/rules/noany.test.ts deleted file mode 100644 index aaf2442762f..00000000000 --- a/test/files/rules/noany.test.ts +++ /dev/null @@ -1,10 +0,0 @@ -var x: any; // error - -function foo(a: any) : any { // 2 errors - return; -} - -let a: any = 2, // error - b: any = 4; // error - -let {a: c, b: d}: {c: any, d: number} = {c: 99, d: 100}; // error diff --git a/test/ruleTests/no-any/test.ts.linttest b/test/ruleTests/no-any/test.ts.linttest new file mode 100644 index 00000000000..4906e177f6f --- /dev/null +++ b/test/ruleTests/no-any/test.ts.linttest @@ -0,0 +1,18 @@ +var x: any; // error + ~~~ [0] + +function foo(a: any) : any { // 2 errors + ~~~ [0] + ~~~ [0] + return; +} + +let a: any = 2, // error + ~~~ [0] + b: any = 4; // error + ~~~ [0] + +let {a: c, b: d}: {c: any, d: number} = {c: 99, d: 100}; // error + ~~~ [0] + +[0]: type decoration of 'any' is forbidden diff --git a/test/ruleTests/no-any/tslint.json b/test/ruleTests/no-any/tslint.json new file mode 100644 index 00000000000..2876d288c08 --- /dev/null +++ b/test/ruleTests/no-any/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-any": true + } +} diff --git a/test/files/rules/noarg.test.ts b/test/ruleTests/no-arg/test.ts.linttest similarity index 69% rename from test/files/rules/noarg.test.ts rename to test/ruleTests/no-arg/test.ts.linttest index c94bcb82a47..a8699cf9dd3 100644 --- a/test/files/rules/noarg.test.ts +++ b/test/ruleTests/no-arg/test.ts.linttest @@ -2,6 +2,7 @@ var testVariable = 123; function testFunction(): number { if(arguments.callee.caller === testFunction) { + ~~~~~~~~~ [access forbidden to arguments property] console.log("called"); } diff --git a/test/ruleTests/no-arg/tslint.json b/test/ruleTests/no-arg/tslint.json new file mode 100644 index 00000000000..139d0955e11 --- /dev/null +++ b/test/ruleTests/no-arg/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-arg": true + } +} diff --git a/test/ruleTests/no-bitwise/test.ts.linttest b/test/ruleTests/no-bitwise/test.ts.linttest new file mode 100644 index 00000000000..635a371923c --- /dev/null +++ b/test/ruleTests/no-bitwise/test.ts.linttest @@ -0,0 +1,6 @@ +var z = (x || 3) && (y || 4); +var yy = x | 3; + ~~~~~ [forbidden bitwise operation] +var zz = (z || y) & (x | y); + ~~~~~~~~~~~~~~~~~~ [forbidden bitwise operation] + ~~~~~ [forbidden bitwise operation] diff --git a/test/ruleTests/no-bitwise/tslint.json b/test/ruleTests/no-bitwise/tslint.json new file mode 100644 index 00000000000..9dfce74f345 --- /dev/null +++ b/test/ruleTests/no-bitwise/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-bitwise": true + } +} diff --git a/test/rules/noAnyRuleTests.ts b/test/rules/noAnyRuleTests.ts deleted file mode 100644 index a6da3cf8699..00000000000 --- a/test/rules/noAnyRuleTests.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - const fileName = "rules/noany.test.ts"; - const NoAnyRule = TestUtils.getRule("no-any"); - const actualFailures = TestUtils.applyRuleOnFile(fileName, NoAnyRule); - - const createFailure = TestUtils.createFailuresOnFile(fileName, NoAnyRule.FAILURE_STRING); - - it("disallows variables with type 'any'", () => { - const expectedFailures = [ - createFailure([1, 8], [1, 11]), - createFailure([7, 8], [7, 11]), - createFailure([8, 8], [8, 11]) - ]; - - for (let failure of expectedFailures) { - TestUtils.assertContainsFailure(actualFailures, failure); - } - }); - - it("disallows functions with parameter type 'any'", () => { - const expectedFailure = createFailure([3, 17], [3, 20]); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("disallows functions with return type 'any'", () => { - const expectedFailure = createFailure([3, 24], [3, 27]); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("catches destructuring bindings with member types of 'any'", () => { - const expectedFailure = createFailure([10, 23], [10, 26]); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("finds the expected number of errors", () => { - assert.equal(actualFailures.length, 6); - }); - -}); diff --git a/test/rules/noArgRuleTests.ts b/test/rules/noArgRuleTests.ts deleted file mode 100644 index 390e9d04ec4..00000000000 --- a/test/rules/noArgRuleTests.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - it("forbids access to arguments properties", () => { - const fileName = "rules/noarg.test.ts"; - const NoArgRule = TestUtils.getRule("no-arg"); - const expectedFailure = TestUtils.createFailure(fileName, [4, 8], [4, 17], NoArgRule.FAILURE_STRING); - - const actualFailures = TestUtils.applyRuleOnFile(fileName, NoArgRule); - - assert.equal(actualFailures.length, 1); - assert.isTrue(actualFailures[0].equals(expectedFailure)); - }); -}); diff --git a/test/rules/noBitwiseRuleTests.ts b/test/rules/noBitwiseRuleTests.ts deleted file mode 100644 index 7867221dd44..00000000000 --- a/test/rules/noBitwiseRuleTests.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {RuleFailure, TestUtils} from "../lint"; - -describe("", () => { - const NoBitwiseRule = TestUtils.getRule("no-bitwise"); - const fileName = "rules/bitwise.test.ts"; - - it("forbids access to bitwise operators", () => { - const createFailure = TestUtils.createFailuresOnFile(fileName, NoBitwiseRule.FAILURE_STRING); - const expectedFailures: RuleFailure[] = [ - createFailure([2, 10], [2, 15]), - createFailure([3, 10], [3, 28]), - createFailure([3, 22], [3, 27]), - ]; - const actualFailures = TestUtils.applyRuleOnFile(fileName, NoBitwiseRule); - - TestUtils.assertFailuresEqual(actualFailures, expectedFailures); - }); -}); diff --git a/test/tsconfig.json b/test/tsconfig.json index 9ca58d681e4..440236b385e 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -129,9 +129,6 @@ "ruleTestRunnerTests/testData.ts", "ruleTestRunnerTests/utilsTests.ts", "rules/eofLineRuleTests.ts", - "rules/noAnyRuleTests.ts", - "rules/noArgRuleTests.ts", - "rules/noBitwiseRuleTests.ts", "rules/noConditionalAssignmentRuleTests.ts", "rules/noConsecutiveBlankLinesRuleTests.ts", "rules/noConsoleRuleTests.ts", From 21d0c43ef293113f8a88e8915ad0e53eb5ef1ceb Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Tue, 22 Dec 2015 20:04:20 -0500 Subject: [PATCH 13/30] convert tests for no-conditional-assignment, no-console, no-construct, no-constructor-vars --- test/files/rules/nocondassign.test.ts | 35 ---------- test/files/rules/noconsole.test.ts | 9 --- test/files/rules/noconstruct.test.ts | 8 --- test/files/rules/noconstructorvars.test.ts | 17 ----- .../test.ts.linttest | 48 +++++++++++++ .../no-conditional-assignment/tslint.json | 5 ++ test/ruleTests/no-console/test.ts.linttest | 13 ++++ test/ruleTests/no-console/tslint.json | 5 ++ test/ruleTests/no-construct/test.ts.linttest | 11 +++ test/ruleTests/no-construct/tslint.json | 5 ++ .../no-constructor-vars/test.ts.linttest | 20 ++++++ .../ruleTests/no-constructor-vars/tslint.json | 5 ++ .../rules/noConditionalAssignmentRuleTests.ts | 70 ------------------- test/rules/noConsoleRuleTests.ts | 35 ---------- test/rules/noConstructRuleTests.ts | 43 ------------ test/rules/noConstructorVarsRuleTests.ts | 38 ---------- test/tsconfig.json | 4 -- 17 files changed, 112 insertions(+), 259 deletions(-) delete mode 100644 test/files/rules/nocondassign.test.ts delete mode 100644 test/files/rules/noconsole.test.ts delete mode 100644 test/files/rules/noconstruct.test.ts delete mode 100644 test/files/rules/noconstructorvars.test.ts create mode 100644 test/ruleTests/no-conditional-assignment/test.ts.linttest create mode 100644 test/ruleTests/no-conditional-assignment/tslint.json create mode 100644 test/ruleTests/no-console/test.ts.linttest create mode 100644 test/ruleTests/no-console/tslint.json create mode 100644 test/ruleTests/no-construct/test.ts.linttest create mode 100644 test/ruleTests/no-construct/tslint.json create mode 100644 test/ruleTests/no-constructor-vars/test.ts.linttest create mode 100644 test/ruleTests/no-constructor-vars/tslint.json delete mode 100644 test/rules/noConditionalAssignmentRuleTests.ts delete mode 100644 test/rules/noConsoleRuleTests.ts delete mode 100644 test/rules/noConstructRuleTests.ts delete mode 100644 test/rules/noConstructorVarsRuleTests.ts diff --git a/test/files/rules/nocondassign.test.ts b/test/files/rules/nocondassign.test.ts deleted file mode 100644 index c93a4edbf3e..00000000000 --- a/test/files/rules/nocondassign.test.ts +++ /dev/null @@ -1,35 +0,0 @@ -// valid cases -if (x == 5) { } -if (x === 5) { } -else if (y <= 23) { } -else if ((z && a) == 7) { } -else { } - -do { } while (x == 2); -do { } while (x !== 2); - -while (x == 2) { } -while (x !== 2) { } - -for (var x = 8; x == 8; ++x) { } -for (var x = 8; x == 8; x = 12) { } -for (;;) { } - -// invalid cases -if (x = 5) { } -if (a && (b = 5)) { } -else if (x = 2) { } - -do { } while (x = 4); - -while (x = 4); -while ((x = y - 12)); - -for (var x = 4; x = 8; x++) { } -for (; (y == 2) && (x = 3); ) { } - -if (x += 2) { } -else if (h || (x <<= 4)) { } - -do { } while (x ^= 4) { } -while ((a = 5) && ((b == 4) || (c = 3))) diff --git a/test/files/rules/noconsole.test.ts b/test/files/rules/noconsole.test.ts deleted file mode 100644 index d4c0b8b98ca..00000000000 --- a/test/files/rules/noconsole.test.ts +++ /dev/null @@ -1,9 +0,0 @@ -console.time(); -console.log("log"); -console.dir(object); -console.info("info"); -console.trace("trace"); -console.warn("warn"); -console.error("error"); -console.something(); -console.timeEnd(); diff --git a/test/files/rules/noconstruct.test.ts b/test/files/rules/noconstruct.test.ts deleted file mode 100644 index 0d79b370efb..00000000000 --- a/test/files/rules/noconstruct.test.ts +++ /dev/null @@ -1,8 +0,0 @@ -var s1 = "s"; -var s2 = new String("s"); - -var n1 = 1; -var n2 = new Number(1); - -var b1 = true; -var b2 = new Boolean (true); diff --git a/test/files/rules/noconstructorvars.test.ts b/test/files/rules/noconstructorvars.test.ts deleted file mode 100644 index 104894ee5ab..00000000000 --- a/test/files/rules/noconstructorvars.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -class Class1 { - // one error - constructor(private foo: string) { - } -} - -class Class2 { - // two errors, last one is correct - constructor(private foo: string, public bar: string, qux: any) { - } -} - -class Class3 { - // no errors - constructor() { - } -} diff --git a/test/ruleTests/no-conditional-assignment/test.ts.linttest b/test/ruleTests/no-conditional-assignment/test.ts.linttest new file mode 100644 index 00000000000..c1816290a98 --- /dev/null +++ b/test/ruleTests/no-conditional-assignment/test.ts.linttest @@ -0,0 +1,48 @@ +// valid cases +if (x == 5) { } +if (x === 5) { } +else if (y <= 23) { } +else if ((z && a) == 7) { } +else { } + +do { } while (x == 2); +do { } while (x !== 2); + +while (x == 2) { } +while (x !== 2) { } + +for (var x = 8; x == 8; ++x) { } +for (var x = 8; x == 8; x = 12) { } +for (;;) { } + +// invalid cases +if (x = 5) { } + ~~~~~ [assignment in conditional: ] +if (a && (b = 5)) { } + ~~~~~ [assignment in conditional: ] +else if (x = 2) { } + ~~~~~ [assignment in conditional: ] + +do { } while (x = 4); + ~~~~~ [assignment in conditional: ] + +while (x = 4); + ~~~~~ [assignment in conditional: ] +while ((x = y - 12)); + ~~~~~~~~~~ [assignment in conditional: ] + +for (var x = 4; x = 8; x++) { } + ~~~~~ [assignment in conditional: ] +for (; (y == 2) && (x = 3); ) { } + ~~~~~ [assignment in conditional: ] + +if (x += 2) { } + ~~~~~~ [assignment in conditional: ] +else if (h || (x <<= 4)) { } + ~~~~~~~ [assignment in conditional: ] + +do { } while (x ^= 4) { } + ~~~~~~ [assignment in conditional: ] +while ((a = 5) && ((b == 4) || (c = 3))) + ~~~~~ [assignment in conditional: ] + ~~~~~ [assignment in conditional: ] diff --git a/test/ruleTests/no-conditional-assignment/tslint.json b/test/ruleTests/no-conditional-assignment/tslint.json new file mode 100644 index 00000000000..014f7127c44 --- /dev/null +++ b/test/ruleTests/no-conditional-assignment/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-conditional-assignment": true + } +} diff --git a/test/ruleTests/no-console/test.ts.linttest b/test/ruleTests/no-console/test.ts.linttest new file mode 100644 index 00000000000..a4062a0aa8c --- /dev/null +++ b/test/ruleTests/no-console/test.ts.linttest @@ -0,0 +1,13 @@ +console.time(); +console.log("log"); +~~~~~~~~~~~ [function invocation disallowed: console.log] +console.dir(object); +~~~~~~~~~~~ [function invocation disallowed: console.dir] +console.info("info"); +console.trace("trace"); +console.warn("warn"); +~~~~~~~~~~~~ [function invocation disallowed: console.warn] +console.error("error"); +~~~~~~~~~~~~~ [function invocation disallowed: console.error] +console.something(); +console.timeEnd(); diff --git a/test/ruleTests/no-console/tslint.json b/test/ruleTests/no-console/tslint.json new file mode 100644 index 00000000000..08a0d1815f8 --- /dev/null +++ b/test/ruleTests/no-console/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-console": [true, "dir", "error", "log", "warn"] + } +} diff --git a/test/ruleTests/no-construct/test.ts.linttest b/test/ruleTests/no-construct/test.ts.linttest new file mode 100644 index 00000000000..03d7f187655 --- /dev/null +++ b/test/ruleTests/no-construct/test.ts.linttest @@ -0,0 +1,11 @@ +var s1 = "s"; +var s2 = new String("s"); + ~~~~~~~~~~ [undesirable constructor use] + +var n1 = 1; +var n2 = new Number(1); + ~~~~~~~~~~~~~ [undesirable constructor use] + +var b1 = true; +var b2 = new Boolean (true); + ~~~~~~~~~~~ [undesirable constructor use] diff --git a/test/ruleTests/no-construct/tslint.json b/test/ruleTests/no-construct/tslint.json new file mode 100644 index 00000000000..9d1db2e04c1 --- /dev/null +++ b/test/ruleTests/no-construct/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-construct": true + } +} diff --git a/test/ruleTests/no-constructor-vars/test.ts.linttest b/test/ruleTests/no-constructor-vars/test.ts.linttest new file mode 100644 index 00000000000..56b3acc118a --- /dev/null +++ b/test/ruleTests/no-constructor-vars/test.ts.linttest @@ -0,0 +1,20 @@ +class Class1 { + // one error + constructor(private foo: string) { + ~~~~~~~ ['foo' cannot be declared in the constructor] + } +} + +class Class2 { + // two errors, last one is correct + constructor(private foo: string, public bar: string, qux: any) { + ~~~~~~~ ['foo' cannot be declared in the constructor] + ~~~~~~ ['bar' cannot be declared in the constructor] + } +} + +class Class3 { + // no errors + constructor() { + } +} diff --git a/test/ruleTests/no-constructor-vars/tslint.json b/test/ruleTests/no-constructor-vars/tslint.json new file mode 100644 index 00000000000..6a614c47fcf --- /dev/null +++ b/test/ruleTests/no-constructor-vars/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-constructor-vars": true + } +} diff --git a/test/rules/noConditionalAssignmentRuleTests.ts b/test/rules/noConditionalAssignmentRuleTests.ts deleted file mode 100644 index 86084923f4c..00000000000 --- a/test/rules/noConditionalAssignmentRuleTests.ts +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2015 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 {RuleFailure, TestUtils} from "../lint"; - -describe("", () => { - const fileName = "rules/nocondassign.test.ts"; - const NoConditionalAssignmentRule = TestUtils.getRule("no-conditional-assignment"); - const createFailure = TestUtils.createFailuresOnFile(fileName, NoConditionalAssignmentRule.FAILURE_STRING); - let actualFailures: RuleFailure[]; - - before(() => { - actualFailures = TestUtils.applyRuleOnFile(fileName, NoConditionalAssignmentRule); - }); - - it("should detect assignments in if conditionals", () => { - const expectedFailure1 = createFailure([19, 5], [19, 10]); - const expectedFailure2 = createFailure([20, 11], [20, 16]); - const expectedFailure3 = createFailure([21, 10], [21, 15]); - const expectedFailure4 = createFailure([31, 5], [31, 11]); - const expectedFailure5 = createFailure([32, 16], [32, 23]); - TestUtils.assertContainsFailure(actualFailures, expectedFailure1); - TestUtils.assertContainsFailure(actualFailures, expectedFailure2); - TestUtils.assertContainsFailure(actualFailures, expectedFailure3); - TestUtils.assertContainsFailure(actualFailures, expectedFailure4); - TestUtils.assertContainsFailure(actualFailures, expectedFailure5); - }); - - it("should detect assignments in do-while conditionals", () => { - const expectedFailure1 = createFailure([23, 15], [23, 20]); - const expectedFailure2 = createFailure([34, 15], [34, 21]); - TestUtils.assertContainsFailure(actualFailures, expectedFailure1); - TestUtils.assertContainsFailure(actualFailures, expectedFailure2); - }); - - it("should detect assignments in while conditionals", () => { - const expectedFailure1 = createFailure([25, 8], [25, 13]); - const expectedFailure2 = createFailure([26, 9], [26, 19]); - const expectedFailure3 = createFailure([35, 9], [35, 14]); - const expectedFailure4 = createFailure([35, 33], [35, 38]); - TestUtils.assertContainsFailure(actualFailures, expectedFailure1); - TestUtils.assertContainsFailure(actualFailures, expectedFailure2); - TestUtils.assertContainsFailure(actualFailures, expectedFailure3); - TestUtils.assertContainsFailure(actualFailures, expectedFailure4); - }); - - it("should detect assignments in for conditionals", () => { - const expectedFailure1 = createFailure([28, 17], [28, 22]); - const expectedFailure2 = createFailure([29, 21], [29, 26]); - TestUtils.assertContainsFailure(actualFailures, expectedFailure1); - TestUtils.assertContainsFailure(actualFailures, expectedFailure2); - }); - - it("no false positives for rule", () => { - assert.lengthOf(actualFailures, 13); - }); -}); diff --git a/test/rules/noConsoleRuleTests.ts b/test/rules/noConsoleRuleTests.ts deleted file mode 100644 index 07da4ee81a2..00000000000 --- a/test/rules/noConsoleRuleTests.ts +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - const NoConsoleRule = TestUtils.getRule("no-console"); - const fileName = "rules/noconsole.test.ts"; - - it("forbids access to specified console properties", () => { - const dirFailure = TestUtils.createFailuresOnFile(fileName, NoConsoleRule.FAILURE_STRING_PART + "console.dir")([3, 1], [3, 12]); - const errorFailure = TestUtils.createFailuresOnFile(fileName, NoConsoleRule.FAILURE_STRING_PART + "console.error")([7, 1], [7, 14]); - const logFailure = TestUtils.createFailuresOnFile(fileName, NoConsoleRule.FAILURE_STRING_PART + "console.log")([2, 1], [2, 12]); - const warnFailure = TestUtils.createFailuresOnFile(fileName, NoConsoleRule.FAILURE_STRING_PART + "console.warn")([6, 1], [6, 13]); - - const actualFailures = TestUtils.applyRuleOnFile(fileName, NoConsoleRule, [true, "dir", "error", "log", "warn"]); - TestUtils.assertContainsFailure(actualFailures, dirFailure); - TestUtils.assertContainsFailure(actualFailures, errorFailure); - TestUtils.assertContainsFailure(actualFailures, logFailure); - TestUtils.assertContainsFailure(actualFailures, warnFailure); - }); -}); diff --git a/test/rules/noConstructRuleTests.ts b/test/rules/noConstructRuleTests.ts deleted file mode 100644 index deb8aa0e9b4..00000000000 --- a/test/rules/noConstructRuleTests.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {RuleFailure, TestUtils} from "../lint"; - -describe("", () => { - const fileName = "rules/noconstruct.test.ts"; - const NoConstructRule = TestUtils.getRule("no-construct"); - const createFailure = TestUtils.createFailuresOnFile(fileName, NoConstructRule.FAILURE_STRING); - let actualFailures: RuleFailure[]; - - before(() => { - actualFailures = TestUtils.applyRuleOnFile(fileName, NoConstructRule); - }); - - it("forbids access to String constructor", () => { - const expectedFailure = createFailure([2, 13], [2, 23]); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("forbids access to Number constructor", () => { - const expectedFailure = createFailure([5, 10], [5, 23]); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("forbids access to Boolean constructor", () => { - const expectedFailure = createFailure([8, 10], [8, 21]); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); -}); diff --git a/test/rules/noConstructorVarsRuleTests.ts b/test/rules/noConstructorVarsRuleTests.ts deleted file mode 100644 index b26a9225092..00000000000 --- a/test/rules/noConstructorVarsRuleTests.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2014 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 {TestUtils} from "../lint"; - -describe("", () => { - const Rule = TestUtils.getRule("no-constructor-vars"); - const fileName = "rules/noconstructorvars.test.ts"; - const failureString = Rule.FAILURE_STRING_PART; - - it("no constructor variable declarations", () => { - const failureFoo = TestUtils.createFailuresOnFile(fileName, "'foo'" + failureString); - const failureBar = TestUtils.createFailuresOnFile(fileName, "'bar'" + failureString); - - const expectedFailures = [ - failureFoo([3, 17], [3, 24]), - failureFoo([9, 17], [9, 24]), - failureBar([9, 38], [9, 44]) - ]; - const actualFailures = TestUtils.applyRuleOnFile(fileName, Rule); - assert.lengthOf(actualFailures, 3); - - TestUtils.assertFailuresEqual(actualFailures, expectedFailures); - }); -}); diff --git a/test/tsconfig.json b/test/tsconfig.json index 440236b385e..c45d770edea 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -129,11 +129,7 @@ "ruleTestRunnerTests/testData.ts", "ruleTestRunnerTests/utilsTests.ts", "rules/eofLineRuleTests.ts", - "rules/noConditionalAssignmentRuleTests.ts", "rules/noConsecutiveBlankLinesRuleTests.ts", - "rules/noConsoleRuleTests.ts", - "rules/noConstructRuleTests.ts", - "rules/noConstructorVarsRuleTests.ts", "rules/noDuplicateKeyRuleTests.ts", "rules/noDuplicateVariableRuleTests.ts", "rules/noEmptyRuleTests.ts", From 51ee25fc472f82e123f0cbf9088908ae8eb3f2c3 Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Tue, 22 Dec 2015 23:23:06 -0500 Subject: [PATCH 14/30] Add '~nil' notation for zero-length errors Convert tests for no-consecutive-blank-lines, no-duplicate-key no-duplicate-variable, no-empty, and no-eval rules --- test/files/rules/blanklines.test.ts | 15 ----- test/ruleTestRunner/lines.ts | 28 +++++++--- test/ruleTestRunnerTests/linesTests.ts | 16 +++++- test/ruleTestRunnerTests/parseTests.ts | 12 ++++ test/ruleTestRunnerTests/testData.ts | 22 ++++++++ .../test.ts.linttest | 24 ++++++++ .../no-consecutive-blank-lines/tslint.json | 5 ++ .../no-duplicate-key/test.ts.linttest} | 4 ++ test/ruleTests/no-duplicate-key/tslint.json | 5 ++ .../no-duplicate-variable/test.ts.linttest} | 7 +++ .../no-duplicate-variable/tslint.json | 5 ++ .../no-empty/test.ts.linttest} | 13 ++++- test/ruleTests/no-empty/tslint.json | 5 ++ .../no-eval/test.ts.linttest} | 1 + test/ruleTests/no-eval/tslint.json | 5 ++ .../rules/noConsecutiveBlankLinesRuleTests.ts | 36 ------------ test/rules/noDuplicateKeyRuleTests.ts | 38 ------------- test/rules/noDuplicateVariableRuleTests.ts | 39 ------------- test/rules/noEmptyRuleTests.ts | 55 ------------------- test/rules/noEvalRuleTests.ts | 31 ----------- test/tsconfig.json | 5 -- 21 files changed, 141 insertions(+), 230 deletions(-) delete mode 100644 test/files/rules/blanklines.test.ts create mode 100644 test/ruleTests/no-consecutive-blank-lines/test.ts.linttest create mode 100644 test/ruleTests/no-consecutive-blank-lines/tslint.json rename test/{files/rules/dupkey.test.ts => ruleTests/no-duplicate-key/test.ts.linttest} (73%) create mode 100644 test/ruleTests/no-duplicate-key/tslint.json rename test/{files/rules/no-duplicate-variable.test.ts => ruleTests/no-duplicate-variable/test.ts.linttest} (86%) create mode 100644 test/ruleTests/no-duplicate-variable/tslint.json rename test/{files/rules/noempty.test.ts => ruleTests/no-empty/test.ts.linttest} (64%) create mode 100644 test/ruleTests/no-empty/tslint.json rename test/{files/rules/evil.test.ts => ruleTests/no-eval/test.ts.linttest} (71%) create mode 100644 test/ruleTests/no-eval/tslint.json delete mode 100644 test/rules/noConsecutiveBlankLinesRuleTests.ts delete mode 100644 test/rules/noDuplicateKeyRuleTests.ts delete mode 100644 test/rules/noDuplicateVariableRuleTests.ts delete mode 100644 test/rules/noEmptyRuleTests.ts delete mode 100644 test/rules/noEvalRuleTests.ts diff --git a/test/files/rules/blanklines.test.ts b/test/files/rules/blanklines.test.ts deleted file mode 100644 index d8b4ab1fdd8..00000000000 --- a/test/files/rules/blanklines.test.ts +++ /dev/null @@ -1,15 +0,0 @@ - - -class Clazz { // comment - - public funcxion() { - - // also comment - - - console.log("test"); - - } - - -} diff --git a/test/ruleTestRunner/lines.ts b/test/ruleTestRunner/lines.ts index 02125d5694f..70eba2a6458 100644 --- a/test/ruleTestRunner/lines.ts +++ b/test/ruleTestRunner/lines.ts @@ -32,8 +32,8 @@ export class MessageSubstitutionLine { export type ErrorLine = MultilineErrorLine | EndErrorLine; export type Line = CodeLine | ErrorLine | MessageSubstitutionLine; -const multilineErrorRegex = /^\s*~+$/; -const endErrorRegex = /^\s*~+\s*\[(.+)\]\s*$/; +const multilineErrorRegex = /^\s*(~+|~nil)$/; +const endErrorRegex = /^\s*(~+|~nil)\s*\[(.+)\]\s*$/; const messageSubstitutionRegex = /^\[(\w+?)]: \s*(.+?)\s*$/; export function classifyLine(line: string): Line { @@ -44,10 +44,10 @@ export function classifyLine(line: string): Line { const startErrorCol = line.indexOf("~"); return new MultilineErrorLine(startErrorCol); } else if (matches = line.match(endErrorRegex)) { + const [, squiggles, message] = matches; const startErrorCol = line.indexOf("~"); - // exclusive endpoint - const endErrorCol = line.lastIndexOf("~") + 1; - const [, message] = matches; + const zeroLengthError = (squiggles === "~nil"); + const endErrorCol = zeroLengthError ? startErrorCol : line.lastIndexOf("~") + 1; return new EndErrorLine(startErrorCol, endErrorCol, message); } else if (matches = line.match(messageSubstitutionRegex)) { const [, key, message] = matches; @@ -61,11 +61,23 @@ export function classifyLine(line: string): Line { export function createErrorString(code: string, errorLine: ErrorLine) { const startSpaces = strMult(" ", errorLine.startCol); if (errorLine instanceof MultilineErrorLine) { - const tildes = strMult("~", code.length - startSpaces.length); + // special case for when the line of code is simply a newline. + // use "~nil" to indicate the error continues on that line + if (code.length === 0 && errorLine.startCol === 0) { + return "~nil"; + } + + let tildes = strMult("~", code.length - startSpaces.length); return `${startSpaces}${tildes}`; } else if (errorLine instanceof EndErrorLine) { - const tildes = strMult("~", errorLine.endCol - errorLine.startCol); - const endSpaces = strMult(" ", code.length - errorLine.endCol); + let tildes = strMult("~", errorLine.endCol - errorLine.startCol); + let endSpaces = strMult(" ", code.length - errorLine.endCol); + if (tildes.length === 0) { + tildes = "~nil"; + // because we add "~nil" we need three less spaces than normal. + // always make sure we have at least one space though + endSpaces = endSpaces.substring(0, Math.max(endSpaces.length - 4, 1)); + } return `${startSpaces}${tildes}${endSpaces} [${errorLine.message}]`; } } diff --git a/test/ruleTestRunnerTests/linesTests.ts b/test/ruleTestRunnerTests/linesTests.ts index c167106ed8b..93535492833 100644 --- a/test/ruleTestRunnerTests/linesTests.ts +++ b/test/ruleTestRunnerTests/linesTests.ts @@ -21,13 +21,25 @@ describe("Rule Test Runner", () => { describe("::createErrorString", () => { it("should correctly create strings", () => { const code1 = "this is a line of code"; - const errorMarkup1 = " ~~~~~~~~~~~~~~~~~~~~"; const errorLine1 = new lines.MultilineErrorLine(2); + const errorMarkup1 = " ~~~~~~~~~~~~~~~~~~~~"; assert.strictEqual(lines.createErrorString(code1, errorLine1), errorMarkup1); const code2 = "another line of code here"; - const errorMarkup2 = "~~~~~~~~~~~~~~~~~~~~~~~~~ [foo]"; const errorLine2 = new lines.EndErrorLine(0, code2.length, "foo"); + const errorMarkup2 = "~~~~~~~~~~~~~~~~~~~~~~~~~ [foo]"; + assert.strictEqual(lines.createErrorString(code2, errorLine2), errorMarkup2); + }); + + it("should correctly create strings with empty lines of code", () => { + const code1 = ""; + const errorLine1 = new lines.MultilineErrorLine(0); + const errorMarkup1 = "~nil"; + assert.strictEqual(lines.createErrorString(code1, errorLine1), errorMarkup1); + + const code2 = ""; + const errorLine2 = new lines.EndErrorLine(0, 0, "foo"); + const errorMarkup2 = "~nil [foo]"; assert.strictEqual(lines.createErrorString(code2, errorLine2), errorMarkup2); }); }); diff --git a/test/ruleTestRunnerTests/parseTests.ts b/test/ruleTestRunnerTests/parseTests.ts index 3404a919ac4..761d22fcdcb 100644 --- a/test/ruleTestRunnerTests/parseTests.ts +++ b/test/ruleTestRunnerTests/parseTests.ts @@ -35,6 +35,10 @@ describe("Rule Test Runner", () => { it("should handle message substitutions correctly", () => { assert.strictEqual(parse.removeErrorMarkup(testData.lintStr6), testData.codeStr6); }); + + it("should handle nil-length errors correctly", () => { + assert.strictEqual(parse.removeErrorMarkup(testData.lintStr7), testData.codeStr7); + }); }); describe("::parseErrors", () => { @@ -53,12 +57,20 @@ describe("Rule Test Runner", () => { it("should handle message substitutions correctly", () => { assert.deepEqual(parse.parseErrorsFromMarkup(testData.lintStr6), testData.resultErrs6); }); + + it("should handle nil-length errors correctly", () => { + assert.deepEqual(parse.parseErrorsFromMarkup(testData.lintStr7), testData.resultErrs7); + }); }); describe("::createMarkupFromErrors", () => { it("should generate correct markup", () => { assert.strictEqual(parse.createMarkupFromErrors(testData.codeStr5, testData.resultErrs5), testData.lintStr5); }); + + it("should generate correct markup with nil-length errors", () => { + assert.strictEqual(parse.createMarkupFromErrors(testData.codeStr7, testData.resultErrs7), testData.lintStr7); + }); }); }); }); diff --git a/test/ruleTestRunnerTests/testData.ts b/test/ruleTestRunnerTests/testData.ts index 6a10e74bbef..2803f213c7e 100644 --- a/test/ruleTestRunnerTests/testData.ts +++ b/test/ruleTestRunnerTests/testData.ts @@ -108,6 +108,28 @@ export const resultErrs6: LintError[] = [ { startPos: { line: 1, col: 13 }, endPos: { line: 1, col: 28 }, message: "A longer error message I didn't want to type every time!" }, ]; +export const lintStr7 = ` +someCode.something(); + ~nil [some error] +more code { + +~nil + +~nil [another error] +} +`; +export const codeStr7 = ` +someCode.something(); +more code { + + +} +`; +export const resultErrs7: LintError[] = [ + { startPos: { line: 1, col: 1 }, endPos: { line: 1, col: 1 }, message: "some error" }, + { startPos: { line: 3, col: 0 }, endPos: { line: 4, col: 0 }, message: "another error" } +]; + /* tslint:enable:object-literal-sort-keys */ diff --git a/test/ruleTests/no-consecutive-blank-lines/test.ts.linttest b/test/ruleTests/no-consecutive-blank-lines/test.ts.linttest new file mode 100644 index 00000000000..c289eecc7b0 --- /dev/null +++ b/test/ruleTests/no-consecutive-blank-lines/test.ts.linttest @@ -0,0 +1,24 @@ +// the markup for this test is a little bit weird +// tslint, for the first error below, says it goes from +// [5, 1] to [6, 1], and thus the markup appears to be off (but it's not) + + +~nil +class Clazz { // comment +~nil [consecutive blank lines are disallowed] + + public funcxion() { + + // also comment + + +~nil + console.log("test"); +~nil [consecutive blank lines are disallowed] + + } + + +~nil +} +~nil [consecutive blank lines are disallowed] diff --git a/test/ruleTests/no-consecutive-blank-lines/tslint.json b/test/ruleTests/no-consecutive-blank-lines/tslint.json new file mode 100644 index 00000000000..3aa56ee6643 --- /dev/null +++ b/test/ruleTests/no-consecutive-blank-lines/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-consecutive-blank-lines": true + } +} diff --git a/test/files/rules/dupkey.test.ts b/test/ruleTests/no-duplicate-key/test.ts.linttest similarity index 73% rename from test/files/rules/dupkey.test.ts rename to test/ruleTests/no-duplicate-key/test.ts.linttest index 4071572ffb3..76ae4096b5e 100644 --- a/test/files/rules/dupkey.test.ts +++ b/test/ruleTests/no-duplicate-key/test.ts.linttest @@ -8,10 +8,13 @@ var x = { bd: 2, c: 3, axa: 4, // failure + ~~~ [duplicate key 'axa'] d: 5, ba: 3, bd: 6, // failure + ~~ [duplicate key 'bd'] axa: 6 // failure + ~~~ [duplicate key 'axa'] }; var z = { @@ -29,6 +32,7 @@ var interspersed = { duplicated: 1, // failure newContext: {}, duplicated: 2 // failure + ~~~~~~~~~~ [duplicate key 'duplicated'] }; var n = { diff --git a/test/ruleTests/no-duplicate-key/tslint.json b/test/ruleTests/no-duplicate-key/tslint.json new file mode 100644 index 00000000000..69550402f75 --- /dev/null +++ b/test/ruleTests/no-duplicate-key/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-duplicate-key": true + } +} diff --git a/test/files/rules/no-duplicate-variable.test.ts b/test/ruleTests/no-duplicate-variable/test.ts.linttest similarity index 86% rename from test/files/rules/no-duplicate-variable.test.ts rename to test/ruleTests/no-duplicate-variable/test.ts.linttest index 90b43cace42..8a6d92adb9b 100644 --- a/test/files/rules/no-duplicate-variable.test.ts +++ b/test/ruleTests/no-duplicate-variable/test.ts.linttest @@ -9,6 +9,7 @@ class Test { }; var duplicated = null; + ~~~~~~~~~~ [duplicate variable: 'duplicated'] } } @@ -20,10 +21,12 @@ function test() { }; var duplicated = null; + ~~~~~~~~~~ [duplicate variable: 'duplicated'] } duplicated = 2; var duplicated = 3; + ~~~~~~~~~~ [duplicate variable: 'duplicated'] // valid code module tmp { @@ -139,6 +142,7 @@ function testDestructuring() { var [x, y] = myFunc(); var [z, z] = myFunc(); // failure + ~ [duplicate variable: 'z'] let [x1, y1] = myFunc(); let [z1, z1] = myFunc(); // tsc error @@ -151,6 +155,7 @@ function testDestructuring() { var [a2, [b2, c2]] = [1, [2, 3]]; var [{a2, d2}] = [{a2: 1, d2: 4}]; // failure + ~~ [duplicate variable: 'a2'] function myFunc2([a, b]) { var a; // not a failure; caught by no-shadowed-variable @@ -158,5 +163,7 @@ function testDestructuring() { } var [x, y3] = myFunc(); // failure + ~ [duplicate variable: 'x'] var [x3, ...y] = [1, 2, 3, 4]; // failure + ~ [duplicate variable: 'y'] } diff --git a/test/ruleTests/no-duplicate-variable/tslint.json b/test/ruleTests/no-duplicate-variable/tslint.json new file mode 100644 index 00000000000..9d9b7a7156a --- /dev/null +++ b/test/ruleTests/no-duplicate-variable/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-duplicate-variable": true + } +} diff --git a/test/files/rules/noempty.test.ts b/test/ruleTests/no-empty/test.ts.linttest similarity index 64% rename from test/files/rules/noempty.test.ts rename to test/ruleTests/no-empty/test.ts.linttest index 565bb32b908..d78423babb0 100644 --- a/test/files/rules/noempty.test.ts +++ b/test/ruleTests/no-empty/test.ts.linttest @@ -1,14 +1,23 @@ if (x === 1) {} + ~~ [block is empty] if (x === 2) { + ~ +~nil +~nil } +~ [block is empty] function testFunction() { + ~ +~nil } +~ [block is empty] for (var x = 0; x < 1; ++x) { } + ~~~ [block is empty] // empty blocks with comments should be legal for (var y = 0; y < 1; ++y) { @@ -27,5 +36,7 @@ class testClass2 { class testClass3 { constructor(notAllowed: any) { + ~ } -} +~~~~~ [block is empty] +} \ No newline at end of file diff --git a/test/ruleTests/no-empty/tslint.json b/test/ruleTests/no-empty/tslint.json new file mode 100644 index 00000000000..282eaa1ffa3 --- /dev/null +++ b/test/ruleTests/no-empty/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-empty": true + } +} diff --git a/test/files/rules/evil.test.ts b/test/ruleTests/no-eval/test.ts.linttest similarity index 71% rename from test/files/rules/evil.test.ts rename to test/ruleTests/no-eval/test.ts.linttest index b093df9029d..d7ffe5c856c 100644 --- a/test/files/rules/evil.test.ts +++ b/test/ruleTests/no-eval/test.ts.linttest @@ -4,6 +4,7 @@ function a() { function b() { function c() { eval("console.log('hi');"); + ~~~~ [forbidden eval] } } } diff --git a/test/ruleTests/no-eval/tslint.json b/test/ruleTests/no-eval/tslint.json new file mode 100644 index 00000000000..1f0ba96f559 --- /dev/null +++ b/test/ruleTests/no-eval/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-eval": true + } +} diff --git a/test/rules/noConsecutiveBlankLinesRuleTests.ts b/test/rules/noConsecutiveBlankLinesRuleTests.ts deleted file mode 100644 index 4d1e6647806..00000000000 --- a/test/rules/noConsecutiveBlankLinesRuleTests.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - const NoConsecutiveBlankLinesRule = TestUtils.getRule("no-consecutive-blank-lines"); - const fileName = "rules/blanklines.test.ts"; - - it("ensures there is at most one consecutive blank line", () => { - const createFailure = TestUtils.createFailuresOnFile(fileName, NoConsecutiveBlankLinesRule.FAILURE_STRING); - const expectedFailure1 = createFailure([2, 1], [3, 1]); - const expectedFailure2 = createFailure([9, 1], [10, 1]); - const expectedFailure3 = createFailure([14, 1], [15, 1]); - - const actualFailures = TestUtils.applyRuleOnFile(fileName, NoConsecutiveBlankLinesRule); - - TestUtils.assertContainsFailure(actualFailures, expectedFailure1); - TestUtils.assertContainsFailure(actualFailures, expectedFailure2); - TestUtils.assertContainsFailure(actualFailures, expectedFailure3); - assert.lengthOf(actualFailures, 3); - }); -}); diff --git a/test/rules/noDuplicateKeyRuleTests.ts b/test/rules/noDuplicateKeyRuleTests.ts deleted file mode 100644 index 2b09812929e..00000000000 --- a/test/rules/noDuplicateKeyRuleTests.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - const NoDuplicateKeyRule = TestUtils.getRule("no-duplicate-key"); - const fileName = "rules/dupkey.test.ts"; - const failureString = NoDuplicateKeyRule.FAILURE_STRING; - - it("forbids duplicate keys in object literals", () => { - const actualFailures = TestUtils.applyRuleOnFile(fileName, NoDuplicateKeyRule); - const createFailure1 = TestUtils.createFailuresOnFile(fileName, failureString + "axa'"); - const createFailure2 = TestUtils.createFailuresOnFile(fileName, failureString + "bd'"); - const createFailure3 = TestUtils.createFailuresOnFile(fileName, failureString + "duplicated'"); - const expectedFailures = [ - createFailure1([10, 5], [10, 8]), - createFailure2([13, 5], [13, 7]), - createFailure1([14, 5], [14, 8]), - createFailure3([31, 5], [31, 15]) - ]; - - TestUtils.assertFailuresEqual(actualFailures, expectedFailures); - }); -}); diff --git a/test/rules/noDuplicateVariableRuleTests.ts b/test/rules/noDuplicateVariableRuleTests.ts deleted file mode 100644 index 9175c11a28b..00000000000 --- a/test/rules/noDuplicateVariableRuleTests.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - const NoDuplicateVariableRule = TestUtils.getRule("no-duplicate-variable"); - const fileName = "rules/no-duplicate-variable.test.ts"; - const failureString = NoDuplicateVariableRule.FAILURE_STRING + "duplicated'"; - - it("ensures that variable declarations are unique within a scope", () => { - const createFailure = TestUtils.createFailuresOnFile(fileName, failureString); - const expectedFailures = [ - createFailure([11, 13], [11, 23]), - createFailure([22, 9], [22, 19]), - createFailure([26, 5], [26, 15]), - TestUtils.createFailure(fileName, [141, 13], [141, 14], NoDuplicateVariableRule.FAILURE_STRING + "z'"), - TestUtils.createFailure(fileName, [153, 11], [153, 13], NoDuplicateVariableRule.FAILURE_STRING + "a2'"), - TestUtils.createFailure(fileName, [160, 10], [160, 11], NoDuplicateVariableRule.FAILURE_STRING + "x'"), - TestUtils.createFailure(fileName, [161, 17], [161, 18], NoDuplicateVariableRule.FAILURE_STRING + "y'") - ]; - - const actualFailures = TestUtils.applyRuleOnFile(fileName, NoDuplicateVariableRule); - TestUtils.assertFailuresEqual(actualFailures, expectedFailures); - }); -}); diff --git a/test/rules/noEmptyRuleTests.ts b/test/rules/noEmptyRuleTests.ts deleted file mode 100644 index d191dd90008..00000000000 --- a/test/rules/noEmptyRuleTests.ts +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {RuleFailure, TestUtils} from "../lint"; - -describe("", () => { - const fileName = "rules/noempty.test.ts"; - const NoEmptyRule = TestUtils.getRule("no-empty"); - const createFailure = TestUtils.createFailuresOnFile(fileName, NoEmptyRule.FAILURE_STRING); - let actualFailures: RuleFailure[]; - - before(() => { - actualFailures = TestUtils.applyRuleOnFile(fileName, NoEmptyRule); - }); - - it("forbids empty conditional blocks", () => { - const expectedFailure1 = createFailure([1, 14], [1, 16]); - const expectedFailure2 = createFailure([2, 14], [5, 2]); - - TestUtils.assertContainsFailure(actualFailures, expectedFailure1); - TestUtils.assertContainsFailure(actualFailures, expectedFailure2); - }); - - it("forbids empty function blocks", () => { - const expectedFailure = createFailure([7, 25], [9, 2]); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("forbids empty loop blocks", () => { - const expectedFailure = createFailure([11, 29], [11, 32]); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("forbids empty constructors", () => { - const expectedFailure = createFailure([29, 34], [30, 6]); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("non empty blocks are allowed", () => { - assert.lengthOf(actualFailures, 5); - }); -}); diff --git a/test/rules/noEvalRuleTests.ts b/test/rules/noEvalRuleTests.ts deleted file mode 100644 index 2d65810cb24..00000000000 --- a/test/rules/noEvalRuleTests.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - const NoEvalRule = TestUtils.getRule("no-eval"); - const fileName = "rules/evil.test.ts"; - const failureString = NoEvalRule.FAILURE_STRING; - - it("forbids eval", () => { - const expectedFailure = TestUtils.createFailure(fileName, [6, 13], [6, 17], failureString); - const actualFailures = TestUtils.applyRuleOnFile(fileName, NoEvalRule); - - assert.equal(actualFailures.length, 1); - assert.isTrue(actualFailures[0].equals(expectedFailure)); - }); -}); diff --git a/test/tsconfig.json b/test/tsconfig.json index c45d770edea..f340c2bf0d7 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -129,11 +129,6 @@ "ruleTestRunnerTests/testData.ts", "ruleTestRunnerTests/utilsTests.ts", "rules/eofLineRuleTests.ts", - "rules/noConsecutiveBlankLinesRuleTests.ts", - "rules/noDuplicateKeyRuleTests.ts", - "rules/noDuplicateVariableRuleTests.ts", - "rules/noEmptyRuleTests.ts", - "rules/noEvalRuleTests.ts", "rules/noInferrableTypesRuleTests.ts", "rules/noInternalModuleRuleTests.ts", "rules/noNullKeywordRuleTests.ts", From e8b3b257f467f6ac48a995968f16bc6c16d76c61 Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Tue, 22 Dec 2015 23:43:36 -0500 Subject: [PATCH 15/30] Convert tests for no-inferrable-types, no-internal-modules, no-null-keyword, and no-require-imports. Allow '-' and '_' in message shortcuts --- test/files/rules/noinferrabletypes.test.ts | 21 ---------- test/files/rules/nonullkeyword.test.ts | 2 - test/ruleTestRunner/lines.ts | 2 +- .../no-inferrable-types/test.ts.linttest | 31 ++++++++++++++ .../ruleTests/no-inferrable-types/tslint.json | 5 +++ .../no-internal-module/test.ts.linttest} | 26 ++++++++++++ test/ruleTests/no-internal-module/tslint.json | 5 +++ .../no-null-keyword/test.ts.linttest | 4 ++ test/ruleTests/no-null-keyword/tslint.json | 5 +++ .../no-require-imports/test.ts.linttest} | 7 ++++ test/ruleTests/no-require-imports/tslint.json | 5 +++ test/rules/noInferrableTypesRuleTests.ts | 40 ------------------- test/rules/noInternalModuleRuleTests.ts | 40 ------------------- test/rules/noNullKeywordRuleTests.ts | 39 ------------------ test/rules/noRequireImportsRuleTests.ts | 39 ------------------ test/tsconfig.json | 4 -- 16 files changed, 89 insertions(+), 186 deletions(-) delete mode 100644 test/files/rules/noinferrabletypes.test.ts delete mode 100644 test/files/rules/nonullkeyword.test.ts create mode 100644 test/ruleTests/no-inferrable-types/test.ts.linttest create mode 100644 test/ruleTests/no-inferrable-types/tslint.json rename test/{files/rules/nointernalmodule.test.ts => ruleTests/no-internal-module/test.ts.linttest} (60%) create mode 100644 test/ruleTests/no-internal-module/tslint.json create mode 100644 test/ruleTests/no-null-keyword/test.ts.linttest create mode 100644 test/ruleTests/no-null-keyword/tslint.json rename test/{files/rules/norequireimports.test.ts => ruleTests/no-require-imports/test.ts.linttest} (52%) create mode 100644 test/ruleTests/no-require-imports/tslint.json delete mode 100644 test/rules/noInferrableTypesRuleTests.ts delete mode 100644 test/rules/noInternalModuleRuleTests.ts delete mode 100644 test/rules/noNullKeywordRuleTests.ts delete mode 100644 test/rules/noRequireImportsRuleTests.ts diff --git a/test/files/rules/noinferrabletypes.test.ts b/test/files/rules/noinferrabletypes.test.ts deleted file mode 100644 index 27c40f2aca3..00000000000 --- a/test/files/rules/noinferrabletypes.test.ts +++ /dev/null @@ -1,21 +0,0 @@ -// errors, inferrable type is declared -let x: number = 7; -let y: boolean = false; -let z: string = "foo"; - -// errors, types are inferrable -function foo (a: number = 5, b: boolean = true, c: string = "bah") { } - -// not errors, inferrable type is not declared -let _x = 7; -let _y = false; -let _z = "foo"; - -// not error, type is not inferrable -let weird: any = 123; - -// not errors, inferrable type is not declared -function bar(a = 5, b = true, c = "bah") { } - -// not errors, types are not inferrable -function baz(a: any = 5, b: any = true, c: any = "bah") { } diff --git a/test/files/rules/nonullkeyword.test.ts b/test/files/rules/nonullkeyword.test.ts deleted file mode 100644 index b8554126bce..00000000000 --- a/test/files/rules/nonullkeyword.test.ts +++ /dev/null @@ -1,2 +0,0 @@ -var x = null; // error -console.log(null, x); // error diff --git a/test/ruleTestRunner/lines.ts b/test/ruleTestRunner/lines.ts index 70eba2a6458..e67db863ac7 100644 --- a/test/ruleTestRunner/lines.ts +++ b/test/ruleTestRunner/lines.ts @@ -34,7 +34,7 @@ export type Line = CodeLine | ErrorLine | MessageSubstitutionLine; const multilineErrorRegex = /^\s*(~+|~nil)$/; const endErrorRegex = /^\s*(~+|~nil)\s*\[(.+)\]\s*$/; -const messageSubstitutionRegex = /^\[(\w+?)]: \s*(.+?)\s*$/; +const messageSubstitutionRegex = /^\[([\w\-\_]+?)]: \s*(.+?)\s*$/; export function classifyLine(line: string): Line { let matches: RegExpMatchArray; diff --git a/test/ruleTests/no-inferrable-types/test.ts.linttest b/test/ruleTests/no-inferrable-types/test.ts.linttest new file mode 100644 index 00000000000..1dc436a1163 --- /dev/null +++ b/test/ruleTests/no-inferrable-types/test.ts.linttest @@ -0,0 +1,31 @@ +// errors, inferrable type is declared +let x: number = 7; + ~~~~~~ [number] +let y: boolean = false; + ~~~~~~~ [boolean] +let z: string = "foo"; + ~~~~~~ [string] + +// errors, types are inferrable +function foo (a: number = 5, b: boolean = true, c: string = "bah") { } + ~~~~~~ [number] + ~~~~~~~ [boolean] + ~~~~~~ [string] + +// not errors, inferrable type is not declared +let _x = 7; +let _y = false; +let _z = "foo"; + +// not error, type is not inferrable +let weird: any = 123; + +// not errors, inferrable type is not declared +function bar(a = 5, b = true, c = "bah") { } + +// not errors, types are not inferrable +function baz(a: any = 5, b: any = true, c: any = "bah") { } + +[number]: LHS type (number) inferred by RHS expression, remove type annotation +[boolean]: LHS type (boolean) inferred by RHS expression, remove type annotation +[string]: LHS type (string) inferred by RHS expression, remove type annotation diff --git a/test/ruleTests/no-inferrable-types/tslint.json b/test/ruleTests/no-inferrable-types/tslint.json new file mode 100644 index 00000000000..e753f48f599 --- /dev/null +++ b/test/ruleTests/no-inferrable-types/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-inferrable-types": true + } +} diff --git a/test/files/rules/nointernalmodule.test.ts b/test/ruleTests/no-internal-module/test.ts.linttest similarity index 60% rename from test/files/rules/nointernalmodule.test.ts rename to test/ruleTests/no-internal-module/test.ts.linttest index 02841ffcc14..aee14190a5c 100644 --- a/test/files/rules/nointernalmodule.test.ts +++ b/test/ruleTests/no-internal-module/test.ts.linttest @@ -2,10 +2,14 @@ namespace foo { } module bar { +~~~~~~~~~~~~ } +~ [0] declare module buzz { +~~~~~~~~~~~~~~~~~~~~~ } +~ [0] declare module "hoge" { } @@ -23,17 +27,29 @@ namespace foo { namespace foo.bar { module baz { + ~~~~~~~~~~~~ namespace buzz { +~~~~~~~~~~~~~~~~~~~~~~~~ } +~~~~~~~~~ } +~~~~~ [0] } module foo.bar { +~~~~~~~~~~~~~~~~ namespace baz { +~~~~~~~~~~~~~~~~~~~ module buzz { +~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~ } +~~~~~~~~~ +~~~~~~~~~ [0] } +~~~~~ } +~ [0] namespace name.namespace { } @@ -42,11 +58,21 @@ namespace namespace.name { // intentionally malformed for test cases, do not format declare module declare +~~~~~~~~~~~~~~~~~~~~~~ .dec{} +~~~~~~ [0] declare module dec . declare { +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ } +~ [0] module mod.module{} +~~~~~~~~~~~~~~~~~~~~ [0] module module.mod +~~~~~~~~~~~~~~~~~ { +~ } +~ [0] + +[0]: forbidden internal module diff --git a/test/ruleTests/no-internal-module/tslint.json b/test/ruleTests/no-internal-module/tslint.json new file mode 100644 index 00000000000..ac4edc57f5f --- /dev/null +++ b/test/ruleTests/no-internal-module/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-internal-module": true + } +} diff --git a/test/ruleTests/no-null-keyword/test.ts.linttest b/test/ruleTests/no-null-keyword/test.ts.linttest new file mode 100644 index 00000000000..1cab307c4a1 --- /dev/null +++ b/test/ruleTests/no-null-keyword/test.ts.linttest @@ -0,0 +1,4 @@ +var x = null; // error + ~~~~ [Use 'undefined' instead of 'null'] +console.log(null, x); // error + ~~~~ [Use 'undefined' instead of 'null'] diff --git a/test/ruleTests/no-null-keyword/tslint.json b/test/ruleTests/no-null-keyword/tslint.json new file mode 100644 index 00000000000..1e4bf06a307 --- /dev/null +++ b/test/ruleTests/no-null-keyword/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-null-keyword": true + } +} diff --git a/test/files/rules/norequireimports.test.ts b/test/ruleTests/no-require-imports/test.ts.linttest similarity index 52% rename from test/files/rules/norequireimports.test.ts rename to test/ruleTests/no-require-imports/test.ts.linttest index 6d4ba626888..b54741ed2b8 100644 --- a/test/files/rules/norequireimports.test.ts +++ b/test/ruleTests/no-require-imports/test.ts.linttest @@ -1,6 +1,8 @@ var lib = require('lib'); // failure + ~~~~~~~~~~~~~~ [no-require] let lib2 = require('lib2'); // failure + ~~~~~~~~~~~~~~~ [no-require] import {l} from 'lib'; @@ -9,9 +11,14 @@ var lib3 = load('not_an_import'); var lib4 = lib2.subImport; var lib5 = require('lib5'), // failure + ~~~~~~~~~~~~~~~ [no-require] lib6 = require('lib6'), // failure + ~~~~~~~~~~~~~~~ [no-require] lib7 = 700; import lib8 = require('lib8'); // failure + ~~~~~~~~~~~~~~~ [no-require] import lib9 = lib2.anotherSubImport; + +[no-require]: require() style import is forbidden diff --git a/test/ruleTests/no-require-imports/tslint.json b/test/ruleTests/no-require-imports/tslint.json new file mode 100644 index 00000000000..39bc26f8312 --- /dev/null +++ b/test/ruleTests/no-require-imports/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-require-imports": true + } +} diff --git a/test/rules/noInferrableTypesRuleTests.ts b/test/rules/noInferrableTypesRuleTests.ts deleted file mode 100644 index 2fd16637d6b..00000000000 --- a/test/rules/noInferrableTypesRuleTests.ts +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2015 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 {TestUtils} from "../lint"; - -describe("", () => { - const Rule = TestUtils.getRule("no-inferrable-types"); - const fileName = "rules/noinferrabletypes.test.ts"; - - it("forbids explicit type declarations where easily inferrable", () => { - const createFailure = (start: number[], end: number[], type: string) => { - const failureString = Rule.FAILURE_STRING_FACTORY(type); - return TestUtils.createFailure(fileName, start, end, failureString); - }; - - const expectedFailures = [ - createFailure([2, 8], [2, 14], "number"), - createFailure([3, 8], [3, 15], "boolean"), - createFailure([4, 8], [4, 14], "string"), - createFailure([7, 18], [7, 24], "number"), - createFailure([7, 33], [7, 40], "boolean"), - createFailure([7, 52], [7, 58], "string") - ]; - const actualFailures = TestUtils.applyRuleOnFile(fileName, Rule); - TestUtils.assertFailuresEqual(actualFailures, expectedFailures); - }); -}); diff --git a/test/rules/noInternalModuleRuleTests.ts b/test/rules/noInternalModuleRuleTests.ts deleted file mode 100644 index 91924f0400d..00000000000 --- a/test/rules/noInternalModuleRuleTests.ts +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - const NoInternalModule = TestUtils.getRule("no-internal-module"); - const fileName = "rules/nointernalmodule.test.ts"; - const failureString = NoInternalModule.FAILURE_STRING; - - it("forbids internal module", () => { - const actualFailures = TestUtils.applyRuleOnFile(fileName, NoInternalModule); - const expectedFailures = [ - TestUtils.createFailure(fileName, [4, 1], [4, 15], failureString), - TestUtils.createFailure(fileName, [7, 1], [7, 24], failureString), - TestUtils.createFailure(fileName, [25, 5], [28, 6], failureString), - TestUtils.createFailure(fileName, [31, 1], [36, 2], failureString), - TestUtils.createFailure(fileName, [33, 9], [33, 32], failureString), - TestUtils.createFailure(fileName, [44, 1], [44, 30], failureString), - TestUtils.createFailure(fileName, [46, 1], [46, 35], failureString), - TestUtils.createFailure(fileName, [49, 1], [49, 21], failureString), - TestUtils.createFailure(fileName, [50, 1], [50, 22], failureString) - ]; - - TestUtils.assertFailuresEqual(actualFailures, expectedFailures); - }); -}); diff --git a/test/rules/noNullKeywordRuleTests.ts b/test/rules/noNullKeywordRuleTests.ts deleted file mode 100644 index 868a7ef6ead..00000000000 --- a/test/rules/noNullKeywordRuleTests.ts +++ /dev/null @@ -1,39 +0,0 @@ -/** - * @license - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - const fileName = "rules/nonullkeyword.test.ts"; - const NoNullKeywordRule = TestUtils.getRule("no-null-keyword"); - const actualFailures = TestUtils.applyRuleOnFile(fileName, NoNullKeywordRule); - - const createFailure = TestUtils.createFailuresOnFile(fileName, NoNullKeywordRule.FAILURE_STRING); - - it("disallows assignment 'null'", () => { - assert.equal(actualFailures.length, 2); - - const expectedFailures = [ - createFailure([1, 9], [1, 13]), - createFailure([2, 13], [2, 17]) - ]; - - for (let failure of expectedFailures) { - TestUtils.assertContainsFailure(actualFailures, failure); - } - }); -}); diff --git a/test/rules/noRequireImportsRuleTests.ts b/test/rules/noRequireImportsRuleTests.ts deleted file mode 100644 index 237e2d68a31..00000000000 --- a/test/rules/noRequireImportsRuleTests.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - const Rule = TestUtils.getRule("no-require-imports"); - const fileName = "rules/norequireimports.test.ts"; - - it("forbids require() imports", () => { - const actualFailures = TestUtils.applyRuleOnFile(fileName, Rule); - - assert(actualFailures.length === 5, "Expected 5 failures, got " + actualFailures.length); - const failure1 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING)([1, 11], [1, 25]); - const failure2 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING)([3, 12], [3, 27]); - const failure3 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING)([11, 12], [11, 27]); - const failure4 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING)([12, 12], [12, 27]); - const failure5 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING)([15, 15], [15, 30]); - - TestUtils.assertContainsFailure(actualFailures, failure1); - TestUtils.assertContainsFailure(actualFailures, failure2); - TestUtils.assertContainsFailure(actualFailures, failure3); - TestUtils.assertContainsFailure(actualFailures, failure4); - TestUtils.assertContainsFailure(actualFailures, failure5); - }); -}); diff --git a/test/tsconfig.json b/test/tsconfig.json index f340c2bf0d7..d9ae92330eb 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -129,10 +129,6 @@ "ruleTestRunnerTests/testData.ts", "ruleTestRunnerTests/utilsTests.ts", "rules/eofLineRuleTests.ts", - "rules/noInferrableTypesRuleTests.ts", - "rules/noInternalModuleRuleTests.ts", - "rules/noNullKeywordRuleTests.ts", - "rules/noRequireImportsRuleTests.ts", "rules/noShadowedVariableRuleTests.ts", "rules/noStringLiteralRuleTests.ts", "rules/noSwitchCaseFallThroughRuleTests.ts", From 4b1daaa65c73a20ddb776e151392992e79a24454 Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Wed, 23 Dec 2015 00:29:12 -0500 Subject: [PATCH 16/30] Convert tests for no-shadowed-variable, no-string-literal, no-switch-case-fall-through, and no-trailing-whitespace rules Tweak no-switch-case-fall-through rule to have saner error start and end locations --- src/rules/noSwitchCaseFallThroughRule.ts | 6 +- .../no-shadowed-variable/test.ts.linttest} | 26 ++++++++- .../no-shadowed-variable/tslint.json | 5 ++ .../no-string-literal/test.ts.linttest} | 6 ++ test/ruleTests/no-string-literal/tslint.json | 5 ++ .../test.ts.linttest} | 7 +++ .../no-switch-case-fall-through/tslint.json | 5 ++ .../no-trailing-whitespace/test.ts.linttest} | 7 +++ .../no-trailing-whitespace/tslint.json | 5 ++ test/rules/noShadowedVariableRuleTests.ts | 58 ------------------- test/rules/noStringLiteralRuleTests.ts | 36 ------------ .../rules/noSwitchCaseFallThroughRuleTests.ts | 41 ------------- test/rules/noTrailingWhitespaceRuleTests.ts | 39 ------------- test/tsconfig.json | 4 -- 14 files changed, 68 insertions(+), 182 deletions(-) rename test/{files/rules/no-shadowed-variable.test.ts => ruleTests/no-shadowed-variable/test.ts.linttest} (63%) create mode 100644 test/ruleTests/no-shadowed-variable/tslint.json rename test/{files/rules/sub.test.ts => ruleTests/no-string-literal/test.ts.linttest} (61%) create mode 100644 test/ruleTests/no-string-literal/tslint.json rename test/{files/rules/noswitchcasefallthrough.test.ts => ruleTests/no-switch-case-fall-through/test.ts.linttest} (72%) create mode 100644 test/ruleTests/no-switch-case-fall-through/tslint.json rename test/{files/rules/trailing.test.ts => ruleTests/no-trailing-whitespace/test.ts.linttest} (50%) create mode 100644 test/ruleTests/no-trailing-whitespace/tslint.json delete mode 100644 test/rules/noShadowedVariableRuleTests.ts delete mode 100644 test/rules/noStringLiteralRuleTests.ts delete mode 100644 test/rules/noSwitchCaseFallThroughRuleTests.ts delete mode 100644 test/rules/noTrailingWhitespaceRuleTests.ts diff --git a/src/rules/noSwitchCaseFallThroughRule.ts b/src/rules/noSwitchCaseFallThroughRule.ts index 68edec04a0d..d4102e8bb00 100644 --- a/src/rules/noSwitchCaseFallThroughRule.ts +++ b/src/rules/noSwitchCaseFallThroughRule.ts @@ -42,8 +42,8 @@ export class NoSwitchCaseFallThroughWalker extends Lint.RuleWalker { if (isFallingThrough && switchClause.statements.length > 0 && ((switchClauses.length - 1) > i)) { if (!isFallThroughAllowed(switchClauses[i + 1])) { this.addFailure(this.createFailure( - child.getEnd(), - 1, + switchClauses[i + 1].getStart(), + "case".length, `${Rule.FAILURE_STRING_PART}'case'` )); } @@ -52,7 +52,7 @@ export class NoSwitchCaseFallThroughWalker extends Lint.RuleWalker { // case statement falling through a default if (isFallingThrough && !isFallThroughAllowed(child)) { const failureString = Rule.FAILURE_STRING_PART + "'default'"; - this.addFailure(this.createFailure(switchClauses[i - 1].getEnd(), 1, failureString)); + this.addFailure(this.createFailure(switchClauses[i].getStart(), "default".length, failureString)); } } }); diff --git a/test/files/rules/no-shadowed-variable.test.ts b/test/ruleTests/no-shadowed-variable/test.ts.linttest similarity index 63% rename from test/files/rules/no-shadowed-variable.test.ts rename to test/ruleTests/no-shadowed-variable/test.ts.linttest index 36b63434301..740fc097b73 100644 --- a/test/files/rules/no-shadowed-variable.test.ts +++ b/test/ruleTests/no-shadowed-variable/test.ts.linttest @@ -4,13 +4,17 @@ function letTesting() { if (true) { let a = 2; // failure + ~ [shadowed variable: 'a'] let b = 2; // failure + ~ [shadowed variable: 'b'] let c = 2; var e = 2; } else { let b = 3; // failure + ~ [shadowed variable: 'b'] let c = 3; let e = 3; // failure + ~ [shadowed variable: 'e'] let f = 3; } @@ -20,11 +24,13 @@ function letTesting() { let a = 1; if (true) { let a = 2; // failure + ~ [shadowed variable: 'a'] } var g = 1; for (var index in [0, 1, 2]) { var g = 2; // failure + ~ [shadowed variable: 'g'] } function constTesting() { @@ -33,18 +39,24 @@ function constTesting() { if (true) { const h = 2; // failure + ~ [shadowed variable: 'h'] const i = 2; // failure + ~ [shadowed variable: 'i'] } } function testArguments(x: number, y: number): void { var x = 1; // failure + ~ [shadowed variable: 'x'] let y = 2; // tsc error + ~ [shadowed variable: 'y'] } let j = 1; for (var index in [0, 1, 2]) { // failure + ~~~~~ [shadowed variable: 'index'] let j = 2; // failure + ~ [shadowed variable: 'j'] } function testTryStatement() { @@ -57,6 +69,7 @@ function testTryStatement() { } finally { let foo = 3; let bar = 3; // failure + ~~~ [shadowed variable: 'bar'] } } @@ -65,6 +78,7 @@ function testWhileStatement() { while (true) { let foo = 2; // failure + ~~~ [shadowed variable: 'foo'] } } @@ -73,6 +87,7 @@ function testDoStatement() { do { let foo = 2; // failure + ~~~ [shadowed variable: 'foo'] } while (true); } @@ -86,15 +101,21 @@ function testDestructuring(x: number) { function innerFunc() { var [foo] = myFunc(); var [x] = myFunc(); // failure + ~ [shadowed variable: 'x'] let [y] = myFunc(); // failure + ~ [shadowed variable: 'y'] const [z] = myFunc(); // failure + ~ [shadowed variable: 'z'] } function anotherInnerFunc() { var [{x}] = [{x: 1}]; // failure + ~ [shadowed variable: 'x'] let [[y]] = [[2]]; // failure + ~ [shadowed variable: 'y'] var [foo, ...bar] = [1, 2, 3, 4]; var [...z] = [1, 2, 3, 4]; // failure + ~ [shadowed variable: 'z'] } } @@ -118,13 +139,16 @@ interface FalsePositive4 { let p = 1; function testParameterDestructuring( { pos: p }: FalsePositive3, // failure + ~ [shadowed variable: 'p'] { pos: q, specular: r }: FalsePositive3, { pos }: FalsePositive3 ) { p = 2; var q = 1; // failure + ~ [shadowed variable: 'q'] function someInnerFunc() { let pos = 3; // failure + ~~~ [shadowed variable: 'pos'] } -} +} \ No newline at end of file diff --git a/test/ruleTests/no-shadowed-variable/tslint.json b/test/ruleTests/no-shadowed-variable/tslint.json new file mode 100644 index 00000000000..f9d0b34237a --- /dev/null +++ b/test/ruleTests/no-shadowed-variable/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-shadowed-variable": true + } +} diff --git a/test/files/rules/sub.test.ts b/test/ruleTests/no-string-literal/test.ts.linttest similarity index 61% rename from test/files/rules/sub.test.ts rename to test/ruleTests/no-string-literal/test.ts.linttest index 2de0e9db93b..e262bc9114b 100644 --- a/test/files/rules/sub.test.ts +++ b/test/ruleTests/no-string-literal/test.ts.linttest @@ -8,14 +8,20 @@ var obj = { function test() { var a = obj.a; var b = obj[ 'bcd' ]; + ~~~~~ [0] var c = obj["c"]; + ~~~ [0] var d = obj[b]; } obj["invalid_accessor"]; + ~~~~~~~~~~~~~~~~~~ [0] obj["_AnotherInvalidAccessor"]; + ~~~~~~~~~~~~~~~~~~~~~~~~~ [0] // valid accessors obj["a-2"]; obj["2a"]; obj["?a#$!$^&%&"]; + +[0]: object access via string literals is disallowed \ No newline at end of file diff --git a/test/ruleTests/no-string-literal/tslint.json b/test/ruleTests/no-string-literal/tslint.json new file mode 100644 index 00000000000..ade4197c3d3 --- /dev/null +++ b/test/ruleTests/no-string-literal/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-string-literal": true + } +} diff --git a/test/files/rules/noswitchcasefallthrough.test.ts b/test/ruleTests/no-switch-case-fall-through/test.ts.linttest similarity index 72% rename from test/files/rules/noswitchcasefallthrough.test.ts rename to test/ruleTests/no-switch-case-fall-through/test.ts.linttest index 19e4bb2eb06..1dc40e8627b 100644 --- a/test/files/rules/noswitchcasefallthrough.test.ts +++ b/test/ruleTests/no-switch-case-fall-through/test.ts.linttest @@ -2,11 +2,14 @@ switch (foo) { case 1: bar(); case 2: + ~~~~ [expected a 'break' before 'case'] bar(); bar(); case 3: + ~~~~ [expected a 'break' before 'case'] case 4: default: + ~~~~~~~ [expected a 'break' before 'default'] break; } @@ -15,6 +18,7 @@ switch (foo) { case 1: bar(); case 2: + ~~~~ [expected a 'break' before 'case'] bar(); } @@ -23,6 +27,7 @@ switch (foo) { case 1: case 2: default: + ~~~~~~~ [expected a 'break' before 'default'] bar(); } @@ -31,9 +36,11 @@ switch (foo) { switch (bar) { case "": default: + ~~~~~~~ [expected a 'break' before 'default'] break; } case 2: + ~~~~ [expected a 'break' before 'case'] } switch (foo) { diff --git a/test/ruleTests/no-switch-case-fall-through/tslint.json b/test/ruleTests/no-switch-case-fall-through/tslint.json new file mode 100644 index 00000000000..31c7fba4e6e --- /dev/null +++ b/test/ruleTests/no-switch-case-fall-through/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-switch-case-fall-through": true + } +} diff --git a/test/files/rules/trailing.test.ts b/test/ruleTests/no-trailing-whitespace/test.ts.linttest similarity index 50% rename from test/files/rules/trailing.test.ts rename to test/ruleTests/no-trailing-whitespace/test.ts.linttest index b5076c863aa..6ef8b5e18b4 100644 --- a/test/files/rules/trailing.test.ts +++ b/test/ruleTests/no-trailing-whitespace/test.ts.linttest @@ -1,9 +1,16 @@ class Clazz { public funcxion() { + ~~~~ [0] console.log("test") ; + ~~~~ [0] } +~~~~ [0] +~~~~ [0] private foobar() { } } + ~~~~ [0] + +[0]: trailing whitespace diff --git a/test/ruleTests/no-trailing-whitespace/tslint.json b/test/ruleTests/no-trailing-whitespace/tslint.json new file mode 100644 index 00000000000..f81bfe73957 --- /dev/null +++ b/test/ruleTests/no-trailing-whitespace/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-trailing-whitespace": true + } +} diff --git a/test/rules/noShadowedVariableRuleTests.ts b/test/rules/noShadowedVariableRuleTests.ts deleted file mode 100644 index da1502111e5..00000000000 --- a/test/rules/noShadowedVariableRuleTests.ts +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - const NoShadowedVariableRule = TestUtils.getRule("no-shadowed-variable"); - const fileName = "rules/no-shadowed-variable.test.ts"; - - it("ensures that variable declarations are not shadowed", () => { - const expectedFailures = [ - createFailure("a", [6, 13], [6, 14]), - createFailure("b", [7, 13], [7, 14]), - createFailure("b", [11, 13], [11, 14]), - createFailure("e", [13, 13], [13, 14]), - createFailure("a", [22, 9], [22, 10]), - createFailure("g", [27, 9], [27, 10]), - createFailure("h", [35, 15], [35, 16]), - createFailure("i", [36, 15], [36, 16]), - createFailure("x", [41, 9], [41, 10]), - createFailure("y", [42, 9], [42, 10]), - createFailure("index", [46, 10], [46, 15]), - createFailure("j", [47, 9], [47, 10]), - createFailure("bar", [59, 13], [59, 16]), - createFailure("foo", [67, 13], [67, 16]), - createFailure("foo", [75, 13], [75, 16]), - createFailure("x", [88, 14], [88, 15]), - createFailure("y", [89, 14], [89, 15]), - createFailure("z", [90, 16], [90, 17]), - createFailure("x", [94, 15], [94, 16]), - createFailure("y", [95, 15], [95, 16]), - createFailure("z", [97, 17], [97, 18]), - createFailure("p", [120, 12], [120, 13]), - createFailure("q", [125, 9], [125, 10]), - createFailure("pos", [128, 13], [128, 16]) - ]; - const actualFailures = TestUtils.applyRuleOnFile(fileName, NoShadowedVariableRule); - - TestUtils.assertFailuresEqual(actualFailures, expectedFailures); - }); - - function createFailure(identifier: string, start: number[], end: number[]) { - return TestUtils.createFailure(fileName, start, end, `${NoShadowedVariableRule.FAILURE_STRING}${identifier}'`); - } -}); diff --git a/test/rules/noStringLiteralRuleTests.ts b/test/rules/noStringLiteralRuleTests.ts deleted file mode 100644 index f7de34f09b0..00000000000 --- a/test/rules/noStringLiteralRuleTests.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - const NoStringLiteralRule = TestUtils.getRule("no-string-literal"); - const fileName = "rules/sub.test.ts"; - - it("forbids object access via string literals", () => { - const actualFailures = TestUtils.applyRuleOnFile(fileName, NoStringLiteralRule); - const expectedFailures = [ - TestUtils.createFailure(fileName, [10, 20], [10, 25], NoStringLiteralRule.FAILURE_STRING), - TestUtils.createFailure(fileName, [11, 21], [11, 24], NoStringLiteralRule.FAILURE_STRING), - TestUtils.createFailure(fileName, [15, 5], [15, 23], NoStringLiteralRule.FAILURE_STRING), - TestUtils.createFailure(fileName, [16, 5], [16, 30], NoStringLiteralRule.FAILURE_STRING) - ]; - - for (const expectedFailure of expectedFailures) { - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - } - }); -}); diff --git a/test/rules/noSwitchCaseFallThroughRuleTests.ts b/test/rules/noSwitchCaseFallThroughRuleTests.ts deleted file mode 100644 index e5f0aaef148..00000000000 --- a/test/rules/noSwitchCaseFallThroughRuleTests.ts +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2014 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 {TestUtils} from "../lint"; - -describe("", () => { - const Rule = TestUtils.getRule("no-switch-case-fall-through"); - const fileName = "rules/noswitchcasefallthrough.test.ts"; - - it("Switch fall through", () => { - const failureString = Rule.FAILURE_STRING_PART; - const failureDefault = TestUtils.createFailuresOnFile(fileName, failureString + "'default'"); - const failureCase = TestUtils.createFailuresOnFile(fileName, failureString + "'case'"); - const expectedFailures = [ - failureCase([3, 15], [3, 16]), - failureCase([6, 15], [6, 16]), - failureDefault([8, 12], [8, 13]), - failureCase([16, 15], [16, 16]), - failureDefault([24, 12], [24, 13]), - failureCase([35, 10], [35, 11]), - failureDefault([32, 21], [32, 22]) - ]; - const actualFailures = TestUtils.applyRuleOnFile(fileName, Rule); - - assert.lengthOf(actualFailures, 7); - TestUtils.assertFailuresEqual(actualFailures, expectedFailures); - }); -}); diff --git a/test/rules/noTrailingWhitespaceRuleTests.ts b/test/rules/noTrailingWhitespaceRuleTests.ts deleted file mode 100644 index 34e39b3040d..00000000000 --- a/test/rules/noTrailingWhitespaceRuleTests.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - const NoTrailingWhitespaceRule = TestUtils.getRule("no-trailing-whitespace"); - const fileName = "rules/trailing.test.ts"; - const createFailure = TestUtils.createFailuresOnFile(fileName, NoTrailingWhitespaceRule.FAILURE_STRING); - - it("forbids trailing whitespace", () => { - const actualFailures = TestUtils.applyRuleOnFile(fileName, NoTrailingWhitespaceRule); - const expectedFailure1 = createFailure([2, 24], [2, 28]); - const expectedFailure2 = createFailure([3, 32], [3, 36]); - const expectedFailure3 = createFailure([5, 1], [5, 5]); - const expectedFailure4 = createFailure([6, 1], [6, 5]); - const expectedFailure5 = createFailure([9, 2], [9, 6]); - - TestUtils.assertContainsFailure(actualFailures, expectedFailure1); - TestUtils.assertContainsFailure(actualFailures, expectedFailure2); - TestUtils.assertContainsFailure(actualFailures, expectedFailure3); - TestUtils.assertContainsFailure(actualFailures, expectedFailure4); - TestUtils.assertContainsFailure(actualFailures, expectedFailure5); - assert.lengthOf(actualFailures, 5); - }); -}); diff --git a/test/tsconfig.json b/test/tsconfig.json index d9ae92330eb..06091186690 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -129,10 +129,6 @@ "ruleTestRunnerTests/testData.ts", "ruleTestRunnerTests/utilsTests.ts", "rules/eofLineRuleTests.ts", - "rules/noShadowedVariableRuleTests.ts", - "rules/noStringLiteralRuleTests.ts", - "rules/noSwitchCaseFallThroughRuleTests.ts", - "rules/noTrailingWhitespaceRuleTests.ts", "rules/noUnreachableRuleTests.ts", "rules/noUnusedExpressionRuleTests.ts", "rules/noUnusedVariableRuleTests.ts", From 55288c63d12eb7cf2f42ef043212cff3f0dff789 Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Wed, 23 Dec 2015 14:45:53 -0500 Subject: [PATCH 17/30] Convert tests for no-unreachable, no-unused-expression, and no-unused-variable rules --- .../rules/nounusedvariable-imports.test.ts | 26 --- .../nounusedvariable-react3-react.test.tsx | 1 - ...nusedvariable-react3-react_addons.test.tsx | 1 - .../no-unreachable/test.ts.linttest} | 7 +- test/ruleTests/no-unreachable/tslint.json | 5 + .../no-unused-expression/test.ts.linttest} | 14 ++ .../no-unused-expression/tslint.json | 5 + .../test.ts.linttest} | 24 ++- .../tslint.json | 5 + .../react-addons1.tsx.linttest} | 0 .../react-addons2.tsx.linttest} | 0 .../react-addons3.tsx.linttest | 2 + .../react1.tsx.linttest} | 0 .../react2.tsx.linttest} | 0 .../react3.tsx.linttest | 2 + .../react4.tsx.linttest} | 0 .../no-unused-variable-react/tslint.json | 5 + .../no-unused-variable/class.ts.linttest} | 6 +- .../false-positives.ts.linttest} | 0 .../no-unused-variable/function.ts.linttest} | 4 +- .../no-unused-variable/import.ts.linttest | 31 +++ .../react-addons1.tsx.linttest | 4 + .../react-addons2.tsx.linttest | 3 + .../react-addons3.tsx.linttest | 2 + .../no-unused-variable/react1.tsx.linttest | 4 + .../no-unused-variable/react2.tsx.linttest | 3 + .../no-unused-variable/react3.tsx.linttest | 2 + .../no-unused-variable/react4.tsx.linttest | 4 + test/ruleTests/no-unused-variable/tslint.json | 5 + .../no-unused-variable/var.ts.linttest} | 18 +- test/rules/noUnreachableRuleTests.ts | 36 ---- test/rules/noUnusedExpressionRuleTests.ts | 43 ---- test/rules/noUnusedVariableRuleTests.ts | 183 ------------------ test/tsconfig.json | 3 - 34 files changed, 138 insertions(+), 310 deletions(-) delete mode 100644 test/files/rules/nounusedvariable-imports.test.ts delete mode 100644 test/files/rules/nounusedvariable-react3-react.test.tsx delete mode 100644 test/files/rules/nounusedvariable-react3-react_addons.test.tsx rename test/{files/rules/nounreachable.test.ts => ruleTests/no-unreachable/test.ts.linttest} (87%) create mode 100644 test/ruleTests/no-unreachable/tslint.json rename test/{files/rules/unused.expression.test.ts => ruleTests/no-unused-expression/test.ts.linttest} (72%) create mode 100644 test/ruleTests/no-unused-expression/tslint.json rename test/{files/rules/nounusedvariable-parameter.test.ts => ruleTests/no-unused-variable-check-parameters/test.ts.linttest} (54%) create mode 100644 test/ruleTests/no-unused-variable-check-parameters/tslint.json rename test/{files/rules/nounusedvariable-react1-react_addons.test.tsx => ruleTests/no-unused-variable-react/react-addons1.tsx.linttest} (100%) rename test/{files/rules/nounusedvariable-react2-react_addons.test.tsx => ruleTests/no-unused-variable-react/react-addons2.tsx.linttest} (100%) create mode 100644 test/ruleTests/no-unused-variable-react/react-addons3.tsx.linttest rename test/{files/rules/nounusedvariable-react1-react.test.tsx => ruleTests/no-unused-variable-react/react1.tsx.linttest} (100%) rename test/{files/rules/nounusedvariable-react2-react.test.tsx => ruleTests/no-unused-variable-react/react2.tsx.linttest} (100%) create mode 100644 test/ruleTests/no-unused-variable-react/react3.tsx.linttest rename test/{files/rules/nounusedvariable-react4-react.test.tsx => ruleTests/no-unused-variable-react/react4.tsx.linttest} (100%) create mode 100644 test/ruleTests/no-unused-variable-react/tslint.json rename test/{files/rules/nounusedvariable-class.test.ts => ruleTests/no-unused-variable/class.ts.linttest} (59%) rename test/{files/rules/nounusedvariable-falsepositives.test.ts => ruleTests/no-unused-variable/false-positives.ts.linttest} (100%) rename test/{files/rules/nounusedvariable-function.test.ts => ruleTests/no-unused-variable/function.ts.linttest} (73%) create mode 100644 test/ruleTests/no-unused-variable/import.ts.linttest create mode 100644 test/ruleTests/no-unused-variable/react-addons1.tsx.linttest create mode 100644 test/ruleTests/no-unused-variable/react-addons2.tsx.linttest create mode 100644 test/ruleTests/no-unused-variable/react-addons3.tsx.linttest create mode 100644 test/ruleTests/no-unused-variable/react1.tsx.linttest create mode 100644 test/ruleTests/no-unused-variable/react2.tsx.linttest create mode 100644 test/ruleTests/no-unused-variable/react3.tsx.linttest create mode 100644 test/ruleTests/no-unused-variable/react4.tsx.linttest create mode 100644 test/ruleTests/no-unused-variable/tslint.json rename test/{files/rules/nounusedvariable-var.test.ts => ruleTests/no-unused-variable/var.ts.linttest} (55%) delete mode 100644 test/rules/noUnreachableRuleTests.ts delete mode 100644 test/rules/noUnusedExpressionRuleTests.ts delete mode 100644 test/rules/noUnusedVariableRuleTests.ts diff --git a/test/files/rules/nounusedvariable-imports.test.ts b/test/files/rules/nounusedvariable-imports.test.ts deleted file mode 100644 index 28e8ee73d02..00000000000 --- a/test/files/rules/nounusedvariable-imports.test.ts +++ /dev/null @@ -1,26 +0,0 @@ -import $ = require("jquery"); -import _ = require("underscore"); -import xyz = require("xyz"); // failure -import {createReadStream, createWriteStream} from "fs"; // failure -export import a = require("a"); - -createWriteStream(); - -$(_.xyz()); - -/// - -module S { - var template = ""; // failure -} - -import * as foo from "libA"; // failure on 'foo' -import * as bar from "libB"; -import baz from "libC"; -import defaultExport, { namedExport } from "libD"; // failure on 'defaultExport' - -bar.someFunc(); -baz(); -namedExport(); - -import "jquery"; diff --git a/test/files/rules/nounusedvariable-react3-react.test.tsx b/test/files/rules/nounusedvariable-react3-react.test.tsx deleted file mode 100644 index 4b7c4cb5fbd..00000000000 --- a/test/files/rules/nounusedvariable-react3-react.test.tsx +++ /dev/null @@ -1 +0,0 @@ -import * as React from "react"; diff --git a/test/files/rules/nounusedvariable-react3-react_addons.test.tsx b/test/files/rules/nounusedvariable-react3-react_addons.test.tsx deleted file mode 100644 index be225642ba4..00000000000 --- a/test/files/rules/nounusedvariable-react3-react_addons.test.tsx +++ /dev/null @@ -1 +0,0 @@ -import * as React from "react/addons"; diff --git a/test/files/rules/nounreachable.test.ts b/test/ruleTests/no-unreachable/test.ts.linttest similarity index 87% rename from test/files/rules/nounreachable.test.ts rename to test/ruleTests/no-unreachable/test.ts.linttest index 77b17cd06b6..7f1c945214e 100644 --- a/test/files/rules/nounreachable.test.ts +++ b/test/ruleTests/no-unreachable/test.ts.linttest @@ -4,6 +4,7 @@ function f1() { var x = 3; return; var y; + ~~~~~~ [unreachable code] var z; } @@ -11,6 +12,7 @@ var f2 = () => { if (x === 3) { throw new Error("error"); "123"; + ~~~~~~ [unreachable code] } else { return y; } @@ -23,9 +25,11 @@ for (var i = 0; i < 10; ++i) { if (i === 3) { break; console.log("hi"); + ~~~~~~~~~~~~~~~~~~ [unreachable code] } else { continue lab; i = 4; + ~~~~~~ [unreachable code] } } @@ -86,6 +90,7 @@ function f7() { } var y = 7; + ~~~~~~~~~~ [unreachable code] } // more valid code @@ -96,4 +101,4 @@ function f8() { } catch (e) { console.log("here"); } -} +} \ No newline at end of file diff --git a/test/ruleTests/no-unreachable/tslint.json b/test/ruleTests/no-unreachable/tslint.json new file mode 100644 index 00000000000..8219288f905 --- /dev/null +++ b/test/ruleTests/no-unreachable/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-unreachable": true + } +} diff --git a/test/files/rules/unused.expression.test.ts b/test/ruleTests/no-unused-expression/test.ts.linttest similarity index 72% rename from test/files/rules/unused.expression.test.ts rename to test/ruleTests/no-unused-expression/test.ts.linttest index 87f87bf73ad..eaa1a3ad461 100644 --- a/test/files/rules/unused.expression.test.ts +++ b/test/ruleTests/no-unused-expression/test.ts.linttest @@ -32,17 +32,29 @@ j = (j === 0 ? 5 : 6); // invalid code: 5; +~~ [0] i; +~~ [0] 3 + 5; +~~~~~~ [0] fun1() + fun1(); +~~~~~~~~~~~~~~~~ [0] fun2(i) + fun3(4,7); +~~~~~~~~~~~~~~~~~~~~ [0] fun1() + 4; +~~~~~~~~~~~ [0] 4 + fun2(j); +~~~~~~~~~~~~ [0] (j === 0 ? fun1() : 5); +~~~~~~~~~~~~~~~~~~~~~~~ [0] (j === 0 ? i : fun2(j)); +~~~~~~~~~~~~~~~~~~~~~~~~ [0] a => fun2(a); +~~~~~~~~~~~~~ [0] () => {return fun1();}; +~~~~~~~~~~~~~~~~~~~~~~~ [0] "use strct"; +~~~~~~~~~~~~ [0] // sigh, valid code again: @@ -53,3 +65,5 @@ function* g(): Iterable { yield i; } } + +[0]: expected an assignment or function call diff --git a/test/ruleTests/no-unused-expression/tslint.json b/test/ruleTests/no-unused-expression/tslint.json new file mode 100644 index 00000000000..042bc2f9ac4 --- /dev/null +++ b/test/ruleTests/no-unused-expression/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-unused-expression": true + } +} diff --git a/test/files/rules/nounusedvariable-parameter.test.ts b/test/ruleTests/no-unused-variable-check-parameters/test.ts.linttest similarity index 54% rename from test/files/rules/nounusedvariable-parameter.test.ts rename to test/ruleTests/no-unused-variable-check-parameters/test.ts.linttest index cececc3f9af..6e3c65ff18b 100644 --- a/test/files/rules/nounusedvariable-parameter.test.ts +++ b/test/ruleTests/no-unused-variable-check-parameters/test.ts.linttest @@ -1,12 +1,15 @@ -export function func1(x: number, y: number, ...args: number[]) { // 'args' failure +export function func1(x: number, y: number, ...args: number[]) { + ~~~~ [unused variable: 'args'] return x + y; } -export function func2(x: number, y: number, ...args: number[]) { // 'y' failure +export function func2(x: number, y: number, ...args: number[]) { + ~ [unused variable: 'y'] return x + args[0]; } -export function func3(x?: number, y?: number) { // 'y' failure +export function func3(x?: number, y?: number) { + ~ [unused variable: 'y'] return x; } @@ -15,7 +18,8 @@ export interface ITestInterface { } export class ABCD { - constructor(private x: number, public y: number, private z: number) { // 'x' failure + constructor(private x: number, public y: number, private z: number) { + ~ [unused variable: 'x'] } func5() { @@ -35,7 +39,8 @@ export function func7(f: (x: number) => number) { return f; } -export function func8([x, y]: [number, number]) { // 'y' failure +export function func8([x, y]: [number, number]) { + ~ [unused variable: 'y'] return x; } @@ -43,16 +48,19 @@ export class DestructuringTests { constructor(public x: number, public [y, z]) { // tsc error on binding pattern } - public func9({a, b}) { // 'b' failure + public func9({a, b}) { + ~ [unused variable: 'b'] return a; } - public func10([a, b]) { // 'b' failure + public func10([a, b]) { + ~ [unused variable: 'b'] return [a]; } // destructuring with default value - public func11([x = 0]) { // 'x' failure + public func11([x = 0]) { + ~ [unused variable: 'x'] return; } } diff --git a/test/ruleTests/no-unused-variable-check-parameters/tslint.json b/test/ruleTests/no-unused-variable-check-parameters/tslint.json new file mode 100644 index 00000000000..ab3b45be1f5 --- /dev/null +++ b/test/ruleTests/no-unused-variable-check-parameters/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-unused-variable": [true, "check-parameters"] + } +} diff --git a/test/files/rules/nounusedvariable-react1-react_addons.test.tsx b/test/ruleTests/no-unused-variable-react/react-addons1.tsx.linttest similarity index 100% rename from test/files/rules/nounusedvariable-react1-react_addons.test.tsx rename to test/ruleTests/no-unused-variable-react/react-addons1.tsx.linttest diff --git a/test/files/rules/nounusedvariable-react2-react_addons.test.tsx b/test/ruleTests/no-unused-variable-react/react-addons2.tsx.linttest similarity index 100% rename from test/files/rules/nounusedvariable-react2-react_addons.test.tsx rename to test/ruleTests/no-unused-variable-react/react-addons2.tsx.linttest diff --git a/test/ruleTests/no-unused-variable-react/react-addons3.tsx.linttest b/test/ruleTests/no-unused-variable-react/react-addons3.tsx.linttest new file mode 100644 index 00000000000..19a030046f3 --- /dev/null +++ b/test/ruleTests/no-unused-variable-react/react-addons3.tsx.linttest @@ -0,0 +1,2 @@ +import * as React from "react/addons"; + ~~~~~ [unused variable: 'React'] diff --git a/test/files/rules/nounusedvariable-react1-react.test.tsx b/test/ruleTests/no-unused-variable-react/react1.tsx.linttest similarity index 100% rename from test/files/rules/nounusedvariable-react1-react.test.tsx rename to test/ruleTests/no-unused-variable-react/react1.tsx.linttest diff --git a/test/files/rules/nounusedvariable-react2-react.test.tsx b/test/ruleTests/no-unused-variable-react/react2.tsx.linttest similarity index 100% rename from test/files/rules/nounusedvariable-react2-react.test.tsx rename to test/ruleTests/no-unused-variable-react/react2.tsx.linttest diff --git a/test/ruleTests/no-unused-variable-react/react3.tsx.linttest b/test/ruleTests/no-unused-variable-react/react3.tsx.linttest new file mode 100644 index 00000000000..e9db7cf5a43 --- /dev/null +++ b/test/ruleTests/no-unused-variable-react/react3.tsx.linttest @@ -0,0 +1,2 @@ +import * as React from "react"; + ~~~~~ [unused variable: 'React'] diff --git a/test/files/rules/nounusedvariable-react4-react.test.tsx b/test/ruleTests/no-unused-variable-react/react4.tsx.linttest similarity index 100% rename from test/files/rules/nounusedvariable-react4-react.test.tsx rename to test/ruleTests/no-unused-variable-react/react4.tsx.linttest diff --git a/test/ruleTests/no-unused-variable-react/tslint.json b/test/ruleTests/no-unused-variable-react/tslint.json new file mode 100644 index 00000000000..e6e2a72813c --- /dev/null +++ b/test/ruleTests/no-unused-variable-react/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-unused-variable": [true, "react"] + } +} diff --git a/test/files/rules/nounusedvariable-class.test.ts b/test/ruleTests/no-unused-variable/class.ts.linttest similarity index 59% rename from test/files/rules/nounusedvariable-class.test.ts rename to test/ruleTests/no-unused-variable/class.ts.linttest index 65c93fba619..da98df55db2 100644 --- a/test/files/rules/nounusedvariable-class.test.ts +++ b/test/ruleTests/no-unused-variable/class.ts.linttest @@ -1,5 +1,6 @@ class ABCD { - private z2: number; // failure + private z2: number; + ~~ [unused variable: 'z2'] constructor() { } @@ -15,7 +16,8 @@ class ABCD { // } - private mfunc4() { // failure + private mfunc4() { + ~~~~~~ [unused variable: 'mfunc4'] // } static stillPublic: number; diff --git a/test/files/rules/nounusedvariable-falsepositives.test.ts b/test/ruleTests/no-unused-variable/false-positives.ts.linttest similarity index 100% rename from test/files/rules/nounusedvariable-falsepositives.test.ts rename to test/ruleTests/no-unused-variable/false-positives.ts.linttest diff --git a/test/files/rules/nounusedvariable-function.test.ts b/test/ruleTests/no-unused-variable/function.ts.linttest similarity index 73% rename from test/files/rules/nounusedvariable-function.test.ts rename to test/ruleTests/no-unused-variable/function.ts.linttest index def91856540..1ed63d3f839 100644 --- a/test/files/rules/nounusedvariable-function.test.ts +++ b/test/ruleTests/no-unused-variable/function.ts.linttest @@ -3,10 +3,12 @@ function func1(x: number, y: number) { } var func2 = () => { + ~~~~~ [unused variable: 'func2'] // }; function func3() { + ~~~~~ [unused variable: 'func3'] return func1(1, 2); } @@ -18,4 +20,4 @@ declare function func5(): any; export default function () { return 0; -} +} \ No newline at end of file diff --git a/test/ruleTests/no-unused-variable/import.ts.linttest b/test/ruleTests/no-unused-variable/import.ts.linttest new file mode 100644 index 00000000000..2b749704644 --- /dev/null +++ b/test/ruleTests/no-unused-variable/import.ts.linttest @@ -0,0 +1,31 @@ +import $ = require("jquery"); +import _ = require("underscore"); +import xyz = require("xyz"); + ~~~ [unused variable: 'xyz'] +import {createReadStream, createWriteStream} from "fs"; + ~~~~~~~~~~~~~~~~ [unused variable: 'createReadStream'] +export import a = require("a"); + +createWriteStream(); + +$(_.xyz()); + +/// + +module S { + var template = ""; + ~~~~~~~~ [unused variable: 'template'] +} + +import * as foo from "libA"; + ~~~ [unused variable: 'foo'] +import * as bar from "libB"; +import baz from "libC"; +import defaultExport, { namedExport } from "libD"; + ~~~~~~~~~~~~~ [unused variable: 'defaultExport'] + +bar.someFunc(); +baz(); +namedExport(); + +import "jquery"; diff --git a/test/ruleTests/no-unused-variable/react-addons1.tsx.linttest b/test/ruleTests/no-unused-variable/react-addons1.tsx.linttest new file mode 100644 index 00000000000..324a3893fce --- /dev/null +++ b/test/ruleTests/no-unused-variable/react-addons1.tsx.linttest @@ -0,0 +1,4 @@ +import * as React from "react/addons"; + ~~~~~ [unused variable: 'React'] + +console.log(
); diff --git a/test/ruleTests/no-unused-variable/react-addons2.tsx.linttest b/test/ruleTests/no-unused-variable/react-addons2.tsx.linttest new file mode 100644 index 00000000000..259677ba1b1 --- /dev/null +++ b/test/ruleTests/no-unused-variable/react-addons2.tsx.linttest @@ -0,0 +1,3 @@ +import * as React from "react/addons"; + +export class MyComponent extends React.Component<{}, {}> {} diff --git a/test/ruleTests/no-unused-variable/react-addons3.tsx.linttest b/test/ruleTests/no-unused-variable/react-addons3.tsx.linttest new file mode 100644 index 00000000000..19a030046f3 --- /dev/null +++ b/test/ruleTests/no-unused-variable/react-addons3.tsx.linttest @@ -0,0 +1,2 @@ +import * as React from "react/addons"; + ~~~~~ [unused variable: 'React'] diff --git a/test/ruleTests/no-unused-variable/react1.tsx.linttest b/test/ruleTests/no-unused-variable/react1.tsx.linttest new file mode 100644 index 00000000000..b85b8f0a266 --- /dev/null +++ b/test/ruleTests/no-unused-variable/react1.tsx.linttest @@ -0,0 +1,4 @@ +import * as React from "react"; + ~~~~~ [unused variable: 'React'] + +console.log(
); diff --git a/test/ruleTests/no-unused-variable/react2.tsx.linttest b/test/ruleTests/no-unused-variable/react2.tsx.linttest new file mode 100644 index 00000000000..0045f6b2065 --- /dev/null +++ b/test/ruleTests/no-unused-variable/react2.tsx.linttest @@ -0,0 +1,3 @@ +import * as React from "react"; + +export class MyComponent extends React.Component<{}, {}> {} diff --git a/test/ruleTests/no-unused-variable/react3.tsx.linttest b/test/ruleTests/no-unused-variable/react3.tsx.linttest new file mode 100644 index 00000000000..e9db7cf5a43 --- /dev/null +++ b/test/ruleTests/no-unused-variable/react3.tsx.linttest @@ -0,0 +1,2 @@ +import * as React from "react"; + ~~~~~ [unused variable: 'React'] diff --git a/test/ruleTests/no-unused-variable/react4.tsx.linttest b/test/ruleTests/no-unused-variable/react4.tsx.linttest new file mode 100644 index 00000000000..cea71b615df --- /dev/null +++ b/test/ruleTests/no-unused-variable/react4.tsx.linttest @@ -0,0 +1,4 @@ +import * as React from "react"; + ~~~~~ [unused variable: 'React'] + +console.log(); diff --git a/test/ruleTests/no-unused-variable/tslint.json b/test/ruleTests/no-unused-variable/tslint.json new file mode 100644 index 00000000000..b1d833a0963 --- /dev/null +++ b/test/ruleTests/no-unused-variable/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-unused-variable": true + } +} diff --git a/test/files/rules/nounusedvariable-var.test.ts b/test/ruleTests/no-unused-variable/var.ts.linttest similarity index 55% rename from test/files/rules/nounusedvariable-var.test.ts rename to test/ruleTests/no-unused-variable/var.ts.linttest index 36cdb306d13..8e07934d84c 100644 --- a/test/files/rules/nounusedvariable-var.test.ts +++ b/test/ruleTests/no-unused-variable/var.ts.linttest @@ -1,6 +1,7 @@ var x = 3; -var y = x; // failure +var y = x; + ~ [unused variable: 'y'] var z; export var abcd = 3; @@ -20,10 +21,14 @@ try { declare var tmp: any; export function testDestructuring() { - var [a, b] = [1, 2]; // 2 failures + var [a, b] = [1, 2]; + ~ [unused variable: 'a'] + ~ [unused variable: 'b'] var [c] = [3]; - var {d, e} = { d: 1, e: 2 }; // 2 failures + var {d, e} = { d: 1, e: 2 }; + ~ [unused variable: 'd'] + ~ [unused variable: 'e'] var {f} = { f: 3 }; return c * f; @@ -32,7 +37,8 @@ export function testDestructuring() { export var [foo, bar] = [1, 2]; export function testUnusedSpread() { - var a = [1, 2]; // 1 failure + var a = [1, 2]; + ~ [unused variable: 'a'] var b = [3, 4]; var c = [...b, 5]; // make sure we see that b is being used @@ -41,12 +47,14 @@ export function testUnusedSpread() { } for(let e of [1,2,3]) { + ~ [unused variable: 'e'] } export function testRenamingDestructure() { var a = 2; - let {a: b} = {a: 4}; // 1 error (b is unused) + let {a: b} = {a: 4}; + ~ [unused variable: 'b'] let {x: y} = {x: 7}; // false positive return a + y; } diff --git a/test/rules/noUnreachableRuleTests.ts b/test/rules/noUnreachableRuleTests.ts deleted file mode 100644 index b019071c125..00000000000 --- a/test/rules/noUnreachableRuleTests.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {RuleFailure, TestUtils} from "../lint"; - -describe("", () => { - const NoUnreachableRule = TestUtils.getRule("no-unreachable"); - const fileName = "rules/nounreachable.test.ts"; - - it("restricts the use of unreachable code statements", () => { - const createFailure = TestUtils.createFailuresOnFile(fileName, NoUnreachableRule.FAILURE_STRING); - const expectedFailures: RuleFailure[] = [ - createFailure([6, 5], [6, 11]), - createFailure([13, 9], [13, 15]), - createFailure([25, 9], [25, 27]), - createFailure([28, 9], [28, 15]), - createFailure([88, 5], [88, 15]) - ]; - const actualFailures = TestUtils.applyRuleOnFile(fileName, NoUnreachableRule); - - TestUtils.assertFailuresEqual(actualFailures, expectedFailures); - }); -}); diff --git a/test/rules/noUnusedExpressionRuleTests.ts b/test/rules/noUnusedExpressionRuleTests.ts deleted file mode 100644 index 7b750eb2d9a..00000000000 --- a/test/rules/noUnusedExpressionRuleTests.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2014 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 {RuleFailure, TestUtils} from "../lint"; - -describe("", () => { - const NoUnusedExpressionRule = TestUtils.getRule("no-unused-expression"); - const fileName = "rules/unused.expression.test.ts"; - - it("disallows unused expression statements", () => { - const createFailure = TestUtils.createFailuresOnFile(fileName, NoUnusedExpressionRule.FAILURE_STRING); - const expectedFailures: RuleFailure[] = [ - createFailure([34, 1], [34, 3]), - createFailure([35, 1], [35, 3]), - createFailure([36, 1], [36, 7]), - createFailure([37, 1], [37, 17]), - createFailure([38, 1], [38, 21]), - createFailure([39, 1], [39, 12]), - createFailure([40, 1], [40, 13]), - createFailure([41, 1], [41, 24]), - createFailure([42, 1], [42, 25]), - createFailure([43, 1], [43, 14]), - createFailure([44, 1], [44, 24]), - createFailure([45, 1], [45, 13]), - ]; - const actualFailures = TestUtils.applyRuleOnFile(fileName, NoUnusedExpressionRule); - - TestUtils.assertFailuresEqual(actualFailures, expectedFailures); - }); -}); diff --git a/test/rules/noUnusedVariableRuleTests.ts b/test/rules/noUnusedVariableRuleTests.ts deleted file mode 100644 index a9bbbd0a439..00000000000 --- a/test/rules/noUnusedVariableRuleTests.ts +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright 2014 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 {TestUtils} from "../lint"; - -describe("", () => { - const Rule = TestUtils.getRule("no-unused-variable"); - - it("restricts unused imports", () => { - const fileName = "rules/nounusedvariable-imports.test.ts"; - const failure1 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'xyz'")([3, 9], [3, 12]); - const failure2 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'createReadStream'")([4, 9], [4, 25]); - const failure3 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'template'")([14, 7], [14, 15]); - const failure4 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'foo'")([17, 13], [17, 16]); - const failure5 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'defaultExport'")([20, 8], [20, 21]); - const actualFailures = TestUtils.applyRuleOnFile(fileName, Rule); - - assert.lengthOf(actualFailures, 5); - TestUtils.assertContainsFailure(actualFailures, failure1); - TestUtils.assertContainsFailure(actualFailures, failure2); - TestUtils.assertContainsFailure(actualFailures, failure3); - TestUtils.assertContainsFailure(actualFailures, failure4); - TestUtils.assertContainsFailure(actualFailures, failure5); - }); - - it("restricts unused variables", () => { - const fileName = "rules/nounusedvariable-var.test.ts"; - const failure1 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'y'")([3, 5], [3, 6]); - const failure2 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'a'")([23, 10], [23, 11]); - const failure3 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'b'")([23, 13], [23, 14]); - const failure4 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'d'")([26, 10], [26, 11]); - const failure5 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'e'")([26, 13], [26, 14]); - const failure6 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'a'")([35, 7], [35, 8]); - const failure7 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'e'")([43, 9], [43, 10]); - const failure8 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'b'")([49, 11], [49, 12]); - - const actualFailures = TestUtils.applyRuleOnFile(fileName, Rule); - - assert.lengthOf(actualFailures, 8); - TestUtils.assertContainsFailure(actualFailures, failure1); - TestUtils.assertContainsFailure(actualFailures, failure2); - TestUtils.assertContainsFailure(actualFailures, failure3); - TestUtils.assertContainsFailure(actualFailures, failure4); - TestUtils.assertContainsFailure(actualFailures, failure5); - TestUtils.assertContainsFailure(actualFailures, failure6); - TestUtils.assertContainsFailure(actualFailures, failure7); - TestUtils.assertContainsFailure(actualFailures, failure8); - }); - - it("restricts unused functions", () => { - const fileName = "rules/nounusedvariable-function.test.ts"; - const failure1 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'func2'")([5, 5], [5, 10]); - const failure2 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'func3'")([9, 10], [9, 15]); - - const actualFailures = TestUtils.applyRuleOnFile(fileName, Rule); - - assert.lengthOf(actualFailures, 2); - TestUtils.assertContainsFailure(actualFailures, failure1); - TestUtils.assertContainsFailure(actualFailures, failure2); - }); - - it("restricts unused class members", () => { - const fileName = "rules/nounusedvariable-class.test.ts"; - const failure1 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'z2'")([2, 13], [2, 15]); - const failure2 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'mfunc4'")([18, 13], [18, 19]); - - const actualFailures = TestUtils.applyRuleOnFile(fileName, Rule); - - assert.lengthOf(actualFailures, 2); - TestUtils.assertContainsFailure(actualFailures, failure1); - TestUtils.assertContainsFailure(actualFailures, failure2); - }); - - it("restricts unused parameters", () => { - const fileName = "rules/nounusedvariable-parameter.test.ts"; - const failure1 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'args'")([1, 48], [1, 52]); - const failure2 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'y'")([5, 34], [5, 35]); - const failure3 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'y'")([9, 35], [9, 36]); - const failure4 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'x'")([18, 25], [18, 26]); - const failure5 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'y'")([38, 27], [38, 28]); - const failure6 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'b'")([46, 22], [46, 23]); - const failure7 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'b'")([50, 23], [50, 24]); - const failure8 = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'x'")([55, 20], [55, 21]); - - const actualFailures = TestUtils.applyRuleOnFile(fileName, Rule, [true, "check-parameters"]); - - assert.lengthOf(actualFailures, 8); - TestUtils.assertContainsFailure(actualFailures, failure1); - TestUtils.assertContainsFailure(actualFailures, failure2); - TestUtils.assertContainsFailure(actualFailures, failure3); - TestUtils.assertContainsFailure(actualFailures, failure4); - TestUtils.assertContainsFailure(actualFailures, failure5); - TestUtils.assertContainsFailure(actualFailures, failure6); - TestUtils.assertContainsFailure(actualFailures, failure7); - TestUtils.assertContainsFailure(actualFailures, failure8); - }); - - it("shouldn't find false positives", () => { - const fileName = "rules/nounusedvariable-falsepositives.test.ts"; - const actualFailures = TestUtils.applyRuleOnFile(fileName, Rule); - - assert.lengthOf(actualFailures, 0); - }); - - describe("with react option", () => { - describe("set", () => { - function describeSuite(importModuleName: string) { - const suffix = moduleNameToFilenameSuffix(importModuleName); - describe(`importing \"${importModuleName}\"`, () => { - it("should not fail if only JSX present", () => { - assertNoFailures(`rules/nounusedvariable-react1-${suffix}.test.tsx`, true); - }); - - it("should not fail if React namespace is used", () => { - assertNoFailures(`rules/nounusedvariable-react2-${suffix}.test.tsx`, true); - }); - - it("should fail if neither JSX nor React namespace is seen", () => { - assertSingleFailure(`rules/nounusedvariable-react3-${suffix}.test.tsx`, true); - }); - }); - } - - describeSuite("react"); - describeSuite("react/addons"); - - it("should not fail if JSX self-closing element is used", () => { - assertNoFailures("rules/nounusedvariable-react4-react.test.tsx", true); - }); - }); - - describe("not set", () => { - function describeSuite(importModuleName: string) { - const suffix = moduleNameToFilenameSuffix(importModuleName); - describe(`importing \"${importModuleName}\"`, () => { - it("should fail if only JSX present", () => { - assertSingleFailure(`rules/nounusedvariable-react1-${suffix}.test.tsx`, false); - }); - - it("should not fail if React namespace is used", () => { - assertNoFailures(`rules/nounusedvariable-react2-${suffix}.test.tsx`, false); - }); - - it("should fail if neither JSX nor React namespace is seen", () => { - assertSingleFailure(`rules/nounusedvariable-react3-${suffix}.test.tsx`, false); - }); - }); - } - - describeSuite("react"); - describeSuite("react/addons"); - }); - - function assertNoFailures(fileName: string, isReactOptionSet: boolean) { - const actualFailures = TestUtils.applyRuleOnFile(fileName, Rule, isReactOptionSet ? [true, "react"] : [true]); - assert.lengthOf(actualFailures, 0); - } - - function assertSingleFailure(fileName: string, isReactOptionSet: boolean) { - const expectedFailure = TestUtils.createFailuresOnFile(fileName, Rule.FAILURE_STRING + "'React'")([1, 13], [1, 18]); - const actualFailures = TestUtils.applyRuleOnFile(fileName, Rule, isReactOptionSet ? [true, "react"] : [true]); - assert.lengthOf(actualFailures, 1); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - } - - function moduleNameToFilenameSuffix(moduleName: string): string { - return moduleName.replace(/\//g, "_"); - } - }); -}); diff --git a/test/tsconfig.json b/test/tsconfig.json index 06091186690..fea19e0f3d4 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -129,9 +129,6 @@ "ruleTestRunnerTests/testData.ts", "ruleTestRunnerTests/utilsTests.ts", "rules/eofLineRuleTests.ts", - "rules/noUnreachableRuleTests.ts", - "rules/noUnusedExpressionRuleTests.ts", - "rules/noUnusedVariableRuleTests.ts", "rules/noUseBeforeDeclareRuleTests.ts", "rules/noVarKeywordRuleTests.ts", "rules/noVarRequiresRuleTests.ts", From cb3fb6aeb64318b49ccc1b31948664d8efd1a25d Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Wed, 23 Dec 2015 23:51:54 -0500 Subject: [PATCH 18/30] Convert tests for no-use-before-declare, no-var-keyword, no-var-requires, and object-literal-sort-keys rules --- test/files/rules/novarkeyword.test.ts | 35 ---------- test/files/rules/novarrequires.test.ts | 2 - .../no-use-before-declare/test.ts.linttest} | 24 ++++--- .../no-use-before-declare/tslint.json | 5 ++ .../ruleTests/no-var-keyword/test.ts.linttest | 42 ++++++++++++ test/ruleTests/no-var-keyword/tslint.json | 5 ++ .../no-var-requires/test.ts.linttest | 3 + test/ruleTests/no-var-requires/tslint.json | 5 ++ .../test.ts.linttest} | 6 ++ .../object-literal-sort-keys/tslint.json | 5 ++ test/rules/noUseBeforeDeclareRuleTests.ts | 64 ------------------- test/rules/noVarKeywordRuleTests.ts | 38 ----------- test/rules/noVarRequiresRuleTests.ts | 30 --------- test/rules/objectLiteralSortKeysRuleTests.ts | 43 ------------- test/tsconfig.json | 4 -- 15 files changed, 87 insertions(+), 224 deletions(-) delete mode 100644 test/files/rules/novarkeyword.test.ts delete mode 100644 test/files/rules/novarrequires.test.ts rename test/{files/rules/nousebeforedeclare.test.ts => ruleTests/no-use-before-declare/test.ts.linttest} (58%) create mode 100644 test/ruleTests/no-use-before-declare/tslint.json create mode 100644 test/ruleTests/no-var-keyword/test.ts.linttest create mode 100644 test/ruleTests/no-var-keyword/tslint.json create mode 100644 test/ruleTests/no-var-requires/test.ts.linttest create mode 100644 test/ruleTests/no-var-requires/tslint.json rename test/{files/rules/objectliteralsortkeys.test.ts => ruleTests/object-literal-sort-keys/test.ts.linttest} (78%) create mode 100644 test/ruleTests/object-literal-sort-keys/tslint.json delete mode 100644 test/rules/noUseBeforeDeclareRuleTests.ts delete mode 100644 test/rules/noVarKeywordRuleTests.ts delete mode 100644 test/rules/noVarRequiresRuleTests.ts delete mode 100644 test/rules/objectLiteralSortKeysRuleTests.ts diff --git a/test/files/rules/novarkeyword.test.ts b/test/files/rules/novarkeyword.test.ts deleted file mode 100644 index af0f9eaf1f1..00000000000 --- a/test/files/rules/novarkeyword.test.ts +++ /dev/null @@ -1,35 +0,0 @@ -var foo; // failure - -function tmp(t: any) { - var x = 3; // failure -} - -var i, // failure - j; - -var [a, b] = [1, 2]; // failure - -for (var n; false;); // failure -for (var n1 in foo); // failure -for (var n2 of foo); // failure - -declare var tmp2: any; - -let bar; -const qux; - -let k, - l; - -module quz { - export var i; -} - -let [x, y] = [1, 2]; - -for (n; false;); -for (let n; false;); -for (let name in foo); -for (let name of foo); -for (const name in foo); -for (const name of foo); diff --git a/test/files/rules/novarrequires.test.ts b/test/files/rules/novarrequires.test.ts deleted file mode 100644 index 1336f77074b..00000000000 --- a/test/files/rules/novarrequires.test.ts +++ /dev/null @@ -1,2 +0,0 @@ -import a = require("a"); -var b = require("b"); diff --git a/test/files/rules/nousebeforedeclare.test.ts b/test/ruleTests/no-use-before-declare/test.ts.linttest similarity index 58% rename from test/files/rules/nousebeforedeclare.test.ts rename to test/ruleTests/no-use-before-declare/test.ts.linttest index 06fb820f482..2bb7e7feff3 100644 --- a/test/files/rules/nousebeforedeclare.test.ts +++ b/test/ruleTests/no-use-before-declare/test.ts.linttest @@ -1,6 +1,8 @@ -$.x = 3; // failure on '$' +$.x = 3; +~ [variable '$' used before declaration] import $ = require("$"); -var vara = varb, varb; // failure on 'varb' +var vara = varb, varb; + ~~~~ [variable 'varb' used before declaration] class Test { constructor() { @@ -10,7 +12,8 @@ class Test { private a: number; } -var i = j; // failure on 'j' +var i = j; + ~ [variable 'j' used before declaration] class ClassA { prop: number; @@ -32,10 +35,14 @@ if (something) { } function testUndeclaredImports() { - console.log(foo1); // failure on 'foo1' - console.log(foo2); // failure on 'foo2' - console.log(foo3); // failure on 'foo3' - map([], (x) => x); // failure on 'map' + console.log(foo1); + ~~~~ [variable 'foo1' used before declaration] + console.log(foo2); + ~~~~ [variable 'foo2' used before declaration] + console.log(foo3); + ~~~~ [variable 'foo3' used before declaration] + map([], (x) => x); + ~~~ [variable 'map' used before declaration] } import { default as foo1 } from "lib"; @@ -49,7 +56,8 @@ export default function () { }; export { - undeclaredA, // failure + undeclaredA, + ~~~~~~~~~~~ [variable 'undeclaredA' used before declaration] undeclaredB, // tsc error undeclaredC, // tsc error testUndeclaredImports diff --git a/test/ruleTests/no-use-before-declare/tslint.json b/test/ruleTests/no-use-before-declare/tslint.json new file mode 100644 index 00000000000..744ae40f6ff --- /dev/null +++ b/test/ruleTests/no-use-before-declare/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-use-before-declare": true + } +} diff --git a/test/ruleTests/no-var-keyword/test.ts.linttest b/test/ruleTests/no-var-keyword/test.ts.linttest new file mode 100644 index 00000000000..153defb4bfb --- /dev/null +++ b/test/ruleTests/no-var-keyword/test.ts.linttest @@ -0,0 +1,42 @@ +var foo; +~~~ [forbidden var keyword] + +function tmp(t: any) { + var x = 3; + ~~~ [forbidden var keyword] +} + +var i, +~~~ [forbidden var keyword] + j; + +var [a, b] = [1, 2]; +~~~ [forbidden var keyword] + +for (var n; false;); + ~~~ [forbidden var keyword] +for (var n1 in foo); + ~~~ [forbidden var keyword] +for (var n2 of foo); + ~~~ [forbidden var keyword] + +declare var tmp2: any; + +let bar; +const qux; + +let k, + l; + +module quz { + export var i; +} + +let [x, y] = [1, 2]; + +for (n; false;); +for (let n; false;); +for (let name in foo); +for (let name of foo); +for (const name in foo); +for (const name of foo); diff --git a/test/ruleTests/no-var-keyword/tslint.json b/test/ruleTests/no-var-keyword/tslint.json new file mode 100644 index 00000000000..1de4119c014 --- /dev/null +++ b/test/ruleTests/no-var-keyword/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-var-keyword": true + } +} diff --git a/test/ruleTests/no-var-requires/test.ts.linttest b/test/ruleTests/no-var-requires/test.ts.linttest new file mode 100644 index 00000000000..de02a16a8ad --- /dev/null +++ b/test/ruleTests/no-var-requires/test.ts.linttest @@ -0,0 +1,3 @@ +import a = require("a"); +var b = require("b"); + ~~~~~~~~~~~~ [require statement not part of an import statement] diff --git a/test/ruleTests/no-var-requires/tslint.json b/test/ruleTests/no-var-requires/tslint.json new file mode 100644 index 00000000000..665051136ed --- /dev/null +++ b/test/ruleTests/no-var-requires/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-var-requires": true + } +} diff --git a/test/files/rules/objectliteralsortkeys.test.ts b/test/ruleTests/object-literal-sort-keys/test.ts.linttest similarity index 78% rename from test/files/rules/objectliteralsortkeys.test.ts rename to test/ruleTests/object-literal-sort-keys/test.ts.linttest index 6e4e792647b..5d9dda3eada 100644 --- a/test/files/rules/objectliteralsortkeys.test.ts +++ b/test/ruleTests/object-literal-sort-keys/test.ts.linttest @@ -6,6 +6,7 @@ var passA = { var failA = { b: 1, a: 2 + ~ [unsorted key 'a'] }; var passB = { @@ -18,6 +19,7 @@ var passB = { var failB = { c: 3, a: 1, + ~ [unsorted key 'a'] b: 2, d: 4 }; @@ -35,6 +37,7 @@ var failC = { b: { bb: 2, aa: 1 + ~~ [unsorted key 'aa'] } }; @@ -54,6 +57,7 @@ var failD = { bb: 2 }, b: 3 + ~ [unsorted key 'b'] }; var passE = {}; @@ -66,6 +70,7 @@ var passF = { var failF = { sdfa: {}, asdf: [1, 2, 3] + ~~~~ [unsorted key 'asdf'] }; var passG = { @@ -76,4 +81,5 @@ var passG = { var failG = { sdafn: function () {}, asdfn: function () {} + ~~~~~ [unsorted key 'asdfn'] }; diff --git a/test/ruleTests/object-literal-sort-keys/tslint.json b/test/ruleTests/object-literal-sort-keys/tslint.json new file mode 100644 index 00000000000..280382fe390 --- /dev/null +++ b/test/ruleTests/object-literal-sort-keys/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "object-literal-sort-keys": true + } +} diff --git a/test/rules/noUseBeforeDeclareRuleTests.ts b/test/rules/noUseBeforeDeclareRuleTests.ts deleted file mode 100644 index 0803a12ce89..00000000000 --- a/test/rules/noUseBeforeDeclareRuleTests.ts +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2014 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 {TestUtils} from "../lint"; - -describe("", () => { - const Rule = TestUtils.getRule("no-use-before-declare"); - const fileName = "rules/nousebeforedeclare.test.ts"; - - it("restricts usage before declaration", () => { - const actualFailures = TestUtils.applyRuleOnFile(fileName, Rule); - assert.equal(actualFailures.length, 8); - }); - - it("restricts usage of imports before declaration", () => { - const actualFailures = TestUtils.applyRuleOnFile(fileName, Rule); - - const failure1 = TestUtils.createFailuresOnFile(fileName, makeFailureString("$"))([1, 1], [1, 2]); - const failure2 = TestUtils.createFailuresOnFile(fileName, makeFailureString("foo1"))([35, 17], [35, 21]); - const failure3 = TestUtils.createFailuresOnFile(fileName, makeFailureString("foo2"))([36, 17], [36, 21]); - const failure4 = TestUtils.createFailuresOnFile(fileName, makeFailureString("foo3"))([37, 17], [37, 21]); - const failure5 = TestUtils.createFailuresOnFile(fileName, makeFailureString("map"))([38, 5], [38, 8]); - - TestUtils.assertContainsFailure(actualFailures, failure1); - TestUtils.assertContainsFailure(actualFailures, failure2); - TestUtils.assertContainsFailure(actualFailures, failure3); - TestUtils.assertContainsFailure(actualFailures, failure4); - TestUtils.assertContainsFailure(actualFailures, failure5); - }); - - it("restricts usage of variables before declaration", () => { - const actualFailures = TestUtils.applyRuleOnFile(fileName, Rule); - - const failure1 = TestUtils.createFailuresOnFile(fileName, makeFailureString("varb"))([3, 12], [3, 16]); - const failure2 = TestUtils.createFailuresOnFile(fileName, makeFailureString("j"))([13, 9], [13, 10]); - - TestUtils.assertContainsFailure(actualFailures, failure1); - TestUtils.assertContainsFailure(actualFailures, failure2); - }); - - it("restricts exporting variables before declaration", () => { - const actualFailures = TestUtils.applyRuleOnFile(fileName, Rule); - const failure1 = TestUtils.createFailuresOnFile(fileName, makeFailureString("undeclaredA"))([52, 5], [52, 16]); - - TestUtils.assertContainsFailure(actualFailures, failure1); - }); - - function makeFailureString(varName: string) { - return `${Rule.FAILURE_STRING_PREFIX}${varName}${Rule.FAILURE_STRING_POSTFIX}`; - } -}); diff --git a/test/rules/noVarKeywordRuleTests.ts b/test/rules/noVarKeywordRuleTests.ts deleted file mode 100644 index bfa530651c2..00000000000 --- a/test/rules/noVarKeywordRuleTests.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2015 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 {TestUtils} from "../lint"; - -describe("", () => { - const NoVarKeywordRule = TestUtils.getRule("no-var-keyword"); - const fileName = "rules/novarkeyword.test.ts"; - - it("disallows use of creating variables with 'var'", () => { - const createFailure = TestUtils.createFailuresOnFile(fileName, NoVarKeywordRule.FAILURE_STRING); - const expectedFailures = [ - createFailure([1, 1], [1, 4]), - createFailure([4, 5], [4, 8]), - createFailure([7, 1], [7, 4]), - createFailure([10, 1], [10, 4]), - createFailure([12, 6], [12, 9]), - createFailure([13, 6], [13, 9]), - createFailure([14, 6], [14, 9]), - ]; - const actualFailures = TestUtils.applyRuleOnFile(fileName, NoVarKeywordRule); - - TestUtils.assertFailuresEqual(actualFailures, expectedFailures); - }); -}); diff --git a/test/rules/noVarRequiresRuleTests.ts b/test/rules/noVarRequiresRuleTests.ts deleted file mode 100644 index b1fe49989a5..00000000000 --- a/test/rules/noVarRequiresRuleTests.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2014 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 {TestUtils} from "../lint"; - -describe("", () => { - const NoVarRequiresRule = TestUtils.getRule("no-var-requires"); - const fileName = "rules/novarrequires.test.ts"; - - it("disallows use of require outside import statements", () => { - const expectedFailure = TestUtils.createFailure(fileName, [2, 9], [2, 21], NoVarRequiresRule.FAILURE_STRING); - const actualFailures = TestUtils.applyRuleOnFile(fileName, NoVarRequiresRule); - - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - assert.lengthOf(actualFailures, 1); - }); -}); diff --git a/test/rules/objectLiteralSortKeysRuleTests.ts b/test/rules/objectLiteralSortKeysRuleTests.ts deleted file mode 100644 index 4d6a9b9d957..00000000000 --- a/test/rules/objectLiteralSortKeysRuleTests.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - const SortedKeyRule = TestUtils.getRule("object-literal-sort-keys"); - const fileName = "rules/objectliteralsortkeys.test.ts"; - const failureString = SortedKeyRule.FAILURE_STRING; - - it("forbids unsorted keys in object literals", () => { - const actualFailures = TestUtils.applyRuleOnFile(fileName, SortedKeyRule); - const createFailure1 = TestUtils.createFailuresOnFile(fileName, failureString + "a'"); - const createFailure2 = TestUtils.createFailuresOnFile(fileName, failureString + "a'"); - const createFailure3 = TestUtils.createFailuresOnFile(fileName, failureString + "aa'"); - const createFailure4 = TestUtils.createFailuresOnFile(fileName, failureString + "b'"); - const createFailure5 = TestUtils.createFailuresOnFile(fileName, failureString + "asdf'"); - const createFailure6 = TestUtils.createFailuresOnFile(fileName, failureString + "asdfn'"); - const expectedFailures = [ - createFailure1([8, 5], [8, 6]), - createFailure2([20, 5], [20, 6]), - createFailure3([37, 9], [37, 11]), - createFailure4([56, 5], [56, 6]), - createFailure5([68, 5], [68, 9]), - createFailure6([78, 5], [78, 10]) - ]; - - TestUtils.assertFailuresEqual(actualFailures, expectedFailures); - }); -}); diff --git a/test/tsconfig.json b/test/tsconfig.json index fea19e0f3d4..faa2f000a95 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -129,10 +129,6 @@ "ruleTestRunnerTests/testData.ts", "ruleTestRunnerTests/utilsTests.ts", "rules/eofLineRuleTests.ts", - "rules/noUseBeforeDeclareRuleTests.ts", - "rules/noVarKeywordRuleTests.ts", - "rules/noVarRequiresRuleTests.ts", - "rules/objectLiteralSortKeysRuleTests.ts", "rules/oneLineRuleTests.ts", "rules/quotemarkRuleTests.ts", "rules/radixRuleTests.ts", From 171e7941375d0187b842a8370924b508d7396742 Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Thu, 24 Dec 2015 00:50:49 -0500 Subject: [PATCH 19/30] Convert tests for one-line, quotemark, radix, and semicolon rules. Switch to one directory per rule with subdirectories for different options --- test/files/rules/semicolon.test.ts | 54 --------- test/ruleTestRunner.ts | 2 +- .../arguments}/test.ts.linttest | 0 .../arguments}/tslint.json | 0 .../parameters}/test.ts.linttest | 0 .../parameters}/tslint.json | 0 .../statements}/test.ts.linttest | 0 .../statements}/tslint.json | 0 .../lower}/test.ts.linttest | 0 .../lower}/tslint.json | 0 .../upper}/test.ts.linttest | 0 .../upper}/tslint.json | 0 .../spaces}/.test.ts.linttest.swp | Bin .../spaces}/test.ts.linttest | 0 .../spaces}/tslint.json | 0 .../tabs}/test.ts.linttest | 0 .../{indent-tabs => indent/tabs}/tslint.json | 0 .../accessor}/test.ts.linttest | 0 .../accessor}/tslint.json | 0 .../constructor}/test.ts.linttest | 0 .../constructor}/tslint.json | 0 .../{ => default}/test.ts.linttest | 0 .../member-access/{ => default}/tslint.json | 0 .../method}/test.ts.linttest | 0 .../method}/tslint.json | 0 .../private}/test.ts.linttest | 0 .../private}/tslint.json | 0 .../static}/test.ts.linttest | 0 .../static}/tslint.json | 0 .../check-parameters}/test.ts.linttest | 0 .../check-parameters}/tslint.json | 0 .../{ => default}/class.ts.linttest | 0 .../{ => default}/false-positives.ts.linttest | 0 .../{ => default}/function.ts.linttest | 0 .../{ => default}/import.ts.linttest | 0 .../{ => default}/react-addons1.tsx.linttest | 0 .../default}/react-addons2.tsx.linttest | 0 .../default}/react-addons3.tsx.linttest | 0 .../{ => default}/react1.tsx.linttest | 0 .../default}/react2.tsx.linttest | 0 .../default}/react3.tsx.linttest | 0 .../{ => default}/react4.tsx.linttest | 0 .../{ => default}/tslint.json | 0 .../{ => default}/var.ts.linttest | 0 .../react}/react-addons1.tsx.linttest | 0 .../{ => react}/react-addons2.tsx.linttest | 0 .../{ => react}/react-addons3.tsx.linttest | 0 .../react}/react1.tsx.linttest | 0 .../{ => react}/react2.tsx.linttest | 0 .../{ => react}/react3.tsx.linttest | 0 .../react}/react4.tsx.linttest | 0 .../react}/tslint.json | 0 test/ruleTests/one-line/all/test.ts.linttest | 105 +++++++++++++++++ test/ruleTests/one-line/all/tslint.json | 5 + .../one-line/none/test.ts.linttest} | 0 test/ruleTests/one-line/none/tslint.json | 5 + .../double-avoid-escape/test.ts.linttest} | 1 + .../quotemark/double-avoid-escape/tslint.json | 5 + .../quotemark/double/test.ts.linttest | 6 + test/ruleTests/quotemark/double/tslint.json | 5 + .../single-avoid-escape/test.ts.linttest | 5 + .../quotemark/single-avoid-escape/tslint.json | 5 + .../quotemark/single/test.ts.linttest | 6 + test/ruleTests/quotemark/single/tslint.json | 5 + .../radix/test.ts.linttest} | 1 + test/ruleTests/radix/tslint.json | 5 + test/ruleTests/semicolon/test.ts.linttest | 74 ++++++++++++ test/ruleTests/semicolon/tslint.json | 5 + test/rules/oneLineRuleTests.ts | 108 ------------------ test/rules/quotemarkRuleTests.ts | 64 ----------- test/rules/radixRuleTests.ts | 30 ----- test/rules/semicolonRuleTests.ts | 94 --------------- test/tsconfig.json | 4 - 73 files changed, 239 insertions(+), 355 deletions(-) delete mode 100644 test/files/rules/semicolon.test.ts rename test/ruleTests/{align-arguments => align/arguments}/test.ts.linttest (100%) rename test/ruleTests/{align-arguments => align/arguments}/tslint.json (100%) rename test/ruleTests/{align-parameters => align/parameters}/test.ts.linttest (100%) rename test/ruleTests/{align-parameters => align/parameters}/tslint.json (100%) rename test/ruleTests/{align-statements => align/statements}/test.ts.linttest (100%) rename test/ruleTests/{align-statements => align/statements}/tslint.json (100%) rename test/ruleTests/{comment-format-lower => comment-format/lower}/test.ts.linttest (100%) rename test/ruleTests/{comment-format-lower => comment-format/lower}/tslint.json (100%) rename test/ruleTests/{comment-format-upper => comment-format/upper}/test.ts.linttest (100%) rename test/ruleTests/{comment-format-upper => comment-format/upper}/tslint.json (100%) rename test/ruleTests/{indent-spaces => indent/spaces}/.test.ts.linttest.swp (100%) rename test/ruleTests/{indent-spaces => indent/spaces}/test.ts.linttest (100%) rename test/ruleTests/{indent-spaces => indent/spaces}/tslint.json (100%) rename test/ruleTests/{indent-tabs => indent/tabs}/test.ts.linttest (100%) rename test/ruleTests/{indent-tabs => indent/tabs}/tslint.json (100%) rename test/ruleTests/{member-access-accessor => member-access/accessor}/test.ts.linttest (100%) rename test/ruleTests/{member-access-accessor => member-access/accessor}/tslint.json (100%) rename test/ruleTests/{member-access-constructor => member-access/constructor}/test.ts.linttest (100%) rename test/ruleTests/{member-access-constructor => member-access/constructor}/tslint.json (100%) rename test/ruleTests/member-access/{ => default}/test.ts.linttest (100%) rename test/ruleTests/member-access/{ => default}/tslint.json (100%) rename test/ruleTests/{member-ordering-method => member-ordering/method}/test.ts.linttest (100%) rename test/ruleTests/{member-ordering-method => member-ordering/method}/tslint.json (100%) rename test/ruleTests/{member-ordering-private => member-ordering/private}/test.ts.linttest (100%) rename test/ruleTests/{member-ordering-private => member-ordering/private}/tslint.json (100%) rename test/ruleTests/{member-ordering-static => member-ordering/static}/test.ts.linttest (100%) rename test/ruleTests/{member-ordering-static => member-ordering/static}/tslint.json (100%) rename test/ruleTests/{no-unused-variable-check-parameters => no-unused-variable/check-parameters}/test.ts.linttest (100%) rename test/ruleTests/{no-unused-variable-check-parameters => no-unused-variable/check-parameters}/tslint.json (100%) rename test/ruleTests/no-unused-variable/{ => default}/class.ts.linttest (100%) rename test/ruleTests/no-unused-variable/{ => default}/false-positives.ts.linttest (100%) rename test/ruleTests/no-unused-variable/{ => default}/function.ts.linttest (100%) rename test/ruleTests/no-unused-variable/{ => default}/import.ts.linttest (100%) rename test/ruleTests/no-unused-variable/{ => default}/react-addons1.tsx.linttest (100%) rename test/ruleTests/{no-unused-variable-react => no-unused-variable/default}/react-addons2.tsx.linttest (100%) rename test/ruleTests/{no-unused-variable-react => no-unused-variable/default}/react-addons3.tsx.linttest (100%) rename test/ruleTests/no-unused-variable/{ => default}/react1.tsx.linttest (100%) rename test/ruleTests/{no-unused-variable-react => no-unused-variable/default}/react2.tsx.linttest (100%) rename test/ruleTests/{no-unused-variable-react => no-unused-variable/default}/react3.tsx.linttest (100%) rename test/ruleTests/no-unused-variable/{ => default}/react4.tsx.linttest (100%) rename test/ruleTests/no-unused-variable/{ => default}/tslint.json (100%) rename test/ruleTests/no-unused-variable/{ => default}/var.ts.linttest (100%) rename test/ruleTests/{no-unused-variable-react => no-unused-variable/react}/react-addons1.tsx.linttest (100%) rename test/ruleTests/no-unused-variable/{ => react}/react-addons2.tsx.linttest (100%) rename test/ruleTests/no-unused-variable/{ => react}/react-addons3.tsx.linttest (100%) rename test/ruleTests/{no-unused-variable-react => no-unused-variable/react}/react1.tsx.linttest (100%) rename test/ruleTests/no-unused-variable/{ => react}/react2.tsx.linttest (100%) rename test/ruleTests/no-unused-variable/{ => react}/react3.tsx.linttest (100%) rename test/ruleTests/{no-unused-variable-react => no-unused-variable/react}/react4.tsx.linttest (100%) rename test/ruleTests/{no-unused-variable-react => no-unused-variable/react}/tslint.json (100%) create mode 100644 test/ruleTests/one-line/all/test.ts.linttest create mode 100644 test/ruleTests/one-line/all/tslint.json rename test/{files/rules/oneline.test.ts => ruleTests/one-line/none/test.ts.linttest} (100%) create mode 100644 test/ruleTests/one-line/none/tslint.json rename test/{files/rules/quotemark.test.ts => ruleTests/quotemark/double-avoid-escape/test.ts.linttest} (79%) create mode 100644 test/ruleTests/quotemark/double-avoid-escape/tslint.json create mode 100644 test/ruleTests/quotemark/double/test.ts.linttest create mode 100644 test/ruleTests/quotemark/double/tslint.json create mode 100644 test/ruleTests/quotemark/single-avoid-escape/test.ts.linttest create mode 100644 test/ruleTests/quotemark/single-avoid-escape/tslint.json create mode 100644 test/ruleTests/quotemark/single/test.ts.linttest create mode 100644 test/ruleTests/quotemark/single/tslint.json rename test/{files/rules/radix.test.ts => ruleTests/radix/test.ts.linttest} (61%) create mode 100644 test/ruleTests/radix/tslint.json create mode 100644 test/ruleTests/semicolon/test.ts.linttest create mode 100644 test/ruleTests/semicolon/tslint.json delete mode 100644 test/rules/oneLineRuleTests.ts delete mode 100644 test/rules/quotemarkRuleTests.ts delete mode 100644 test/rules/radixRuleTests.ts delete mode 100644 test/rules/semicolonRuleTests.ts diff --git a/test/files/rules/semicolon.test.ts b/test/files/rules/semicolon.test.ts deleted file mode 100644 index 944c2d721b9..00000000000 --- a/test/files/rules/semicolon.test.ts +++ /dev/null @@ -1,54 +0,0 @@ -var x = 3 -a += b - -c = () => { -} - -d = function() { } - -console.log("i am adam, am i?") - -function xyz() { - return -} - -switch(xyz) { - case 1: - break - case 2: - continue -} - -throw new Error("some error") - -do { - var a = 4 -} while(x == 3) - -debugger - -import v = require("i") -module M { - export var x -} - -function useStrictMissingSemicolon() { - "use strict" - return null; -} - -class MyClass { - public name : string - private index : number - private email : string; // no error -} - -interface ITest { - foo?: string - bar: number - baz: boolean; // no error -} - -import {Router} from 'aurelia-router'; // no error - -import {Controller} from 'my-lib' // error diff --git a/test/ruleTestRunner.ts b/test/ruleTestRunner.ts index 6a30d050c4e..f111701c6f3 100644 --- a/test/ruleTestRunner.ts +++ b/test/ruleTestRunner.ts @@ -31,7 +31,7 @@ console.log(); console.log(colors.underline("Testing Lint Rules:")); let hadTestFailure = false; -const testDirectories = glob.sync("test/ruleTests/*"); +const testDirectories = glob.sync("test/ruleTests/**/tslint.json").map(path.dirname); for (const testDirectory of testDirectories) { const filesToLint = glob.sync(path.join(testDirectory, `**/*${FILE_EXTENSION}`)); diff --git a/test/ruleTests/align-arguments/test.ts.linttest b/test/ruleTests/align/arguments/test.ts.linttest similarity index 100% rename from test/ruleTests/align-arguments/test.ts.linttest rename to test/ruleTests/align/arguments/test.ts.linttest diff --git a/test/ruleTests/align-arguments/tslint.json b/test/ruleTests/align/arguments/tslint.json similarity index 100% rename from test/ruleTests/align-arguments/tslint.json rename to test/ruleTests/align/arguments/tslint.json diff --git a/test/ruleTests/align-parameters/test.ts.linttest b/test/ruleTests/align/parameters/test.ts.linttest similarity index 100% rename from test/ruleTests/align-parameters/test.ts.linttest rename to test/ruleTests/align/parameters/test.ts.linttest diff --git a/test/ruleTests/align-parameters/tslint.json b/test/ruleTests/align/parameters/tslint.json similarity index 100% rename from test/ruleTests/align-parameters/tslint.json rename to test/ruleTests/align/parameters/tslint.json diff --git a/test/ruleTests/align-statements/test.ts.linttest b/test/ruleTests/align/statements/test.ts.linttest similarity index 100% rename from test/ruleTests/align-statements/test.ts.linttest rename to test/ruleTests/align/statements/test.ts.linttest diff --git a/test/ruleTests/align-statements/tslint.json b/test/ruleTests/align/statements/tslint.json similarity index 100% rename from test/ruleTests/align-statements/tslint.json rename to test/ruleTests/align/statements/tslint.json diff --git a/test/ruleTests/comment-format-lower/test.ts.linttest b/test/ruleTests/comment-format/lower/test.ts.linttest similarity index 100% rename from test/ruleTests/comment-format-lower/test.ts.linttest rename to test/ruleTests/comment-format/lower/test.ts.linttest diff --git a/test/ruleTests/comment-format-lower/tslint.json b/test/ruleTests/comment-format/lower/tslint.json similarity index 100% rename from test/ruleTests/comment-format-lower/tslint.json rename to test/ruleTests/comment-format/lower/tslint.json diff --git a/test/ruleTests/comment-format-upper/test.ts.linttest b/test/ruleTests/comment-format/upper/test.ts.linttest similarity index 100% rename from test/ruleTests/comment-format-upper/test.ts.linttest rename to test/ruleTests/comment-format/upper/test.ts.linttest diff --git a/test/ruleTests/comment-format-upper/tslint.json b/test/ruleTests/comment-format/upper/tslint.json similarity index 100% rename from test/ruleTests/comment-format-upper/tslint.json rename to test/ruleTests/comment-format/upper/tslint.json diff --git a/test/ruleTests/indent-spaces/.test.ts.linttest.swp b/test/ruleTests/indent/spaces/.test.ts.linttest.swp similarity index 100% rename from test/ruleTests/indent-spaces/.test.ts.linttest.swp rename to test/ruleTests/indent/spaces/.test.ts.linttest.swp diff --git a/test/ruleTests/indent-spaces/test.ts.linttest b/test/ruleTests/indent/spaces/test.ts.linttest similarity index 100% rename from test/ruleTests/indent-spaces/test.ts.linttest rename to test/ruleTests/indent/spaces/test.ts.linttest diff --git a/test/ruleTests/indent-spaces/tslint.json b/test/ruleTests/indent/spaces/tslint.json similarity index 100% rename from test/ruleTests/indent-spaces/tslint.json rename to test/ruleTests/indent/spaces/tslint.json diff --git a/test/ruleTests/indent-tabs/test.ts.linttest b/test/ruleTests/indent/tabs/test.ts.linttest similarity index 100% rename from test/ruleTests/indent-tabs/test.ts.linttest rename to test/ruleTests/indent/tabs/test.ts.linttest diff --git a/test/ruleTests/indent-tabs/tslint.json b/test/ruleTests/indent/tabs/tslint.json similarity index 100% rename from test/ruleTests/indent-tabs/tslint.json rename to test/ruleTests/indent/tabs/tslint.json diff --git a/test/ruleTests/member-access-accessor/test.ts.linttest b/test/ruleTests/member-access/accessor/test.ts.linttest similarity index 100% rename from test/ruleTests/member-access-accessor/test.ts.linttest rename to test/ruleTests/member-access/accessor/test.ts.linttest diff --git a/test/ruleTests/member-access-accessor/tslint.json b/test/ruleTests/member-access/accessor/tslint.json similarity index 100% rename from test/ruleTests/member-access-accessor/tslint.json rename to test/ruleTests/member-access/accessor/tslint.json diff --git a/test/ruleTests/member-access-constructor/test.ts.linttest b/test/ruleTests/member-access/constructor/test.ts.linttest similarity index 100% rename from test/ruleTests/member-access-constructor/test.ts.linttest rename to test/ruleTests/member-access/constructor/test.ts.linttest diff --git a/test/ruleTests/member-access-constructor/tslint.json b/test/ruleTests/member-access/constructor/tslint.json similarity index 100% rename from test/ruleTests/member-access-constructor/tslint.json rename to test/ruleTests/member-access/constructor/tslint.json diff --git a/test/ruleTests/member-access/test.ts.linttest b/test/ruleTests/member-access/default/test.ts.linttest similarity index 100% rename from test/ruleTests/member-access/test.ts.linttest rename to test/ruleTests/member-access/default/test.ts.linttest diff --git a/test/ruleTests/member-access/tslint.json b/test/ruleTests/member-access/default/tslint.json similarity index 100% rename from test/ruleTests/member-access/tslint.json rename to test/ruleTests/member-access/default/tslint.json diff --git a/test/ruleTests/member-ordering-method/test.ts.linttest b/test/ruleTests/member-ordering/method/test.ts.linttest similarity index 100% rename from test/ruleTests/member-ordering-method/test.ts.linttest rename to test/ruleTests/member-ordering/method/test.ts.linttest diff --git a/test/ruleTests/member-ordering-method/tslint.json b/test/ruleTests/member-ordering/method/tslint.json similarity index 100% rename from test/ruleTests/member-ordering-method/tslint.json rename to test/ruleTests/member-ordering/method/tslint.json diff --git a/test/ruleTests/member-ordering-private/test.ts.linttest b/test/ruleTests/member-ordering/private/test.ts.linttest similarity index 100% rename from test/ruleTests/member-ordering-private/test.ts.linttest rename to test/ruleTests/member-ordering/private/test.ts.linttest diff --git a/test/ruleTests/member-ordering-private/tslint.json b/test/ruleTests/member-ordering/private/tslint.json similarity index 100% rename from test/ruleTests/member-ordering-private/tslint.json rename to test/ruleTests/member-ordering/private/tslint.json diff --git a/test/ruleTests/member-ordering-static/test.ts.linttest b/test/ruleTests/member-ordering/static/test.ts.linttest similarity index 100% rename from test/ruleTests/member-ordering-static/test.ts.linttest rename to test/ruleTests/member-ordering/static/test.ts.linttest diff --git a/test/ruleTests/member-ordering-static/tslint.json b/test/ruleTests/member-ordering/static/tslint.json similarity index 100% rename from test/ruleTests/member-ordering-static/tslint.json rename to test/ruleTests/member-ordering/static/tslint.json diff --git a/test/ruleTests/no-unused-variable-check-parameters/test.ts.linttest b/test/ruleTests/no-unused-variable/check-parameters/test.ts.linttest similarity index 100% rename from test/ruleTests/no-unused-variable-check-parameters/test.ts.linttest rename to test/ruleTests/no-unused-variable/check-parameters/test.ts.linttest diff --git a/test/ruleTests/no-unused-variable-check-parameters/tslint.json b/test/ruleTests/no-unused-variable/check-parameters/tslint.json similarity index 100% rename from test/ruleTests/no-unused-variable-check-parameters/tslint.json rename to test/ruleTests/no-unused-variable/check-parameters/tslint.json diff --git a/test/ruleTests/no-unused-variable/class.ts.linttest b/test/ruleTests/no-unused-variable/default/class.ts.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/class.ts.linttest rename to test/ruleTests/no-unused-variable/default/class.ts.linttest diff --git a/test/ruleTests/no-unused-variable/false-positives.ts.linttest b/test/ruleTests/no-unused-variable/default/false-positives.ts.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/false-positives.ts.linttest rename to test/ruleTests/no-unused-variable/default/false-positives.ts.linttest diff --git a/test/ruleTests/no-unused-variable/function.ts.linttest b/test/ruleTests/no-unused-variable/default/function.ts.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/function.ts.linttest rename to test/ruleTests/no-unused-variable/default/function.ts.linttest diff --git a/test/ruleTests/no-unused-variable/import.ts.linttest b/test/ruleTests/no-unused-variable/default/import.ts.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/import.ts.linttest rename to test/ruleTests/no-unused-variable/default/import.ts.linttest diff --git a/test/ruleTests/no-unused-variable/react-addons1.tsx.linttest b/test/ruleTests/no-unused-variable/default/react-addons1.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/react-addons1.tsx.linttest rename to test/ruleTests/no-unused-variable/default/react-addons1.tsx.linttest diff --git a/test/ruleTests/no-unused-variable-react/react-addons2.tsx.linttest b/test/ruleTests/no-unused-variable/default/react-addons2.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable-react/react-addons2.tsx.linttest rename to test/ruleTests/no-unused-variable/default/react-addons2.tsx.linttest diff --git a/test/ruleTests/no-unused-variable-react/react-addons3.tsx.linttest b/test/ruleTests/no-unused-variable/default/react-addons3.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable-react/react-addons3.tsx.linttest rename to test/ruleTests/no-unused-variable/default/react-addons3.tsx.linttest diff --git a/test/ruleTests/no-unused-variable/react1.tsx.linttest b/test/ruleTests/no-unused-variable/default/react1.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/react1.tsx.linttest rename to test/ruleTests/no-unused-variable/default/react1.tsx.linttest diff --git a/test/ruleTests/no-unused-variable-react/react2.tsx.linttest b/test/ruleTests/no-unused-variable/default/react2.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable-react/react2.tsx.linttest rename to test/ruleTests/no-unused-variable/default/react2.tsx.linttest diff --git a/test/ruleTests/no-unused-variable-react/react3.tsx.linttest b/test/ruleTests/no-unused-variable/default/react3.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable-react/react3.tsx.linttest rename to test/ruleTests/no-unused-variable/default/react3.tsx.linttest diff --git a/test/ruleTests/no-unused-variable/react4.tsx.linttest b/test/ruleTests/no-unused-variable/default/react4.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/react4.tsx.linttest rename to test/ruleTests/no-unused-variable/default/react4.tsx.linttest diff --git a/test/ruleTests/no-unused-variable/tslint.json b/test/ruleTests/no-unused-variable/default/tslint.json similarity index 100% rename from test/ruleTests/no-unused-variable/tslint.json rename to test/ruleTests/no-unused-variable/default/tslint.json diff --git a/test/ruleTests/no-unused-variable/var.ts.linttest b/test/ruleTests/no-unused-variable/default/var.ts.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/var.ts.linttest rename to test/ruleTests/no-unused-variable/default/var.ts.linttest diff --git a/test/ruleTests/no-unused-variable-react/react-addons1.tsx.linttest b/test/ruleTests/no-unused-variable/react/react-addons1.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable-react/react-addons1.tsx.linttest rename to test/ruleTests/no-unused-variable/react/react-addons1.tsx.linttest diff --git a/test/ruleTests/no-unused-variable/react-addons2.tsx.linttest b/test/ruleTests/no-unused-variable/react/react-addons2.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/react-addons2.tsx.linttest rename to test/ruleTests/no-unused-variable/react/react-addons2.tsx.linttest diff --git a/test/ruleTests/no-unused-variable/react-addons3.tsx.linttest b/test/ruleTests/no-unused-variable/react/react-addons3.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/react-addons3.tsx.linttest rename to test/ruleTests/no-unused-variable/react/react-addons3.tsx.linttest diff --git a/test/ruleTests/no-unused-variable-react/react1.tsx.linttest b/test/ruleTests/no-unused-variable/react/react1.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable-react/react1.tsx.linttest rename to test/ruleTests/no-unused-variable/react/react1.tsx.linttest diff --git a/test/ruleTests/no-unused-variable/react2.tsx.linttest b/test/ruleTests/no-unused-variable/react/react2.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/react2.tsx.linttest rename to test/ruleTests/no-unused-variable/react/react2.tsx.linttest diff --git a/test/ruleTests/no-unused-variable/react3.tsx.linttest b/test/ruleTests/no-unused-variable/react/react3.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/react3.tsx.linttest rename to test/ruleTests/no-unused-variable/react/react3.tsx.linttest diff --git a/test/ruleTests/no-unused-variable-react/react4.tsx.linttest b/test/ruleTests/no-unused-variable/react/react4.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable-react/react4.tsx.linttest rename to test/ruleTests/no-unused-variable/react/react4.tsx.linttest diff --git a/test/ruleTests/no-unused-variable-react/tslint.json b/test/ruleTests/no-unused-variable/react/tslint.json similarity index 100% rename from test/ruleTests/no-unused-variable-react/tslint.json rename to test/ruleTests/no-unused-variable/react/tslint.json diff --git a/test/ruleTests/one-line/all/test.ts.linttest b/test/ruleTests/one-line/all/test.ts.linttest new file mode 100644 index 00000000000..a35d6f1d362 --- /dev/null +++ b/test/ruleTests/one-line/all/test.ts.linttest @@ -0,0 +1,105 @@ +module Module +{ +~ [misplaced opening brace] + export enum Enumeration + { + ~ [misplaced opening brace] + A, + B, + C, + D + } + + export function Call() + { + ~ [misplaced opening brace] + if (x == 3) + { + ~ [misplaced opening brace] + x = 4; + } + else { + ~~~~ [misplaced 'else'] + x = 5; + } + return "called"; + } +} + +interface Class +{ +~ [misplaced opening brace] + variable: string; +} + +var object = +{ +~ [misplaced opening brace] + a: 1, + b: 2 +}; + +for(var x= 0; x < 1; ++x) +{ +~ [misplaced opening brace] + ++i; +} + +switch(y) +{ +~ [misplaced opening brace] + case 0: + x--; + break; + default: + x++; + break; +} + +try +{ +~ [misplaced opening brace] + throw new Error("hi"); +} +catch (e) +~~~~~ [misplaced 'catch'] +{ +~ [misplaced opening brace] + throw(e); +} + +while(x < 10){ + ~ [missing whitespace] + x++; +} + +function f(): + number { + + return 5; +} + +class BarBooBaz +{ +~ [misplaced opening brace] + +} + +class FooBarBaz { +} + +// Valid multiline declarations +export class LongDescriptiveClassName, S> + extends SomeAbstractBaseClass implements IImportantInterface { +} + +export interface LongDescriptiveInterfaceName + extends AThirdInterface { +} + +function longFunctionNameWithLotsOfParams( + x: number, + y: number, + z: number, + a: T) { +} diff --git a/test/ruleTests/one-line/all/tslint.json b/test/ruleTests/one-line/all/tslint.json new file mode 100644 index 00000000000..5d4cb77f9f2 --- /dev/null +++ b/test/ruleTests/one-line/all/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "one-line": [true, "check-open-brace", "check-catch", "check-else", "check-whitespace"] + } +} diff --git a/test/files/rules/oneline.test.ts b/test/ruleTests/one-line/none/test.ts.linttest similarity index 100% rename from test/files/rules/oneline.test.ts rename to test/ruleTests/one-line/none/test.ts.linttest diff --git a/test/ruleTests/one-line/none/tslint.json b/test/ruleTests/one-line/none/tslint.json new file mode 100644 index 00000000000..ea05ac32938 --- /dev/null +++ b/test/ruleTests/one-line/none/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "one-line": true + } +} diff --git a/test/files/rules/quotemark.test.ts b/test/ruleTests/quotemark/double-avoid-escape/test.ts.linttest similarity index 79% rename from test/files/rules/quotemark.test.ts rename to test/ruleTests/quotemark/double-avoid-escape/test.ts.linttest index 6e5900cee4b..03f86c4826e 100644 --- a/test/files/rules/quotemark.test.ts +++ b/test/ruleTests/quotemark/double-avoid-escape/test.ts.linttest @@ -1,4 +1,5 @@ var single = 'single'; + ~~~~~~~~ [' should be "] var doublee = "married"; var singleWithinDouble = "'singleWithinDouble'"; var doubleWithinSingle = '"doubleWithinSingle"'; diff --git a/test/ruleTests/quotemark/double-avoid-escape/tslint.json b/test/ruleTests/quotemark/double-avoid-escape/tslint.json new file mode 100644 index 00000000000..6c0f14e3051 --- /dev/null +++ b/test/ruleTests/quotemark/double-avoid-escape/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "quotemark": [true, "double", "avoid-escape"] + } +} diff --git a/test/ruleTests/quotemark/double/test.ts.linttest b/test/ruleTests/quotemark/double/test.ts.linttest new file mode 100644 index 00000000000..2efd3df18b3 --- /dev/null +++ b/test/ruleTests/quotemark/double/test.ts.linttest @@ -0,0 +1,6 @@ +var single = 'single'; + ~~~~~~~~ [' should be "] + var doublee = "married"; +var singleWithinDouble = "'singleWithinDouble'"; +var doubleWithinSingle = '"doubleWithinSingle"'; + ~~~~~~~~~~~~~~~~~~~~~~ [' should be "] diff --git a/test/ruleTests/quotemark/double/tslint.json b/test/ruleTests/quotemark/double/tslint.json new file mode 100644 index 00000000000..9318e0d53e4 --- /dev/null +++ b/test/ruleTests/quotemark/double/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "quotemark": [true, "double"] + } +} diff --git a/test/ruleTests/quotemark/single-avoid-escape/test.ts.linttest b/test/ruleTests/quotemark/single-avoid-escape/test.ts.linttest new file mode 100644 index 00000000000..52e21fb78a9 --- /dev/null +++ b/test/ruleTests/quotemark/single-avoid-escape/test.ts.linttest @@ -0,0 +1,5 @@ +var single = 'single'; + var doublee = "married"; + ~~~~~~~~~ [" should be '] +var singleWithinDouble = "'singleWithinDouble'"; +var doubleWithinSingle = '"doubleWithinSingle"'; diff --git a/test/ruleTests/quotemark/single-avoid-escape/tslint.json b/test/ruleTests/quotemark/single-avoid-escape/tslint.json new file mode 100644 index 00000000000..c360887f9d7 --- /dev/null +++ b/test/ruleTests/quotemark/single-avoid-escape/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "quotemark": [true, "single", "avoid-escape"] + } +} diff --git a/test/ruleTests/quotemark/single/test.ts.linttest b/test/ruleTests/quotemark/single/test.ts.linttest new file mode 100644 index 00000000000..bba732c703b --- /dev/null +++ b/test/ruleTests/quotemark/single/test.ts.linttest @@ -0,0 +1,6 @@ +var single = 'single'; + var doublee = "married"; + ~~~~~~~~~ [" should be '] +var singleWithinDouble = "'singleWithinDouble'"; + ~~~~~~~~~~~~~~~~~~~~~~ [" should be '] +var doubleWithinSingle = '"doubleWithinSingle"'; diff --git a/test/ruleTests/quotemark/single/tslint.json b/test/ruleTests/quotemark/single/tslint.json new file mode 100644 index 00000000000..4a5f880d8ab --- /dev/null +++ b/test/ruleTests/quotemark/single/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "quotemark": [true, "single"] + } +} diff --git a/test/files/rules/radix.test.ts b/test/ruleTests/radix/test.ts.linttest similarity index 61% rename from test/files/rules/radix.test.ts rename to test/ruleTests/radix/test.ts.linttest index bba2f6c5899..9ebf0526a7a 100644 --- a/test/files/rules/radix.test.ts +++ b/test/ruleTests/radix/test.ts.linttest @@ -1,3 +1,4 @@ var x = parseInt(3, 10) + parseInt(4); + ~~~~~~~~~~~ [missing radix parameter] var y = parseFloat("2.5"); diff --git a/test/ruleTests/radix/tslint.json b/test/ruleTests/radix/tslint.json new file mode 100644 index 00000000000..38441411292 --- /dev/null +++ b/test/ruleTests/radix/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "radix": true + } +} diff --git a/test/ruleTests/semicolon/test.ts.linttest b/test/ruleTests/semicolon/test.ts.linttest new file mode 100644 index 00000000000..f7cf090a042 --- /dev/null +++ b/test/ruleTests/semicolon/test.ts.linttest @@ -0,0 +1,74 @@ +var x = 3 + ~nil [missing semicolon] +a += b + ~nil [missing semicolon] + +c = () => { +} + ~nil [missing semicolon] + +d = function() { } + ~nil [missing semicolon] + +console.log("i am adam, am i?") + ~nil [missing semicolon] + +function xyz() { + return + ~nil [missing semicolon] +} + +switch(xyz) { + case 1: + break + ~nil [missing semicolon] + case 2: + continue + ~nil [missing semicolon] +} + +throw new Error("some error") + ~nil [missing semicolon] + +do { + var a = 4 + ~nil [missing semicolon] +} while(x == 3) + ~nil [missing semicolon] + +debugger + ~nil [missing semicolon] + +import v = require("i") + ~nil [missing semicolon] +module M { + export var x + ~nil [missing semicolon] +} + +function useStrictMissingSemicolon() { + "use strict" + ~nil [missing semicolon] + return null; +} + +class MyClass { + public name : string + ~nil [missing semicolon] + private index : number + ~nil [missing semicolon] + private email : string; +} + +interface ITest { + foo?: string + ~nil [missing semicolon] + bar: number + ~nil [missing semicolon] + baz: boolean; +} + +import {Router} from 'aurelia-router'; + +import {Controller} from 'my-lib' + ~nil [missing semicolon] diff --git a/test/ruleTests/semicolon/tslint.json b/test/ruleTests/semicolon/tslint.json new file mode 100644 index 00000000000..7a7a8e7d42a --- /dev/null +++ b/test/ruleTests/semicolon/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "semicolon": true + } +} diff --git a/test/rules/oneLineRuleTests.ts b/test/rules/oneLineRuleTests.ts deleted file mode 100644 index ea66ed6a6cc..00000000000 --- a/test/rules/oneLineRuleTests.ts +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {RuleFailure, TestUtils} from "../lint"; - -describe("", () => { - const fileName = "rules/oneline.test.ts"; - const OneLineRule = TestUtils.getRule("one-line"); - const braceFailure = OneLineRule.BRACE_FAILURE_STRING; - const elseFailure = OneLineRule.ELSE_FAILURE_STRING; - const whitespaceFailure = OneLineRule.WHITESPACE_FAILURE_STRING; - const catchFailure = OneLineRule.CATCH_FAILURE_STRING; - let actualFailures: RuleFailure[]; - - before(() => { - const options = [true, "check-open-brace", "check-catch", "check-else", "check-whitespace"]; - actualFailures = TestUtils.applyRuleOnFile(fileName, OneLineRule, options); - assert.lengthOf(actualFailures, 14); - }); - - it("enforces rules only when enabled", () => { - const failures = TestUtils.applyRuleOnFile(fileName, OneLineRule); - assert.equal(failures.length, 0); - }); - - it("enforces module brace", () => { - const expectedFailure = TestUtils.createFailure(fileName, [2, 1], [2, 2], braceFailure); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("enforces enumeration brace", () => { - const expectedFailure = TestUtils.createFailure(fileName, [4, 5], [4, 6], braceFailure); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("enforces function brace", () => { - const expectedFailure = TestUtils.createFailure(fileName, [12, 5], [12, 6], braceFailure); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("enforces if brace", () => { - const expectedFailure = TestUtils.createFailure(fileName, [14, 9], [14, 10], braceFailure); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("enforces else position", () => { - const expectedFailure = TestUtils.createFailure(fileName, [17, 9], [17, 13], elseFailure); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("enforces interface brace", () => { - const expectedFailure = TestUtils.createFailure(fileName, [25, 1], [25, 2], braceFailure); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("enforces object literal brace", () => { - const expectedFailure = TestUtils.createFailure(fileName, [30, 1], [30, 2], braceFailure); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("enforces block brace", () => { - const expectedFailure = TestUtils.createFailure(fileName, [36, 1], [36, 2], braceFailure); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("enforces switch brace", () => { - const expectedFailure = TestUtils.createFailure(fileName, [41, 1], [41, 2], braceFailure); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("enforces try brace", () => { - const expectedFailure = TestUtils.createFailure(fileName, [51, 1], [51, 2], braceFailure); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("enforces catch position", () => { - const expectedFailure = TestUtils.createFailure(fileName, [54, 1], [54, 6], catchFailure); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("enforces catch brace", () => { - const expectedFailure = TestUtils.createFailure(fileName, [55, 1], [55, 2], braceFailure); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("enforces class brace", () => { - const expectedFailure = TestUtils.createFailure(fileName, [70, 1], [70, 2], braceFailure); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("enforces whitespace before a brace", () => { - const expectedFailure = TestUtils.createFailure(fileName, [59, 14], [59, 15], whitespaceFailure); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); -}); diff --git a/test/rules/quotemarkRuleTests.ts b/test/rules/quotemarkRuleTests.ts deleted file mode 100644 index 0bab400a0f1..00000000000 --- a/test/rules/quotemarkRuleTests.ts +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - const QuoteMarkRule = TestUtils.getRule("quotemark"); - const fileName = "rules/quotemark.test.ts"; - const singleFailureString = QuoteMarkRule.SINGLE_QUOTE_FAILURE; - const doubleFailureString = QuoteMarkRule.DOUBLE_QUOTE_FAILURE; - - it("enforces single quotes", () => { - const actualFailures = TestUtils.applyRuleOnFile(fileName, QuoteMarkRule, [true, "single"]); - const expectedFailures = [ - TestUtils.createFailure(fileName, [2, 19], [2, 28], singleFailureString), - TestUtils.createFailure(fileName, [3, 26], [3, 48], singleFailureString) - ]; - - assert.equal(actualFailures.length, 2); - assert.isTrue(actualFailures[0].equals(expectedFailures[0])); - assert.isTrue(actualFailures[1].equals(expectedFailures[1])); - }); - - it("enforces double quotes", () => { - const actualFailures = TestUtils.applyRuleOnFile(fileName, QuoteMarkRule, [true, "double"]); - const expectedFailures = [ - TestUtils.createFailure(fileName, [1, 14], [1, 22], doubleFailureString), - TestUtils.createFailure(fileName, [4, 26], [4, 48], doubleFailureString) - ]; - - assert.equal(actualFailures.length, 2); - assert.isTrue(actualFailures[0].equals(expectedFailures[0])); - assert.isTrue(actualFailures[1].equals(expectedFailures[1])); - }); - - it("enforces single quotes but allow other quote marks to avoid having to escape", () => { - const actualFailures = TestUtils.applyRuleOnFile(fileName, QuoteMarkRule, [true, "single", "avoid-escape"]); - const expectedFailure = TestUtils.createFailure(fileName, [2, 19], [2, 28], singleFailureString); - - assert.equal(actualFailures.length, 1); - assert.isTrue(actualFailures[0].equals(expectedFailure)); - }); - - it("enforces double quotes but allow other quote marks to avoid having to escape", () => { - const actualFailures = TestUtils.applyRuleOnFile(fileName, QuoteMarkRule, [true, "double", "avoid-escape"]); - const expectedFailure = TestUtils.createFailure(fileName, [1, 14], [1, 22], doubleFailureString); - - assert.equal(actualFailures.length, 1); - assert.isTrue(actualFailures[0].equals(expectedFailure)); - }); -}); diff --git a/test/rules/radixRuleTests.ts b/test/rules/radixRuleTests.ts deleted file mode 100644 index aba44e90754..00000000000 --- a/test/rules/radixRuleTests.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - const RadixRule = TestUtils.getRule("radix"); - const fileName = "rules/radix.test.ts"; - const failureString = RadixRule.FAILURE_STRING; - - it("enforces radix parameter of parseInt", () => { - const actualFailures = TestUtils.applyRuleOnFile(fileName, RadixRule); - const expectedFailure = TestUtils.createFailure(fileName, [2, 9], [2, 20], failureString); - - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); -}); diff --git a/test/rules/semicolonRuleTests.ts b/test/rules/semicolonRuleTests.ts deleted file mode 100644 index 9ffa12497cd..00000000000 --- a/test/rules/semicolonRuleTests.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {RuleFailure, TestUtils} from "../lint"; - -describe("", () => { - const SemicolonRule = TestUtils.getRule("semicolon"); - const fileName = "rules/semicolon.test.ts"; - const failureString = SemicolonRule.FAILURE_STRING; - const createFailure = (start: number[], end: number[]) => { - return TestUtils.createFailure(fileName, start, end, failureString); - }; - let actualFailures: RuleFailure[]; - - before(() => { - actualFailures = TestUtils.applyRuleOnFile(fileName, SemicolonRule); - }); - - it("warns on all statements", () => { - assert.equal(actualFailures.length, 20); - }); - - it("warns on variable statements", () => { - TestUtils.assertContainsFailure(actualFailures, createFailure([1, 10], [1, 10])); - TestUtils.assertContainsFailure(actualFailures, createFailure([25, 14], [25, 14])); - }); - - it("warns on expression statements", () => { - TestUtils.assertContainsFailure(actualFailures, createFailure([2, 7], [2, 7])); - TestUtils.assertContainsFailure(actualFailures, createFailure([5, 2], [5, 2])); - TestUtils.assertContainsFailure(actualFailures, createFailure([7, 19], [7, 19])); - TestUtils.assertContainsFailure(actualFailures, createFailure([9, 32], [9, 32])); - }); - - it("warns on return statements", () => { - TestUtils.assertContainsFailure(actualFailures, createFailure([12, 11], [12, 11])); - }); - - it("warns on break statements", () => { - TestUtils.assertContainsFailure(actualFailures, createFailure([17, 14], [17, 14])); - }); - - it("warns on continue statements", () => { - TestUtils.assertContainsFailure(actualFailures, createFailure([19, 17], [19, 17])); - }); - - it("warns on throw statements", () => { - TestUtils.assertContainsFailure(actualFailures, createFailure([22, 30], [22, 30])); - }); - - it("warns on do while statements", () => { - TestUtils.assertContainsFailure(actualFailures, createFailure([26, 16], [26, 16])); - }); - - it("warns on debugger statements", () => { - TestUtils.assertContainsFailure(actualFailures, createFailure([28, 9], [28, 9])); - }); - - it("warns on import and export statements", () => { - TestUtils.assertContainsFailure(actualFailures, createFailure([30, 24], [30, 24])); - TestUtils.assertContainsFailure(actualFailures, createFailure([32, 17], [32, 17])); - }); - - it("warns on use strict statements", () => { - TestUtils.assertContainsFailure(actualFailures, createFailure([36, 17], [36, 17])); - }); - - it("warns on property declarations", () => { - TestUtils.assertContainsFailure(actualFailures, createFailure([41, 25], [41, 25])); - TestUtils.assertContainsFailure(actualFailures, createFailure([42, 27], [42, 27])); - }); - - it("warns on interface declaration", () => { - TestUtils.assertContainsFailure(actualFailures, createFailure([47, 17], [47, 17])); - TestUtils.assertContainsFailure(actualFailures, createFailure([48, 16], [48, 16])); - }); - - it("warns on import statement", () => { - TestUtils.assertContainsFailure(actualFailures, createFailure([54, 34], [54, 34])); - }); -}); diff --git a/test/tsconfig.json b/test/tsconfig.json index faa2f000a95..37be4ccb758 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -129,10 +129,6 @@ "ruleTestRunnerTests/testData.ts", "ruleTestRunnerTests/utilsTests.ts", "rules/eofLineRuleTests.ts", - "rules/oneLineRuleTests.ts", - "rules/quotemarkRuleTests.ts", - "rules/radixRuleTests.ts", - "rules/semicolonRuleTests.ts", "rules/switchDefaultRuleTests.ts", "rules/trailingCommaRuleTests.ts", "rules/tripleEqualsRuleTests.ts", From fc061569792475347d1dc37f508abe51b8c253b6 Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Thu, 24 Dec 2015 01:11:59 -0500 Subject: [PATCH 20/30] Convert tests for switch-default, trailing-comma, triple-equals, and typedef rules Fix trailing-comma rule to have more sensible error locations --- src/rules/trailingCommaRule.ts | 2 +- .../switch-default/test.ts.linttest} | 17 +- test/ruleTests/switch-default/tslint.json | 5 + .../multiline-always/test.ts.linttest | 94 ++++++++++ .../multiline-always/tslint.json | 5 + .../multiline-never/test.ts.linttest} | 7 + .../multiline-never/tslint.json | 5 + .../singleline-always/test.ts.linttest | 94 ++++++++++ .../singleline-always/tslint.json | 5 + .../singleline-never/test.ts.linttest | 94 ++++++++++ .../singleline-never/tslint.json | 5 + .../triple-equals/test.ts.linttest} | 2 + test/ruleTests/triple-equals/tslint.json | 5 + test/ruleTests/typedef/all/test.ts.linttest | 42 +++++ test/ruleTests/typedef/all/tslint.json | 11 ++ .../typedef/none/test.ts.linttest} | 0 test/ruleTests/typedef/none/tslint.json | 5 + test/rules/switchDefaultRuleTests.ts | 33 ---- test/rules/trailingCommaRuleTests.ts | 118 ------------ test/rules/tripleEqualsRuleTests.ts | 42 ----- test/rules/typedefRuleTests.ts | 169 ------------------ test/tsconfig.json | 4 - 22 files changed, 396 insertions(+), 368 deletions(-) rename test/{files/rules/switchdefault.test.ts => ruleTests/switch-default/test.ts.linttest} (67%) create mode 100644 test/ruleTests/switch-default/tslint.json create mode 100644 test/ruleTests/trailing-comma/multiline-always/test.ts.linttest create mode 100644 test/ruleTests/trailing-comma/multiline-always/tslint.json rename test/{files/rules/trailingcomma.test.ts => ruleTests/trailing-comma/multiline-never/test.ts.linttest} (81%) create mode 100644 test/ruleTests/trailing-comma/multiline-never/tslint.json create mode 100644 test/ruleTests/trailing-comma/singleline-always/test.ts.linttest create mode 100644 test/ruleTests/trailing-comma/singleline-always/tslint.json create mode 100644 test/ruleTests/trailing-comma/singleline-never/test.ts.linttest create mode 100644 test/ruleTests/trailing-comma/singleline-never/tslint.json rename test/{files/rules/eqeqeq.test.ts => ruleTests/triple-equals/test.ts.linttest} (69%) create mode 100644 test/ruleTests/triple-equals/tslint.json create mode 100644 test/ruleTests/typedef/all/test.ts.linttest create mode 100644 test/ruleTests/typedef/all/tslint.json rename test/{files/rules/typedef.test.ts => ruleTests/typedef/none/test.ts.linttest} (100%) create mode 100644 test/ruleTests/typedef/none/tslint.json delete mode 100644 test/rules/switchDefaultRuleTests.ts delete mode 100644 test/rules/trailingCommaRuleTests.ts delete mode 100644 test/rules/tripleEqualsRuleTests.ts delete mode 100644 test/rules/typedefRuleTests.ts diff --git a/src/rules/trailingCommaRule.ts b/src/rules/trailingCommaRule.ts index 19fb6677639..a5e28552665 100644 --- a/src/rules/trailingCommaRule.ts +++ b/src/rules/trailingCommaRule.ts @@ -64,7 +64,7 @@ class TrailingCommaWalker extends Lint.RuleWalker { if (hasTrailingComma && option === "never") { this.addFailure(this.createFailure(lastGrandChild.getStart(), 1, Rule.FAILURE_STRING_NEVER)); } else if (!hasTrailingComma && option === "always") { - this.addFailure(this.createFailure(lastGrandChild.getEnd(), 1, Rule.FAILURE_STRING_ALWAYS)); + this.addFailure(this.createFailure(lastGrandChild.getEnd() - 1, 1, Rule.FAILURE_STRING_ALWAYS)); } } } diff --git a/test/files/rules/switchdefault.test.ts b/test/ruleTests/switch-default/test.ts.linttest similarity index 67% rename from test/files/rules/switchdefault.test.ts rename to test/ruleTests/switch-default/test.ts.linttest index f35ca8594ee..1bab075af11 100644 --- a/test/files/rules/switchdefault.test.ts +++ b/test/ruleTests/switch-default/test.ts.linttest @@ -1,21 +1,36 @@ - switch (foo) { +~~~~~~~~~~~~~~ case 1: +~~~~~~~ bar(); +~~~~~~~~~~ break; +~~~~~~~~~~ } +~ [switch statement doesn't include a 'default' case] switch (foo) { +~~~~~~~~~~~~~~ case 1: +~~~~~~~ bar(); +~~~~~~~~~~ break; +~~~~~~~~~~ case 2: +~~~~~~~ bar(); +~~~~~~~~~~ break; +~~~~~~~~~~ case 3: +~~~~~~~ bar(); +~~~~~~~~~~ break; +~~~~~~~~~~ } +~ [switch statement doesn't include a 'default' case] // valid switch (foo) { diff --git a/test/ruleTests/switch-default/tslint.json b/test/ruleTests/switch-default/tslint.json new file mode 100644 index 00000000000..05e34955935 --- /dev/null +++ b/test/ruleTests/switch-default/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "switch-default": true + } +} diff --git a/test/ruleTests/trailing-comma/multiline-always/test.ts.linttest b/test/ruleTests/trailing-comma/multiline-always/test.ts.linttest new file mode 100644 index 00000000000..2cece0a0b67 --- /dev/null +++ b/test/ruleTests/trailing-comma/multiline-always/test.ts.linttest @@ -0,0 +1,94 @@ +var v = [{ + a: 1, + b: 2, + d: 34, + c: (a + b), +},]; + +var x = [{ + a: 1, + b: 2, + d: 34, + c: (a + b) + ~ [missing trailing comma] +}]; +~ [missing trailing comma] + +var y = { + yA: 42, + yB: 24, +}; + +var z = { + zOne: 2, + zTwo: 1 + ~ [missing trailing comma] +}; + +var yy = [ + 42, + 24, +]; + +var zz = [ + 2, + 1 + ~ [missing trailing comma] +]; + +var a = [{a: 1, b: 2, d: 34, c: (a + b),},]; + +var b = [{a: 1, b: 2, d: 34, c: (a + b)}]; + +var c = {cA: 42, cB: 24,}; + +var d = {dOne: 2, dTwo: 1}; + +var cc = [42, 24,]; + +var dd = [2, 1]; + +var { + yA, + yB, +} = y; + +var { + zOne, + zTwo + ~ [missing trailing comma] +} = z; + +var [ + yyA, + yyB, +] = yy; + +var [ + zzOne, + zzTwo + ~ [missing trailing comma] +] = zz; + +var {cA, cB,} = c; + +var {dOne, dTwo} = d; + +var [ccA, ccB,] = cc; + +var [ddOne, ddTwo] = dd; + +import { + ClassV, + ClassX, +} from "module"; + +import { + ClassY, + ClassZ + ~ [missing trailing comma] +} from "module"; + +import {ClassA, ClassB,} from "module"; + +import {ClassC, ClassD} from "module"; diff --git a/test/ruleTests/trailing-comma/multiline-always/tslint.json b/test/ruleTests/trailing-comma/multiline-always/tslint.json new file mode 100644 index 00000000000..b9d77c2ab7c --- /dev/null +++ b/test/ruleTests/trailing-comma/multiline-always/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "trailing-comma": [true, {"multiline": "always"}] + } +} diff --git a/test/files/rules/trailingcomma.test.ts b/test/ruleTests/trailing-comma/multiline-never/test.ts.linttest similarity index 81% rename from test/files/rules/trailingcomma.test.ts rename to test/ruleTests/trailing-comma/multiline-never/test.ts.linttest index d051ebfc7d5..926a3f79730 100644 --- a/test/files/rules/trailingcomma.test.ts +++ b/test/ruleTests/trailing-comma/multiline-never/test.ts.linttest @@ -3,7 +3,9 @@ var v = [{ b: 2, d: 34, c: (a + b), + ~ [trailing comma] },]; + ~ [trailing comma] var x = [{ a: 1, @@ -15,6 +17,7 @@ var x = [{ var y = { yA: 42, yB: 24, + ~ [trailing comma] }; var z = { @@ -25,6 +28,7 @@ var z = { var yy = [ 42, 24, + ~ [trailing comma] ]; var zz = [ @@ -47,6 +51,7 @@ var dd = [2, 1]; var { yA, yB, + ~ [trailing comma] } = y; var { @@ -57,6 +62,7 @@ var { var [ yyA, yyB, + ~ [trailing comma] ] = yy; var [ @@ -75,6 +81,7 @@ var [ddOne, ddTwo] = dd; import { ClassV, ClassX, + ~ [trailing comma] } from "module"; import { diff --git a/test/ruleTests/trailing-comma/multiline-never/tslint.json b/test/ruleTests/trailing-comma/multiline-never/tslint.json new file mode 100644 index 00000000000..4ad240b0790 --- /dev/null +++ b/test/ruleTests/trailing-comma/multiline-never/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "trailing-comma": [true, {"multiline": "never"}] + } +} diff --git a/test/ruleTests/trailing-comma/singleline-always/test.ts.linttest b/test/ruleTests/trailing-comma/singleline-always/test.ts.linttest new file mode 100644 index 00000000000..56537674519 --- /dev/null +++ b/test/ruleTests/trailing-comma/singleline-always/test.ts.linttest @@ -0,0 +1,94 @@ +var v = [{ + a: 1, + b: 2, + d: 34, + c: (a + b), +},]; + +var x = [{ + a: 1, + b: 2, + d: 34, + c: (a + b) +}]; + +var y = { + yA: 42, + yB: 24, +}; + +var z = { + zOne: 2, + zTwo: 1 +}; + +var yy = [ + 42, + 24, +]; + +var zz = [ + 2, + 1 +]; + +var a = [{a: 1, b: 2, d: 34, c: (a + b),},]; + +var b = [{a: 1, b: 2, d: 34, c: (a + b)}]; + ~ [missing trailing comma] + ~ [missing trailing comma] + +var c = {cA: 42, cB: 24,}; + +var d = {dOne: 2, dTwo: 1}; + ~ [missing trailing comma] + +var cc = [42, 24,]; + +var dd = [2, 1]; + ~ [missing trailing comma] + +var { + yA, + yB, +} = y; + +var { + zOne, + zTwo +} = z; + +var [ + yyA, + yyB, +] = yy; + +var [ + zzOne, + zzTwo +] = zz; + +var {cA, cB,} = c; + +var {dOne, dTwo} = d; + ~ [missing trailing comma] + +var [ccA, ccB,] = cc; + +var [ddOne, ddTwo] = dd; + ~ [missing trailing comma] + +import { + ClassV, + ClassX, +} from "module"; + +import { + ClassY, + ClassZ +} from "module"; + +import {ClassA, ClassB,} from "module"; + +import {ClassC, ClassD} from "module"; + ~ [missing trailing comma] diff --git a/test/ruleTests/trailing-comma/singleline-always/tslint.json b/test/ruleTests/trailing-comma/singleline-always/tslint.json new file mode 100644 index 00000000000..05767a6a9fc --- /dev/null +++ b/test/ruleTests/trailing-comma/singleline-always/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "trailing-comma": [true, {"singleline": "always"}] + } +} diff --git a/test/ruleTests/trailing-comma/singleline-never/test.ts.linttest b/test/ruleTests/trailing-comma/singleline-never/test.ts.linttest new file mode 100644 index 00000000000..503cfdd2bd3 --- /dev/null +++ b/test/ruleTests/trailing-comma/singleline-never/test.ts.linttest @@ -0,0 +1,94 @@ +var v = [{ + a: 1, + b: 2, + d: 34, + c: (a + b), +},]; + +var x = [{ + a: 1, + b: 2, + d: 34, + c: (a + b) +}]; + +var y = { + yA: 42, + yB: 24, +}; + +var z = { + zOne: 2, + zTwo: 1 +}; + +var yy = [ + 42, + 24, +]; + +var zz = [ + 2, + 1 +]; + +var a = [{a: 1, b: 2, d: 34, c: (a + b),},]; + ~ [trailing comma] + ~ [trailing comma] + +var b = [{a: 1, b: 2, d: 34, c: (a + b)}]; + +var c = {cA: 42, cB: 24,}; + ~ [trailing comma] + +var d = {dOne: 2, dTwo: 1}; + +var cc = [42, 24,]; + ~ [trailing comma] + +var dd = [2, 1]; + +var { + yA, + yB, +} = y; + +var { + zOne, + zTwo +} = z; + +var [ + yyA, + yyB, +] = yy; + +var [ + zzOne, + zzTwo +] = zz; + +var {cA, cB,} = c; + ~ [trailing comma] + +var {dOne, dTwo} = d; + +var [ccA, ccB,] = cc; + ~ [trailing comma] + +var [ddOne, ddTwo] = dd; + +import { + ClassV, + ClassX, +} from "module"; + +import { + ClassY, + ClassZ +} from "module"; + +import {ClassA, ClassB,} from "module"; + ~ [trailing comma] + +import {ClassC, ClassD} from "module"; diff --git a/test/ruleTests/trailing-comma/singleline-never/tslint.json b/test/ruleTests/trailing-comma/singleline-never/tslint.json new file mode 100644 index 00000000000..9cf46fd84b6 --- /dev/null +++ b/test/ruleTests/trailing-comma/singleline-never/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "trailing-comma": [true, {"singleline": "never"}] + } +} diff --git a/test/files/rules/eqeqeq.test.ts b/test/ruleTests/triple-equals/test.ts.linttest similarity index 69% rename from test/files/rules/eqeqeq.test.ts rename to test/ruleTests/triple-equals/test.ts.linttest index 360704a54b6..6c803a52465 100644 --- a/test/files/rules/eqeqeq.test.ts +++ b/test/ruleTests/triple-equals/test.ts.linttest @@ -2,10 +2,12 @@ var testVariable = 123; function testFunction() { if (x === testFunction && y == 4) { + ~~ [== should be ===] console.log("called"); } var z = (x + 3) != 5; + ~~ [!= should be !==] return; } diff --git a/test/ruleTests/triple-equals/tslint.json b/test/ruleTests/triple-equals/tslint.json new file mode 100644 index 00000000000..b60bf169ef6 --- /dev/null +++ b/test/ruleTests/triple-equals/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "triple-equals": [true, "allow-null-check"] + } +} diff --git a/test/ruleTests/typedef/all/test.ts.linttest b/test/ruleTests/typedef/all/test.ts.linttest new file mode 100644 index 00000000000..f80fb138778 --- /dev/null +++ b/test/ruleTests/typedef/all/test.ts.linttest @@ -0,0 +1,42 @@ +var NoTypeObjectLiteralWithPropertyGetter = { + ~ [expected variable-declaration: 'NoTypeObjectLiteralWithPropertyGetter' to have a typedef] + Prop: "some property", + + get PropDef() { + ~ [expected call-signature: 'PropDef' to have a typedef] + return this.Prop; + }, + + methodDef() { + ~ [expected call-signature: 'methodDef' to have a typedef] + return 'untyped'; + }, + + anotherMethodDef: function() { + ~ [expected call-signature to have a typedef] + return 'also untyped'; + }, + + arrowMethodDef: () => { + ~ [expected call-signature to have a typedef] + return 'also untyped'; + } +}; + +interface NoTypeInterface { + Prop; + ~ [expected property-declaration: 'Prop' to have a typedef] + PropWithType: string; +} + +var NoTypesFn = function ( + ~ [expected variable-declaration: 'NoTypesFn' to have a typedef] + a, + ~ [expected parameter: 'a' to have a typedef] + b) { + ~ [expected call-signature to have a typedef] + ~ [expected parameter: 'b' to have a typedef] + var c = a + b, + ~ [expected variable-declaration: 'c' to have a typedef] + d = a - b; + ~ [expected variable-declaration: 'd' to have a typedef] diff --git a/test/ruleTests/typedef/all/tslint.json b/test/ruleTests/typedef/all/tslint.json new file mode 100644 index 00000000000..779e4eb4197 --- /dev/null +++ b/test/ruleTests/typedef/all/tslint.json @@ -0,0 +1,11 @@ +{ + "rules": { + "typedef": [true, + "call-signature", + "parameter", + "variable-declaration", + "property-declaration", + "member-variable-declaration" + ] + } +} diff --git a/test/files/rules/typedef.test.ts b/test/ruleTests/typedef/none/test.ts.linttest similarity index 100% rename from test/files/rules/typedef.test.ts rename to test/ruleTests/typedef/none/test.ts.linttest diff --git a/test/ruleTests/typedef/none/tslint.json b/test/ruleTests/typedef/none/tslint.json new file mode 100644 index 00000000000..08b740b4692 --- /dev/null +++ b/test/ruleTests/typedef/none/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "typedef": true + } +} diff --git a/test/rules/switchDefaultRuleTests.ts b/test/rules/switchDefaultRuleTests.ts deleted file mode 100644 index 6a34a9c3351..00000000000 --- a/test/rules/switchDefaultRuleTests.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2015 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 {TestUtils} from "../lint"; - -describe("", () => { - const SwitchDefaultRule = TestUtils.getRule("switch-default"); - const fileName = "rules/switchdefault.test.ts"; - const failureString = SwitchDefaultRule.FAILURE_STRING; - - it("Switch default", () => { - const failure = TestUtils.createFailuresOnFile(fileName, failureString); - const expectedFailures = [ - failure([2, 1], [6, 2]), - failure([8, 1], [18, 2]) - ]; - const actualFailures = TestUtils.applyRuleOnFile(fileName, SwitchDefaultRule); - TestUtils.assertFailuresEqual(actualFailures, expectedFailures); - }); -}); diff --git a/test/rules/trailingCommaRuleTests.ts b/test/rules/trailingCommaRuleTests.ts deleted file mode 100644 index e7022fa6806..00000000000 --- a/test/rules/trailingCommaRuleTests.ts +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - const TrailingCommaRule = TestUtils.getRule("trailing-comma"); - const fileName = "rules/trailingcomma.test.ts"; - - describe("multiline", () => { - it("restricts the use of trailing commas if set to never", () => { - const options = [true, {multiline: "never"}]; - - const expectedFailure1 = TestUtils.createFailure(fileName, [6, 2], [6, 3], TrailingCommaRule.FAILURE_STRING_NEVER); - const expectedFailure2 = TestUtils.createFailure(fileName, [5, 15], [5, 16], TrailingCommaRule.FAILURE_STRING_NEVER); - const expectedFailure3 = TestUtils.createFailure(fileName, [17, 11], [17, 12], TrailingCommaRule.FAILURE_STRING_NEVER); - const expectedFailure4 = TestUtils.createFailure(fileName, [27, 7], [27, 8], TrailingCommaRule.FAILURE_STRING_NEVER); - const expectedFailure5 = TestUtils.createFailure(fileName, [49, 7], [49, 8], TrailingCommaRule.FAILURE_STRING_NEVER); - const expectedFailure6 = TestUtils.createFailure(fileName, [59, 8], [59, 9], TrailingCommaRule.FAILURE_STRING_NEVER); - const expectedFailure7 = TestUtils.createFailure(fileName, [77, 11], [77, 12], TrailingCommaRule.FAILURE_STRING_NEVER); - const actualFailures = TestUtils.applyRuleOnFile(fileName, TrailingCommaRule, options); - - TestUtils.assertFailuresEqual(actualFailures, [ - expectedFailure1, - expectedFailure2, - expectedFailure3, - expectedFailure4, - expectedFailure5, - expectedFailure6, - expectedFailure7 - ]); - }); - - it("enforces the use of trailing commas if set to always", () => { - const options = [true, {multiline: "always"}]; - - const expectedFailure1 = TestUtils.createFailure(fileName, [13, 2], [13, 3], TrailingCommaRule.FAILURE_STRING_ALWAYS); - const expectedFailure2 = TestUtils.createFailure(fileName, [12, 15], [13, 1], TrailingCommaRule.FAILURE_STRING_ALWAYS); - const expectedFailure3 = TestUtils.createFailure(fileName, [22, 12], [23, 1], TrailingCommaRule.FAILURE_STRING_ALWAYS); - const expectedFailure4 = TestUtils.createFailure(fileName, [32, 6], [33, 1], TrailingCommaRule.FAILURE_STRING_ALWAYS); - const expectedFailure5 = TestUtils.createFailure(fileName, [54, 9], [55, 1], TrailingCommaRule.FAILURE_STRING_ALWAYS); - const expectedFailure6 = TestUtils.createFailure(fileName, [64, 10], [65, 1], TrailingCommaRule.FAILURE_STRING_ALWAYS); - const expectedFailure7 = TestUtils.createFailure(fileName, [82, 11], [83, 1], TrailingCommaRule.FAILURE_STRING_ALWAYS); - const actualFailures = TestUtils.applyRuleOnFile(fileName, TrailingCommaRule, options); - - TestUtils.assertFailuresEqual(actualFailures, [ - expectedFailure1, - expectedFailure2, - expectedFailure3, - expectedFailure4, - expectedFailure5, - expectedFailure6, - expectedFailure7 - ]); - }); - }); - - describe("singleline", () => { - it("restricts the use of trailing commas if set to never", () => { - const options = [true, {singleline: "never"}]; - - const expectedFailure1 = TestUtils.createFailure(fileName, [35, 42], [35, 43], TrailingCommaRule.FAILURE_STRING_NEVER); - const expectedFailure2 = TestUtils.createFailure(fileName, [35, 40], [35, 41], TrailingCommaRule.FAILURE_STRING_NEVER); - const expectedFailure3 = TestUtils.createFailure(fileName, [39, 24], [39, 25], TrailingCommaRule.FAILURE_STRING_NEVER); - const expectedFailure4 = TestUtils.createFailure(fileName, [43, 17], [43, 18], TrailingCommaRule.FAILURE_STRING_NEVER); - const expectedFailure5 = TestUtils.createFailure(fileName, [67, 12], [67, 13], TrailingCommaRule.FAILURE_STRING_NEVER); - const expectedFailure6 = TestUtils.createFailure(fileName, [71, 14], [71, 15], TrailingCommaRule.FAILURE_STRING_NEVER); - const expectedFailure7 = TestUtils.createFailure(fileName, [85, 23], [85, 24], TrailingCommaRule.FAILURE_STRING_NEVER); - const actualFailures = TestUtils.applyRuleOnFile(fileName, TrailingCommaRule, options); - - TestUtils.assertFailuresEqual(actualFailures, [ - expectedFailure1, - expectedFailure2, - expectedFailure3, - expectedFailure4, - expectedFailure5, - expectedFailure6, - expectedFailure7 - ]); - }); - - it("enforces the use of trailing commas in if set to always", () => { - const options = [true, {singleline: "always"}]; - - const expectedFailure1 = TestUtils.createFailure(fileName, [37, 41], [37, 42], TrailingCommaRule.FAILURE_STRING_ALWAYS); - const expectedFailure2 = TestUtils.createFailure(fileName, [37, 40], [37, 41], TrailingCommaRule.FAILURE_STRING_ALWAYS); - const expectedFailure3 = TestUtils.createFailure(fileName, [41, 26], [41, 27], TrailingCommaRule.FAILURE_STRING_ALWAYS); - const expectedFailure4 = TestUtils.createFailure(fileName, [45, 15], [45, 16], TrailingCommaRule.FAILURE_STRING_ALWAYS); - const expectedFailure5 = TestUtils.createFailure(fileName, [69, 16], [69, 17], TrailingCommaRule.FAILURE_STRING_ALWAYS); - const expectedFailure6 = TestUtils.createFailure(fileName, [73, 18], [73, 19], TrailingCommaRule.FAILURE_STRING_ALWAYS); - const expectedFailure7 = TestUtils.createFailure(fileName, [87, 23], [87, 24], TrailingCommaRule.FAILURE_STRING_ALWAYS); - const actualFailures = TestUtils.applyRuleOnFile(fileName, TrailingCommaRule, options); - - TestUtils.assertFailuresEqual(actualFailures, [ - expectedFailure1, - expectedFailure2, - expectedFailure3, - expectedFailure4, - expectedFailure5, - expectedFailure6, - expectedFailure7 - ]); - }); - }); -}); diff --git a/test/rules/tripleEqualsRuleTests.ts b/test/rules/tripleEqualsRuleTests.ts deleted file mode 100644 index 06400bc5691..00000000000 --- a/test/rules/tripleEqualsRuleTests.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {RuleFailure, TestUtils} from "../lint"; - -describe("", () => { - const fileName = "rules/eqeqeq.test.ts"; - const TripleEqualsRule = TestUtils.getRule("triple-equals"); - let actualFailures: RuleFailure[]; - - before(() => { - actualFailures = TestUtils.applyRuleOnFile(fileName, TripleEqualsRule, [true, "allow-null-check"]); - assert.equal(actualFailures.length, 2); - }); - - it("ensures ===", () => { - const failureString = TripleEqualsRule.EQ_FAILURE_STRING; - const expectedFailure = TestUtils.createFailure(fileName, [4, 33], [4, 35], failureString); - - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("ensures !==", () => { - const failureString = TripleEqualsRule.NEQ_FAILURE_STRING; - const expectedFailure = TestUtils.createFailure(fileName, [8, 21], [8, 23], failureString); - - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); -}); diff --git a/test/rules/typedefRuleTests.ts b/test/rules/typedefRuleTests.ts deleted file mode 100644 index 195ef3fe453..00000000000 --- a/test/rules/typedefRuleTests.ts +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {RuleFailure, TestUtils} from "../lint"; - -describe("", () => { - const fileName = "rules/typedef.test.ts"; - const TypedefRule = TestUtils.getRule("typedef"); - - it("enforces rules only when enabled (unspecified)", () => { - const failures = TestUtils.applyRuleOnFile(fileName, TypedefRule); - assert.equal(failures.length, 0); - }); - - it("enforces rules only when enabled (disabled)", () => { - const options = [false]; - const failures = TestUtils.applyRuleOnFile(fileName, TypedefRule, options); - assert.equal(failures.length, 0); - }); -}); - -describe("", () => { - const fileName = "rules/typedef.test.ts"; - const TypedefRule = TestUtils.getRule("typedef"); - let actualFailures: RuleFailure[]; - - function assertFailures(...failures: RuleFailure[]) { - failures.forEach((failure) => { - TestUtils.assertContainsFailure(actualFailures, failure); - actualFailures = actualFailures.filter((actualFailure) => !actualFailure.equals(failure)); - }); - } - - before(() => { - const options = [true, - "call-signature", - "parameter", - "variable-declaration", - "property-declaration", - "member-variable-declaration" - ]; - actualFailures = TestUtils.applyRuleOnFile(fileName, TypedefRule, options); - }); - - it("enforces typedef in call signatures", () => { - const expectedFailure1 = TestUtils.createFailure(fileName, - [28, 6], - [28, 7], - "expected call-signature to have a typedef"); - const expectedFailure2 = TestUtils.createFailure(fileName, - [4, 17], - [4, 18], - "expected call-signature: 'PropDef' to have a typedef"); - const expectedFailure3 = TestUtils.createFailure(fileName, - [38, 21], - [38, 22], - "expected call-signature: 'name' to have a typedef"); - const expectedFailure4 = TestUtils.createFailure(fileName, - [53, 31], - [53, 32], - "expected call-signature: 'anotherNoTypesFn' to have a typedef"); - const expectedFailure5 = TestUtils.createFailure(fileName, - [8, 15], - [8, 16], - "expected call-signature: 'methodDef' to have a typedef"); - const expectedFailure6 = TestUtils.createFailure(fileName, - [12, 32], - [12, 33], - "expected call-signature to have a typedef"); - const expectedFailure7 = TestUtils.createFailure(fileName, - [16, 22], - [16, 23], - "expected call-signature to have a typedef"); - const expectedFailure8 = TestUtils.createFailure(fileName, - [42, 21], - [42, 22], - "expected call-signature: 'unTyped' to have a typedef"); - - assertFailures(expectedFailure1, expectedFailure2, expectedFailure3, expectedFailure4, - expectedFailure5, expectedFailure6, expectedFailure7, expectedFailure8); - }); - - it("enforces typedef in parameter", () => { - const expectedFailure1 = TestUtils.createFailure(fileName, - [27, 6], - [27, 7], - "expected parameter: 'a' to have a typedef"); - const expectedFailure2 = TestUtils.createFailure(fileName, - [28, 6], - [28, 7], - "expected parameter: 'b' to have a typedef"); - const expectedFailure3 = TestUtils.createFailure(fileName, - [48, 21], - [48, 22], - "expected parameter: 'type' to have a typedef"); - const expectedFailure4 = TestUtils.createFailure(fileName, - [53, 28], - [53, 29], - "expected parameter: 'a' to have a typedef"); - const expectedFailure5 = TestUtils.createFailure(fileName, - [53, 31], - [53, 32], - "expected parameter: 'b' to have a typedef"); - const expectedFailure6 = TestUtils.createFailure(fileName, - [61, 29], - [61, 30], - "expected parameter: 'n' to have a typedef"); - - assertFailures(expectedFailure1, expectedFailure2, expectedFailure3, expectedFailure4, expectedFailure5, expectedFailure6); - }); - - it("enforces typedef in property declaration", () => { - const expectedFailure = TestUtils.createFailure(fileName, - [22, 9], - [22, 10], - "expected property-declaration: 'Prop' to have a typedef"); - - assertFailures(expectedFailure); - }); - - it("enforces typedef in variable declaration", () => { - const expectedFailure1 = TestUtils.createFailure(fileName, - [1, 42], - [1, 43], - "expected variable-declaration: 'NoTypeObjectLiteralWithPropertyGetter' to have a typedef"); - const expectedFailure2 = TestUtils.createFailure(fileName, - [26, 14], - [26, 15], - "expected variable-declaration: 'NoTypesFn' to have a typedef"); - const expectedFailure3 = TestUtils.createFailure(fileName, - [29, 10], - [29, 11], - "expected variable-declaration: 'c' to have a typedef"); - const expectedFailure4 = TestUtils.createFailure(fileName, - [30, 10], - [30, 11], - "expected variable-declaration: 'd' to have a typedef"); - - assertFailures(expectedFailure1, expectedFailure2, expectedFailure3, expectedFailure4); - }); - - it("enforces typedef in member variable declaration", () => { - const expectedFailure = TestUtils.createFailure(fileName, - [36, 11], - [36, 12], - "expected member-variable-declaration: 'Member' to have a typedef"); - - assertFailures(expectedFailure); - }); - - it("only has the expected failures", function() { - if (actualFailures.length > 0) { - assert(false, "got " + actualFailures.length + " extra errors"); - } - }); -}); diff --git a/test/tsconfig.json b/test/tsconfig.json index 37be4ccb758..eb269d0d6ae 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -129,10 +129,6 @@ "ruleTestRunnerTests/testData.ts", "ruleTestRunnerTests/utilsTests.ts", "rules/eofLineRuleTests.ts", - "rules/switchDefaultRuleTests.ts", - "rules/trailingCommaRuleTests.ts", - "rules/tripleEqualsRuleTests.ts", - "rules/typedefRuleTests.ts", "rules/typedefWhitespaceRuleTests.ts", "rules/useStrictRuleTests.ts", "rules/variableNameRuleTests.ts", From 35b9426d45e5f24b658f1036bc49c27a321395e4 Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Thu, 24 Dec 2015 01:32:48 -0500 Subject: [PATCH 21/30] Finish converting tests - yay --- test/files/rules/varname-keywords.test.ts | 17 -- test/files/rules/varname.test.ts | 35 ---- .../typedef-whitespace/none/test.ts.linttest} | 0 .../typedef-whitespace/none/tslint.json | 5 + .../nospace/test.ts.linttest | 77 ++++++++ .../typedef-whitespace/nospace/tslint.json | 11 ++ .../typedef-whitespace/space/test.ts.linttest | 77 ++++++++ .../typedef-whitespace/space/tslint.json | 11 ++ .../use-strict/test.ts.linttest} | 5 +- test/ruleTests/use-strict/tslint.json | 5 + .../test.ts.linttest | 47 +++++ .../tslint.json | 5 + .../allow-leading-underscore/test.ts.linttest | 49 +++++ .../allow-leading-underscore/tslint.json | 5 + .../test.ts.linttest | 49 +++++ .../allow-trailing-underscore/tslint.json | 5 + .../ban-keywords/test.ts.linttest | 21 +++ .../variable-name/ban-keywords/tslint.json | 5 + .../variable-name/default/test.ts.linttest | 50 ++++++ .../variable-name/default/tslint.json | 5 + .../ruleTests/whitespace/all/test.ts.linttest | 110 ++++++++++++ test/ruleTests/whitespace/all/tslint.json | 13 ++ .../whitespace/none/test.ts.linttest} | 0 test/ruleTests/whitespace/none/tslint.json | 5 + test/rules/typedefWhitespaceRuleTests.ts | 147 --------------- test/rules/useStrictRuleTests.ts | 44 ----- test/rules/variableNameRuleTests.ts | 113 ------------ test/rules/whitespaceRuleTests.ts | 169 ------------------ test/tsconfig.json | 4 - 29 files changed, 559 insertions(+), 530 deletions(-) delete mode 100644 test/files/rules/varname-keywords.test.ts delete mode 100644 test/files/rules/varname.test.ts rename test/{files/rules/typedefWhitespace.test.ts => ruleTests/typedef-whitespace/none/test.ts.linttest} (100%) create mode 100644 test/ruleTests/typedef-whitespace/none/tslint.json create mode 100644 test/ruleTests/typedef-whitespace/nospace/test.ts.linttest create mode 100644 test/ruleTests/typedef-whitespace/nospace/tslint.json create mode 100644 test/ruleTests/typedef-whitespace/space/test.ts.linttest create mode 100644 test/ruleTests/typedef-whitespace/space/tslint.json rename test/{files/rules/usestrict.test.ts => ruleTests/use-strict/test.ts.linttest} (82%) create mode 100644 test/ruleTests/use-strict/tslint.json create mode 100644 test/ruleTests/variable-name/allow-leading-trailing-underscore/test.ts.linttest create mode 100644 test/ruleTests/variable-name/allow-leading-trailing-underscore/tslint.json create mode 100644 test/ruleTests/variable-name/allow-leading-underscore/test.ts.linttest create mode 100644 test/ruleTests/variable-name/allow-leading-underscore/tslint.json create mode 100644 test/ruleTests/variable-name/allow-trailing-underscore/test.ts.linttest create mode 100644 test/ruleTests/variable-name/allow-trailing-underscore/tslint.json create mode 100644 test/ruleTests/variable-name/ban-keywords/test.ts.linttest create mode 100644 test/ruleTests/variable-name/ban-keywords/tslint.json create mode 100644 test/ruleTests/variable-name/default/test.ts.linttest create mode 100644 test/ruleTests/variable-name/default/tslint.json create mode 100644 test/ruleTests/whitespace/all/test.ts.linttest create mode 100644 test/ruleTests/whitespace/all/tslint.json rename test/{files/rules/whitespace.test.ts => ruleTests/whitespace/none/test.ts.linttest} (100%) create mode 100644 test/ruleTests/whitespace/none/tslint.json delete mode 100644 test/rules/typedefWhitespaceRuleTests.ts delete mode 100644 test/rules/useStrictRuleTests.ts delete mode 100644 test/rules/variableNameRuleTests.ts delete mode 100644 test/rules/whitespaceRuleTests.ts diff --git a/test/files/rules/varname-keywords.test.ts b/test/files/rules/varname-keywords.test.ts deleted file mode 100644 index 654201c2046..00000000000 --- a/test/files/rules/varname-keywords.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -let undefined = 8; -let boolean: boolean; -function bad(any: any) { } -let [number] = [3]; -let {String} = {String: 1}; - -// good: -let foo = 2; -let bar: any; -function good(baz: any) { } -let [faz] = [5]; -const {pom} = {pom: 5}; - -interface Wob { - number: string; -} - diff --git a/test/files/rules/varname.test.ts b/test/files/rules/varname.test.ts deleted file mode 100644 index a7dc617d0ed..00000000000 --- a/test/files/rules/varname.test.ts +++ /dev/null @@ -1,35 +0,0 @@ -var validName1 = "hi"; -var VALIDNAME2 = "there"; -var InvalidName1 = ","; // failure -var invalid_name2 = " "; // failure - -class Test { - private Invalid_name3 = "how"; // failure - private _optionallyValid = "are"; // sometimes a failure -} - -function test() { - () => { - var InVaLiDnAmE4 = "you"; // failure - }; -} - -declare var DeclaresAreValid: any; - -export function functionWithInvalidParamNames (bad_name, AnotherOne) { // 2 failures - // -} - -let { foo, bar } = { foo: 1, bar: 2 }; -let [ InvalidFoo, invalid_bar, ...invalid_baz ] = [1, 2, 3, 4]; // 3 failures - -export function anotherFunctionWithInvalidParamNames ([first_element, SecondElement]) { // 2 failures - // -} - -export function functionWithInvalidSpread(invalid_arg: ...number) { // 1 failure - // -} - -let optionallyValid_ = "bar"; -let _$httpBackend_ = "leading and trailing"; \ No newline at end of file diff --git a/test/files/rules/typedefWhitespace.test.ts b/test/ruleTests/typedef-whitespace/none/test.ts.linttest similarity index 100% rename from test/files/rules/typedefWhitespace.test.ts rename to test/ruleTests/typedef-whitespace/none/test.ts.linttest diff --git a/test/ruleTests/typedef-whitespace/none/tslint.json b/test/ruleTests/typedef-whitespace/none/tslint.json new file mode 100644 index 00000000000..09c46892473 --- /dev/null +++ b/test/ruleTests/typedef-whitespace/none/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "typedef-whitespace": true + } +} diff --git a/test/ruleTests/typedef-whitespace/nospace/test.ts.linttest b/test/ruleTests/typedef-whitespace/nospace/test.ts.linttest new file mode 100644 index 00000000000..d15786b5dd6 --- /dev/null +++ b/test/ruleTests/typedef-whitespace/nospace/test.ts.linttest @@ -0,0 +1,77 @@ +var noPreceedingSpaceObjectLiteralWithPropertyGetter = { + _Prop: "some property", + + get Prop(): string { + return this._Prop; + } +}; + +var withPreceedingSpaceObjectLiteralWithPropertyGetter = { + _Prop: "some property", + + get Prop() : string { + ~ [expected nospace in call-signature] + return this._Prop; + } +}; + +interface NoPreceedingSpaceInterface { + Prop: string; +} + +interface WithPreceedingSpaceInterface { + Prop : string; + ~ [expected nospace in property-declaration] +} + +var noPreceedingSpacesFn = function (a: number, b: number): number { + var c: number = a + b; + var d: number = a - b; + + try { + return c / d; + } catch (ex: Exception) { + console.log(ex); + } +}; + +var withPreceedingSpacesFn = function (a : number, b : number) : number { + ~ [expected nospace in parameter] + ~ [expected nospace in parameter] + ~ [expected nospace in call-signature] + var c : number = a + b; + ~ [expected nospace in variable-declaration] + var d : number = a - b; + ~ [expected nospace in variable-declaration] + + try { + return c / d; + } catch (ex : Exception) { + ~ [expected nospace in variable-declaration] + console.log(ex); + } +}; + +class NoPreceedingSpacesClass { + [index: number]: string + + Prop: string = "some property"; + + public get name(): string { + return "some name"; + } +} + +class WithPreceedingSpacesClass { + [index : number] : string + ~ [expected nospace in index-signature] + ~ [expected nospace in parameter] + + Prop : string = "some property"; + ~ [expected nospace in property-declaration] + + public get name() : string { + ~ [expected nospace in call-signature] + return "some name"; + } +} diff --git a/test/ruleTests/typedef-whitespace/nospace/tslint.json b/test/ruleTests/typedef-whitespace/nospace/tslint.json new file mode 100644 index 00000000000..96ded7b8822 --- /dev/null +++ b/test/ruleTests/typedef-whitespace/nospace/tslint.json @@ -0,0 +1,11 @@ +{ + "rules": { + "typedef-whitespace": [true, { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + }] + } +} \ No newline at end of file diff --git a/test/ruleTests/typedef-whitespace/space/test.ts.linttest b/test/ruleTests/typedef-whitespace/space/test.ts.linttest new file mode 100644 index 00000000000..5b9f60e97ee --- /dev/null +++ b/test/ruleTests/typedef-whitespace/space/test.ts.linttest @@ -0,0 +1,77 @@ +var noPreceedingSpaceObjectLiteralWithPropertyGetter = { + _Prop: "some property", + + get Prop(): string { + ~ [expected space in call-signature] + return this._Prop; + } +}; + +var withPreceedingSpaceObjectLiteralWithPropertyGetter = { + _Prop: "some property", + + get Prop() : string { + return this._Prop; + } +}; + +interface NoPreceedingSpaceInterface { + Prop: string; + ~ [expected space in property-declaration] +} + +interface WithPreceedingSpaceInterface { + Prop : string; +} + +var noPreceedingSpacesFn = function (a: number, b: number): number { + ~ [expected space in parameter] + ~ [expected space in parameter] + ~ [expected space in call-signature] + var c: number = a + b; + ~ [expected space in variable-declaration] + var d: number = a - b; + ~ [expected space in variable-declaration] + + try { + return c / d; + } catch (ex: Exception) { + ~ [expected space in variable-declaration] + console.log(ex); + } +}; + +var withPreceedingSpacesFn = function (a : number, b : number) : number { + var c : number = a + b; + var d : number = a - b; + + try { + return c / d; + } catch (ex : Exception) { + console.log(ex); + } +}; + +class NoPreceedingSpacesClass { + [index: number]: string + ~ [expected space in index-signature] + ~ [expected space in parameter] + + Prop: string = "some property"; + ~ [expected space in property-declaration] + + public get name(): string { + ~ [expected space in call-signature] + return "some name"; + } +} + +class WithPreceedingSpacesClass { + [index : number] : string + + Prop : string = "some property"; + + public get name() : string { + return "some name"; + } +} diff --git a/test/ruleTests/typedef-whitespace/space/tslint.json b/test/ruleTests/typedef-whitespace/space/tslint.json new file mode 100644 index 00000000000..02fe6996115 --- /dev/null +++ b/test/ruleTests/typedef-whitespace/space/tslint.json @@ -0,0 +1,11 @@ +{ + "rules": { + "typedef-whitespace": [true, { + "call-signature": "space", + "index-signature": "space", + "parameter": "space", + "property-declaration": "space", + "variable-declaration": "space" + }] + } +} diff --git a/test/files/rules/usestrict.test.ts b/test/ruleTests/use-strict/test.ts.linttest similarity index 82% rename from test/files/rules/usestrict.test.ts rename to test/ruleTests/use-strict/test.ts.linttest index f562f492399..e80f0664713 100644 --- a/test/files/rules/usestrict.test.ts +++ b/test/ruleTests/use-strict/test.ts.linttest @@ -12,6 +12,7 @@ function testSingleQuotes() { } function testNoUseStrict() { +~~~~~~~~ [missing 'use strict'] } module TestModule { @@ -22,11 +23,13 @@ module TestModule { } module TestNoUseStrictModule { +~~~~~~ [missing 'use strict'] // hello var i = 3; } module TestNoUseStrictModule.Namespaced.AndAgain { +~~~~~~ [missing 'use strict'] // hello var i = 3; } @@ -56,4 +59,4 @@ declare module foo { function shouldPassUseStrictRule(): string { "use strict" return "This is a test" -} \ No newline at end of file +} diff --git a/test/ruleTests/use-strict/tslint.json b/test/ruleTests/use-strict/tslint.json new file mode 100644 index 00000000000..3784cf991b7 --- /dev/null +++ b/test/ruleTests/use-strict/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "use-strict": [true, "check-function", "check-module"] + } +} diff --git a/test/ruleTests/variable-name/allow-leading-trailing-underscore/test.ts.linttest b/test/ruleTests/variable-name/allow-leading-trailing-underscore/test.ts.linttest new file mode 100644 index 00000000000..88465c22c19 --- /dev/null +++ b/test/ruleTests/variable-name/allow-leading-trailing-underscore/test.ts.linttest @@ -0,0 +1,47 @@ +var validName1 = "hi"; +var VALIDNAME2 = "there"; +var InvalidName1 = ","; // failure + ~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] +var invalid_name2 = " "; // failure + ~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + +class Test { + private Invalid_name3 = "how"; // failure + ~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + private _optionallyValid = "are"; // sometimes a failure +} + +function test() { + () => { + var InVaLiDnAmE4 = "you"; // failure + ~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + }; +} + +declare var DeclaresAreValid: any; + +export function functionWithInvalidParamNames (bad_name, AnotherOne) { // 2 failures + ~~~~~~~~ [variable name must be in camelcase or uppercase] + ~~~~~~~~~~ [variable name must be in camelcase or uppercase] + // +} + +let { foo, bar } = { foo: 1, bar: 2 }; +let [ InvalidFoo, invalid_bar, ...invalid_baz ] = [1, 2, 3, 4]; // 3 failures + ~~~~~~~~~~ [variable name must be in camelcase or uppercase] + ~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + ~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + +export function anotherFunctionWithInvalidParamNames ([first_element, SecondElement]) { // 2 failures + ~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + ~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + // +} + +export function functionWithInvalidSpread(invalid_arg: ...number) { // 1 failure + ~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + // +} + +let optionallyValid_ = "bar"; +let _$httpBackend_ = "leading and trailing"; diff --git a/test/ruleTests/variable-name/allow-leading-trailing-underscore/tslint.json b/test/ruleTests/variable-name/allow-leading-trailing-underscore/tslint.json new file mode 100644 index 00000000000..c5d657add43 --- /dev/null +++ b/test/ruleTests/variable-name/allow-leading-trailing-underscore/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "variable-name": [true, "allow-leading-underscore", "allow-trailing-underscore"] + } +} diff --git a/test/ruleTests/variable-name/allow-leading-underscore/test.ts.linttest b/test/ruleTests/variable-name/allow-leading-underscore/test.ts.linttest new file mode 100644 index 00000000000..8d17177ce8e --- /dev/null +++ b/test/ruleTests/variable-name/allow-leading-underscore/test.ts.linttest @@ -0,0 +1,49 @@ +var validName1 = "hi"; +var VALIDNAME2 = "there"; +var InvalidName1 = ","; // failure + ~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] +var invalid_name2 = " "; // failure + ~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + +class Test { + private Invalid_name3 = "how"; // failure + ~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + private _optionallyValid = "are"; // sometimes a failure +} + +function test() { + () => { + var InVaLiDnAmE4 = "you"; // failure + ~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + }; +} + +declare var DeclaresAreValid: any; + +export function functionWithInvalidParamNames (bad_name, AnotherOne) { // 2 failures + ~~~~~~~~ [variable name must be in camelcase or uppercase] + ~~~~~~~~~~ [variable name must be in camelcase or uppercase] + // +} + +let { foo, bar } = { foo: 1, bar: 2 }; +let [ InvalidFoo, invalid_bar, ...invalid_baz ] = [1, 2, 3, 4]; // 3 failures + ~~~~~~~~~~ [variable name must be in camelcase or uppercase] + ~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + ~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + +export function anotherFunctionWithInvalidParamNames ([first_element, SecondElement]) { // 2 failures + ~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + ~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + // +} + +export function functionWithInvalidSpread(invalid_arg: ...number) { // 1 failure + ~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + // +} + +let optionallyValid_ = "bar"; + ~~~~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] +let _$httpBackend_ = "leading and trailing"; + ~~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] diff --git a/test/ruleTests/variable-name/allow-leading-underscore/tslint.json b/test/ruleTests/variable-name/allow-leading-underscore/tslint.json new file mode 100644 index 00000000000..4f9cde74fec --- /dev/null +++ b/test/ruleTests/variable-name/allow-leading-underscore/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "variable-name": [true, "allow-leading-underscore"] + } +} diff --git a/test/ruleTests/variable-name/allow-trailing-underscore/test.ts.linttest b/test/ruleTests/variable-name/allow-trailing-underscore/test.ts.linttest new file mode 100644 index 00000000000..e7ee86cabbb --- /dev/null +++ b/test/ruleTests/variable-name/allow-trailing-underscore/test.ts.linttest @@ -0,0 +1,49 @@ +var validName1 = "hi"; +var VALIDNAME2 = "there"; +var InvalidName1 = ","; // failure + ~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] +var invalid_name2 = " "; // failure + ~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + +class Test { + private Invalid_name3 = "how"; // failure + ~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + private _optionallyValid = "are"; // sometimes a failure + ~~~~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] +} + +function test() { + () => { + var InVaLiDnAmE4 = "you"; // failure + ~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + }; +} + +declare var DeclaresAreValid: any; + +export function functionWithInvalidParamNames (bad_name, AnotherOne) { // 2 failures + ~~~~~~~~ [variable name must be in camelcase or uppercase] + ~~~~~~~~~~ [variable name must be in camelcase or uppercase] + // +} + +let { foo, bar } = { foo: 1, bar: 2 }; +let [ InvalidFoo, invalid_bar, ...invalid_baz ] = [1, 2, 3, 4]; // 3 failures + ~~~~~~~~~~ [variable name must be in camelcase or uppercase] + ~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + ~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + +export function anotherFunctionWithInvalidParamNames ([first_element, SecondElement]) { // 2 failures + ~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + ~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + // +} + +export function functionWithInvalidSpread(invalid_arg: ...number) { // 1 failure + ~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + // +} + +let optionallyValid_ = "bar"; +let _$httpBackend_ = "leading and trailing"; + ~~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] diff --git a/test/ruleTests/variable-name/allow-trailing-underscore/tslint.json b/test/ruleTests/variable-name/allow-trailing-underscore/tslint.json new file mode 100644 index 00000000000..86b02a3ad4f --- /dev/null +++ b/test/ruleTests/variable-name/allow-trailing-underscore/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "variable-name": [true, "allow-trailing-underscore"] + } +} diff --git a/test/ruleTests/variable-name/ban-keywords/test.ts.linttest b/test/ruleTests/variable-name/ban-keywords/test.ts.linttest new file mode 100644 index 00000000000..3bf0f62aa0e --- /dev/null +++ b/test/ruleTests/variable-name/ban-keywords/test.ts.linttest @@ -0,0 +1,21 @@ +let undefined = 8; + ~~~~~~~~~ [variable name clashes with keyword/type] +let boolean: boolean; + ~~~~~~~ [variable name clashes with keyword/type] +function bad(any: any) { } + ~~~ [variable name clashes with keyword/type] +let [number] = [3]; + ~~~~~~ [variable name clashes with keyword/type] +let {String} = {String: 1}; + ~~~~~~ [variable name clashes with keyword/type] + +// good: +let foo = 2; +let bar: any; +function good(baz: any) { } +let [faz] = [5]; +const {pom} = {pom: 5}; + +interface Wob { + number: string; +} diff --git a/test/ruleTests/variable-name/ban-keywords/tslint.json b/test/ruleTests/variable-name/ban-keywords/tslint.json new file mode 100644 index 00000000000..9b5db62cf01 --- /dev/null +++ b/test/ruleTests/variable-name/ban-keywords/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "variable-name": [true, "ban-keywords"] + } +} diff --git a/test/ruleTests/variable-name/default/test.ts.linttest b/test/ruleTests/variable-name/default/test.ts.linttest new file mode 100644 index 00000000000..03d063e88b2 --- /dev/null +++ b/test/ruleTests/variable-name/default/test.ts.linttest @@ -0,0 +1,50 @@ +var validName1 = "hi"; +var VALIDNAME2 = "there"; +var InvalidName1 = ","; // failure + ~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] +var invalid_name2 = " "; // failure + ~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + +class Test { + private Invalid_name3 = "how"; // failure + ~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + private _optionallyValid = "are"; // sometimes a failure + ~~~~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] +} + +function test() { + () => { + var InVaLiDnAmE4 = "you"; // failure + ~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + }; +} + +declare var DeclaresAreValid: any; + +export function functionWithInvalidParamNames (bad_name, AnotherOne) { // 2 failures + ~~~~~~~~ [variable name must be in camelcase or uppercase] + ~~~~~~~~~~ [variable name must be in camelcase or uppercase] + // +} + +let { foo, bar } = { foo: 1, bar: 2 }; +let [ InvalidFoo, invalid_bar, ...invalid_baz ] = [1, 2, 3, 4]; // 3 failures + ~~~~~~~~~~ [variable name must be in camelcase or uppercase] + ~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + ~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + +export function anotherFunctionWithInvalidParamNames ([first_element, SecondElement]) { // 2 failures + ~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + ~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + // +} + +export function functionWithInvalidSpread(invalid_arg: ...number) { // 1 failure + ~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + // +} + +let optionallyValid_ = "bar"; + ~~~~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] +let _$httpBackend_ = "leading and trailing"; + ~~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] diff --git a/test/ruleTests/variable-name/default/tslint.json b/test/ruleTests/variable-name/default/tslint.json new file mode 100644 index 00000000000..4c41fc82fc7 --- /dev/null +++ b/test/ruleTests/variable-name/default/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "variable-name": true + } +} diff --git a/test/ruleTests/whitespace/all/test.ts.linttest b/test/ruleTests/whitespace/all/test.ts.linttest new file mode 100644 index 00000000000..d452b93d54e --- /dev/null +++ b/test/ruleTests/whitespace/all/test.ts.linttest @@ -0,0 +1,110 @@ +import ast=AST; + ~ [missing whitespace] + ~ [missing whitespace] +module M { + export var ast=AST; + ~ [missing whitespace] + ~ [missing whitespace] + + var x:number; + ~ [missing whitespace] + + var y = (x === 10)?1:2; + ~ [missing whitespace] + ~ [missing whitespace] + ~ [missing whitespace] + ~ [missing whitespace] + + var zz = (y===4); + ~ [missing whitespace] + ~ [missing whitespace] + + var z=y; + ~ [missing whitespace] + ~ [missing whitespace] + + var a,b; + ~ [missing whitespace] + + switch(x) { + ~ [missing whitespace] + case 1:break; + ~ [missing whitespace] + default:break; + ~ [missing whitespace] + } + + for(x = 1;x <2; ++x) { + ~ [missing whitespace] + ~ [missing whitespace] + ~ [missing whitespace] + goto:console.log("hi"); + ~ [missing whitespace] + } + + while(i < 1) { + ~ [missing whitespace] + ++i; + } + + var q; + q.forEach(()=>3); + ~ [missing whitespace] + ~ [missing whitespace] + q.forEach(()=>{ + ~ [missing whitespace] + ~ [missing whitespace] + return 3; + }); + + var r: ()=>string; + ~ [missing whitespace] + ~ [missing whitespace] + var s: new ()=>string; + ~ [missing whitespace] + ~ [missing whitespace] + var a = "10"; + ~ [missing whitespace] + var a = "10"; +} + +var a; + +export=a; + ~ [missing whitespace] + ~ [missing whitespace] + +a.then(() => { + return 1; +}).if(() => { + return 1; +}); + +var name = "something"; +var test = ` + +
", () => { - const fileName = "rules/typedefWhitespace.test.ts"; - const TypedefWhitespaceRule = TestUtils.getRule("typedefWhitespace"); - - it("enforces rules only when enabled (unspecified)", () => { - const failures = TestUtils.applyRuleOnFile(fileName, TypedefWhitespaceRule); - assert.equal(failures.length, 0); - }); - - it("enforces rules only when enabled (disabled)", () => { - const options = [false]; - const failures = TestUtils.applyRuleOnFile(fileName, TypedefWhitespaceRule, options); - assert.equal(failures.length, 0); - }); -}); - -describe("", () => { - const fileName = "rules/typedefWhitespace.test.ts"; - const TypedefWhitespaceRule = TestUtils.getRule("typedefWhitespace"); - let actualFailures: RuleFailure[]; - - before(() => { - const options = [true, { - "call-signature": "space", - "index-signature": "space", - "parameter": "space", - "property-declaration": "space", - "variable-declaration": "space" - }]; - actualFailures = TestUtils.applyRuleOnFile(fileName, TypedefWhitespaceRule, options); - }); - - it("enforces whitespace in call signatures", () => { - const expectedFailure1 = TestUtils.createFailure(fileName, [4, 15], [4, 16], "expected space in call-signature"); - const expectedFailure2 = TestUtils.createFailure(fileName, [25, 59], [25, 60], "expected space in call-signature"); - const expectedFailure3 = TestUtils.createFailure(fileName, [52, 22], [52, 23], "expected space in call-signature"); - - TestUtils.assertContainsFailure(actualFailures, expectedFailure1); - TestUtils.assertContainsFailure(actualFailures, expectedFailure2); - TestUtils.assertContainsFailure(actualFailures, expectedFailure3); - }); - - it("enforces whitespace in index signature", () => { - const expectedFailure = TestUtils.createFailure(fileName, [48, 11], [48, 12], "expected space in index-signature"); - - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("enforces whitespace in parameter", () => { - const expectedFailure1 = TestUtils.createFailure(fileName, [25, 39], [25, 40], "expected space in parameter"); - const expectedFailure2 = TestUtils.createFailure(fileName, [25, 50], [25, 51], "expected space in parameter"); - const expectedFailure3 = TestUtils.createFailure(fileName, [48, 11], [48, 12], "expected space in parameter"); - - TestUtils.assertContainsFailure(actualFailures, expectedFailure1); - TestUtils.assertContainsFailure(actualFailures, expectedFailure2); - TestUtils.assertContainsFailure(actualFailures, expectedFailure3); - }); - - it("enforces whitespace in property declaration", () => { - const expectedFailure = TestUtils.createFailure(fileName, [18, 9], [18, 10], "expected space in property-declaration"); - - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("enforces whitespace in variable declarator", () => { - const expectedFailure1 = TestUtils.createFailure(fileName, [26, 10], [26, 11], "expected space in variable-declaration"); - const expectedFailure2 = TestUtils.createFailure(fileName, [27, 10], [27, 11], "expected space in variable-declaration"); - - TestUtils.assertContainsFailure(actualFailures, expectedFailure1); - TestUtils.assertContainsFailure(actualFailures, expectedFailure2); - }); -}); - -describe("", () => { - const fileName = "rules/typedefWhitespace.test.ts"; - const TypedefWhitespaceRule = TestUtils.getRule("typedefWhitespace"); - let actualFailures: RuleFailure[]; - - before(() => { - const options = [true, { - "call-signature": "nospace", - "index-signature": "nospace", - "parameter": "nospace", - "property-declaration": "nospace", - "variable-declaration": "nospace" - }]; - actualFailures = TestUtils.applyRuleOnFile(fileName, TypedefWhitespaceRule, options); - }); - - it("enforces no whitespace in call signatures", () => { - const expectedFailure1 = TestUtils.createFailure(fileName, [12, 15], [12, 16], "expected nospace in call-signature"); - const expectedFailure2 = TestUtils.createFailure(fileName, [36, 63], [36, 64], "expected nospace in call-signature"); - const expectedFailure3 = TestUtils.createFailure(fileName, [62, 22], [62, 23], "expected nospace in call-signature"); - - TestUtils.assertContainsFailure(actualFailures, expectedFailure1); - TestUtils.assertContainsFailure(actualFailures, expectedFailure2); - TestUtils.assertContainsFailure(actualFailures, expectedFailure3); - }); - - it("enforces no whitespace in indexSignature", () => { - const expectedFailure = TestUtils.createFailure(fileName, [58, 11], [58, 12], "expected nospace in index-signature"); - - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("enforces no whitespace in parameter", () => { - const expectedFailure1 = TestUtils.createFailure(fileName, [36, 41], [36, 42], "expected nospace in parameter"); - const expectedFailure2 = TestUtils.createFailure(fileName, [36, 53], [36, 54], "expected nospace in parameter"); - const expectedFailure3 = TestUtils.createFailure(fileName, [58, 11], [58, 12], "expected nospace in parameter"); - - TestUtils.assertContainsFailure(actualFailures, expectedFailure1); - TestUtils.assertContainsFailure(actualFailures, expectedFailure2); - TestUtils.assertContainsFailure(actualFailures, expectedFailure3); - }); - - it("enforces no whitespace in propertySignature", () => { - const expectedFailure = TestUtils.createFailure(fileName, [22, 9], [22, 10], "expected nospace in property-declaration"); - - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("enforces no whitespace in variable declarator", () => { - const expectedFailure1 = TestUtils.createFailure(fileName, [37, 10], [37, 11], "expected nospace in variable-declaration"); - const expectedFailure2 = TestUtils.createFailure(fileName, [38, 10], [38, 11], "expected nospace in variable-declaration"); - - TestUtils.assertContainsFailure(actualFailures, expectedFailure1); - TestUtils.assertContainsFailure(actualFailures, expectedFailure2); - }); -}); diff --git a/test/rules/useStrictRuleTests.ts b/test/rules/useStrictRuleTests.ts deleted file mode 100644 index 55fd2ccdb8e..00000000000 --- a/test/rules/useStrictRuleTests.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {RuleFailure, TestUtils} from "../lint"; - -describe("", () => { - const UseStrictRule = TestUtils.getRule("use-strict"); - const fileName = "rules/usestrict.test.ts"; - let actualFailures: RuleFailure[]; - - before(() => { - const options = [true, "check-function", "check-module"]; - actualFailures = TestUtils.applyRuleOnFile(fileName, UseStrictRule, options); - assert.lengthOf(actualFailures, 3); - }); - - it("enforces checks for 'use strict' in functions", () => { - const expectedFailures = TestUtils.createFailure(fileName, [14, 1], [14, 9], UseStrictRule.FAILURE_STRING); - TestUtils.assertContainsFailure(actualFailures, expectedFailures); - }); - - it("enforces checks for 'use strict' in modules", () => { - const expectedFailures = TestUtils.createFailure(fileName, [24, 1], [24, 7], UseStrictRule.FAILURE_STRING); - TestUtils.assertContainsFailure(actualFailures, expectedFailures); - }); - - it("enforces checks for 'use strict' in module declaration with more than one identifier", () => { - const expectedFailures = TestUtils.createFailure(fileName, [29, 1], [29, 7], UseStrictRule.FAILURE_STRING); - TestUtils.assertContainsFailure(actualFailures, expectedFailures); - }); -}); diff --git a/test/rules/variableNameRuleTests.ts b/test/rules/variableNameRuleTests.ts deleted file mode 100644 index ce0c0181bc3..00000000000 --- a/test/rules/variableNameRuleTests.ts +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {TestUtils} from "../lint"; - -describe("", () => { - const VariableNameRule = TestUtils.getRule("variable-name"); - const failureString = VariableNameRule.FORMAT_FAILURE; - const fileName = "rules/varname.test.ts"; - const createFailure = TestUtils.createFailuresOnFile(fileName, failureString); - - it("ensures only (camel/upper)case naming convention for variables & parameters", () => { - const expectedFailures = [ - createFailure([3, 5], [3, 17]), - createFailure([4, 5], [4, 18]), - createFailure([7, 13], [7, 26]), - createFailure([8, 13], [8, 29]), - createFailure([13, 13], [13, 25]), - createFailure([19, 48], [19, 56]), - createFailure([19, 58], [19, 68]), - createFailure([24, 7], [24, 17]), - createFailure([24, 19], [24, 30]), - createFailure([24, 35], [24, 46]), - createFailure([26, 56], [26, 69]), - createFailure([26, 71], [26, 84]), - createFailure([30, 43], [30, 54]), - createFailure([34, 5], [34, 21]), - createFailure([35, 5], [35, 19]) - ]; - - const actualFailures = TestUtils.applyRuleOnFile(fileName, VariableNameRule); - TestUtils.assertFailuresEqual(actualFailures, expectedFailures); - }); - - it("ensures leading underscores can optionally be legal", () => { - const options = [true, - "allow-leading-underscore" - ]; - - const actualFailures = TestUtils.applyRuleOnFile(fileName, VariableNameRule, options); - const optionallyValidFailures = [ - createFailure([8, 13], [8, 29]) - ]; - - // none of the optionally valid names should appear in the failures list - assert.isFalse(actualFailures.some((failure) => { - return optionallyValidFailures.some((f) => f.equals(failure)); - })); - }); - - it("ensures trailing underscores can optionally be legal", () => { - const options = [true, - "allow-trailing-underscore" - ]; - - const actualFailures = TestUtils.applyRuleOnFile(fileName, VariableNameRule, options); - const optionallyValidFailures = [ - createFailure([34, 5], [34, 21]) - ]; - - // none of the optionally valid names should appear in the failures list - assert.isFalse(actualFailures.some((failure) => { - return optionallyValidFailures.some((f) => f.equals(failure)); - })); - }); - - it("ensures leading & trailing underscores can optionally be legal", () => { - const options = [true, - "allow-leading-underscore", - "allow-trailing-underscore" - ]; - - const actualFailures = TestUtils.applyRuleOnFile(fileName, VariableNameRule, options); - const optionallyValidFailures = [ - createFailure([35, 5], [35, 19]) - ]; - - // none of the optionally valid names should appear in the failures list - assert.isFalse(actualFailures.some((failure) => { - return optionallyValidFailures.some((f) => f.equals(failure)); - })); - }); - - it("ensures keywords can optionally be banned", () => { - const file = "rules/varname-keywords.test.ts"; - const failure = TestUtils.createFailuresOnFile(file, VariableNameRule.KEYWORD_FAILURE); - const options = [true, "ban-keywords"]; - - const expectedFailures = [ - failure([1, 5], [1, 14]), - failure([2, 5], [2, 12]), - failure([3, 14], [3, 17]), - failure([4, 6], [4, 12]), - failure([5, 6], [5, 12]) - ]; - - const actualFailures = TestUtils.applyRuleOnFile(file, VariableNameRule, options); - TestUtils.assertFailuresEqual(actualFailures, expectedFailures); - }); -}); diff --git a/test/rules/whitespaceRuleTests.ts b/test/rules/whitespaceRuleTests.ts deleted file mode 100644 index 3258ecb5052..00000000000 --- a/test/rules/whitespaceRuleTests.ts +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {RuleFailure, TestUtils} from "../lint"; - -describe("", () => { - const fileName = "rules/whitespace.test.ts"; - const WhitespaceRule = TestUtils.getRule("whitespace"); - const createFailure = TestUtils.createFailuresOnFile(fileName, WhitespaceRule.FAILURE_STRING); - let actualFailures: RuleFailure[]; - - before(() => { - const options = [true, - "check-branch", - "check-decl", - "check-operator", - "check-module", - "check-separator", - "check-type", - "check-typecast" - ]; - actualFailures = TestUtils.applyRuleOnFile(fileName, WhitespaceRule, options); - assert.lengthOf(actualFailures, 39); - }); - - it("enforces rules only when enabled", () => { - const failures = TestUtils.applyRuleOnFile(fileName, WhitespaceRule); - assert.equal(failures.length, 0); - }); - - it("enforces whitespace in import statements", () => { - const expectedFailures = [ - createFailure([1, 11], [1, 12]), - createFailure([1, 12], [1, 13]), - createFailure([57, 19], [57, 20]), - createFailure([58, 7], [58, 8]), - createFailure([58, 16], [58, 17]), - createFailure([58, 20], [58, 21]), - createFailure([59, 26], [59, 27]) - ]; - - expectedFailures.forEach((failure) => { - TestUtils.assertContainsFailure(actualFailures, failure); - }); - }); - - it("enforces whitespace in export statements", () => { - const expectedFailures = [ - createFailure([3, 19], [3, 20]), - createFailure([3, 20], [3, 21]), - createFailure([42, 7], [42, 8]), - createFailure([42, 8], [42, 9]), - createFailure([64, 7], [64, 8]) - ]; - - expectedFailures.forEach((failure) => { - TestUtils.assertContainsFailure(actualFailures, failure); - }); - }); - - it("enforces whitespace in type declarations", () => { - const expectedFailure = createFailure([5, 11], [5, 12]); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("enforces whitespace in conditional statements", () => { - const expectedFailures = [ - createFailure([7, 23], [7, 24]), - createFailure([7, 24], [7, 25]), - createFailure([7, 25], [7, 26]), - createFailure([7, 26], [7, 27]) - ]; - - expectedFailures.forEach((failure) => { - TestUtils.assertContainsFailure(actualFailures, failure); - }); - }); - - it("enforces whitespace in binary expressions", () => { - const expectedFailures = [ - createFailure([9, 16], [9, 17]), - createFailure([9, 19], [9, 20]) - ]; - - expectedFailures.forEach((failure) => { - TestUtils.assertContainsFailure(actualFailures, failure); - }); - }); - - it("enforces whitespace in variable definitions", () => { - const expectedFailures = [ - createFailure([11, 10], [11, 11]), - createFailure([11, 11], [11, 12]), - createFailure([13, 11], [13, 12]) - ]; - - expectedFailures.forEach((failure) => { - TestUtils.assertContainsFailure(actualFailures, failure); - }); - }); - - it("enforces whitespace in switch statements", () => { - const expectedFailures = [ - createFailure([15, 11], [15, 12]), - createFailure([16, 16], [16, 17]), - createFailure([17, 17], [17, 18]) - ]; - - expectedFailures.forEach((failure) => { - TestUtils.assertContainsFailure(actualFailures, failure); - }); - }); - - it("enforces whitespace in for statements", () => { - const expectedFailures = [ - createFailure([20, 8], [20, 9]), - createFailure([20, 15], [20, 16]), - createFailure([20, 18], [20, 19]) - ]; - - expectedFailures.forEach((failure) => { - TestUtils.assertContainsFailure(actualFailures, failure); - }); - }); - - it("enforces whitespace in while statements", () => { - const expectedFailure = createFailure([24, 10], [24, 11]); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("enforces whitespace in label definitions", () => { - const expectedFailure = createFailure([21, 14], [21, 15]); - TestUtils.assertContainsFailure(actualFailures, expectedFailure); - }); - - it("enforces whitespace around the => token", () => { - const expectedFailures = [ - createFailure([29, 17], [29, 18]), - createFailure([29, 19], [29, 20]), - createFailure([30, 17], [30, 18]), - createFailure([30, 19], [30, 20]), - createFailure([34, 14], [34, 15]), - createFailure([34, 16], [34, 17]), - createFailure([35, 18], [35, 19]), - createFailure([35, 20], [35, 21]) - ]; - - expectedFailures.forEach((failure) => { - TestUtils.assertContainsFailure(actualFailures, failure); - }); - }); - - it("enforces whitespace around typecasts", () => { - TestUtils.assertContainsFailure(actualFailures, createFailure([36, 21], [36, 22])); - }); -}); diff --git a/test/tsconfig.json b/test/tsconfig.json index eb269d0d6ae..520414288cc 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -129,10 +129,6 @@ "ruleTestRunnerTests/testData.ts", "ruleTestRunnerTests/utilsTests.ts", "rules/eofLineRuleTests.ts", - "rules/typedefWhitespaceRuleTests.ts", - "rules/useStrictRuleTests.ts", - "rules/variableNameRuleTests.ts", - "rules/whitespaceRuleTests.ts", "formatters/externalFormatterTest.ts", "formatters/jsonFormatterTests.ts", "formatters/pmdFormatterTests.ts", From 8191a4fc79c9a9d7a77b3ab117f908c8f656ff9b Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Mon, 4 Jan 2016 11:07:31 -0500 Subject: [PATCH 22/30] Reorganize directory structure for tests for rules Adjust Gruntfile so tests for rules run on Windows Convert tsx test to new format --- Gruntfile.js | 12 +- test/{rules => }/eofLineRuleTests.ts | 4 +- test/files/{rules => }/eofline.test.ts | 0 test/files/rules/.gitattributes | 1 - test/ruleTestRunner/{ => modules}/lines.ts | 0 test/ruleTestRunner/{ => modules}/parse.ts | 0 test/ruleTestRunner/{ => modules}/types.ts | 0 test/ruleTestRunner/{ => modules}/utils.ts | 0 test/{ => ruleTestRunner}/ruleTestRunner.ts | 8 +- test/ruleTestRunnerTests/linesTests.ts | 2 +- test/ruleTestRunnerTests/parseTests.ts | 2 +- test/ruleTestRunnerTests/testData.ts | 2 +- test/ruleTestRunnerTests/utilsTests.ts | 2 +- .../_comprehensive/react/test.tsx.linttest} | 3 + test/rules/_comprehensive/react/tslint.json | 24 ++++ .../align/arguments/test.ts.linttest | 0 .../align/arguments/tslint.json | 0 .../align/parameters/test.ts.linttest | 0 .../align/parameters/tslint.json | 0 .../align/statements/test.ts.linttest | 0 .../align/statements/tslint.json | 0 .../{ruleTests => rules}/ban/test.ts.linttest | 0 test/{ruleTests => rules}/ban/tslint.json | 0 .../class-name/test.ts.linttest | 0 .../class-name/tslint.json | 0 .../comment-format/lower/test.ts.linttest | 0 .../comment-format/lower/tslint.json | 0 .../comment-format/upper/test.ts.linttest | 0 .../comment-format/upper/tslint.json | 0 .../curly/test.ts.linttest | 0 test/{ruleTests => rules}/curly/tslint.json | 0 .../forin/test.ts.linttest | 0 test/{ruleTests => rules}/forin/tslint.json | 0 .../indent/spaces/.test.ts.linttest.swp | Bin .../indent/spaces/test.ts.linttest | 0 .../indent/spaces/tslint.json | 0 .../indent/tabs/test.ts.linttest | 0 .../indent/tabs/tslint.json | 0 .../interface-name/test.ts.linttest | 0 .../interface-name/tslint.json | 0 .../jsdoc-format/jsdoc-windows.ts.linttest | 0 .../jsdoc-format/jsdoc.ts.linttest | 0 .../jsdoc-format/tslint.json | 0 .../label-position/test.ts.linttest | 0 .../label-position/tslint.json | 0 .../label-undefined/test.ts.linttest | 0 .../label-undefined/tslint.json | 0 .../max-line-length/test.ts.linttest | 0 .../max-line-length/tslint.json | 0 .../member-access/accessor/test.ts.linttest | 0 .../member-access/accessor/tslint.json | 0 .../constructor/test.ts.linttest | 0 .../member-access/constructor/tslint.json | 0 .../member-access/default/test.ts.linttest | 0 .../member-access/default/tslint.json | 0 .../member-ordering/method/test.ts.linttest | 0 .../member-ordering/method/tslint.json | 0 .../member-ordering/private/test.ts.linttest | 0 .../member-ordering/private/tslint.json | 0 .../member-ordering/static/test.ts.linttest | 0 .../member-ordering/static/tslint.json | 0 .../no-any/test.ts.linttest | 0 test/{ruleTests => rules}/no-any/tslint.json | 0 .../no-arg/test.ts.linttest | 0 test/{ruleTests => rules}/no-arg/tslint.json | 0 .../no-bitwise/test.ts.linttest | 0 .../no-bitwise/tslint.json | 0 .../test.ts.linttest | 0 .../no-conditional-assignment/tslint.json | 0 .../test.ts.linttest | 0 .../no-consecutive-blank-lines/tslint.json | 0 .../no-console/test.ts.linttest | 0 .../no-console/tslint.json | 0 .../no-construct/test.ts.linttest | 0 .../no-construct/tslint.json | 0 .../no-constructor-vars/test.ts.linttest | 0 .../no-constructor-vars/tslint.json | 0 .../no-debugger/test.ts.linttest | 0 .../no-debugger/tslint.json | 0 .../no-duplicate-key/test.ts.linttest | 0 .../no-duplicate-key/tslint.json | 0 .../no-duplicate-variable/test.ts.linttest | 0 .../no-duplicate-variable/tslint.json | 0 .../no-empty/test.ts.linttest | 0 .../{ruleTests => rules}/no-empty/tslint.json | 0 .../no-eval/test.ts.linttest | 0 test/{ruleTests => rules}/no-eval/tslint.json | 0 .../no-inferrable-types/test.ts.linttest | 0 .../no-inferrable-types/tslint.json | 0 .../no-internal-module/test.ts.linttest | 0 .../no-internal-module/tslint.json | 0 .../no-null-keyword/test.ts.linttest | 0 .../no-null-keyword/tslint.json | 0 .../no-require-imports/test.ts.linttest | 0 .../no-require-imports/tslint.json | 0 .../no-shadowed-variable/test.ts.linttest | 0 .../no-shadowed-variable/tslint.json | 0 .../no-string-literal/test.ts.linttest | 0 .../no-string-literal/tslint.json | 0 .../test.ts.linttest | 0 .../no-switch-case-fall-through/tslint.json | 0 .../no-trailing-whitespace/test.ts.linttest | 0 .../no-trailing-whitespace/tslint.json | 0 .../no-unreachable/test.ts.linttest | 0 .../no-unreachable/tslint.json | 0 .../no-unused-expression/test.ts.linttest | 0 .../no-unused-expression/tslint.json | 0 .../check-parameters/test.ts.linttest | 0 .../check-parameters/tslint.json | 0 .../default/class.ts.linttest | 0 .../default/false-positives.ts.linttest | 0 .../default/function.ts.linttest | 0 .../default/import.ts.linttest | 0 .../default/react-addons1.tsx.linttest | 0 .../default/react-addons2.tsx.linttest | 0 .../default/react-addons3.tsx.linttest | 0 .../default/react1.tsx.linttest | 0 .../default/react2.tsx.linttest | 0 .../default/react3.tsx.linttest | 0 .../default/react4.tsx.linttest | 0 .../no-unused-variable/default/tslint.json | 0 .../default/var.ts.linttest | 0 .../react/react-addons1.tsx.linttest | 0 .../react/react-addons2.tsx.linttest | 0 .../react/react-addons3.tsx.linttest | 0 .../react/react1.tsx.linttest | 0 .../react/react2.tsx.linttest | 0 .../react/react3.tsx.linttest | 0 .../react/react4.tsx.linttest | 0 .../no-unused-variable/react/tslint.json | 0 .../no-use-before-declare/test.ts.linttest | 0 .../no-use-before-declare/tslint.json | 0 .../no-var-keyword/test.ts.linttest | 0 .../no-var-keyword/tslint.json | 0 .../no-var-requires/test.ts.linttest | 0 .../no-var-requires/tslint.json | 0 .../object-literal-sort-keys/test.ts.linttest | 0 .../object-literal-sort-keys/tslint.json | 0 .../one-line/all/test.ts.linttest | 0 .../one-line/all/tslint.json | 0 .../one-line/none/test.ts.linttest | 0 .../one-line/none/tslint.json | 0 .../double-avoid-escape/test.ts.linttest | 0 .../quotemark/double-avoid-escape/tslint.json | 0 .../quotemark/double/test.ts.linttest | 0 .../quotemark/double/tslint.json | 0 .../single-avoid-escape/test.ts.linttest | 0 .../quotemark/single-avoid-escape/tslint.json | 0 .../quotemark/single/test.ts.linttest | 0 .../quotemark/single/tslint.json | 0 .../radix/test.ts.linttest | 0 test/{ruleTests => rules}/radix/tslint.json | 0 .../semicolon/test.ts.linttest | 0 .../semicolon/tslint.json | 0 .../switch-default/test.ts.linttest | 0 .../switch-default/tslint.json | 0 .../multiline-always/test.ts.linttest | 0 .../multiline-always/tslint.json | 0 .../multiline-never/test.ts.linttest | 0 .../multiline-never/tslint.json | 0 .../singleline-always/test.ts.linttest | 0 .../singleline-always/tslint.json | 0 .../singleline-never/test.ts.linttest | 0 .../singleline-never/tslint.json | 0 .../triple-equals/test.ts.linttest | 0 .../triple-equals/tslint.json | 0 .../typedef-whitespace/none/test.ts.linttest | 0 .../typedef-whitespace/none/tslint.json | 0 .../nospace/test.ts.linttest | 0 .../typedef-whitespace/nospace/tslint.json | 0 .../typedef-whitespace/space/test.ts.linttest | 0 .../typedef-whitespace/space/tslint.json | 0 .../typedef/all/test.ts.linttest | 0 .../typedef/all/tslint.json | 0 .../typedef/none/test.ts.linttest | 0 .../typedef/none/tslint.json | 0 .../use-strict/test.ts.linttest | 0 .../use-strict/tslint.json | 0 .../test.ts.linttest | 0 .../tslint.json | 0 .../allow-leading-underscore/test.ts.linttest | 0 .../allow-leading-underscore/tslint.json | 0 .../test.ts.linttest | 0 .../allow-trailing-underscore/tslint.json | 0 .../ban-keywords/test.ts.linttest | 0 .../variable-name/ban-keywords/tslint.json | 0 .../variable-name/default/test.ts.linttest | 0 .../variable-name/default/tslint.json | 0 .../whitespace/all/test.ts.linttest | 0 .../whitespace/all/tslint.json | 0 .../whitespace/none/test.ts.linttest | 0 .../whitespace/none/tslint.json | 0 test/tsconfig.json | 16 ++- test/tsxTests.ts | 103 ------------------ 194 files changed, 52 insertions(+), 127 deletions(-) rename test/{rules => }/eofLineRuleTests.ts (93%) rename test/files/{rules => }/eofline.test.ts (100%) delete mode 100644 test/files/rules/.gitattributes rename test/ruleTestRunner/{ => modules}/lines.ts (100%) rename test/ruleTestRunner/{ => modules}/parse.ts (100%) rename test/ruleTestRunner/{ => modules}/types.ts (100%) rename test/ruleTestRunner/{ => modules}/utils.ts (100%) rename test/{ => ruleTestRunner}/ruleTestRunner.ts (93%) rename test/{files/tsx/react.test.tsx => rules/_comprehensive/react/test.tsx.linttest} (87%) create mode 100644 test/rules/_comprehensive/react/tslint.json rename test/{ruleTests => rules}/align/arguments/test.ts.linttest (100%) rename test/{ruleTests => rules}/align/arguments/tslint.json (100%) rename test/{ruleTests => rules}/align/parameters/test.ts.linttest (100%) rename test/{ruleTests => rules}/align/parameters/tslint.json (100%) rename test/{ruleTests => rules}/align/statements/test.ts.linttest (100%) rename test/{ruleTests => rules}/align/statements/tslint.json (100%) rename test/{ruleTests => rules}/ban/test.ts.linttest (100%) rename test/{ruleTests => rules}/ban/tslint.json (100%) rename test/{ruleTests => rules}/class-name/test.ts.linttest (100%) rename test/{ruleTests => rules}/class-name/tslint.json (100%) rename test/{ruleTests => rules}/comment-format/lower/test.ts.linttest (100%) rename test/{ruleTests => rules}/comment-format/lower/tslint.json (100%) rename test/{ruleTests => rules}/comment-format/upper/test.ts.linttest (100%) rename test/{ruleTests => rules}/comment-format/upper/tslint.json (100%) rename test/{ruleTests => rules}/curly/test.ts.linttest (100%) rename test/{ruleTests => rules}/curly/tslint.json (100%) rename test/{ruleTests => rules}/forin/test.ts.linttest (100%) rename test/{ruleTests => rules}/forin/tslint.json (100%) rename test/{ruleTests => rules}/indent/spaces/.test.ts.linttest.swp (100%) rename test/{ruleTests => rules}/indent/spaces/test.ts.linttest (100%) rename test/{ruleTests => rules}/indent/spaces/tslint.json (100%) rename test/{ruleTests => rules}/indent/tabs/test.ts.linttest (100%) rename test/{ruleTests => rules}/indent/tabs/tslint.json (100%) rename test/{ruleTests => rules}/interface-name/test.ts.linttest (100%) rename test/{ruleTests => rules}/interface-name/tslint.json (100%) rename test/{ruleTests => rules}/jsdoc-format/jsdoc-windows.ts.linttest (100%) rename test/{ruleTests => rules}/jsdoc-format/jsdoc.ts.linttest (100%) rename test/{ruleTests => rules}/jsdoc-format/tslint.json (100%) rename test/{ruleTests => rules}/label-position/test.ts.linttest (100%) rename test/{ruleTests => rules}/label-position/tslint.json (100%) rename test/{ruleTests => rules}/label-undefined/test.ts.linttest (100%) rename test/{ruleTests => rules}/label-undefined/tslint.json (100%) rename test/{ruleTests => rules}/max-line-length/test.ts.linttest (100%) rename test/{ruleTests => rules}/max-line-length/tslint.json (100%) rename test/{ruleTests => rules}/member-access/accessor/test.ts.linttest (100%) rename test/{ruleTests => rules}/member-access/accessor/tslint.json (100%) rename test/{ruleTests => rules}/member-access/constructor/test.ts.linttest (100%) rename test/{ruleTests => rules}/member-access/constructor/tslint.json (100%) rename test/{ruleTests => rules}/member-access/default/test.ts.linttest (100%) rename test/{ruleTests => rules}/member-access/default/tslint.json (100%) rename test/{ruleTests => rules}/member-ordering/method/test.ts.linttest (100%) rename test/{ruleTests => rules}/member-ordering/method/tslint.json (100%) rename test/{ruleTests => rules}/member-ordering/private/test.ts.linttest (100%) rename test/{ruleTests => rules}/member-ordering/private/tslint.json (100%) rename test/{ruleTests => rules}/member-ordering/static/test.ts.linttest (100%) rename test/{ruleTests => rules}/member-ordering/static/tslint.json (100%) rename test/{ruleTests => rules}/no-any/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-any/tslint.json (100%) rename test/{ruleTests => rules}/no-arg/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-arg/tslint.json (100%) rename test/{ruleTests => rules}/no-bitwise/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-bitwise/tslint.json (100%) rename test/{ruleTests => rules}/no-conditional-assignment/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-conditional-assignment/tslint.json (100%) rename test/{ruleTests => rules}/no-consecutive-blank-lines/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-consecutive-blank-lines/tslint.json (100%) rename test/{ruleTests => rules}/no-console/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-console/tslint.json (100%) rename test/{ruleTests => rules}/no-construct/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-construct/tslint.json (100%) rename test/{ruleTests => rules}/no-constructor-vars/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-constructor-vars/tslint.json (100%) rename test/{ruleTests => rules}/no-debugger/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-debugger/tslint.json (100%) rename test/{ruleTests => rules}/no-duplicate-key/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-duplicate-key/tslint.json (100%) rename test/{ruleTests => rules}/no-duplicate-variable/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-duplicate-variable/tslint.json (100%) rename test/{ruleTests => rules}/no-empty/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-empty/tslint.json (100%) rename test/{ruleTests => rules}/no-eval/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-eval/tslint.json (100%) rename test/{ruleTests => rules}/no-inferrable-types/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-inferrable-types/tslint.json (100%) rename test/{ruleTests => rules}/no-internal-module/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-internal-module/tslint.json (100%) rename test/{ruleTests => rules}/no-null-keyword/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-null-keyword/tslint.json (100%) rename test/{ruleTests => rules}/no-require-imports/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-require-imports/tslint.json (100%) rename test/{ruleTests => rules}/no-shadowed-variable/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-shadowed-variable/tslint.json (100%) rename test/{ruleTests => rules}/no-string-literal/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-string-literal/tslint.json (100%) rename test/{ruleTests => rules}/no-switch-case-fall-through/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-switch-case-fall-through/tslint.json (100%) rename test/{ruleTests => rules}/no-trailing-whitespace/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-trailing-whitespace/tslint.json (100%) rename test/{ruleTests => rules}/no-unreachable/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-unreachable/tslint.json (100%) rename test/{ruleTests => rules}/no-unused-expression/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-unused-expression/tslint.json (100%) rename test/{ruleTests => rules}/no-unused-variable/check-parameters/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-unused-variable/check-parameters/tslint.json (100%) rename test/{ruleTests => rules}/no-unused-variable/default/class.ts.linttest (100%) rename test/{ruleTests => rules}/no-unused-variable/default/false-positives.ts.linttest (100%) rename test/{ruleTests => rules}/no-unused-variable/default/function.ts.linttest (100%) rename test/{ruleTests => rules}/no-unused-variable/default/import.ts.linttest (100%) rename test/{ruleTests => rules}/no-unused-variable/default/react-addons1.tsx.linttest (100%) rename test/{ruleTests => rules}/no-unused-variable/default/react-addons2.tsx.linttest (100%) rename test/{ruleTests => rules}/no-unused-variable/default/react-addons3.tsx.linttest (100%) rename test/{ruleTests => rules}/no-unused-variable/default/react1.tsx.linttest (100%) rename test/{ruleTests => rules}/no-unused-variable/default/react2.tsx.linttest (100%) rename test/{ruleTests => rules}/no-unused-variable/default/react3.tsx.linttest (100%) rename test/{ruleTests => rules}/no-unused-variable/default/react4.tsx.linttest (100%) rename test/{ruleTests => rules}/no-unused-variable/default/tslint.json (100%) rename test/{ruleTests => rules}/no-unused-variable/default/var.ts.linttest (100%) rename test/{ruleTests => rules}/no-unused-variable/react/react-addons1.tsx.linttest (100%) rename test/{ruleTests => rules}/no-unused-variable/react/react-addons2.tsx.linttest (100%) rename test/{ruleTests => rules}/no-unused-variable/react/react-addons3.tsx.linttest (100%) rename test/{ruleTests => rules}/no-unused-variable/react/react1.tsx.linttest (100%) rename test/{ruleTests => rules}/no-unused-variable/react/react2.tsx.linttest (100%) rename test/{ruleTests => rules}/no-unused-variable/react/react3.tsx.linttest (100%) rename test/{ruleTests => rules}/no-unused-variable/react/react4.tsx.linttest (100%) rename test/{ruleTests => rules}/no-unused-variable/react/tslint.json (100%) rename test/{ruleTests => rules}/no-use-before-declare/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-use-before-declare/tslint.json (100%) rename test/{ruleTests => rules}/no-var-keyword/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-var-keyword/tslint.json (100%) rename test/{ruleTests => rules}/no-var-requires/test.ts.linttest (100%) rename test/{ruleTests => rules}/no-var-requires/tslint.json (100%) rename test/{ruleTests => rules}/object-literal-sort-keys/test.ts.linttest (100%) rename test/{ruleTests => rules}/object-literal-sort-keys/tslint.json (100%) rename test/{ruleTests => rules}/one-line/all/test.ts.linttest (100%) rename test/{ruleTests => rules}/one-line/all/tslint.json (100%) rename test/{ruleTests => rules}/one-line/none/test.ts.linttest (100%) rename test/{ruleTests => rules}/one-line/none/tslint.json (100%) rename test/{ruleTests => rules}/quotemark/double-avoid-escape/test.ts.linttest (100%) rename test/{ruleTests => rules}/quotemark/double-avoid-escape/tslint.json (100%) rename test/{ruleTests => rules}/quotemark/double/test.ts.linttest (100%) rename test/{ruleTests => rules}/quotemark/double/tslint.json (100%) rename test/{ruleTests => rules}/quotemark/single-avoid-escape/test.ts.linttest (100%) rename test/{ruleTests => rules}/quotemark/single-avoid-escape/tslint.json (100%) rename test/{ruleTests => rules}/quotemark/single/test.ts.linttest (100%) rename test/{ruleTests => rules}/quotemark/single/tslint.json (100%) rename test/{ruleTests => rules}/radix/test.ts.linttest (100%) rename test/{ruleTests => rules}/radix/tslint.json (100%) rename test/{ruleTests => rules}/semicolon/test.ts.linttest (100%) rename test/{ruleTests => rules}/semicolon/tslint.json (100%) rename test/{ruleTests => rules}/switch-default/test.ts.linttest (100%) rename test/{ruleTests => rules}/switch-default/tslint.json (100%) rename test/{ruleTests => rules}/trailing-comma/multiline-always/test.ts.linttest (100%) rename test/{ruleTests => rules}/trailing-comma/multiline-always/tslint.json (100%) rename test/{ruleTests => rules}/trailing-comma/multiline-never/test.ts.linttest (100%) rename test/{ruleTests => rules}/trailing-comma/multiline-never/tslint.json (100%) rename test/{ruleTests => rules}/trailing-comma/singleline-always/test.ts.linttest (100%) rename test/{ruleTests => rules}/trailing-comma/singleline-always/tslint.json (100%) rename test/{ruleTests => rules}/trailing-comma/singleline-never/test.ts.linttest (100%) rename test/{ruleTests => rules}/trailing-comma/singleline-never/tslint.json (100%) rename test/{ruleTests => rules}/triple-equals/test.ts.linttest (100%) rename test/{ruleTests => rules}/triple-equals/tslint.json (100%) rename test/{ruleTests => rules}/typedef-whitespace/none/test.ts.linttest (100%) rename test/{ruleTests => rules}/typedef-whitespace/none/tslint.json (100%) rename test/{ruleTests => rules}/typedef-whitespace/nospace/test.ts.linttest (100%) rename test/{ruleTests => rules}/typedef-whitespace/nospace/tslint.json (100%) rename test/{ruleTests => rules}/typedef-whitespace/space/test.ts.linttest (100%) rename test/{ruleTests => rules}/typedef-whitespace/space/tslint.json (100%) rename test/{ruleTests => rules}/typedef/all/test.ts.linttest (100%) rename test/{ruleTests => rules}/typedef/all/tslint.json (100%) rename test/{ruleTests => rules}/typedef/none/test.ts.linttest (100%) rename test/{ruleTests => rules}/typedef/none/tslint.json (100%) rename test/{ruleTests => rules}/use-strict/test.ts.linttest (100%) rename test/{ruleTests => rules}/use-strict/tslint.json (100%) rename test/{ruleTests => rules}/variable-name/allow-leading-trailing-underscore/test.ts.linttest (100%) rename test/{ruleTests => rules}/variable-name/allow-leading-trailing-underscore/tslint.json (100%) rename test/{ruleTests => rules}/variable-name/allow-leading-underscore/test.ts.linttest (100%) rename test/{ruleTests => rules}/variable-name/allow-leading-underscore/tslint.json (100%) rename test/{ruleTests => rules}/variable-name/allow-trailing-underscore/test.ts.linttest (100%) rename test/{ruleTests => rules}/variable-name/allow-trailing-underscore/tslint.json (100%) rename test/{ruleTests => rules}/variable-name/ban-keywords/test.ts.linttest (100%) rename test/{ruleTests => rules}/variable-name/ban-keywords/tslint.json (100%) rename test/{ruleTests => rules}/variable-name/default/test.ts.linttest (100%) rename test/{ruleTests => rules}/variable-name/default/tslint.json (100%) rename test/{ruleTests => rules}/whitespace/all/test.ts.linttest (100%) rename test/{ruleTests => rules}/whitespace/all/tslint.json (100%) rename test/{ruleTests => rules}/whitespace/none/test.ts.linttest (100%) rename test/{ruleTests => rules}/whitespace/none/tslint.json (100%) delete mode 100644 test/tsxTests.ts diff --git a/Gruntfile.js b/Gruntfile.js index f5bc9a85a98..cc9fbc9487d 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -4,7 +4,7 @@ var checkBinTest; if (process.platform === "win32") { checkBinTest = []; } else { - checkBinTest = ["run:test"]; + checkBinTest = ["run:testBin"]; } module.exports = function (grunt) { @@ -27,8 +27,11 @@ module.exports = function (grunt) { }, run: { - test: { - exec: "./test/check-bin.sh && node ./build/test/ruleTestRunner.js" + testBin: { + exec: "./test/check-bin.sh" + }, + testRules: { + exec: "node ./build/test/ruleTestRunner/ruleTestRunner.js" } }, @@ -87,7 +90,8 @@ module.exports = function (grunt) { "clean:test", "ts:test", "tslint:test", - "mochaTest" + "mochaTest", + "run:testRules", ].concat(checkBinTest)); // create default task diff --git a/test/rules/eofLineRuleTests.ts b/test/eofLineRuleTests.ts similarity index 93% rename from test/rules/eofLineRuleTests.ts rename to test/eofLineRuleTests.ts index c370b600cf1..b45f9bf2f50 100644 --- a/test/rules/eofLineRuleTests.ts +++ b/test/eofLineRuleTests.ts @@ -14,11 +14,11 @@ * limitations under the License. */ -import {TestUtils} from "../lint"; +import {TestUtils} from "./lint"; describe("", () => { const EofLineRule = TestUtils.getRule("eofline"); - const fileName = "rules/eofline.test.ts"; + const fileName = "eofline.test.ts"; const failureString = EofLineRule.FAILURE_STRING; it("ensures a trailing newline at EOF", () => { diff --git a/test/files/rules/eofline.test.ts b/test/files/eofline.test.ts similarity index 100% rename from test/files/rules/eofline.test.ts rename to test/files/eofline.test.ts diff --git a/test/files/rules/.gitattributes b/test/files/rules/.gitattributes deleted file mode 100644 index 9a8d99eebaf..00000000000 --- a/test/files/rules/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -maxlen.test.ts -text diff --git a/test/ruleTestRunner/lines.ts b/test/ruleTestRunner/modules/lines.ts similarity index 100% rename from test/ruleTestRunner/lines.ts rename to test/ruleTestRunner/modules/lines.ts diff --git a/test/ruleTestRunner/parse.ts b/test/ruleTestRunner/modules/parse.ts similarity index 100% rename from test/ruleTestRunner/parse.ts rename to test/ruleTestRunner/modules/parse.ts diff --git a/test/ruleTestRunner/types.ts b/test/ruleTestRunner/modules/types.ts similarity index 100% rename from test/ruleTestRunner/types.ts rename to test/ruleTestRunner/modules/types.ts diff --git a/test/ruleTestRunner/utils.ts b/test/ruleTestRunner/modules/utils.ts similarity index 100% rename from test/ruleTestRunner/utils.ts rename to test/ruleTestRunner/modules/utils.ts diff --git a/test/ruleTestRunner.ts b/test/ruleTestRunner/ruleTestRunner.ts similarity index 93% rename from test/ruleTestRunner.ts rename to test/ruleTestRunner/ruleTestRunner.ts index f111701c6f3..ace15cd2a98 100644 --- a/test/ruleTestRunner.ts +++ b/test/ruleTestRunner/ruleTestRunner.ts @@ -20,9 +20,9 @@ import * as fs from "fs"; import * as glob from "glob"; import * as path from "path"; -import * as Linter from "../src/tslint"; -import * as parse from "./ruleTestRunner/parse"; -import {LintError, FILE_EXTENSION} from "./ruleTestRunner/types"; +import * as Linter from "../../src/tslint"; +import * as parse from "./modules/parse"; +import {LintError, FILE_EXTENSION} from "./modules/types"; // needed to get colors to show up when passing through Grunt (colors as any).enabled = true; @@ -31,7 +31,7 @@ console.log(); console.log(colors.underline("Testing Lint Rules:")); let hadTestFailure = false; -const testDirectories = glob.sync("test/ruleTests/**/tslint.json").map(path.dirname); +const testDirectories = glob.sync("test/rules/**/tslint.json").map(path.dirname); for (const testDirectory of testDirectories) { const filesToLint = glob.sync(path.join(testDirectory, `**/*${FILE_EXTENSION}`)); diff --git a/test/ruleTestRunnerTests/linesTests.ts b/test/ruleTestRunnerTests/linesTests.ts index 93535492833..dd8b17799cd 100644 --- a/test/ruleTestRunnerTests/linesTests.ts +++ b/test/ruleTestRunnerTests/linesTests.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import * as lines from "../ruleTestRunner/lines"; +import * as lines from "../ruleTestRunner/modules/lines"; describe("Rule Test Runner", () => { describe("lines", () => { diff --git a/test/ruleTestRunnerTests/parseTests.ts b/test/ruleTestRunnerTests/parseTests.ts index 761d22fcdcb..a900b312d68 100644 --- a/test/ruleTestRunnerTests/parseTests.ts +++ b/test/ruleTestRunnerTests/parseTests.ts @@ -15,7 +15,7 @@ */ import * as testData from "./testData"; -import * as parse from "../ruleTestRunner/parse"; +import * as parse from "../ruleTestRunner/modules/parse"; describe("Rule Test Runner", () => { describe("parse", () => { diff --git a/test/ruleTestRunnerTests/testData.ts b/test/ruleTestRunnerTests/testData.ts index 2803f213c7e..255c3a395e2 100644 --- a/test/ruleTestRunnerTests/testData.ts +++ b/test/ruleTestRunnerTests/testData.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import {LintError} from "../ruleTestRunner/types"; +import {LintError} from "../ruleTestRunner/modules/types"; /* tslint:disable:object-literal-sort-keys */ diff --git a/test/ruleTestRunnerTests/utilsTests.ts b/test/ruleTestRunnerTests/utilsTests.ts index e9356d7ff4d..ed4d66e227f 100644 --- a/test/ruleTestRunnerTests/utilsTests.ts +++ b/test/ruleTestRunnerTests/utilsTests.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import * as utils from "../ruleTestRunner/utils"; +import * as utils from "../ruleTestRunner/modules/utils"; describe("Rule Test Runner", () => { describe("utils", () => { diff --git a/test/files/tsx/react.test.tsx b/test/rules/_comprehensive/react/test.tsx.linttest similarity index 87% rename from test/files/tsx/react.test.tsx rename to test/rules/_comprehensive/react/test.tsx.linttest index 06ba9a9dcf0..74101c98b3e 100644 --- a/test/files/tsx/react.test.tsx +++ b/test/rules/_comprehensive/react/test.tsx.linttest @@ -1,4 +1,5 @@ import * as React from 'react'; // quotemark failure + ~~~~~~~ [' should be "] class BazComponent extends React.Component, {}> { public render() { @@ -14,6 +15,7 @@ interface IFooProps extends React.Props { interface IFooState { bar:string[]; // whitespace failure + ~ [missing whitespace] } export class FooComponent extends React.Component { @@ -29,6 +31,7 @@ export class FooComponent extends React.Component {
); } // indent failure +~ [space indentation expected] private onClick() { console.info("foo component clicked"); diff --git a/test/rules/_comprehensive/react/tslint.json b/test/rules/_comprehensive/react/tslint.json new file mode 100644 index 00000000000..4cc8c887f8e --- /dev/null +++ b/test/rules/_comprehensive/react/tslint.json @@ -0,0 +1,24 @@ +{ + "rules": { + "curly": true, + "eofline": true, + "indent": [true, "spaces"], + "max-line-length": true, + "no-bitwise": true, + "no-unreachable": true, + "no-unused-expression": true, + "no-unused-variable": true, + "no-use-before-declare": true, + "quotemark": [true, "double"], + "semicolon": true, + "whitespace": [true, + "check-branch", + "check-decl", + "check-operator", + "check-module", + "check-separator", + "check-type", + "check-typecast" + ] + } +} diff --git a/test/ruleTests/align/arguments/test.ts.linttest b/test/rules/align/arguments/test.ts.linttest similarity index 100% rename from test/ruleTests/align/arguments/test.ts.linttest rename to test/rules/align/arguments/test.ts.linttest diff --git a/test/ruleTests/align/arguments/tslint.json b/test/rules/align/arguments/tslint.json similarity index 100% rename from test/ruleTests/align/arguments/tslint.json rename to test/rules/align/arguments/tslint.json diff --git a/test/ruleTests/align/parameters/test.ts.linttest b/test/rules/align/parameters/test.ts.linttest similarity index 100% rename from test/ruleTests/align/parameters/test.ts.linttest rename to test/rules/align/parameters/test.ts.linttest diff --git a/test/ruleTests/align/parameters/tslint.json b/test/rules/align/parameters/tslint.json similarity index 100% rename from test/ruleTests/align/parameters/tslint.json rename to test/rules/align/parameters/tslint.json diff --git a/test/ruleTests/align/statements/test.ts.linttest b/test/rules/align/statements/test.ts.linttest similarity index 100% rename from test/ruleTests/align/statements/test.ts.linttest rename to test/rules/align/statements/test.ts.linttest diff --git a/test/ruleTests/align/statements/tslint.json b/test/rules/align/statements/tslint.json similarity index 100% rename from test/ruleTests/align/statements/tslint.json rename to test/rules/align/statements/tslint.json diff --git a/test/ruleTests/ban/test.ts.linttest b/test/rules/ban/test.ts.linttest similarity index 100% rename from test/ruleTests/ban/test.ts.linttest rename to test/rules/ban/test.ts.linttest diff --git a/test/ruleTests/ban/tslint.json b/test/rules/ban/tslint.json similarity index 100% rename from test/ruleTests/ban/tslint.json rename to test/rules/ban/tslint.json diff --git a/test/ruleTests/class-name/test.ts.linttest b/test/rules/class-name/test.ts.linttest similarity index 100% rename from test/ruleTests/class-name/test.ts.linttest rename to test/rules/class-name/test.ts.linttest diff --git a/test/ruleTests/class-name/tslint.json b/test/rules/class-name/tslint.json similarity index 100% rename from test/ruleTests/class-name/tslint.json rename to test/rules/class-name/tslint.json diff --git a/test/ruleTests/comment-format/lower/test.ts.linttest b/test/rules/comment-format/lower/test.ts.linttest similarity index 100% rename from test/ruleTests/comment-format/lower/test.ts.linttest rename to test/rules/comment-format/lower/test.ts.linttest diff --git a/test/ruleTests/comment-format/lower/tslint.json b/test/rules/comment-format/lower/tslint.json similarity index 100% rename from test/ruleTests/comment-format/lower/tslint.json rename to test/rules/comment-format/lower/tslint.json diff --git a/test/ruleTests/comment-format/upper/test.ts.linttest b/test/rules/comment-format/upper/test.ts.linttest similarity index 100% rename from test/ruleTests/comment-format/upper/test.ts.linttest rename to test/rules/comment-format/upper/test.ts.linttest diff --git a/test/ruleTests/comment-format/upper/tslint.json b/test/rules/comment-format/upper/tslint.json similarity index 100% rename from test/ruleTests/comment-format/upper/tslint.json rename to test/rules/comment-format/upper/tslint.json diff --git a/test/ruleTests/curly/test.ts.linttest b/test/rules/curly/test.ts.linttest similarity index 100% rename from test/ruleTests/curly/test.ts.linttest rename to test/rules/curly/test.ts.linttest diff --git a/test/ruleTests/curly/tslint.json b/test/rules/curly/tslint.json similarity index 100% rename from test/ruleTests/curly/tslint.json rename to test/rules/curly/tslint.json diff --git a/test/ruleTests/forin/test.ts.linttest b/test/rules/forin/test.ts.linttest similarity index 100% rename from test/ruleTests/forin/test.ts.linttest rename to test/rules/forin/test.ts.linttest diff --git a/test/ruleTests/forin/tslint.json b/test/rules/forin/tslint.json similarity index 100% rename from test/ruleTests/forin/tslint.json rename to test/rules/forin/tslint.json diff --git a/test/ruleTests/indent/spaces/.test.ts.linttest.swp b/test/rules/indent/spaces/.test.ts.linttest.swp similarity index 100% rename from test/ruleTests/indent/spaces/.test.ts.linttest.swp rename to test/rules/indent/spaces/.test.ts.linttest.swp diff --git a/test/ruleTests/indent/spaces/test.ts.linttest b/test/rules/indent/spaces/test.ts.linttest similarity index 100% rename from test/ruleTests/indent/spaces/test.ts.linttest rename to test/rules/indent/spaces/test.ts.linttest diff --git a/test/ruleTests/indent/spaces/tslint.json b/test/rules/indent/spaces/tslint.json similarity index 100% rename from test/ruleTests/indent/spaces/tslint.json rename to test/rules/indent/spaces/tslint.json diff --git a/test/ruleTests/indent/tabs/test.ts.linttest b/test/rules/indent/tabs/test.ts.linttest similarity index 100% rename from test/ruleTests/indent/tabs/test.ts.linttest rename to test/rules/indent/tabs/test.ts.linttest diff --git a/test/ruleTests/indent/tabs/tslint.json b/test/rules/indent/tabs/tslint.json similarity index 100% rename from test/ruleTests/indent/tabs/tslint.json rename to test/rules/indent/tabs/tslint.json diff --git a/test/ruleTests/interface-name/test.ts.linttest b/test/rules/interface-name/test.ts.linttest similarity index 100% rename from test/ruleTests/interface-name/test.ts.linttest rename to test/rules/interface-name/test.ts.linttest diff --git a/test/ruleTests/interface-name/tslint.json b/test/rules/interface-name/tslint.json similarity index 100% rename from test/ruleTests/interface-name/tslint.json rename to test/rules/interface-name/tslint.json diff --git a/test/ruleTests/jsdoc-format/jsdoc-windows.ts.linttest b/test/rules/jsdoc-format/jsdoc-windows.ts.linttest similarity index 100% rename from test/ruleTests/jsdoc-format/jsdoc-windows.ts.linttest rename to test/rules/jsdoc-format/jsdoc-windows.ts.linttest diff --git a/test/ruleTests/jsdoc-format/jsdoc.ts.linttest b/test/rules/jsdoc-format/jsdoc.ts.linttest similarity index 100% rename from test/ruleTests/jsdoc-format/jsdoc.ts.linttest rename to test/rules/jsdoc-format/jsdoc.ts.linttest diff --git a/test/ruleTests/jsdoc-format/tslint.json b/test/rules/jsdoc-format/tslint.json similarity index 100% rename from test/ruleTests/jsdoc-format/tslint.json rename to test/rules/jsdoc-format/tslint.json diff --git a/test/ruleTests/label-position/test.ts.linttest b/test/rules/label-position/test.ts.linttest similarity index 100% rename from test/ruleTests/label-position/test.ts.linttest rename to test/rules/label-position/test.ts.linttest diff --git a/test/ruleTests/label-position/tslint.json b/test/rules/label-position/tslint.json similarity index 100% rename from test/ruleTests/label-position/tslint.json rename to test/rules/label-position/tslint.json diff --git a/test/ruleTests/label-undefined/test.ts.linttest b/test/rules/label-undefined/test.ts.linttest similarity index 100% rename from test/ruleTests/label-undefined/test.ts.linttest rename to test/rules/label-undefined/test.ts.linttest diff --git a/test/ruleTests/label-undefined/tslint.json b/test/rules/label-undefined/tslint.json similarity index 100% rename from test/ruleTests/label-undefined/tslint.json rename to test/rules/label-undefined/tslint.json diff --git a/test/ruleTests/max-line-length/test.ts.linttest b/test/rules/max-line-length/test.ts.linttest similarity index 100% rename from test/ruleTests/max-line-length/test.ts.linttest rename to test/rules/max-line-length/test.ts.linttest diff --git a/test/ruleTests/max-line-length/tslint.json b/test/rules/max-line-length/tslint.json similarity index 100% rename from test/ruleTests/max-line-length/tslint.json rename to test/rules/max-line-length/tslint.json diff --git a/test/ruleTests/member-access/accessor/test.ts.linttest b/test/rules/member-access/accessor/test.ts.linttest similarity index 100% rename from test/ruleTests/member-access/accessor/test.ts.linttest rename to test/rules/member-access/accessor/test.ts.linttest diff --git a/test/ruleTests/member-access/accessor/tslint.json b/test/rules/member-access/accessor/tslint.json similarity index 100% rename from test/ruleTests/member-access/accessor/tslint.json rename to test/rules/member-access/accessor/tslint.json diff --git a/test/ruleTests/member-access/constructor/test.ts.linttest b/test/rules/member-access/constructor/test.ts.linttest similarity index 100% rename from test/ruleTests/member-access/constructor/test.ts.linttest rename to test/rules/member-access/constructor/test.ts.linttest diff --git a/test/ruleTests/member-access/constructor/tslint.json b/test/rules/member-access/constructor/tslint.json similarity index 100% rename from test/ruleTests/member-access/constructor/tslint.json rename to test/rules/member-access/constructor/tslint.json diff --git a/test/ruleTests/member-access/default/test.ts.linttest b/test/rules/member-access/default/test.ts.linttest similarity index 100% rename from test/ruleTests/member-access/default/test.ts.linttest rename to test/rules/member-access/default/test.ts.linttest diff --git a/test/ruleTests/member-access/default/tslint.json b/test/rules/member-access/default/tslint.json similarity index 100% rename from test/ruleTests/member-access/default/tslint.json rename to test/rules/member-access/default/tslint.json diff --git a/test/ruleTests/member-ordering/method/test.ts.linttest b/test/rules/member-ordering/method/test.ts.linttest similarity index 100% rename from test/ruleTests/member-ordering/method/test.ts.linttest rename to test/rules/member-ordering/method/test.ts.linttest diff --git a/test/ruleTests/member-ordering/method/tslint.json b/test/rules/member-ordering/method/tslint.json similarity index 100% rename from test/ruleTests/member-ordering/method/tslint.json rename to test/rules/member-ordering/method/tslint.json diff --git a/test/ruleTests/member-ordering/private/test.ts.linttest b/test/rules/member-ordering/private/test.ts.linttest similarity index 100% rename from test/ruleTests/member-ordering/private/test.ts.linttest rename to test/rules/member-ordering/private/test.ts.linttest diff --git a/test/ruleTests/member-ordering/private/tslint.json b/test/rules/member-ordering/private/tslint.json similarity index 100% rename from test/ruleTests/member-ordering/private/tslint.json rename to test/rules/member-ordering/private/tslint.json diff --git a/test/ruleTests/member-ordering/static/test.ts.linttest b/test/rules/member-ordering/static/test.ts.linttest similarity index 100% rename from test/ruleTests/member-ordering/static/test.ts.linttest rename to test/rules/member-ordering/static/test.ts.linttest diff --git a/test/ruleTests/member-ordering/static/tslint.json b/test/rules/member-ordering/static/tslint.json similarity index 100% rename from test/ruleTests/member-ordering/static/tslint.json rename to test/rules/member-ordering/static/tslint.json diff --git a/test/ruleTests/no-any/test.ts.linttest b/test/rules/no-any/test.ts.linttest similarity index 100% rename from test/ruleTests/no-any/test.ts.linttest rename to test/rules/no-any/test.ts.linttest diff --git a/test/ruleTests/no-any/tslint.json b/test/rules/no-any/tslint.json similarity index 100% rename from test/ruleTests/no-any/tslint.json rename to test/rules/no-any/tslint.json diff --git a/test/ruleTests/no-arg/test.ts.linttest b/test/rules/no-arg/test.ts.linttest similarity index 100% rename from test/ruleTests/no-arg/test.ts.linttest rename to test/rules/no-arg/test.ts.linttest diff --git a/test/ruleTests/no-arg/tslint.json b/test/rules/no-arg/tslint.json similarity index 100% rename from test/ruleTests/no-arg/tslint.json rename to test/rules/no-arg/tslint.json diff --git a/test/ruleTests/no-bitwise/test.ts.linttest b/test/rules/no-bitwise/test.ts.linttest similarity index 100% rename from test/ruleTests/no-bitwise/test.ts.linttest rename to test/rules/no-bitwise/test.ts.linttest diff --git a/test/ruleTests/no-bitwise/tslint.json b/test/rules/no-bitwise/tslint.json similarity index 100% rename from test/ruleTests/no-bitwise/tslint.json rename to test/rules/no-bitwise/tslint.json diff --git a/test/ruleTests/no-conditional-assignment/test.ts.linttest b/test/rules/no-conditional-assignment/test.ts.linttest similarity index 100% rename from test/ruleTests/no-conditional-assignment/test.ts.linttest rename to test/rules/no-conditional-assignment/test.ts.linttest diff --git a/test/ruleTests/no-conditional-assignment/tslint.json b/test/rules/no-conditional-assignment/tslint.json similarity index 100% rename from test/ruleTests/no-conditional-assignment/tslint.json rename to test/rules/no-conditional-assignment/tslint.json diff --git a/test/ruleTests/no-consecutive-blank-lines/test.ts.linttest b/test/rules/no-consecutive-blank-lines/test.ts.linttest similarity index 100% rename from test/ruleTests/no-consecutive-blank-lines/test.ts.linttest rename to test/rules/no-consecutive-blank-lines/test.ts.linttest diff --git a/test/ruleTests/no-consecutive-blank-lines/tslint.json b/test/rules/no-consecutive-blank-lines/tslint.json similarity index 100% rename from test/ruleTests/no-consecutive-blank-lines/tslint.json rename to test/rules/no-consecutive-blank-lines/tslint.json diff --git a/test/ruleTests/no-console/test.ts.linttest b/test/rules/no-console/test.ts.linttest similarity index 100% rename from test/ruleTests/no-console/test.ts.linttest rename to test/rules/no-console/test.ts.linttest diff --git a/test/ruleTests/no-console/tslint.json b/test/rules/no-console/tslint.json similarity index 100% rename from test/ruleTests/no-console/tslint.json rename to test/rules/no-console/tslint.json diff --git a/test/ruleTests/no-construct/test.ts.linttest b/test/rules/no-construct/test.ts.linttest similarity index 100% rename from test/ruleTests/no-construct/test.ts.linttest rename to test/rules/no-construct/test.ts.linttest diff --git a/test/ruleTests/no-construct/tslint.json b/test/rules/no-construct/tslint.json similarity index 100% rename from test/ruleTests/no-construct/tslint.json rename to test/rules/no-construct/tslint.json diff --git a/test/ruleTests/no-constructor-vars/test.ts.linttest b/test/rules/no-constructor-vars/test.ts.linttest similarity index 100% rename from test/ruleTests/no-constructor-vars/test.ts.linttest rename to test/rules/no-constructor-vars/test.ts.linttest diff --git a/test/ruleTests/no-constructor-vars/tslint.json b/test/rules/no-constructor-vars/tslint.json similarity index 100% rename from test/ruleTests/no-constructor-vars/tslint.json rename to test/rules/no-constructor-vars/tslint.json diff --git a/test/ruleTests/no-debugger/test.ts.linttest b/test/rules/no-debugger/test.ts.linttest similarity index 100% rename from test/ruleTests/no-debugger/test.ts.linttest rename to test/rules/no-debugger/test.ts.linttest diff --git a/test/ruleTests/no-debugger/tslint.json b/test/rules/no-debugger/tslint.json similarity index 100% rename from test/ruleTests/no-debugger/tslint.json rename to test/rules/no-debugger/tslint.json diff --git a/test/ruleTests/no-duplicate-key/test.ts.linttest b/test/rules/no-duplicate-key/test.ts.linttest similarity index 100% rename from test/ruleTests/no-duplicate-key/test.ts.linttest rename to test/rules/no-duplicate-key/test.ts.linttest diff --git a/test/ruleTests/no-duplicate-key/tslint.json b/test/rules/no-duplicate-key/tslint.json similarity index 100% rename from test/ruleTests/no-duplicate-key/tslint.json rename to test/rules/no-duplicate-key/tslint.json diff --git a/test/ruleTests/no-duplicate-variable/test.ts.linttest b/test/rules/no-duplicate-variable/test.ts.linttest similarity index 100% rename from test/ruleTests/no-duplicate-variable/test.ts.linttest rename to test/rules/no-duplicate-variable/test.ts.linttest diff --git a/test/ruleTests/no-duplicate-variable/tslint.json b/test/rules/no-duplicate-variable/tslint.json similarity index 100% rename from test/ruleTests/no-duplicate-variable/tslint.json rename to test/rules/no-duplicate-variable/tslint.json diff --git a/test/ruleTests/no-empty/test.ts.linttest b/test/rules/no-empty/test.ts.linttest similarity index 100% rename from test/ruleTests/no-empty/test.ts.linttest rename to test/rules/no-empty/test.ts.linttest diff --git a/test/ruleTests/no-empty/tslint.json b/test/rules/no-empty/tslint.json similarity index 100% rename from test/ruleTests/no-empty/tslint.json rename to test/rules/no-empty/tslint.json diff --git a/test/ruleTests/no-eval/test.ts.linttest b/test/rules/no-eval/test.ts.linttest similarity index 100% rename from test/ruleTests/no-eval/test.ts.linttest rename to test/rules/no-eval/test.ts.linttest diff --git a/test/ruleTests/no-eval/tslint.json b/test/rules/no-eval/tslint.json similarity index 100% rename from test/ruleTests/no-eval/tslint.json rename to test/rules/no-eval/tslint.json diff --git a/test/ruleTests/no-inferrable-types/test.ts.linttest b/test/rules/no-inferrable-types/test.ts.linttest similarity index 100% rename from test/ruleTests/no-inferrable-types/test.ts.linttest rename to test/rules/no-inferrable-types/test.ts.linttest diff --git a/test/ruleTests/no-inferrable-types/tslint.json b/test/rules/no-inferrable-types/tslint.json similarity index 100% rename from test/ruleTests/no-inferrable-types/tslint.json rename to test/rules/no-inferrable-types/tslint.json diff --git a/test/ruleTests/no-internal-module/test.ts.linttest b/test/rules/no-internal-module/test.ts.linttest similarity index 100% rename from test/ruleTests/no-internal-module/test.ts.linttest rename to test/rules/no-internal-module/test.ts.linttest diff --git a/test/ruleTests/no-internal-module/tslint.json b/test/rules/no-internal-module/tslint.json similarity index 100% rename from test/ruleTests/no-internal-module/tslint.json rename to test/rules/no-internal-module/tslint.json diff --git a/test/ruleTests/no-null-keyword/test.ts.linttest b/test/rules/no-null-keyword/test.ts.linttest similarity index 100% rename from test/ruleTests/no-null-keyword/test.ts.linttest rename to test/rules/no-null-keyword/test.ts.linttest diff --git a/test/ruleTests/no-null-keyword/tslint.json b/test/rules/no-null-keyword/tslint.json similarity index 100% rename from test/ruleTests/no-null-keyword/tslint.json rename to test/rules/no-null-keyword/tslint.json diff --git a/test/ruleTests/no-require-imports/test.ts.linttest b/test/rules/no-require-imports/test.ts.linttest similarity index 100% rename from test/ruleTests/no-require-imports/test.ts.linttest rename to test/rules/no-require-imports/test.ts.linttest diff --git a/test/ruleTests/no-require-imports/tslint.json b/test/rules/no-require-imports/tslint.json similarity index 100% rename from test/ruleTests/no-require-imports/tslint.json rename to test/rules/no-require-imports/tslint.json diff --git a/test/ruleTests/no-shadowed-variable/test.ts.linttest b/test/rules/no-shadowed-variable/test.ts.linttest similarity index 100% rename from test/ruleTests/no-shadowed-variable/test.ts.linttest rename to test/rules/no-shadowed-variable/test.ts.linttest diff --git a/test/ruleTests/no-shadowed-variable/tslint.json b/test/rules/no-shadowed-variable/tslint.json similarity index 100% rename from test/ruleTests/no-shadowed-variable/tslint.json rename to test/rules/no-shadowed-variable/tslint.json diff --git a/test/ruleTests/no-string-literal/test.ts.linttest b/test/rules/no-string-literal/test.ts.linttest similarity index 100% rename from test/ruleTests/no-string-literal/test.ts.linttest rename to test/rules/no-string-literal/test.ts.linttest diff --git a/test/ruleTests/no-string-literal/tslint.json b/test/rules/no-string-literal/tslint.json similarity index 100% rename from test/ruleTests/no-string-literal/tslint.json rename to test/rules/no-string-literal/tslint.json diff --git a/test/ruleTests/no-switch-case-fall-through/test.ts.linttest b/test/rules/no-switch-case-fall-through/test.ts.linttest similarity index 100% rename from test/ruleTests/no-switch-case-fall-through/test.ts.linttest rename to test/rules/no-switch-case-fall-through/test.ts.linttest diff --git a/test/ruleTests/no-switch-case-fall-through/tslint.json b/test/rules/no-switch-case-fall-through/tslint.json similarity index 100% rename from test/ruleTests/no-switch-case-fall-through/tslint.json rename to test/rules/no-switch-case-fall-through/tslint.json diff --git a/test/ruleTests/no-trailing-whitespace/test.ts.linttest b/test/rules/no-trailing-whitespace/test.ts.linttest similarity index 100% rename from test/ruleTests/no-trailing-whitespace/test.ts.linttest rename to test/rules/no-trailing-whitespace/test.ts.linttest diff --git a/test/ruleTests/no-trailing-whitespace/tslint.json b/test/rules/no-trailing-whitespace/tslint.json similarity index 100% rename from test/ruleTests/no-trailing-whitespace/tslint.json rename to test/rules/no-trailing-whitespace/tslint.json diff --git a/test/ruleTests/no-unreachable/test.ts.linttest b/test/rules/no-unreachable/test.ts.linttest similarity index 100% rename from test/ruleTests/no-unreachable/test.ts.linttest rename to test/rules/no-unreachable/test.ts.linttest diff --git a/test/ruleTests/no-unreachable/tslint.json b/test/rules/no-unreachable/tslint.json similarity index 100% rename from test/ruleTests/no-unreachable/tslint.json rename to test/rules/no-unreachable/tslint.json diff --git a/test/ruleTests/no-unused-expression/test.ts.linttest b/test/rules/no-unused-expression/test.ts.linttest similarity index 100% rename from test/ruleTests/no-unused-expression/test.ts.linttest rename to test/rules/no-unused-expression/test.ts.linttest diff --git a/test/ruleTests/no-unused-expression/tslint.json b/test/rules/no-unused-expression/tslint.json similarity index 100% rename from test/ruleTests/no-unused-expression/tslint.json rename to test/rules/no-unused-expression/tslint.json diff --git a/test/ruleTests/no-unused-variable/check-parameters/test.ts.linttest b/test/rules/no-unused-variable/check-parameters/test.ts.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/check-parameters/test.ts.linttest rename to test/rules/no-unused-variable/check-parameters/test.ts.linttest diff --git a/test/ruleTests/no-unused-variable/check-parameters/tslint.json b/test/rules/no-unused-variable/check-parameters/tslint.json similarity index 100% rename from test/ruleTests/no-unused-variable/check-parameters/tslint.json rename to test/rules/no-unused-variable/check-parameters/tslint.json diff --git a/test/ruleTests/no-unused-variable/default/class.ts.linttest b/test/rules/no-unused-variable/default/class.ts.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/default/class.ts.linttest rename to test/rules/no-unused-variable/default/class.ts.linttest diff --git a/test/ruleTests/no-unused-variable/default/false-positives.ts.linttest b/test/rules/no-unused-variable/default/false-positives.ts.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/default/false-positives.ts.linttest rename to test/rules/no-unused-variable/default/false-positives.ts.linttest diff --git a/test/ruleTests/no-unused-variable/default/function.ts.linttest b/test/rules/no-unused-variable/default/function.ts.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/default/function.ts.linttest rename to test/rules/no-unused-variable/default/function.ts.linttest diff --git a/test/ruleTests/no-unused-variable/default/import.ts.linttest b/test/rules/no-unused-variable/default/import.ts.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/default/import.ts.linttest rename to test/rules/no-unused-variable/default/import.ts.linttest diff --git a/test/ruleTests/no-unused-variable/default/react-addons1.tsx.linttest b/test/rules/no-unused-variable/default/react-addons1.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/default/react-addons1.tsx.linttest rename to test/rules/no-unused-variable/default/react-addons1.tsx.linttest diff --git a/test/ruleTests/no-unused-variable/default/react-addons2.tsx.linttest b/test/rules/no-unused-variable/default/react-addons2.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/default/react-addons2.tsx.linttest rename to test/rules/no-unused-variable/default/react-addons2.tsx.linttest diff --git a/test/ruleTests/no-unused-variable/default/react-addons3.tsx.linttest b/test/rules/no-unused-variable/default/react-addons3.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/default/react-addons3.tsx.linttest rename to test/rules/no-unused-variable/default/react-addons3.tsx.linttest diff --git a/test/ruleTests/no-unused-variable/default/react1.tsx.linttest b/test/rules/no-unused-variable/default/react1.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/default/react1.tsx.linttest rename to test/rules/no-unused-variable/default/react1.tsx.linttest diff --git a/test/ruleTests/no-unused-variable/default/react2.tsx.linttest b/test/rules/no-unused-variable/default/react2.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/default/react2.tsx.linttest rename to test/rules/no-unused-variable/default/react2.tsx.linttest diff --git a/test/ruleTests/no-unused-variable/default/react3.tsx.linttest b/test/rules/no-unused-variable/default/react3.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/default/react3.tsx.linttest rename to test/rules/no-unused-variable/default/react3.tsx.linttest diff --git a/test/ruleTests/no-unused-variable/default/react4.tsx.linttest b/test/rules/no-unused-variable/default/react4.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/default/react4.tsx.linttest rename to test/rules/no-unused-variable/default/react4.tsx.linttest diff --git a/test/ruleTests/no-unused-variable/default/tslint.json b/test/rules/no-unused-variable/default/tslint.json similarity index 100% rename from test/ruleTests/no-unused-variable/default/tslint.json rename to test/rules/no-unused-variable/default/tslint.json diff --git a/test/ruleTests/no-unused-variable/default/var.ts.linttest b/test/rules/no-unused-variable/default/var.ts.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/default/var.ts.linttest rename to test/rules/no-unused-variable/default/var.ts.linttest diff --git a/test/ruleTests/no-unused-variable/react/react-addons1.tsx.linttest b/test/rules/no-unused-variable/react/react-addons1.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/react/react-addons1.tsx.linttest rename to test/rules/no-unused-variable/react/react-addons1.tsx.linttest diff --git a/test/ruleTests/no-unused-variable/react/react-addons2.tsx.linttest b/test/rules/no-unused-variable/react/react-addons2.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/react/react-addons2.tsx.linttest rename to test/rules/no-unused-variable/react/react-addons2.tsx.linttest diff --git a/test/ruleTests/no-unused-variable/react/react-addons3.tsx.linttest b/test/rules/no-unused-variable/react/react-addons3.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/react/react-addons3.tsx.linttest rename to test/rules/no-unused-variable/react/react-addons3.tsx.linttest diff --git a/test/ruleTests/no-unused-variable/react/react1.tsx.linttest b/test/rules/no-unused-variable/react/react1.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/react/react1.tsx.linttest rename to test/rules/no-unused-variable/react/react1.tsx.linttest diff --git a/test/ruleTests/no-unused-variable/react/react2.tsx.linttest b/test/rules/no-unused-variable/react/react2.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/react/react2.tsx.linttest rename to test/rules/no-unused-variable/react/react2.tsx.linttest diff --git a/test/ruleTests/no-unused-variable/react/react3.tsx.linttest b/test/rules/no-unused-variable/react/react3.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/react/react3.tsx.linttest rename to test/rules/no-unused-variable/react/react3.tsx.linttest diff --git a/test/ruleTests/no-unused-variable/react/react4.tsx.linttest b/test/rules/no-unused-variable/react/react4.tsx.linttest similarity index 100% rename from test/ruleTests/no-unused-variable/react/react4.tsx.linttest rename to test/rules/no-unused-variable/react/react4.tsx.linttest diff --git a/test/ruleTests/no-unused-variable/react/tslint.json b/test/rules/no-unused-variable/react/tslint.json similarity index 100% rename from test/ruleTests/no-unused-variable/react/tslint.json rename to test/rules/no-unused-variable/react/tslint.json diff --git a/test/ruleTests/no-use-before-declare/test.ts.linttest b/test/rules/no-use-before-declare/test.ts.linttest similarity index 100% rename from test/ruleTests/no-use-before-declare/test.ts.linttest rename to test/rules/no-use-before-declare/test.ts.linttest diff --git a/test/ruleTests/no-use-before-declare/tslint.json b/test/rules/no-use-before-declare/tslint.json similarity index 100% rename from test/ruleTests/no-use-before-declare/tslint.json rename to test/rules/no-use-before-declare/tslint.json diff --git a/test/ruleTests/no-var-keyword/test.ts.linttest b/test/rules/no-var-keyword/test.ts.linttest similarity index 100% rename from test/ruleTests/no-var-keyword/test.ts.linttest rename to test/rules/no-var-keyword/test.ts.linttest diff --git a/test/ruleTests/no-var-keyword/tslint.json b/test/rules/no-var-keyword/tslint.json similarity index 100% rename from test/ruleTests/no-var-keyword/tslint.json rename to test/rules/no-var-keyword/tslint.json diff --git a/test/ruleTests/no-var-requires/test.ts.linttest b/test/rules/no-var-requires/test.ts.linttest similarity index 100% rename from test/ruleTests/no-var-requires/test.ts.linttest rename to test/rules/no-var-requires/test.ts.linttest diff --git a/test/ruleTests/no-var-requires/tslint.json b/test/rules/no-var-requires/tslint.json similarity index 100% rename from test/ruleTests/no-var-requires/tslint.json rename to test/rules/no-var-requires/tslint.json diff --git a/test/ruleTests/object-literal-sort-keys/test.ts.linttest b/test/rules/object-literal-sort-keys/test.ts.linttest similarity index 100% rename from test/ruleTests/object-literal-sort-keys/test.ts.linttest rename to test/rules/object-literal-sort-keys/test.ts.linttest diff --git a/test/ruleTests/object-literal-sort-keys/tslint.json b/test/rules/object-literal-sort-keys/tslint.json similarity index 100% rename from test/ruleTests/object-literal-sort-keys/tslint.json rename to test/rules/object-literal-sort-keys/tslint.json diff --git a/test/ruleTests/one-line/all/test.ts.linttest b/test/rules/one-line/all/test.ts.linttest similarity index 100% rename from test/ruleTests/one-line/all/test.ts.linttest rename to test/rules/one-line/all/test.ts.linttest diff --git a/test/ruleTests/one-line/all/tslint.json b/test/rules/one-line/all/tslint.json similarity index 100% rename from test/ruleTests/one-line/all/tslint.json rename to test/rules/one-line/all/tslint.json diff --git a/test/ruleTests/one-line/none/test.ts.linttest b/test/rules/one-line/none/test.ts.linttest similarity index 100% rename from test/ruleTests/one-line/none/test.ts.linttest rename to test/rules/one-line/none/test.ts.linttest diff --git a/test/ruleTests/one-line/none/tslint.json b/test/rules/one-line/none/tslint.json similarity index 100% rename from test/ruleTests/one-line/none/tslint.json rename to test/rules/one-line/none/tslint.json diff --git a/test/ruleTests/quotemark/double-avoid-escape/test.ts.linttest b/test/rules/quotemark/double-avoid-escape/test.ts.linttest similarity index 100% rename from test/ruleTests/quotemark/double-avoid-escape/test.ts.linttest rename to test/rules/quotemark/double-avoid-escape/test.ts.linttest diff --git a/test/ruleTests/quotemark/double-avoid-escape/tslint.json b/test/rules/quotemark/double-avoid-escape/tslint.json similarity index 100% rename from test/ruleTests/quotemark/double-avoid-escape/tslint.json rename to test/rules/quotemark/double-avoid-escape/tslint.json diff --git a/test/ruleTests/quotemark/double/test.ts.linttest b/test/rules/quotemark/double/test.ts.linttest similarity index 100% rename from test/ruleTests/quotemark/double/test.ts.linttest rename to test/rules/quotemark/double/test.ts.linttest diff --git a/test/ruleTests/quotemark/double/tslint.json b/test/rules/quotemark/double/tslint.json similarity index 100% rename from test/ruleTests/quotemark/double/tslint.json rename to test/rules/quotemark/double/tslint.json diff --git a/test/ruleTests/quotemark/single-avoid-escape/test.ts.linttest b/test/rules/quotemark/single-avoid-escape/test.ts.linttest similarity index 100% rename from test/ruleTests/quotemark/single-avoid-escape/test.ts.linttest rename to test/rules/quotemark/single-avoid-escape/test.ts.linttest diff --git a/test/ruleTests/quotemark/single-avoid-escape/tslint.json b/test/rules/quotemark/single-avoid-escape/tslint.json similarity index 100% rename from test/ruleTests/quotemark/single-avoid-escape/tslint.json rename to test/rules/quotemark/single-avoid-escape/tslint.json diff --git a/test/ruleTests/quotemark/single/test.ts.linttest b/test/rules/quotemark/single/test.ts.linttest similarity index 100% rename from test/ruleTests/quotemark/single/test.ts.linttest rename to test/rules/quotemark/single/test.ts.linttest diff --git a/test/ruleTests/quotemark/single/tslint.json b/test/rules/quotemark/single/tslint.json similarity index 100% rename from test/ruleTests/quotemark/single/tslint.json rename to test/rules/quotemark/single/tslint.json diff --git a/test/ruleTests/radix/test.ts.linttest b/test/rules/radix/test.ts.linttest similarity index 100% rename from test/ruleTests/radix/test.ts.linttest rename to test/rules/radix/test.ts.linttest diff --git a/test/ruleTests/radix/tslint.json b/test/rules/radix/tslint.json similarity index 100% rename from test/ruleTests/radix/tslint.json rename to test/rules/radix/tslint.json diff --git a/test/ruleTests/semicolon/test.ts.linttest b/test/rules/semicolon/test.ts.linttest similarity index 100% rename from test/ruleTests/semicolon/test.ts.linttest rename to test/rules/semicolon/test.ts.linttest diff --git a/test/ruleTests/semicolon/tslint.json b/test/rules/semicolon/tslint.json similarity index 100% rename from test/ruleTests/semicolon/tslint.json rename to test/rules/semicolon/tslint.json diff --git a/test/ruleTests/switch-default/test.ts.linttest b/test/rules/switch-default/test.ts.linttest similarity index 100% rename from test/ruleTests/switch-default/test.ts.linttest rename to test/rules/switch-default/test.ts.linttest diff --git a/test/ruleTests/switch-default/tslint.json b/test/rules/switch-default/tslint.json similarity index 100% rename from test/ruleTests/switch-default/tslint.json rename to test/rules/switch-default/tslint.json diff --git a/test/ruleTests/trailing-comma/multiline-always/test.ts.linttest b/test/rules/trailing-comma/multiline-always/test.ts.linttest similarity index 100% rename from test/ruleTests/trailing-comma/multiline-always/test.ts.linttest rename to test/rules/trailing-comma/multiline-always/test.ts.linttest diff --git a/test/ruleTests/trailing-comma/multiline-always/tslint.json b/test/rules/trailing-comma/multiline-always/tslint.json similarity index 100% rename from test/ruleTests/trailing-comma/multiline-always/tslint.json rename to test/rules/trailing-comma/multiline-always/tslint.json diff --git a/test/ruleTests/trailing-comma/multiline-never/test.ts.linttest b/test/rules/trailing-comma/multiline-never/test.ts.linttest similarity index 100% rename from test/ruleTests/trailing-comma/multiline-never/test.ts.linttest rename to test/rules/trailing-comma/multiline-never/test.ts.linttest diff --git a/test/ruleTests/trailing-comma/multiline-never/tslint.json b/test/rules/trailing-comma/multiline-never/tslint.json similarity index 100% rename from test/ruleTests/trailing-comma/multiline-never/tslint.json rename to test/rules/trailing-comma/multiline-never/tslint.json diff --git a/test/ruleTests/trailing-comma/singleline-always/test.ts.linttest b/test/rules/trailing-comma/singleline-always/test.ts.linttest similarity index 100% rename from test/ruleTests/trailing-comma/singleline-always/test.ts.linttest rename to test/rules/trailing-comma/singleline-always/test.ts.linttest diff --git a/test/ruleTests/trailing-comma/singleline-always/tslint.json b/test/rules/trailing-comma/singleline-always/tslint.json similarity index 100% rename from test/ruleTests/trailing-comma/singleline-always/tslint.json rename to test/rules/trailing-comma/singleline-always/tslint.json diff --git a/test/ruleTests/trailing-comma/singleline-never/test.ts.linttest b/test/rules/trailing-comma/singleline-never/test.ts.linttest similarity index 100% rename from test/ruleTests/trailing-comma/singleline-never/test.ts.linttest rename to test/rules/trailing-comma/singleline-never/test.ts.linttest diff --git a/test/ruleTests/trailing-comma/singleline-never/tslint.json b/test/rules/trailing-comma/singleline-never/tslint.json similarity index 100% rename from test/ruleTests/trailing-comma/singleline-never/tslint.json rename to test/rules/trailing-comma/singleline-never/tslint.json diff --git a/test/ruleTests/triple-equals/test.ts.linttest b/test/rules/triple-equals/test.ts.linttest similarity index 100% rename from test/ruleTests/triple-equals/test.ts.linttest rename to test/rules/triple-equals/test.ts.linttest diff --git a/test/ruleTests/triple-equals/tslint.json b/test/rules/triple-equals/tslint.json similarity index 100% rename from test/ruleTests/triple-equals/tslint.json rename to test/rules/triple-equals/tslint.json diff --git a/test/ruleTests/typedef-whitespace/none/test.ts.linttest b/test/rules/typedef-whitespace/none/test.ts.linttest similarity index 100% rename from test/ruleTests/typedef-whitespace/none/test.ts.linttest rename to test/rules/typedef-whitespace/none/test.ts.linttest diff --git a/test/ruleTests/typedef-whitespace/none/tslint.json b/test/rules/typedef-whitespace/none/tslint.json similarity index 100% rename from test/ruleTests/typedef-whitespace/none/tslint.json rename to test/rules/typedef-whitespace/none/tslint.json diff --git a/test/ruleTests/typedef-whitespace/nospace/test.ts.linttest b/test/rules/typedef-whitespace/nospace/test.ts.linttest similarity index 100% rename from test/ruleTests/typedef-whitespace/nospace/test.ts.linttest rename to test/rules/typedef-whitespace/nospace/test.ts.linttest diff --git a/test/ruleTests/typedef-whitespace/nospace/tslint.json b/test/rules/typedef-whitespace/nospace/tslint.json similarity index 100% rename from test/ruleTests/typedef-whitespace/nospace/tslint.json rename to test/rules/typedef-whitespace/nospace/tslint.json diff --git a/test/ruleTests/typedef-whitespace/space/test.ts.linttest b/test/rules/typedef-whitespace/space/test.ts.linttest similarity index 100% rename from test/ruleTests/typedef-whitespace/space/test.ts.linttest rename to test/rules/typedef-whitespace/space/test.ts.linttest diff --git a/test/ruleTests/typedef-whitespace/space/tslint.json b/test/rules/typedef-whitespace/space/tslint.json similarity index 100% rename from test/ruleTests/typedef-whitespace/space/tslint.json rename to test/rules/typedef-whitespace/space/tslint.json diff --git a/test/ruleTests/typedef/all/test.ts.linttest b/test/rules/typedef/all/test.ts.linttest similarity index 100% rename from test/ruleTests/typedef/all/test.ts.linttest rename to test/rules/typedef/all/test.ts.linttest diff --git a/test/ruleTests/typedef/all/tslint.json b/test/rules/typedef/all/tslint.json similarity index 100% rename from test/ruleTests/typedef/all/tslint.json rename to test/rules/typedef/all/tslint.json diff --git a/test/ruleTests/typedef/none/test.ts.linttest b/test/rules/typedef/none/test.ts.linttest similarity index 100% rename from test/ruleTests/typedef/none/test.ts.linttest rename to test/rules/typedef/none/test.ts.linttest diff --git a/test/ruleTests/typedef/none/tslint.json b/test/rules/typedef/none/tslint.json similarity index 100% rename from test/ruleTests/typedef/none/tslint.json rename to test/rules/typedef/none/tslint.json diff --git a/test/ruleTests/use-strict/test.ts.linttest b/test/rules/use-strict/test.ts.linttest similarity index 100% rename from test/ruleTests/use-strict/test.ts.linttest rename to test/rules/use-strict/test.ts.linttest diff --git a/test/ruleTests/use-strict/tslint.json b/test/rules/use-strict/tslint.json similarity index 100% rename from test/ruleTests/use-strict/tslint.json rename to test/rules/use-strict/tslint.json diff --git a/test/ruleTests/variable-name/allow-leading-trailing-underscore/test.ts.linttest b/test/rules/variable-name/allow-leading-trailing-underscore/test.ts.linttest similarity index 100% rename from test/ruleTests/variable-name/allow-leading-trailing-underscore/test.ts.linttest rename to test/rules/variable-name/allow-leading-trailing-underscore/test.ts.linttest diff --git a/test/ruleTests/variable-name/allow-leading-trailing-underscore/tslint.json b/test/rules/variable-name/allow-leading-trailing-underscore/tslint.json similarity index 100% rename from test/ruleTests/variable-name/allow-leading-trailing-underscore/tslint.json rename to test/rules/variable-name/allow-leading-trailing-underscore/tslint.json diff --git a/test/ruleTests/variable-name/allow-leading-underscore/test.ts.linttest b/test/rules/variable-name/allow-leading-underscore/test.ts.linttest similarity index 100% rename from test/ruleTests/variable-name/allow-leading-underscore/test.ts.linttest rename to test/rules/variable-name/allow-leading-underscore/test.ts.linttest diff --git a/test/ruleTests/variable-name/allow-leading-underscore/tslint.json b/test/rules/variable-name/allow-leading-underscore/tslint.json similarity index 100% rename from test/ruleTests/variable-name/allow-leading-underscore/tslint.json rename to test/rules/variable-name/allow-leading-underscore/tslint.json diff --git a/test/ruleTests/variable-name/allow-trailing-underscore/test.ts.linttest b/test/rules/variable-name/allow-trailing-underscore/test.ts.linttest similarity index 100% rename from test/ruleTests/variable-name/allow-trailing-underscore/test.ts.linttest rename to test/rules/variable-name/allow-trailing-underscore/test.ts.linttest diff --git a/test/ruleTests/variable-name/allow-trailing-underscore/tslint.json b/test/rules/variable-name/allow-trailing-underscore/tslint.json similarity index 100% rename from test/ruleTests/variable-name/allow-trailing-underscore/tslint.json rename to test/rules/variable-name/allow-trailing-underscore/tslint.json diff --git a/test/ruleTests/variable-name/ban-keywords/test.ts.linttest b/test/rules/variable-name/ban-keywords/test.ts.linttest similarity index 100% rename from test/ruleTests/variable-name/ban-keywords/test.ts.linttest rename to test/rules/variable-name/ban-keywords/test.ts.linttest diff --git a/test/ruleTests/variable-name/ban-keywords/tslint.json b/test/rules/variable-name/ban-keywords/tslint.json similarity index 100% rename from test/ruleTests/variable-name/ban-keywords/tslint.json rename to test/rules/variable-name/ban-keywords/tslint.json diff --git a/test/ruleTests/variable-name/default/test.ts.linttest b/test/rules/variable-name/default/test.ts.linttest similarity index 100% rename from test/ruleTests/variable-name/default/test.ts.linttest rename to test/rules/variable-name/default/test.ts.linttest diff --git a/test/ruleTests/variable-name/default/tslint.json b/test/rules/variable-name/default/tslint.json similarity index 100% rename from test/ruleTests/variable-name/default/tslint.json rename to test/rules/variable-name/default/tslint.json diff --git a/test/ruleTests/whitespace/all/test.ts.linttest b/test/rules/whitespace/all/test.ts.linttest similarity index 100% rename from test/ruleTests/whitespace/all/test.ts.linttest rename to test/rules/whitespace/all/test.ts.linttest diff --git a/test/ruleTests/whitespace/all/tslint.json b/test/rules/whitespace/all/tslint.json similarity index 100% rename from test/ruleTests/whitespace/all/tslint.json rename to test/rules/whitespace/all/tslint.json diff --git a/test/ruleTests/whitespace/none/test.ts.linttest b/test/rules/whitespace/none/test.ts.linttest similarity index 100% rename from test/ruleTests/whitespace/none/test.ts.linttest rename to test/rules/whitespace/none/test.ts.linttest diff --git a/test/ruleTests/whitespace/none/tslint.json b/test/rules/whitespace/none/tslint.json similarity index 100% rename from test/ruleTests/whitespace/none/tslint.json rename to test/rules/whitespace/none/tslint.json diff --git a/test/tsconfig.json b/test/tsconfig.json index 520414288cc..2158bb4386f 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -15,9 +15,8 @@ "./typings/**/*.d.ts", "../src/**/*.ts", "./*.ts", - "./ruleTestRunner/*.ts", + "./ruleTestRunner/**/*.ts", "./ruleTestRunnerTests/*.ts", - "./rules/*.ts", "./formatters/*.ts" ], "files": [ @@ -114,21 +113,20 @@ "../src/tslint-cli.ts", "../src/tslint.ts", "assert.ts", + "eofLineRuleTests.ts", "lint.ts", "ruleDisableEnableTests.ts", "ruleLoaderTests.ts", - "ruleTestRunner.ts", - "tsxTests.ts", "utils.ts", - "ruleTestRunner/lines.ts", - "ruleTestRunner/parse.ts", - "ruleTestRunner/types.ts", - "ruleTestRunner/utils.ts", + "ruleTestRunner/modules/lines.ts", + "ruleTestRunner/modules/parse.ts", + "ruleTestRunner/modules/types.ts", + "ruleTestRunner/modules/utils.ts", + "ruleTestRunner/ruleTestRunner.ts", "ruleTestRunnerTests/linesTests.ts", "ruleTestRunnerTests/parseTests.ts", "ruleTestRunnerTests/testData.ts", "ruleTestRunnerTests/utilsTests.ts", - "rules/eofLineRuleTests.ts", "formatters/externalFormatterTest.ts", "formatters/jsonFormatterTests.ts", "formatters/pmdFormatterTests.ts", diff --git a/test/tsxTests.ts b/test/tsxTests.ts deleted file mode 100644 index e7ae941115e..00000000000 --- a/test/tsxTests.ts +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {ILinterOptions, Linter, LintResult, RuleFailure, TestUtils} from "./lint"; - -describe("TSX syntax", () => { - const fs = require("fs"); - const path = require("path"); - const fileName = "react.test.tsx"; - - it("doesn't blow up linter", () => { - const validConfiguration = {}; - const lintResult = runLinterWithConfiguration(validConfiguration); - const parsedResult = JSON.parse(lintResult.output); - - assert.lengthOf(parsedResult, 0); - }); - - describe("catches common lint failures", () => { - const lintResult = runLinterWithConfiguration({ - rules: { - "curly": true, - "eofline": true, - "indent": [true, "spaces"], - "max-line-length": true, - "no-bitwise": true, - "no-unreachable": true, - "no-unused-expression": true, - "no-unused-variable": true, - "no-use-before-declare": true, - "quotemark": [true, "double"], - "semicolon": true, - "whitespace": [true, - "check-branch", - "check-decl", - "check-operator", - "check-module", - "check-separator", - "check-type", - "check-typecast" - ] - } - }); - const parsedResult = JSON.parse(lintResult.output); - const actualFailures: RuleFailure[] = []; - for (let failure of parsedResult) { - const startArray = [failure.startPosition.line + 1, failure.startPosition.character + 1]; - const endArray = [failure.endPosition.line + 1, failure.endPosition.character + 1]; - actualFailures.push(TestUtils.createFailure(`tsx/${fileName}`, startArray, endArray, failure.failure)); - } - - it("", () => { - const IndentRule = TestUtils.getRule("indent"); - const indentFailure = TestUtils.createFailuresOnFile(`tsx/${fileName}`, IndentRule.FAILURE_STRING_SPACES); - - TestUtils.assertContainsFailure(actualFailures, indentFailure([31, 1], [31, 2])); - }); - - it("", () => { - const QuotemarkRule = TestUtils.getRule("quotemark"); - const quotemarkFailure = TestUtils.createFailuresOnFile(`tsx/${fileName}`, QuotemarkRule.DOUBLE_QUOTE_FAILURE); - - TestUtils.assertContainsFailure(actualFailures, quotemarkFailure([1, 24], [1, 31])); - }); - - it("", () => { - const WhitespaceRule = TestUtils.getRule("whitespace"); - const whitespaceFailure = TestUtils.createFailuresOnFile(`tsx/${fileName}`, WhitespaceRule.FAILURE_STRING); - - TestUtils.assertContainsFailure(actualFailures, whitespaceFailure([16, 9], [16, 10])); - }); - - it("with no false positives", () => { - assert.lengthOf(actualFailures, 3); - }); - }); - - function runLinterWithConfiguration(config: any): LintResult { - const relativePath = path.join("test", "files", "tsx", fileName); - const source = fs.readFileSync(relativePath, "utf8"); - const options: ILinterOptions = { - configuration: config, - formatter: "json", - formattersDirectory: null, - rulesDirectory: null - }; - const ll = new Linter(relativePath, source, options); - return ll.lint(); - } -}); From 7683ca5067c2b5ac0c4b6af6dcbfe551b6fd5531 Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Mon, 4 Jan 2016 14:08:21 -0500 Subject: [PATCH 23/30] Move rule test code over to src/ from test/ This lets us add a --test command that people can use to test custom rules if they wish --- Gruntfile.js | 2 +- package.json | 4 +- src/lint.ts | 2 + src/test.ts | 97 +++++++++++++++++ .../modules => src/test}/lines.ts | 0 .../modules => src/test}/parse.ts | 0 .../modules => src/test}/types.ts | 0 .../modules => src/test}/utils.ts | 0 src/tsconfig.json | 3 + src/tslint-cli.ts | 12 ++- test/check-bin.sh | 7 ++ .../incorrect-rule-test/test.ts.linttest | 10 ++ test/files/incorrect-rule-test/tslint.json | 5 + .../linesTests.ts | 2 +- .../parseTests.ts | 2 +- .../testData.ts | 2 +- .../utilsTests.ts | 2 +- test/ruleTestRunner.ts | 39 +++++++ test/ruleTestRunner/ruleTestRunner.ts | 102 ------------------ test/tsconfig.json | 30 +++--- test/tsd.json | 6 -- tsd.json | 6 ++ {test/typings => typings}/colors/colors.d.ts | 0 {test/typings => typings}/diff/diff.d.ts | 0 typings/optimist/optimist.d.ts | 2 +- 25 files changed, 203 insertions(+), 132 deletions(-) create mode 100644 src/test.ts rename {test/ruleTestRunner/modules => src/test}/lines.ts (100%) rename {test/ruleTestRunner/modules => src/test}/parse.ts (100%) rename {test/ruleTestRunner/modules => src/test}/types.ts (100%) rename {test/ruleTestRunner/modules => src/test}/utils.ts (100%) create mode 100644 test/files/incorrect-rule-test/test.ts.linttest create mode 100644 test/files/incorrect-rule-test/tslint.json rename test/{ruleTestRunnerTests => rule-tester}/linesTests.ts (97%) rename test/{ruleTestRunnerTests => rule-tester}/parseTests.ts (98%) rename test/{ruleTestRunnerTests => rule-tester}/testData.ts (98%) rename test/{ruleTestRunnerTests => rule-tester}/utilsTests.ts (94%) create mode 100644 test/ruleTestRunner.ts delete mode 100644 test/ruleTestRunner/ruleTestRunner.ts rename {test/typings => typings}/colors/colors.d.ts (100%) rename {test/typings => typings}/diff/diff.d.ts (100%) diff --git a/Gruntfile.js b/Gruntfile.js index cc9fbc9487d..377e62aa670 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -31,7 +31,7 @@ module.exports = function (grunt) { exec: "./test/check-bin.sh" }, testRules: { - exec: "node ./build/test/ruleTestRunner/ruleTestRunner.js" + exec: "node ./build/test/ruleTestRunner.js" } }, diff --git a/package.json b/package.json index c4666467cd7..894d70468dd 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,8 @@ "test": "grunt" }, "dependencies": { + "colors": "^1.1.2", + "diff": "^2.2.1", "findup-sync": "~0.2.1", "glob": "^6.0.1", "optimist": "~0.6.0", @@ -27,8 +29,6 @@ }, "devDependencies": { "chai": "^3.0.0", - "colors": "^1.1.2", - "diff": "^2.2.1", "grunt": "^0.4.5", "grunt-cli": "^0.1.9", "grunt-contrib-clean": "^0.6.0", diff --git a/src/lint.ts b/src/lint.ts index f96e1af340c..b50d31e8ee3 100644 --- a/src/lint.ts +++ b/src/lint.ts @@ -19,6 +19,7 @@ import * as configuration from "./configuration"; import * as formatters from "./formatters"; import * as linter from "./tslint"; import * as rules from "./rules"; +import * as test from "./test"; import {RuleFailure} from "./language/rule/rule"; export * from "./language/rule/rule"; @@ -34,6 +35,7 @@ export var Configuration = configuration; export var Formatters = formatters; export var Linter = linter; export var Rules = rules; +export var Test = test; export interface LintResult { failureCount: number; diff --git a/src/test.ts b/src/test.ts new file mode 100644 index 00000000000..80f55e94f01 --- /dev/null +++ b/src/test.ts @@ -0,0 +1,97 @@ +import * as colors from "colors"; +import * as diff from "diff"; +import * as fs from "fs"; +import * as glob from "glob"; +import * as path from "path"; + +import * as Linter from "./tslint"; +import * as parse from "./test/parse"; +import {LintError, FILE_EXTENSION} from "./test/types"; + +export interface TestResult { + directory: string; + results: { + [fileName: string]: { + errorsFromMarkup: LintError[]; + errorsFromLinter: LintError[]; + markupFromLinter: string; + markupFromMarkup: string; + } + }; +} + +export function runTest(testDirectory: string): TestResult { + const filesToLint = glob.sync(path.join(testDirectory, `**/*${FILE_EXTENSION}`)); + const tslintConfig = JSON.parse(fs.readFileSync(path.join(testDirectory, "tslint.json"), "utf8")); + const results: TestResult = { directory: testDirectory, results: {} }; + + for (const fileToLint of filesToLint) { + const fileBasename = path.basename(fileToLint, ".linttest"); + const fileText = fs.readFileSync(fileToLint, "utf8"); + const fileTextWithoutMarkup = parse.removeErrorMarkup(fileText); + const errorsFromMarkup = parse.parseErrorsFromMarkup(fileText); + + const lintOptions = { + configuration: tslintConfig, + formatter: "prose", + formattersDirectory: "", + rulesDirectory: "", + }; + const linter = new Linter(fileBasename, fileTextWithoutMarkup, lintOptions); + const errorsFromLinter: LintError[] = linter.lint().failures.map((failure) => { + const startLineAndCharacter = failure.getStartPosition().getLineAndCharacter(); + const endLineAndCharacter = failure.getEndPosition().getLineAndCharacter(); + + return { + endPos: { col: endLineAndCharacter.character, line: endLineAndCharacter.line }, + message: failure.getFailure(), + startPos: { col: startLineAndCharacter.character, line: startLineAndCharacter.line }, + }; + }); + + results.results[fileToLint] = { + errorsFromMarkup, + errorsFromLinter, + markupFromLinter: parse.createMarkupFromErrors(fileTextWithoutMarkup, errorsFromMarkup), + markupFromMarkup: parse.createMarkupFromErrors(fileTextWithoutMarkup, errorsFromLinter), + }; + } + + return results; +} + +export function consoleTestResultHandler(testResult: TestResult): boolean { + let didAllTestsPass = true; + + for (const fileName of Object.keys(testResult.results)) { + const results = testResult.results[fileName]; + process.stdout.write(`${fileName}:`); + + const diffResults = diff.diffLines(results.markupFromMarkup, results.markupFromLinter); + const didTestPass = !diffResults.some((diff) => diff.added || diff.removed); + + if (didTestPass) { + console.log(colors.green(" Passed")); + } else { + console.log(colors.red(" Failed!")); + console.log(colors.red("Expected (from .linttest file)")); + console.log(colors.green("Actual (from TSLint)")); + + didAllTestsPass = false; + + for (const diffResult of diffResults) { + let text: string; + if (diffResult.added) { + text = colors.green(diffResult.value); + } else if (diffResult.removed) { + text = colors.red(diffResult.value); + } else { + text = colors.gray(diffResult.value); + } + process.stdout.write(text); + } + } + } + + return didAllTestsPass; +} diff --git a/test/ruleTestRunner/modules/lines.ts b/src/test/lines.ts similarity index 100% rename from test/ruleTestRunner/modules/lines.ts rename to src/test/lines.ts diff --git a/test/ruleTestRunner/modules/parse.ts b/src/test/parse.ts similarity index 100% rename from test/ruleTestRunner/modules/parse.ts rename to src/test/parse.ts diff --git a/test/ruleTestRunner/modules/types.ts b/src/test/types.ts similarity index 100% rename from test/ruleTestRunner/modules/types.ts rename to src/test/types.ts diff --git a/test/ruleTestRunner/modules/utils.ts b/src/test/utils.ts similarity index 100% rename from test/ruleTestRunner/modules/utils.ts rename to src/test/utils.ts diff --git a/src/tsconfig.json b/src/tsconfig.json index e3534ad5e84..3ce382e5e0d 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -19,6 +19,8 @@ "./rules/**/*.ts" ], "files": [ + "../typings/colors/colors.d.ts", + "../typings/diff/diff.d.ts", "../typings/findup-sync/findup-sync.d.ts", "../typings/glob/glob.d.ts", "../typings/minimatch/minimatch.d.ts", @@ -33,6 +35,7 @@ "lint.ts", "ruleLoader.ts", "rules.ts", + "test.ts", "tslint-cli.ts", "tslint.ts", "formatters/index.ts", diff --git a/src/tslint-cli.ts b/src/tslint-cli.ts index 285ea69726d..297bd732418 100644 --- a/src/tslint-cli.ts +++ b/src/tslint-cli.ts @@ -20,12 +20,13 @@ import * as glob from "glob"; import * as optimist from "optimist"; import * as Linter from "./tslint"; import {CONFIG_FILENAME, DEFAULT_CONFIG, getRulesDirectories} from "./configuration"; +import {consoleTestResultHandler, runTest} from "./test"; let processed = optimist .usage("Usage: $0 [options] [file ...]") .check((argv: any) => { // at least one of file, help, version or unqualified argument must be present - if (!(argv.h || argv.i || argv.v || argv._.length > 0)) { + if (!(argv.h || argv.i || argv.test || argv.v || argv._.length > 0)) { throw "Missing files"; } @@ -63,6 +64,9 @@ let processed = optimist default: "prose", describe: "output format (prose, json, verbose)" }, + "test": { + describe: "test that the desired output is produced by tslint" + }, "v": { alias: "version", describe: "current version" @@ -96,6 +100,12 @@ if (argv.i != null) { process.exit(0); } +if (argv.test != null) { + const results = runTest(argv.test); + const didAllTestsPass = consoleTestResultHandler(results); + process.exit(didAllTestsPass ? 0 : 1); +} + if ("help" in argv) { outputStream.write(processed.help()); const outputString = ` diff --git a/test/check-bin.sh b/test/check-bin.sh index 7615e014b9b..5c70da1e252 100755 --- a/test/check-bin.sh +++ b/test/check-bin.sh @@ -61,6 +61,13 @@ expectOut $? 1 "tslint with --init flag did not exit correctly when tslint.json rm tslint.json cd .. +# end tslint --init tests + +./bin/tslint --test test/rules/no-eval +expectOut $? 0 "tslint --test did not exit correctly for a passing test" + +./bin/tslint --test test/files/incorrect-rule-test +expectOut $? 1 "tslint --test did not exit correctly for a failing test" if [ $num_failures != 0 ]; then echo "Failed $num_failures tests" diff --git a/test/files/incorrect-rule-test/test.ts.linttest b/test/files/incorrect-rule-test/test.ts.linttest new file mode 100644 index 00000000000..b11b3ed8e9e --- /dev/null +++ b/test/files/incorrect-rule-test/test.ts.linttest @@ -0,0 +1,10 @@ +var testVariable = "eval"; + +function a() { + function b() { + function c() { + eval("console.log('hi');"); + ~~~~~~~ [wrong error location and message] + } + } +} diff --git a/test/files/incorrect-rule-test/tslint.json b/test/files/incorrect-rule-test/tslint.json new file mode 100644 index 00000000000..1f0ba96f559 --- /dev/null +++ b/test/files/incorrect-rule-test/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-eval": true + } +} diff --git a/test/ruleTestRunnerTests/linesTests.ts b/test/rule-tester/linesTests.ts similarity index 97% rename from test/ruleTestRunnerTests/linesTests.ts rename to test/rule-tester/linesTests.ts index dd8b17799cd..79e0bdce114 100644 --- a/test/ruleTestRunnerTests/linesTests.ts +++ b/test/rule-tester/linesTests.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import * as lines from "../ruleTestRunner/modules/lines"; +import * as lines from "../../src/test/lines"; describe("Rule Test Runner", () => { describe("lines", () => { diff --git a/test/ruleTestRunnerTests/parseTests.ts b/test/rule-tester/parseTests.ts similarity index 98% rename from test/ruleTestRunnerTests/parseTests.ts rename to test/rule-tester/parseTests.ts index a900b312d68..b0845d4aefa 100644 --- a/test/ruleTestRunnerTests/parseTests.ts +++ b/test/rule-tester/parseTests.ts @@ -15,7 +15,7 @@ */ import * as testData from "./testData"; -import * as parse from "../ruleTestRunner/modules/parse"; +import * as parse from "../../src/test/parse"; describe("Rule Test Runner", () => { describe("parse", () => { diff --git a/test/ruleTestRunnerTests/testData.ts b/test/rule-tester/testData.ts similarity index 98% rename from test/ruleTestRunnerTests/testData.ts rename to test/rule-tester/testData.ts index 255c3a395e2..4da731aa4de 100644 --- a/test/ruleTestRunnerTests/testData.ts +++ b/test/rule-tester/testData.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import {LintError} from "../ruleTestRunner/modules/types"; +import {LintError} from "../../src/test/types"; /* tslint:disable:object-literal-sort-keys */ diff --git a/test/ruleTestRunnerTests/utilsTests.ts b/test/rule-tester/utilsTests.ts similarity index 94% rename from test/ruleTestRunnerTests/utilsTests.ts rename to test/rule-tester/utilsTests.ts index ed4d66e227f..21b032a91d6 100644 --- a/test/ruleTestRunnerTests/utilsTests.ts +++ b/test/rule-tester/utilsTests.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import * as utils from "../ruleTestRunner/modules/utils"; +import * as utils from "../../src/test/utils"; describe("Rule Test Runner", () => { describe("utils", () => { diff --git a/test/ruleTestRunner.ts b/test/ruleTestRunner.ts new file mode 100644 index 00000000000..69a35ec151f --- /dev/null +++ b/test/ruleTestRunner.ts @@ -0,0 +1,39 @@ +/* + * 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 colors from "colors"; +import * as glob from "glob"; +import * as path from "path"; + +import {runTest, consoleTestResultHandler} from "../src/test"; + +// needed to get colors to show up when passing through Grunt +(colors as any).enabled = true; + +console.log(); +console.log(colors.underline("Testing Lint Rules:")); + +const testDirectories = glob.sync("test/rules/**/tslint.json").map(path.dirname); + +for (const testDirectory of testDirectories) { + const results = runTest(testDirectory); + const didAllTestsPass = consoleTestResultHandler(results); + if (!didAllTestsPass) { + process.exit(1); + } +} + +process.exit(0); diff --git a/test/ruleTestRunner/ruleTestRunner.ts b/test/ruleTestRunner/ruleTestRunner.ts deleted file mode 100644 index ace15cd2a98..00000000000 --- a/test/ruleTestRunner/ruleTestRunner.ts +++ /dev/null @@ -1,102 +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 diff from "diff"; -import * as colors from "colors"; -import * as fs from "fs"; -import * as glob from "glob"; -import * as path from "path"; - -import * as Linter from "../../src/tslint"; -import * as parse from "./modules/parse"; -import {LintError, FILE_EXTENSION} from "./modules/types"; - -// needed to get colors to show up when passing through Grunt -(colors as any).enabled = true; - -console.log(); -console.log(colors.underline("Testing Lint Rules:")); - -let hadTestFailure = false; -const testDirectories = glob.sync("test/rules/**/tslint.json").map(path.dirname); - -for (const testDirectory of testDirectories) { - const filesToLint = glob.sync(path.join(testDirectory, `**/*${FILE_EXTENSION}`)); - const tslintConfig = JSON.parse(fs.readFileSync(path.join(testDirectory, "tslint.json"), "utf8")); - - for (const fileToLint of filesToLint) { - process.stdout.write(`${fileToLint}:`); - - const baseFilename = path.basename(fileToLint, ".linttest"); - const fileData = fs.readFileSync(fileToLint, "utf8"); - const fileDataWithoutMarkup = parse.removeErrorMarkup(fileData); - const errorsFromMarkup = parse.parseErrorsFromMarkup(fileData); - - const options = { - configuration: tslintConfig, - formatter: "prose", - formattersDirectory: "", - rulesDirectory: "", - }; - - const linter = new Linter(baseFilename, fileDataWithoutMarkup, options); - const errorsFromLinter: LintError[] = linter.lint().failures.map((failure) => { - const startCol = failure.getStartPosition().getLineAndCharacter().character; - const startLine = failure.getStartPosition().getLineAndCharacter().line; - const endCol = failure.getEndPosition().getLineAndCharacter().character; - const endLine = failure.getEndPosition().getLineAndCharacter().line; - - return { - endPos: { col: endCol, line: endLine }, - message: failure.getFailure(), - startPos: { col: startCol, line: startLine }, - }; - }); - - const markupFromMarkup = parse.createMarkupFromErrors(fileDataWithoutMarkup, errorsFromMarkup); - const markupFromLinter = parse.createMarkupFromErrors(fileDataWithoutMarkup, errorsFromLinter); - - const diffResults = diff.diffLines(markupFromMarkup, markupFromLinter); - const didTestPass = !diffResults.some((diff) => diff.added || diff.removed); - - if (didTestPass) { - console.log(colors.green(" Passed")); - } else { - console.log(colors.red(" Failed!")); - console.log(colors.red("Expected (from .linttest file)")); - console.log(colors.green("Actual (from TSLint)")); - - hadTestFailure = true; - - for (const diffResult of diffResults) { - let text: string; - if (diffResult.added) { - text = colors.green(diffResult.value); - } else if (diffResult.removed) { - text = colors.red(diffResult.value); - } else { - text = colors.gray(diffResult.value); - } - process.stdout.write(text); - } - } - - } - } - -if (hadTestFailure) { - process.exit(1); -} diff --git a/test/tsconfig.json b/test/tsconfig.json index 2158bb4386f..77f5f13a85d 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -15,11 +15,12 @@ "./typings/**/*.d.ts", "../src/**/*.ts", "./*.ts", - "./ruleTestRunner/**/*.ts", - "./ruleTestRunnerTests/*.ts", - "./formatters/*.ts" + "./formatters/*.ts", + "./rule-tester/*.ts" ], "files": [ + "../typings/colors/colors.d.ts", + "../typings/diff/diff.d.ts", "../typings/findup-sync/findup-sync.d.ts", "../typings/glob/glob.d.ts", "../typings/minimatch/minimatch.d.ts", @@ -28,8 +29,6 @@ "../typings/underscore.string/underscore.string.d.ts", "../typings/underscore/underscore.d.ts", "typings/chai/chai.d.ts", - "typings/colors/colors.d.ts", - "typings/diff/diff.d.ts", "typings/mocha/mocha.d.ts", "../src/configuration.ts", "../src/enableDisableRules.ts", @@ -110,6 +109,11 @@ "../src/rules/useStrictRule.ts", "../src/rules/variableNameRule.ts", "../src/rules/whitespaceRule.ts", + "../src/test.ts", + "../src/test/lines.ts", + "../src/test/parse.ts", + "../src/test/types.ts", + "../src/test/utils.ts", "../src/tslint-cli.ts", "../src/tslint.ts", "assert.ts", @@ -117,20 +121,16 @@ "lint.ts", "ruleDisableEnableTests.ts", "ruleLoaderTests.ts", + "ruleTestRunner.ts", "utils.ts", - "ruleTestRunner/modules/lines.ts", - "ruleTestRunner/modules/parse.ts", - "ruleTestRunner/modules/types.ts", - "ruleTestRunner/modules/utils.ts", - "ruleTestRunner/ruleTestRunner.ts", - "ruleTestRunnerTests/linesTests.ts", - "ruleTestRunnerTests/parseTests.ts", - "ruleTestRunnerTests/testData.ts", - "ruleTestRunnerTests/utilsTests.ts", "formatters/externalFormatterTest.ts", "formatters/jsonFormatterTests.ts", "formatters/pmdFormatterTests.ts", "formatters/proseFormatterTests.ts", - "formatters/verboseFormatterTests.ts" + "formatters/verboseFormatterTests.ts", + "rule-tester/linesTests.ts", + "rule-tester/parseTests.ts", + "rule-tester/testData.ts", + "rule-tester/utilsTests.ts" ] } \ No newline at end of file diff --git a/test/tsd.json b/test/tsd.json index 2ef63f7467b..7266793fd1c 100644 --- a/test/tsd.json +++ b/test/tsd.json @@ -9,12 +9,6 @@ }, "mocha/mocha.d.ts": { "commit": "aadd63ecae3feb76ea2d4be80511e266b5c2c4a7" - }, - "colors/colors.d.ts": { - "commit": "78ba6e41543e5ababbd1dda19797601be3c1f304" - }, - "diff/diff.d.ts": { - "commit": "78ba6e41543e5ababbd1dda19797601be3c1f304" } } } diff --git a/tsd.json b/tsd.json index 8101b8abd0d..f0b7d033804 100644 --- a/tsd.json +++ b/tsd.json @@ -5,6 +5,12 @@ "path": "typings", "bundle": "typings/tsd.d.ts", "installed": { + "colors/colors.d.ts": { + "commit": "78ba6e41543e5ababbd1dda19797601be3c1f304" + }, + "diff/diff.d.ts": { + "commit": "78ba6e41543e5ababbd1dda19797601be3c1f304" + }, "findup-sync/findup-sync.d.ts": { "commit": "98d3168c2c570352a3a7393788e2ec9fbb08ade6" }, diff --git a/test/typings/colors/colors.d.ts b/typings/colors/colors.d.ts similarity index 100% rename from test/typings/colors/colors.d.ts rename to typings/colors/colors.d.ts diff --git a/test/typings/diff/diff.d.ts b/typings/diff/diff.d.ts similarity index 100% rename from test/typings/diff/diff.d.ts rename to typings/diff/diff.d.ts diff --git a/typings/optimist/optimist.d.ts b/typings/optimist/optimist.d.ts index 3a32bc8d6ab..048fbd87148 100644 --- a/typings/optimist/optimist.d.ts +++ b/typings/optimist/optimist.d.ts @@ -33,7 +33,7 @@ declare module "optimist" { describe(key: string, desc: string): Optimist; - options(obj: {[key: string]: {alias: string, describe: string, default?: any}}): Optimist; + options(obj: {[key: string]: {alias?: string, describe: string, default?: any}}): Optimist; options(key: string, opt: Object): Optimist; check(fn: Function): Optimist; From 03eeef6c7fecf849645f62ff108902ea0647ab6e Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Mon, 4 Jan 2016 17:24:45 -0500 Subject: [PATCH 24/30] Try to make code a little cleaner --- src/test.ts | 12 ++-- src/test/lines.ts | 119 +++++++++++++++++------------- src/test/parse.ts | 128 +++++++++++++++++---------------- src/test/types.ts | 7 +- src/test/utils.ts | 10 --- src/tslint-cli.ts | 8 ++- test/rule-tester/linesTests.ts | 12 ++-- 7 files changed, 156 insertions(+), 140 deletions(-) diff --git a/src/test.ts b/src/test.ts index 80f55e94f01..a3b48eb1acb 100644 --- a/src/test.ts +++ b/src/test.ts @@ -6,7 +6,7 @@ import * as path from "path"; import * as Linter from "./tslint"; import * as parse from "./test/parse"; -import {LintError, FILE_EXTENSION} from "./test/types"; +import {FILE_EXTENSION, LintError} from "./test/types"; export interface TestResult { directory: string; @@ -80,15 +80,13 @@ export function consoleTestResultHandler(testResult: TestResult): boolean { didAllTestsPass = false; for (const diffResult of diffResults) { - let text: string; + let color = colors.gray; if (diffResult.added) { - text = colors.green(diffResult.value); + color = colors.green; } else if (diffResult.removed) { - text = colors.red(diffResult.value); - } else { - text = colors.gray(diffResult.value); + color = colors.red; } - process.stdout.write(text); + process.stdout.write(color(diffResult.value)); } } } diff --git a/src/test/lines.ts b/src/test/lines.ts index e67db863ac7..1b4716dfb6d 100644 --- a/src/test/lines.ts +++ b/src/test/lines.ts @@ -17,67 +17,88 @@ import {strMult} from "./utils"; // Use classes here instead of interfaces because we want runtime type data -export class CodeLine { - constructor(public contents: string) { } -} -export class MultilineErrorLine { - constructor(public startCol: number) { } -} -export class EndErrorLine { - constructor(public startCol: number, public endCol: number, public message: string) { } -} -export class MessageSubstitutionLine { - constructor(public key: string, public message: string) { } +export class Line { } +export class CodeLine extends Line { constructor(public contents: string) { super(); } } +export class MessageSubstitutionLine extends Line { constructor(public key: string, public message: string) { super(); } } + +export class ErrorLine extends Line { constructor(public startCol: number) { super(); } } +export class MultilineErrorLine extends ErrorLine { constructor(startCol: number) { super(startCol); } } +export class EndErrorLine extends ErrorLine { + constructor(startCol: number, public endCol: number, public message: string) { super(startCol); } } -export type ErrorLine = MultilineErrorLine | EndErrorLine; -export type Line = CodeLine | ErrorLine | MessageSubstitutionLine; +// example matches (between the quotes): +// " ~~~~~~~~" const multilineErrorRegex = /^\s*(~+|~nil)$/; +// " ~~~~~~~~~ [some error message]" const endErrorRegex = /^\s*(~+|~nil)\s*\[(.+)\]\s*$/; +// "[shortcut]: full messages goes here!! " const messageSubstitutionRegex = /^\[([\w\-\_]+?)]: \s*(.+?)\s*$/; -export function classifyLine(line: string): Line { - let matches: RegExpMatchArray; - /* tslint:disable:no-conditional-assignment */ - if (line.match(multilineErrorRegex)) { - // 1-based indexing for line and column numbers - const startErrorCol = line.indexOf("~"); +export const ZERO_LENGTH_ERROR = "~nil"; + +/** + * Maps a line of text from a .linttest file to an appropriate Line object + */ +export function textToLineObj(text: string): Line { + const multilineErrorMatch = text.match(multilineErrorRegex); + if (multilineErrorMatch != null) { + const startErrorCol = text.indexOf("~"); return new MultilineErrorLine(startErrorCol); - } else if (matches = line.match(endErrorRegex)) { - const [, squiggles, message] = matches; - const startErrorCol = line.indexOf("~"); - const zeroLengthError = (squiggles === "~nil"); - const endErrorCol = zeroLengthError ? startErrorCol : line.lastIndexOf("~") + 1; + } + + const endErrorMatch = text.match(endErrorRegex); + if (endErrorMatch != null) { + const [, squiggles, message] = endErrorMatch; + const startErrorCol = text.indexOf("~"); + const zeroLengthError = (squiggles === ZERO_LENGTH_ERROR); + const endErrorCol = zeroLengthError ? startErrorCol : text.lastIndexOf("~") + 1; return new EndErrorLine(startErrorCol, endErrorCol, message); - } else if (matches = line.match(messageSubstitutionRegex)) { - const [, key, message] = matches; + } + + const messageSubstitutionMatch = text.match(messageSubstitutionRegex); + if (messageSubstitutionMatch != null) { + const [, key, message] = messageSubstitutionMatch; return new MessageSubstitutionLine(key, message); - } else { - return new CodeLine(line); } - /* tslint:enable:no-conditional-assignment */ + + // line doesn't match any syntax for error markup, so it's a line of code to be linted + return new CodeLine(text); } -export function createErrorString(code: string, errorLine: ErrorLine) { - const startSpaces = strMult(" ", errorLine.startCol); - if (errorLine instanceof MultilineErrorLine) { - // special case for when the line of code is simply a newline. - // use "~nil" to indicate the error continues on that line - if (code.length === 0 && errorLine.startCol === 0) { - return "~nil"; - } +/** + * Maps an ErrorLine object to a matching line of text that could be in a .linttest file. + * This is almost the inverse of classifyLine. + * If you ran `createErrorString(classifyLine(someText))`, the whitespace in the result may be different than in someText + */ +export function lineObjToText(line: Line, code: string) { + if (line instanceof ErrorLine) { + const startSpaces = strMult(" ", 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 + if (code.length === 0 && line.startCol === 0) { + return ZERO_LENGTH_ERROR; + } - let tildes = strMult("~", code.length - startSpaces.length); - return `${startSpaces}${tildes}`; - } else if (errorLine instanceof EndErrorLine) { - let tildes = strMult("~", errorLine.endCol - errorLine.startCol); - let endSpaces = strMult(" ", code.length - errorLine.endCol); - if (tildes.length === 0) { - tildes = "~nil"; - // because we add "~nil" we need three less spaces than normal. - // always make sure we have at least one space though - endSpaces = endSpaces.substring(0, Math.max(endSpaces.length - 4, 1)); - } - return `${startSpaces}${tildes}${endSpaces} [${errorLine.message}]`; + const tildes = strMult("~", code.length - startSpaces.length); + return `${startSpaces}${tildes}`; + } else if (line instanceof EndErrorLine) { + let tildes = strMult("~", line.endCol - line.startCol); + let endSpaces = strMult(" ", 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 + // always make sure we have at least one space though + endSpaces = endSpaces.substring(0, Math.max(endSpaces.length - 4, 1)); + } + return `${startSpaces}${tildes}${endSpaces} [${line.message}]`; + } + } + else if (line instanceof MessageSubstitutionLine) { + return `[${line.key}]: ${line.message}`; + } + else if (line instanceof CodeLine) { + return line.contents; } } diff --git a/src/test/parse.ts b/src/test/parse.ts index 456c14074df..4f392f06ce6 100644 --- a/src/test/parse.ts +++ b/src/test/parse.ts @@ -14,80 +14,78 @@ * limitations under the License. */ -import {LintError, FILE_EXTENSION, errorComparator, lintSyntaxError} from "./types"; -import {ErrorLine, CodeLine, MultilineErrorLine, EndErrorLine, MessageSubstitutionLine, classifyLine, createErrorString} from "./lines"; +import {FILE_EXTENSION, LintError, errorComparator, lintSyntaxError} from "./types"; +import {Line, ErrorLine, CodeLine, MultilineErrorLine, EndErrorLine, MessageSubstitutionLine, + textToLineObj, lineObjToText} from "./lines"; +/** + * Takes the full text of a .linttest file and returns the contents of the file + * with all error markup removed + */ export function removeErrorMarkup(text: string): string { - const textLines = text.split("\n"); - const lines = textLines.map(classifyLine); - const codeLines = lines.filter((line) => (line instanceof CodeLine)).map((line) => (line).contents); - return codeLines.join("\n"); + const textWithMarkup = text.split("\n"); + const lines = textWithMarkup.map(textToLineObj); + const codeText = lines.filter((line) => (line instanceof CodeLine)).map((line) => (line).contents); + return codeText.join("\n"); } /* tslint:disable:object-literal-sort-keys */ +/** + * Takes the full text of a .linttest file and returns an array of LintErrors + * corresponding to the error markup in the file. + */ export function parseErrorsFromMarkup(text: string): LintError[] { - const textLines = text.split("\n"); - const classifiedLines = textLines.map(classifyLine); + const textWithMarkup = text.split("\n"); + const lines = textWithMarkup.map(textToLineObj); - if (classifiedLines.length > 0 && !(classifiedLines[0] instanceof CodeLine)) { + if (lines.length > 0 && !(lines[0] instanceof CodeLine)) { throw lintSyntaxError(`Cannot start a ${FILE_EXTENSION} file with an error mark line.`); } - const messageSubstitutionLines = classifiedLines.filter((l) => l instanceof MessageSubstitutionLine); - const messageSubstitutions = messageSubstitutionLines.reduce((obj, line) => { - obj[line.key] = line.message; - return obj; - }, {}); - - // map each actual line of code to the error markings beneath it - const errorMarkupForLinesOfCode = classifiedLines.reduce((lineMap, line) => { - if (line instanceof CodeLine) { - lineMap.push([]); - } else if (line instanceof MessageSubstitutionLine) { - // do nothing, already processed above - } else { - lineMap[lineMap.length - 1].push(line); - } - return lineMap; - }, ( [])); + const messageSubstitutionLines = lines.filter((l) => l instanceof MessageSubstitutionLine); + const messageSubstitutions: { [key: string]: string } = {}; + for (const line of messageSubstitutionLines) { + messageSubstitutions[line.key] = line.message; + } + // errorLineForCodeLine[5] contains all the ErrorLine objects associated with the 5th line of code, for example + const errorLinesForCodeLines = separateErrorLinesFromCodeLines(lines); const lintErrors: LintError[] = []; - // for each line of code... - errorMarkupForLinesOfCode.forEach((errorMarkupForLineOfCode, lineNo) => { + errorLinesForCodeLines.forEach((errorLinesForLineOfCode, lineNo) => { // for each error marking on that line... - while (errorMarkupForLineOfCode.length > 0) { - const errorMarkup = errorMarkupForLineOfCode.shift(); - const errorStartPos = { line: lineNo, col: errorMarkup.startCol }; + while (errorLinesForLineOfCode.length > 0) { + const errorLine = errorLinesForLineOfCode.shift(); + const errorStartPos = { line: lineNo, col: errorLine.startCol }; // if the error starts and ends on this line, add it now to list of errors - if (errorMarkup instanceof EndErrorLine) { + if (errorLine instanceof EndErrorLine) { lintErrors.push({ startPos: errorStartPos, - endPos: { line: lineNo, col: errorMarkup.endCol }, - message: getFullMessage(messageSubstitutions, errorMarkup.message) + endPos: { line: lineNo, col: errorLine.endCol }, + message: messageSubstitutions[errorLine.message] || errorLine.message }); // if the error is the start of a multiline error - } else if (errorMarkup instanceof MultilineErrorLine) { + } else if (errorLine instanceof MultilineErrorLine) { - // keep going until we get to the end of the multiline error + // iterate through the MultilineErrorLines until we get to an EndErrorLine for (let nextLineNo = lineNo + 1; ; ++nextLineNo) { - if (!validErrorMarkupContinuation(errorMarkupForLinesOfCode, nextLineNo)) { + if (!validErrorMarkupContinuation(errorLinesForCodeLines, nextLineNo)) { throw lintSyntaxError( `Error mark starting at ${errorStartPos.line}:${errorStartPos.col} does not end correctly.` ); } else { - const nextErrorLine = errorMarkupForLinesOfCode[nextLineNo].shift(); + const nextErrorLine = errorLinesForCodeLines[nextLineNo].shift(); // if end of multiline error, add it it list of errors if (nextErrorLine instanceof EndErrorLine) { lintErrors.push({ startPos: errorStartPos, endPos: { line: nextLineNo, col: nextErrorLine.endCol }, - message: getFullMessage(messageSubstitutions, nextErrorLine.message) + message: messageSubstitutions[nextErrorLine.message] || nextErrorLine.message }); break; } @@ -97,54 +95,62 @@ export function parseErrorsFromMarkup(text: string): LintError[] { } }); - // sort errors by startPos then endPos lintErrors.sort(errorComparator); return lintErrors; } export function createMarkupFromErrors(code: string, lintErrors: LintError[]) { - // theoretically, lint errors should be already sorted, but just to play it safe... lintErrors.sort(errorComparator); - const codeLines = code.split("\n"); - const errorMarkupForLinesOfCode: ErrorLine[][] = codeLines.map(() => []); + const codeText = code.split("\n"); + const errorLinesForCodeText: ErrorLine[][] = codeText.map(() => []); for (const error of lintErrors) { const {startPos, endPos, message} = error; if (startPos.line === endPos.line) { // single line error - errorMarkupForLinesOfCode[startPos.line].push(new EndErrorLine( + errorLinesForCodeText[startPos.line].push(new EndErrorLine( startPos.col, endPos.col, message )); } else { // multiline error - errorMarkupForLinesOfCode[startPos.line].push(new MultilineErrorLine(startPos.col)); + errorLinesForCodeText[startPos.line].push(new MultilineErrorLine(startPos.col)); for (let lineNo = startPos.line + 1; lineNo < endPos.line; ++lineNo) { - errorMarkupForLinesOfCode[lineNo].push(new MultilineErrorLine(0)); + errorLinesForCodeText[lineNo].push(new MultilineErrorLine(0)); } - errorMarkupForLinesOfCode[endPos.line].push(new EndErrorLine(0, endPos.col, message)); + errorLinesForCodeText[endPos.line].push(new EndErrorLine(0, endPos.col, message)); } } - const resultLines = codeLines.reduce((finalLines, codeLine, i) => { - finalLines.push(codeLine); - for (const errorMarkup of errorMarkupForLinesOfCode[i]) { - finalLines.push(createErrorString(codeLine, errorMarkup)); - } - return finalLines; + const finalText = combineCodeTextAndErrorLines(codeText, errorLinesForCodeText); + return finalText.join("\n"); +} +/* tslint:enable:object-literal-sort-keys */ + +function combineCodeTextAndErrorLines(codeText: string[], errorLinesForCodeText: ErrorLine[][]) { + return codeText.reduce((finalText, code, i) => { + finalText.push(code); + finalText.push(...errorLinesForCodeText[i].map((line) => lineObjToText(line, code))); + return finalText; }, []); - return resultLines.join("\n"); } -function getFullMessage(messageSubstitutions: {[k: string]: string}, message: string) { - return messageSubstitutions[message] || message; +function separateErrorLinesFromCodeLines(lines: Line[]) { + const errorLinesForCodeLine: ErrorLine[][] = []; + for (const line of lines) { + if (line instanceof CodeLine) { + errorLinesForCodeLine.push([]); + } else if (line instanceof ErrorLine) { + errorLinesForCodeLine[errorLinesForCodeLine.length - 1].push(line); + } + } + return errorLinesForCodeLine; } -function validErrorMarkupContinuation(errorMarkupForLinesOfCode: ErrorLine[][], lineNo: number) { - return lineNo < errorMarkupForLinesOfCode.length - && errorMarkupForLinesOfCode[lineNo].length !== 0 - && errorMarkupForLinesOfCode[lineNo][0].startCol === 0; +function validErrorMarkupContinuation(errorLinesForCodeLines: ErrorLine[][], lineNo: number) { + return lineNo < errorLinesForCodeLines.length + && errorLinesForCodeLines[lineNo].length !== 0 + && errorLinesForCodeLines[lineNo][0].startCol === 0; } -/* tslint:enable:object-literal-sort-keys */ diff --git a/src/test/types.ts b/src/test/types.ts index 15221ee5703..227d3a54277 100644 --- a/src/test/types.ts +++ b/src/test/types.ts @@ -23,15 +23,10 @@ export interface PositionInFile { export interface LintError { startPos: PositionInFile; - endPos?: PositionInFile; + endPos: PositionInFile; message: string; } -export interface LintFile { - contents: string; - lintErrors: LintError[]; -} - export function errorComparator(err1: LintError, err2: LintError) { if (err1.startPos.line !== err2.startPos.line) { return err1.startPos.line - err2.startPos.line; diff --git a/src/test/utils.ts b/src/test/utils.ts index ce8d5c8d6d6..98cfabe7174 100644 --- a/src/test/utils.ts +++ b/src/test/utils.ts @@ -14,16 +14,6 @@ * limitations under the License. */ -export function tempCwd(newCwd: string, callback: () => void) { - const oldCwd = process.cwd(); - process.chdir(newCwd); - try { - callback(); - } finally { - process.chdir(oldCwd); - } -} - export function strMult(str: string, numTimes: number) { return Array(numTimes + 1).join(str); } diff --git a/src/tslint-cli.ts b/src/tslint-cli.ts index 297bd732418..ccc754ac385 100644 --- a/src/tslint-cli.ts +++ b/src/tslint-cli.ts @@ -65,7 +65,7 @@ let processed = optimist describe: "output format (prose, json, verbose)" }, "test": { - describe: "test that the desired output is produced by tslint" + describe: "test that tslint produces the correct output for the specified directory" }, "v": { alias: "version", @@ -155,6 +155,12 @@ tslint accepts the following commandline options: and verbose. prose is the default if this option is not used. Additonal formatters can be added and used if the --formatters-dir option is set. + --test: + Runs tslint on the specified directory and checks if tslint's output matches + the expected output. Automatically loads the tslint.json file in the + specified directory as the configuration file for the tests. See the + full tslint documentation for more details on how this can be used to test custom rules. + -v, --version: The current version of tslint. diff --git a/test/rule-tester/linesTests.ts b/test/rule-tester/linesTests.ts index 79e0bdce114..ba15e9dbde1 100644 --- a/test/rule-tester/linesTests.ts +++ b/test/rule-tester/linesTests.ts @@ -23,24 +23,24 @@ describe("Rule Test Runner", () => { const code1 = "this is a line of code"; const errorLine1 = new lines.MultilineErrorLine(2); const errorMarkup1 = " ~~~~~~~~~~~~~~~~~~~~"; - assert.strictEqual(lines.createErrorString(code1, errorLine1), errorMarkup1); + assert.strictEqual(lines.lineObjToText(errorLine1, code1), errorMarkup1); const code2 = "another line of code here"; const errorLine2 = new lines.EndErrorLine(0, code2.length, "foo"); const errorMarkup2 = "~~~~~~~~~~~~~~~~~~~~~~~~~ [foo]"; - assert.strictEqual(lines.createErrorString(code2, errorLine2), errorMarkup2); + assert.strictEqual(lines.lineObjToText(errorLine2, code2), errorMarkup2); }); it("should correctly create strings with empty lines of code", () => { const code1 = ""; const errorLine1 = new lines.MultilineErrorLine(0); - const errorMarkup1 = "~nil"; - assert.strictEqual(lines.createErrorString(code1, errorLine1), errorMarkup1); + const errorMarkup1 = lines.ZERO_LENGTH_ERROR; + assert.strictEqual(lines.lineObjToText(errorLine1, code1), errorMarkup1); const code2 = ""; const errorLine2 = new lines.EndErrorLine(0, 0, "foo"); - const errorMarkup2 = "~nil [foo]"; - assert.strictEqual(lines.createErrorString(code2, errorLine2), errorMarkup2); + const errorMarkup2 = `${lines.ZERO_LENGTH_ERROR} [foo]`; + assert.strictEqual(lines.lineObjToText(errorLine2, code2), errorMarkup2); }); }); }); From 915c2473e7cb5eaeaf25d605237c6e3f3f782ccb Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Wed, 6 Jan 2016 11:02:42 -0500 Subject: [PATCH 25/30] Fix error message in tests after rebase on master --- test/rules/interface-name/test.ts.linttest | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/rules/interface-name/test.ts.linttest b/test/rules/interface-name/test.ts.linttest index 62ebefbe877..5904c7e823d 100644 --- a/test/rules/interface-name/test.ts.linttest +++ b/test/rules/interface-name/test.ts.linttest @@ -3,6 +3,5 @@ interface IValidInterfaceName { } interface NotValidInterfaceName { - ~~~~~~~~~~~~~~~~~~~~~ [interface name must be a capitalized I] - -} \ No newline at end of file + ~~~~~~~~~~~~~~~~~~~~~ [interface name must start with a capitalized I] +} From 73d5258d44e370ee7e56b6a3a0a040eb34ddeb93 Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Fri, 22 Jan 2016 16:59:21 -0500 Subject: [PATCH 26/30] Prepare release v3.3.0 --- CHANGELOG.md | 8 ++++++++ package.json | 2 +- src/tslint.ts | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d5d7bcf1ca..3d6bda4f7ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ Change Log === +v3.3.0 +--- +* [bugfix] Tweak TSLint build so TSLint works with typescript@next (#926) + +v3.3.0-dev.1 +--- +* [bugfix] Correctly handle more than one custom rules directory (#928) + v3.2.2 --- * Stable release containing changes from the last dev release diff --git a/package.json b/package.json index 3178d5ed050..62dad415010 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tslint", - "version": "3.2.2", + "version": "3.3.0", "description": "a static analysis linter for TypeScript", "bin": { "tslint": "./bin/tslint" diff --git a/src/tslint.ts b/src/tslint.ts index 28987b368b2..9ef97b496c7 100644 --- a/src/tslint.ts +++ b/src/tslint.ts @@ -25,7 +25,7 @@ import {ILinterOptions, LintResult} from "./lint"; import {loadRules} from "./ruleLoader"; class Linter { - public static VERSION = "3.2.2"; + public static VERSION = "3.3.0"; public static findConfiguration = config; private fileName: string; From 23057bda23f1b9a120a7388a88b272fa31c947e2 Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Mon, 25 Jan 2016 15:41:47 -0500 Subject: [PATCH 27/30] Correctly find = token for variable declarations in one-line rule. --- src/rules/oneLineRule.ts | 2 +- test/files/rules/oneline.test.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/rules/oneLineRule.ts b/src/rules/oneLineRule.ts index e9890559c9d..8605fdf65e0 100644 --- a/src/rules/oneLineRule.ts +++ b/src/rules/oneLineRule.ts @@ -127,7 +127,7 @@ class OneLineWalker extends Lint.RuleWalker { public visitVariableDeclaration(node: ts.VariableDeclaration) { const initializer = node.initializer; if (initializer != null && initializer.kind === ts.SyntaxKind.ObjectLiteralExpression) { - const equalsToken = node.getChildAt(1); + const equalsToken = node.getChildren().filter((n) => n.kind === ts.SyntaxKind.EqualsToken)[0]; const openBraceToken = initializer.getChildAt(0); this.handleOpeningBrace(equalsToken, openBraceToken); } diff --git a/test/files/rules/oneline.test.ts b/test/files/rules/oneline.test.ts index 8272feeb0d2..450de98dade 100644 --- a/test/files/rules/oneline.test.ts +++ b/test/files/rules/oneline.test.ts @@ -89,3 +89,13 @@ function longFunctionNameWithLotsOfParams( z: number, a: T) { } + +let geoConfig: { + maximumAge?: number; + timeout?: number; + enableHighAccuracy?: boolean; +} = { + maximumAge: 3000, + timeout: 5000, + enableHighAccuracy: false +}; From 447c0f985b954e16d5fc5baa5678814a7e4e1c03 Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Mon, 25 Jan 2016 17:58:15 -0500 Subject: [PATCH 28/30] CR fixes for new testing system --- Gruntfile.js | 3 +- src/test.ts | 37 +++++++-- src/test/lines.ts | 41 +++++----- src/test/{types.ts => lintError.ts} | 2 - src/test/parse.ts | 36 +++++---- src/test/utils.ts | 2 +- src/tsconfig.json | 9 ++- src/tslint-cli.ts | 2 +- test/check-bin.sh | 2 +- test/rule-tester/linesTests.ts | 44 +++++----- test/rule-tester/parseTests.ts | 80 +++++++++---------- test/rule-tester/testData.ts | 2 +- test/rule-tester/utilsTests.ts | 16 ++-- .../react/test.tsx.linttest | 0 .../react/tslint.json | 0 test/tsconfig.json | 2 +- 16 files changed, 154 insertions(+), 124 deletions(-) rename src/test/{types.ts => lintError.ts} (97%) rename test/rules/{_comprehensive => _integration}/react/test.tsx.linttest (100%) rename test/rules/{_comprehensive => _integration}/react/tslint.json (100%) diff --git a/Gruntfile.js b/Gruntfile.js index 377e62aa670..d7cfc69c307 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -53,7 +53,8 @@ module.exports = function (grunt) { "src/*.ts", "src/formatters/**/*.ts", "src/language/**/*.ts", - "src/rules/**/*.ts" + "src/rules/**/*.ts", + "src/test/**/*.ts" ], test: [ "test/**/*.ts", diff --git a/src/test.ts b/src/test.ts index a3b48eb1acb..8fcaf2539e3 100644 --- a/src/test.ts +++ b/src/test.ts @@ -1,3 +1,20 @@ +/** + * @license + * 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 colors from "colors"; import * as diff from "diff"; import * as fs from "fs"; @@ -6,7 +23,9 @@ import * as path from "path"; import * as Linter from "./tslint"; import * as parse from "./test/parse"; -import {FILE_EXTENSION, LintError} from "./test/types"; +import {LintError} from "./test/lintError"; + +const FILE_EXTENSION = ".linttest"; export interface TestResult { directory: string; @@ -26,7 +45,7 @@ export function runTest(testDirectory: string): TestResult { const results: TestResult = { directory: testDirectory, results: {} }; for (const fileToLint of filesToLint) { - const fileBasename = path.basename(fileToLint, ".linttest"); + const fileBasename = path.basename(fileToLint, FILE_EXTENSION); const fileText = fs.readFileSync(fileToLint, "utf8"); const fileTextWithoutMarkup = parse.removeErrorMarkup(fileText); const errorsFromMarkup = parse.parseErrorsFromMarkup(fileText); @@ -43,9 +62,15 @@ export function runTest(testDirectory: string): TestResult { const endLineAndCharacter = failure.getEndPosition().getLineAndCharacter(); return { - endPos: { col: endLineAndCharacter.character, line: endLineAndCharacter.line }, + endPos: { + col: endLineAndCharacter.character, + line: endLineAndCharacter.line + }, message: failure.getFailure(), - startPos: { col: startLineAndCharacter.character, line: startLineAndCharacter.line }, + startPos: { + col: startLineAndCharacter.character, + line: startLineAndCharacter.line + }, }; }); @@ -74,8 +99,8 @@ export function consoleTestResultHandler(testResult: TestResult): boolean { console.log(colors.green(" Passed")); } else { console.log(colors.red(" Failed!")); - console.log(colors.red("Expected (from .linttest file)")); - console.log(colors.green("Actual (from TSLint)")); + console.log(colors.green(`Expected (from ${FILE_EXTENSION} file)`)); + console.log(colors.red("Actual (from TSLint)")); didAllTestsPass = false; diff --git a/src/test/lines.ts b/src/test/lines.ts index 1b4716dfb6d..93fa0d143dc 100644 --- a/src/test/lines.ts +++ b/src/test/lines.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import {strMult} from "./utils"; +import {replicateStr} from "./utils"; // Use classes here instead of interfaces because we want runtime type data export class Line { } @@ -38,9 +38,9 @@ const messageSubstitutionRegex = /^\[([\w\-\_]+?)]: \s*(.+?)\s*$/; export const ZERO_LENGTH_ERROR = "~nil"; /** - * Maps a line of text from a .linttest file to an appropriate Line object + * Maps a line of text from a .lint file to an appropriate Line object */ -export function textToLineObj(text: string): Line { +export function parseLine(text: string): Line { const multilineErrorMatch = text.match(multilineErrorRegex); if (multilineErrorMatch != null) { const startErrorCol = text.indexOf("~"); @@ -67,13 +67,20 @@ export function textToLineObj(text: string): Line { } /** - * Maps an ErrorLine object to a matching line of text that could be in a .linttest file. - * This is almost the inverse of classifyLine. - * If you ran `createErrorString(classifyLine(someText))`, the whitespace in the result may be different than in someText + * Maps a Line object to a matching line of text that could be in a .lint file. + * This is almost the inverse of parseLine. + * If you ran `printLine(parseLine(someText), code)`, the whitespace in the result may be different than in someText + * @param line - A Line object to convert to text + * @param code - If line represents error markup, this is the line of code preceding the markup. + * Otherwise, this parameter is not required. */ -export function lineObjToText(line: Line, code: string) { +export function printLine(line: Line, code?: string): string { if (line instanceof ErrorLine) { - const startSpaces = strMult(" ", line.startCol); + if (code == null) { + throw new Error("Must supply argument for code parameter when line is an ErrorLine"); + } + + const leadingSpaces = replicateStr(" ", 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 @@ -81,24 +88,22 @@ export function lineObjToText(line: Line, code: string) { return ZERO_LENGTH_ERROR; } - const tildes = strMult("~", code.length - startSpaces.length); - return `${startSpaces}${tildes}`; + const tildes = replicateStr("~", code.length - leadingSpaces.length); + return `${leadingSpaces}${tildes}`; } else if (line instanceof EndErrorLine) { - let tildes = strMult("~", line.endCol - line.startCol); - let endSpaces = strMult(" ", code.length - line.endCol); + let tildes = replicateStr("~", line.endCol - line.startCol); + let endSpaces = replicateStr(" ", 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 // always make sure we have at least one space though endSpaces = endSpaces.substring(0, Math.max(endSpaces.length - 4, 1)); } - return `${startSpaces}${tildes}${endSpaces} [${line.message}]`; - } - } - else if (line instanceof MessageSubstitutionLine) { + return `${leadingSpaces}${tildes}${endSpaces} [${line.message}]`; + } + } else if (line instanceof MessageSubstitutionLine) { return `[${line.key}]: ${line.message}`; - } - else if (line instanceof CodeLine) { + } else if (line instanceof CodeLine) { return line.contents; } } diff --git a/src/test/types.ts b/src/test/lintError.ts similarity index 97% rename from src/test/types.ts rename to src/test/lintError.ts index 227d3a54277..6b04e7b080a 100644 --- a/src/test/types.ts +++ b/src/test/lintError.ts @@ -14,8 +14,6 @@ * limitations under the License. */ -export const FILE_EXTENSION = ".linttest"; - export interface PositionInFile { line: number; col: number; diff --git a/src/test/parse.ts b/src/test/parse.ts index 4f392f06ce6..4c418f08a14 100644 --- a/src/test/parse.ts +++ b/src/test/parse.ts @@ -14,32 +14,32 @@ * limitations under the License. */ -import {FILE_EXTENSION, LintError, errorComparator, lintSyntaxError} from "./types"; +import {LintError, errorComparator, lintSyntaxError} from "./lintError"; import {Line, ErrorLine, CodeLine, MultilineErrorLine, EndErrorLine, MessageSubstitutionLine, - textToLineObj, lineObjToText} from "./lines"; + parseLine, printLine} from "./lines"; /** - * Takes the full text of a .linttest file and returns the contents of the file + * Takes the full text of a .lint file and returns the contents of the file * with all error markup removed */ export function removeErrorMarkup(text: string): string { const textWithMarkup = text.split("\n"); - const lines = textWithMarkup.map(textToLineObj); + const lines = textWithMarkup.map(parseLine); const codeText = lines.filter((line) => (line instanceof CodeLine)).map((line) => (line).contents); return codeText.join("\n"); } /* tslint:disable:object-literal-sort-keys */ /** - * Takes the full text of a .linttest file and returns an array of LintErrors + * Takes the full text of a .lint file and returns an array of LintErrors * corresponding to the error markup in the file. */ export function parseErrorsFromMarkup(text: string): LintError[] { const textWithMarkup = text.split("\n"); - const lines = textWithMarkup.map(textToLineObj); + const lines = textWithMarkup.map(parseLine); if (lines.length > 0 && !(lines[0] instanceof CodeLine)) { - throw lintSyntaxError(`Cannot start a ${FILE_EXTENSION} file with an error mark line.`); + throw lintSyntaxError(`text cannot start with an error mark line.`); } const messageSubstitutionLines = lines.filter((l) => l instanceof MessageSubstitutionLine); @@ -49,7 +49,7 @@ export function parseErrorsFromMarkup(text: string): LintError[] { } // errorLineForCodeLine[5] contains all the ErrorLine objects associated with the 5th line of code, for example - const errorLinesForCodeLines = separateErrorLinesFromCodeLines(lines); + const errorLinesForCodeLines = createCodeLineNoToErrorsMap(lines); const lintErrors: LintError[] = []; // for each line of code... @@ -73,7 +73,7 @@ export function parseErrorsFromMarkup(text: string): LintError[] { // iterate through the MultilineErrorLines until we get to an EndErrorLine for (let nextLineNo = lineNo + 1; ; ++nextLineNo) { - if (!validErrorMarkupContinuation(errorLinesForCodeLines, nextLineNo)) { + if (!isValidErrorMarkupContinuation(errorLinesForCodeLines, nextLineNo)) { throw lintSyntaxError( `Error mark starting at ${errorStartPos.line}:${errorStartPos.col} does not end correctly.` ); @@ -109,13 +109,15 @@ export function createMarkupFromErrors(code: string, lintErrors: LintError[]) { for (const error of lintErrors) { const {startPos, endPos, message} = error; - if (startPos.line === endPos.line) { // single line error + if (startPos.line === endPos.line) { + // single line error errorLinesForCodeText[startPos.line].push(new EndErrorLine( startPos.col, endPos.col, message )); - } else { // multiline error + } else { + // multiline error errorLinesForCodeText[startPos.line].push(new MultilineErrorLine(startPos.col)); for (let lineNo = startPos.line + 1; lineNo < endPos.line; ++lineNo) { errorLinesForCodeText[lineNo].push(new MultilineErrorLine(0)); @@ -130,14 +132,14 @@ export function createMarkupFromErrors(code: string, lintErrors: LintError[]) { /* tslint:enable:object-literal-sort-keys */ function combineCodeTextAndErrorLines(codeText: string[], errorLinesForCodeText: ErrorLine[][]) { - return codeText.reduce((finalText, code, i) => { - finalText.push(code); - finalText.push(...errorLinesForCodeText[i].map((line) => lineObjToText(line, code))); - return finalText; + return codeText.reduce((resultText, code, i) => { + resultText.push(code); + resultText.push(...(errorLinesForCodeText[i].map((line) => printLine(line, code)))); + return resultText; }, []); } -function separateErrorLinesFromCodeLines(lines: Line[]) { +function createCodeLineNoToErrorsMap(lines: Line[]) { const errorLinesForCodeLine: ErrorLine[][] = []; for (const line of lines) { if (line instanceof CodeLine) { @@ -149,7 +151,7 @@ function separateErrorLinesFromCodeLines(lines: Line[]) { return errorLinesForCodeLine; } -function validErrorMarkupContinuation(errorLinesForCodeLines: ErrorLine[][], lineNo: number) { +function isValidErrorMarkupContinuation(errorLinesForCodeLines: ErrorLine[][], lineNo: number) { return lineNo < errorLinesForCodeLines.length && errorLinesForCodeLines[lineNo].length !== 0 && errorLinesForCodeLines[lineNo][0].startCol === 0; diff --git a/src/test/utils.ts b/src/test/utils.ts index 98cfabe7174..a7caec955fc 100644 --- a/src/test/utils.ts +++ b/src/test/utils.ts @@ -14,6 +14,6 @@ * limitations under the License. */ -export function strMult(str: string, numTimes: number) { +export function replicateStr(str: string, numTimes: number) { return Array(numTimes + 1).join(str); } diff --git a/src/tsconfig.json b/src/tsconfig.json index 3ce382e5e0d..3a94b5d738f 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -16,7 +16,8 @@ "./*.ts", "./formatters/**/*.ts", "./language/**/*.ts", - "./rules/**/*.ts" + "./rules/**/*.ts", + "./test/**/*.ts" ], "files": [ "../typings/colors/colors.d.ts", @@ -109,6 +110,10 @@ "rules/typedefWhitespaceRule.ts", "rules/useStrictRule.ts", "rules/variableNameRule.ts", - "rules/whitespaceRule.ts" + "rules/whitespaceRule.ts", + "test/lines.ts", + "test/lintError.ts", + "test/parse.ts", + "test/utils.ts" ] } \ No newline at end of file diff --git a/src/tslint-cli.ts b/src/tslint-cli.ts index 44e343111c4..cb1f2dea050 100644 --- a/src/tslint-cli.ts +++ b/src/tslint-cli.ts @@ -164,7 +164,7 @@ tslint accepts the following commandline options: --test: Runs tslint on the specified directory and checks if tslint's output matches - the expected output. Automatically loads the tslint.json file in the + the expected output in .lint files. Automatically loads the tslint.json file in the specified directory as the configuration file for the tests. See the full tslint documentation for more details on how this can be used to test custom rules. diff --git a/test/check-bin.sh b/test/check-bin.sh index 80d5c49118d..47809b03354 100755 --- a/test/check-bin.sh +++ b/test/check-bin.sh @@ -79,8 +79,8 @@ expectOut $? 1 "tslint with --init flag did not exit correctly when tslint.json rm tslint.json cd .. -# end tslint --init tests +# ensure --test command works correctly ./bin/tslint --test test/rules/no-eval expectOut $? 0 "tslint --test did not exit correctly for a passing test" diff --git a/test/rule-tester/linesTests.ts b/test/rule-tester/linesTests.ts index ba15e9dbde1..ca523a77359 100644 --- a/test/rule-tester/linesTests.ts +++ b/test/rule-tester/linesTests.ts @@ -16,32 +16,30 @@ import * as lines from "../../src/test/lines"; -describe("Rule Test Runner", () => { - describe("lines", () => { - describe("::createErrorString", () => { - it("should correctly create strings", () => { - const code1 = "this is a line of code"; - const errorLine1 = new lines.MultilineErrorLine(2); - const errorMarkup1 = " ~~~~~~~~~~~~~~~~~~~~"; - assert.strictEqual(lines.lineObjToText(errorLine1, code1), errorMarkup1); +describe("Rule Test Lines", () => { + describe("createErrorString", () => { + it("should correctly create strings", () => { + const code1 = "this is a line of code"; + const errorLine1 = new lines.MultilineErrorLine(2); + const errorMarkup1 = " ~~~~~~~~~~~~~~~~~~~~"; + assert.strictEqual(lines.printLine(errorLine1, code1), errorMarkup1); - const code2 = "another line of code here"; - const errorLine2 = new lines.EndErrorLine(0, code2.length, "foo"); - const errorMarkup2 = "~~~~~~~~~~~~~~~~~~~~~~~~~ [foo]"; - assert.strictEqual(lines.lineObjToText(errorLine2, code2), errorMarkup2); - }); + const code2 = "another line of code here"; + const errorLine2 = new lines.EndErrorLine(0, code2.length, "foo"); + const errorMarkup2 = "~~~~~~~~~~~~~~~~~~~~~~~~~ [foo]"; + assert.strictEqual(lines.printLine(errorLine2, code2), errorMarkup2); + }); - it("should correctly create strings with empty lines of code", () => { - const code1 = ""; - const errorLine1 = new lines.MultilineErrorLine(0); - const errorMarkup1 = lines.ZERO_LENGTH_ERROR; - assert.strictEqual(lines.lineObjToText(errorLine1, code1), errorMarkup1); + it("should correctly create strings with empty lines of code", () => { + const code1 = ""; + const errorLine1 = new lines.MultilineErrorLine(0); + const errorMarkup1 = lines.ZERO_LENGTH_ERROR; + assert.strictEqual(lines.printLine(errorLine1, code1), errorMarkup1); - const code2 = ""; - const errorLine2 = new lines.EndErrorLine(0, 0, "foo"); - const errorMarkup2 = `${lines.ZERO_LENGTH_ERROR} [foo]`; - assert.strictEqual(lines.lineObjToText(errorLine2, code2), errorMarkup2); - }); + const code2 = ""; + const errorLine2 = new lines.EndErrorLine(0, 0, "foo"); + const errorMarkup2 = `${lines.ZERO_LENGTH_ERROR} [foo]`; + assert.strictEqual(lines.printLine(errorLine2, code2), errorMarkup2); }); }); }); diff --git a/test/rule-tester/parseTests.ts b/test/rule-tester/parseTests.ts index b0845d4aefa..471735b32f4 100644 --- a/test/rule-tester/parseTests.ts +++ b/test/rule-tester/parseTests.ts @@ -17,60 +17,58 @@ import * as testData from "./testData"; import * as parse from "../../src/test/parse"; -describe("Rule Test Runner", () => { - describe("parse", () => { - describe("::removeErrorMarkup", () => { - it("should return the contents of a regular string unchanged", () => { - assert.strictEqual(parse.removeErrorMarkup(testData.lintStr1), testData.codeStr1); - }); +describe("Rule Test Parse", () => { + describe("removeErrorMarkup", () => { + it("should return the contents of a regular string unchanged", () => { + assert.strictEqual(parse.removeErrorMarkup(testData.lintStr1), testData.codeStr1); + }); - it("should remove a single-line error markup correctly", () => { - assert.strictEqual(parse.removeErrorMarkup(testData.lintStr2), testData.codeStr2); - }); + it("should remove a single-line error markup correctly", () => { + assert.strictEqual(parse.removeErrorMarkup(testData.lintStr2), testData.codeStr2); + }); - it("should remove a mix of error markup correctly", () => { - assert.strictEqual(parse.removeErrorMarkup(testData.lintStr3), testData.codeStr3); - }); + it("should remove a mix of error markup correctly", () => { + assert.strictEqual(parse.removeErrorMarkup(testData.lintStr3), testData.codeStr3); + }); - it("should handle message substitutions correctly", () => { - assert.strictEqual(parse.removeErrorMarkup(testData.lintStr6), testData.codeStr6); - }); + it("should handle message substitutions correctly", () => { + assert.strictEqual(parse.removeErrorMarkup(testData.lintStr6), testData.codeStr6); + }); - it("should handle nil-length errors correctly", () => { - assert.strictEqual(parse.removeErrorMarkup(testData.lintStr7), testData.codeStr7); - }); + it("should handle nil-length errors correctly", () => { + assert.strictEqual(parse.removeErrorMarkup(testData.lintStr7), testData.codeStr7); }); + }); - describe("::parseErrors", () => { - it("should return no errors from a regular string", () => { - assert.deepEqual(parse.parseErrorsFromMarkup(testData.lintStr1), testData.resultErrs1); - }); + describe("parseErrors", () => { + it("should return no errors from a regular string", () => { + assert.deepEqual(parse.parseErrorsFromMarkup(testData.lintStr1), testData.resultErrs1); + }); - it("should find a single-line error correctly", () => { - assert.deepEqual(parse.parseErrorsFromMarkup(testData.lintStr2), testData.resultErrs2); - }); + it("should find a single-line error correctly", () => { + assert.deepEqual(parse.parseErrorsFromMarkup(testData.lintStr2), testData.resultErrs2); + }); - it("should find a mix of errors correctly", () => { - assert.deepEqual(parse.parseErrorsFromMarkup(testData.lintStr3), testData.resultErrs3); - }); + it("should find a mix of errors correctly", () => { + assert.deepEqual(parse.parseErrorsFromMarkup(testData.lintStr3), testData.resultErrs3); + }); - it("should handle message substitutions correctly", () => { - assert.deepEqual(parse.parseErrorsFromMarkup(testData.lintStr6), testData.resultErrs6); - }); + it("should handle message substitutions correctly", () => { + assert.deepEqual(parse.parseErrorsFromMarkup(testData.lintStr6), testData.resultErrs6); + }); - it("should handle nil-length errors correctly", () => { - assert.deepEqual(parse.parseErrorsFromMarkup(testData.lintStr7), testData.resultErrs7); - }); + it("should handle nil-length errors correctly", () => { + assert.deepEqual(parse.parseErrorsFromMarkup(testData.lintStr7), testData.resultErrs7); }); + }); - describe("::createMarkupFromErrors", () => { - it("should generate correct markup", () => { - assert.strictEqual(parse.createMarkupFromErrors(testData.codeStr5, testData.resultErrs5), testData.lintStr5); - }); + describe("createMarkupFromErrors", () => { + it("should generate correct markup", () => { + assert.strictEqual(parse.createMarkupFromErrors(testData.codeStr5, testData.resultErrs5), testData.lintStr5); + }); - it("should generate correct markup with nil-length errors", () => { - assert.strictEqual(parse.createMarkupFromErrors(testData.codeStr7, testData.resultErrs7), testData.lintStr7); - }); + it("should generate correct markup with nil-length errors", () => { + assert.strictEqual(parse.createMarkupFromErrors(testData.codeStr7, testData.resultErrs7), testData.lintStr7); }); }); }); diff --git a/test/rule-tester/testData.ts b/test/rule-tester/testData.ts index 4da731aa4de..e80cefd8cef 100644 --- a/test/rule-tester/testData.ts +++ b/test/rule-tester/testData.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import {LintError} from "../../src/test/types"; +import {LintError} from "../../src/test/lintError"; /* tslint:disable:object-literal-sort-keys */ diff --git a/test/rule-tester/utilsTests.ts b/test/rule-tester/utilsTests.ts index 21b032a91d6..e283a1f8b31 100644 --- a/test/rule-tester/utilsTests.ts +++ b/test/rule-tester/utilsTests.ts @@ -16,15 +16,13 @@ import * as utils from "../../src/test/utils"; -describe("Rule Test Runner", () => { - describe("utils", () => { - describe("::strMult", () => { - it("should duplicate strings correctly", () => { - assert.strictEqual("xxxxx", utils.strMult("x", 5)); - assert.strictEqual("", utils.strMult("abc", 0)); - assert.strictEqual("abcabcabc", utils.strMult("abc", 3)); - assert.strictEqual("one", utils.strMult("one", 1)); - }); +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)); }); }); }); diff --git a/test/rules/_comprehensive/react/test.tsx.linttest b/test/rules/_integration/react/test.tsx.linttest similarity index 100% rename from test/rules/_comprehensive/react/test.tsx.linttest rename to test/rules/_integration/react/test.tsx.linttest diff --git a/test/rules/_comprehensive/react/tslint.json b/test/rules/_integration/react/tslint.json similarity index 100% rename from test/rules/_comprehensive/react/tslint.json rename to test/rules/_integration/react/tslint.json diff --git a/test/tsconfig.json b/test/tsconfig.json index 77f5f13a85d..efdc99eedd6 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -111,8 +111,8 @@ "../src/rules/whitespaceRule.ts", "../src/test.ts", "../src/test/lines.ts", + "../src/test/lintError.ts", "../src/test/parse.ts", - "../src/test/types.ts", "../src/test/utils.ts", "../src/tslint-cli.ts", "../src/tslint.ts", From b47178dd9a5e31b4faf592d92f219e447854ea51 Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Mon, 25 Jan 2016 18:09:04 -0500 Subject: [PATCH 29/30] Change from .linttest to .lint file extension --- src/test.ts | 2 +- .../incorrect-rule-test/{test.ts.linttest => test.ts.lint} | 0 .../_integration/react/{test.tsx.linttest => test.tsx.lint} | 0 test/rules/align/arguments/{test.ts.linttest => test.ts.lint} | 0 test/rules/align/parameters/{test.ts.linttest => test.ts.lint} | 0 test/rules/align/statements/{test.ts.linttest => test.ts.lint} | 0 test/rules/ban/{test.ts.linttest => test.ts.lint} | 0 test/rules/class-name/{test.ts.linttest => test.ts.lint} | 0 .../comment-format/lower/{test.ts.linttest => test.ts.lint} | 0 .../comment-format/upper/{test.ts.linttest => test.ts.lint} | 0 test/rules/curly/{test.ts.linttest => test.ts.lint} | 0 test/rules/forin/{test.ts.linttest => test.ts.lint} | 0 test/rules/indent/spaces/{test.ts.linttest => test.ts.lint} | 0 test/rules/indent/tabs/{test.ts.linttest => test.ts.lint} | 0 test/rules/interface-name/{test.ts.linttest => test.ts.lint} | 0 .../{jsdoc-windows.ts.linttest => jsdoc-windows.ts.lint} | 0 test/rules/jsdoc-format/{jsdoc.ts.linttest => jsdoc.ts.lint} | 0 test/rules/label-position/{test.ts.linttest => test.ts.lint} | 0 test/rules/label-undefined/{test.ts.linttest => test.ts.lint} | 0 test/rules/max-line-length/{test.ts.linttest => test.ts.lint} | 0 .../member-access/accessor/{test.ts.linttest => test.ts.lint} | 0 .../constructor/{test.ts.linttest => test.ts.lint} | 0 .../member-access/default/{test.ts.linttest => test.ts.lint} | 0 .../member-ordering/method/{test.ts.linttest => test.ts.lint} | 0 .../member-ordering/private/{test.ts.linttest => test.ts.lint} | 0 .../member-ordering/static/{test.ts.linttest => test.ts.lint} | 0 test/rules/no-any/{test.ts.linttest => test.ts.lint} | 0 test/rules/no-arg/{test.ts.linttest => test.ts.lint} | 0 test/rules/no-bitwise/{test.ts.linttest => test.ts.lint} | 0 .../{test.ts.linttest => test.ts.lint} | 0 .../{test.ts.linttest => test.ts.lint} | 0 test/rules/no-console/{test.ts.linttest => test.ts.lint} | 0 test/rules/no-construct/{test.ts.linttest => test.ts.lint} | 0 .../no-constructor-vars/{test.ts.linttest => test.ts.lint} | 0 test/rules/no-debugger/{test.ts.linttest => test.ts.lint} | 0 test/rules/no-duplicate-key/{test.ts.linttest => test.ts.lint} | 0 .../no-duplicate-variable/{test.ts.linttest => test.ts.lint} | 0 test/rules/no-empty/{test.ts.linttest => test.ts.lint} | 0 test/rules/no-eval/{test.ts.linttest => test.ts.lint} | 0 .../no-inferrable-types/{test.ts.linttest => test.ts.lint} | 0 .../rules/no-internal-module/{test.ts.linttest => test.ts.lint} | 0 test/rules/no-null-keyword/{test.ts.linttest => test.ts.lint} | 0 .../rules/no-require-imports/{test.ts.linttest => test.ts.lint} | 0 .../no-shadowed-variable/{test.ts.linttest => test.ts.lint} | 0 test/rules/no-string-literal/{test.ts.linttest => test.ts.lint} | 0 .../{test.ts.linttest => test.ts.lint} | 0 .../no-trailing-whitespace/{test.ts.linttest => test.ts.lint} | 0 test/rules/no-unreachable/{test.ts.linttest => test.ts.lint} | 0 .../no-unused-expression/{test.ts.linttest => test.ts.lint} | 0 .../check-parameters/{test.ts.linttest => test.ts.lint} | 0 .../default/{class.ts.linttest => class.ts.lint} | 0 .../{false-positives.ts.linttest => false-positives.ts.lint} | 0 .../default/{function.ts.linttest => function.ts.lint} | 0 .../default/{import.ts.linttest => import.ts.lint} | 0 .../{react-addons1.tsx.linttest => react-addons1.tsx.lint} | 0 .../{react-addons2.tsx.linttest => react-addons2.tsx.lint} | 0 .../{react-addons3.tsx.linttest => react-addons3.tsx.lint} | 0 .../default/{react1.tsx.linttest => react1.tsx.lint} | 0 .../default/{react2.tsx.linttest => react2.tsx.lint} | 0 .../default/{react3.tsx.linttest => react3.tsx.lint} | 0 .../default/{react4.tsx.linttest => react4.tsx.lint} | 0 .../no-unused-variable/default/{var.ts.linttest => var.ts.lint} | 0 .../{react-addons1.tsx.linttest => react-addons1.tsx.lint} | 0 .../{react-addons2.tsx.linttest => react-addons2.tsx.lint} | 0 .../{react-addons3.tsx.linttest => react-addons3.tsx.lint} | 0 .../react/{react1.tsx.linttest => react1.tsx.lint} | 0 .../react/{react2.tsx.linttest => react2.tsx.lint} | 0 .../react/{react3.tsx.linttest => react3.tsx.lint} | 0 .../react/{react4.tsx.linttest => react4.tsx.lint} | 0 .../no-use-before-declare/{test.ts.linttest => test.ts.lint} | 0 test/rules/no-var-keyword/{test.ts.linttest => test.ts.lint} | 0 test/rules/no-var-requires/{test.ts.linttest => test.ts.lint} | 0 .../object-literal-sort-keys/{test.ts.linttest => test.ts.lint} | 0 test/rules/one-line/all/{test.ts.linttest => test.ts.lint} | 0 test/rules/one-line/none/{test.ts.linttest => test.ts.lint} | 0 .../double-avoid-escape/{test.ts.linttest => test.ts.lint} | 0 test/rules/quotemark/double/{test.ts.linttest => test.ts.lint} | 0 .../quotemark/jsx-double/{test.tsx.linttest => test.tsx.lint} | 0 .../quotemark/jsx-single/{test.tsx.linttest => test.tsx.lint} | 0 .../single-avoid-escape/{test.ts.linttest => test.ts.lint} | 0 test/rules/quotemark/single/{test.ts.linttest => test.ts.lint} | 0 test/rules/radix/{test.ts.linttest => test.ts.lint} | 0 test/rules/semicolon/{test.ts.linttest => test.ts.lint} | 0 test/rules/switch-default/{test.ts.linttest => test.ts.lint} | 0 .../multiline-always/{test.ts.linttest => test.ts.lint} | 0 .../multiline-never/{test.ts.linttest => test.ts.lint} | 0 .../singleline-always/{test.ts.linttest => test.ts.lint} | 0 .../singleline-never/{test.ts.linttest => test.ts.lint} | 0 test/rules/triple-equals/{test.ts.linttest => test.ts.lint} | 0 .../typedef-whitespace/none/{test.ts.linttest => test.ts.lint} | 0 .../nospace/{test.ts.linttest => test.ts.lint} | 0 .../typedef-whitespace/space/{test.ts.linttest => test.ts.lint} | 0 test/rules/typedef/all/{test.ts.linttest => test.ts.lint} | 0 test/rules/typedef/none/{test.ts.linttest => test.ts.lint} | 0 test/rules/use-strict/{test.ts.linttest => test.ts.lint} | 0 .../{test.ts.linttest => test.ts.lint} | 0 .../allow-leading-underscore/{test.ts.linttest => test.ts.lint} | 0 .../{test.ts.linttest => test.ts.lint} | 0 .../ban-keywords/{test.ts.linttest => test.ts.lint} | 0 .../variable-name/default/{test.ts.linttest => test.ts.lint} | 0 test/rules/whitespace/all/{test.ts.linttest => test.ts.lint} | 0 test/rules/whitespace/none/{test.ts.linttest => test.ts.lint} | 0 102 files changed, 1 insertion(+), 1 deletion(-) rename test/files/incorrect-rule-test/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/_integration/react/{test.tsx.linttest => test.tsx.lint} (100%) rename test/rules/align/arguments/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/align/parameters/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/align/statements/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/ban/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/class-name/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/comment-format/lower/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/comment-format/upper/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/curly/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/forin/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/indent/spaces/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/indent/tabs/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/interface-name/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/jsdoc-format/{jsdoc-windows.ts.linttest => jsdoc-windows.ts.lint} (100%) rename test/rules/jsdoc-format/{jsdoc.ts.linttest => jsdoc.ts.lint} (100%) rename test/rules/label-position/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/label-undefined/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/max-line-length/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/member-access/accessor/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/member-access/constructor/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/member-access/default/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/member-ordering/method/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/member-ordering/private/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/member-ordering/static/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-any/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-arg/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-bitwise/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-conditional-assignment/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-consecutive-blank-lines/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-console/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-construct/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-constructor-vars/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-debugger/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-duplicate-key/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-duplicate-variable/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-empty/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-eval/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-inferrable-types/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-internal-module/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-null-keyword/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-require-imports/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-shadowed-variable/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-string-literal/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-switch-case-fall-through/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-trailing-whitespace/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-unreachable/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-unused-expression/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-unused-variable/check-parameters/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-unused-variable/default/{class.ts.linttest => class.ts.lint} (100%) rename test/rules/no-unused-variable/default/{false-positives.ts.linttest => false-positives.ts.lint} (100%) rename test/rules/no-unused-variable/default/{function.ts.linttest => function.ts.lint} (100%) rename test/rules/no-unused-variable/default/{import.ts.linttest => import.ts.lint} (100%) rename test/rules/no-unused-variable/default/{react-addons1.tsx.linttest => react-addons1.tsx.lint} (100%) rename test/rules/no-unused-variable/default/{react-addons2.tsx.linttest => react-addons2.tsx.lint} (100%) rename test/rules/no-unused-variable/default/{react-addons3.tsx.linttest => react-addons3.tsx.lint} (100%) rename test/rules/no-unused-variable/default/{react1.tsx.linttest => react1.tsx.lint} (100%) rename test/rules/no-unused-variable/default/{react2.tsx.linttest => react2.tsx.lint} (100%) rename test/rules/no-unused-variable/default/{react3.tsx.linttest => react3.tsx.lint} (100%) rename test/rules/no-unused-variable/default/{react4.tsx.linttest => react4.tsx.lint} (100%) rename test/rules/no-unused-variable/default/{var.ts.linttest => var.ts.lint} (100%) rename test/rules/no-unused-variable/react/{react-addons1.tsx.linttest => react-addons1.tsx.lint} (100%) rename test/rules/no-unused-variable/react/{react-addons2.tsx.linttest => react-addons2.tsx.lint} (100%) rename test/rules/no-unused-variable/react/{react-addons3.tsx.linttest => react-addons3.tsx.lint} (100%) rename test/rules/no-unused-variable/react/{react1.tsx.linttest => react1.tsx.lint} (100%) rename test/rules/no-unused-variable/react/{react2.tsx.linttest => react2.tsx.lint} (100%) rename test/rules/no-unused-variable/react/{react3.tsx.linttest => react3.tsx.lint} (100%) rename test/rules/no-unused-variable/react/{react4.tsx.linttest => react4.tsx.lint} (100%) rename test/rules/no-use-before-declare/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-var-keyword/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/no-var-requires/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/object-literal-sort-keys/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/one-line/all/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/one-line/none/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/quotemark/double-avoid-escape/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/quotemark/double/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/quotemark/jsx-double/{test.tsx.linttest => test.tsx.lint} (100%) rename test/rules/quotemark/jsx-single/{test.tsx.linttest => test.tsx.lint} (100%) rename test/rules/quotemark/single-avoid-escape/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/quotemark/single/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/radix/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/semicolon/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/switch-default/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/trailing-comma/multiline-always/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/trailing-comma/multiline-never/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/trailing-comma/singleline-always/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/trailing-comma/singleline-never/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/triple-equals/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/typedef-whitespace/none/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/typedef-whitespace/nospace/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/typedef-whitespace/space/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/typedef/all/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/typedef/none/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/use-strict/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/variable-name/allow-leading-trailing-underscore/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/variable-name/allow-leading-underscore/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/variable-name/allow-trailing-underscore/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/variable-name/ban-keywords/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/variable-name/default/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/whitespace/all/{test.ts.linttest => test.ts.lint} (100%) rename test/rules/whitespace/none/{test.ts.linttest => test.ts.lint} (100%) diff --git a/src/test.ts b/src/test.ts index 8fcaf2539e3..94e4f8a624e 100644 --- a/src/test.ts +++ b/src/test.ts @@ -25,7 +25,7 @@ import * as Linter from "./tslint"; import * as parse from "./test/parse"; import {LintError} from "./test/lintError"; -const FILE_EXTENSION = ".linttest"; +const FILE_EXTENSION = ".lint"; export interface TestResult { directory: string; diff --git a/test/files/incorrect-rule-test/test.ts.linttest b/test/files/incorrect-rule-test/test.ts.lint similarity index 100% rename from test/files/incorrect-rule-test/test.ts.linttest rename to test/files/incorrect-rule-test/test.ts.lint diff --git a/test/rules/_integration/react/test.tsx.linttest b/test/rules/_integration/react/test.tsx.lint similarity index 100% rename from test/rules/_integration/react/test.tsx.linttest rename to test/rules/_integration/react/test.tsx.lint diff --git a/test/rules/align/arguments/test.ts.linttest b/test/rules/align/arguments/test.ts.lint similarity index 100% rename from test/rules/align/arguments/test.ts.linttest rename to test/rules/align/arguments/test.ts.lint diff --git a/test/rules/align/parameters/test.ts.linttest b/test/rules/align/parameters/test.ts.lint similarity index 100% rename from test/rules/align/parameters/test.ts.linttest rename to test/rules/align/parameters/test.ts.lint diff --git a/test/rules/align/statements/test.ts.linttest b/test/rules/align/statements/test.ts.lint similarity index 100% rename from test/rules/align/statements/test.ts.linttest rename to test/rules/align/statements/test.ts.lint diff --git a/test/rules/ban/test.ts.linttest b/test/rules/ban/test.ts.lint similarity index 100% rename from test/rules/ban/test.ts.linttest rename to test/rules/ban/test.ts.lint diff --git a/test/rules/class-name/test.ts.linttest b/test/rules/class-name/test.ts.lint similarity index 100% rename from test/rules/class-name/test.ts.linttest rename to test/rules/class-name/test.ts.lint diff --git a/test/rules/comment-format/lower/test.ts.linttest b/test/rules/comment-format/lower/test.ts.lint similarity index 100% rename from test/rules/comment-format/lower/test.ts.linttest rename to test/rules/comment-format/lower/test.ts.lint diff --git a/test/rules/comment-format/upper/test.ts.linttest b/test/rules/comment-format/upper/test.ts.lint similarity index 100% rename from test/rules/comment-format/upper/test.ts.linttest rename to test/rules/comment-format/upper/test.ts.lint diff --git a/test/rules/curly/test.ts.linttest b/test/rules/curly/test.ts.lint similarity index 100% rename from test/rules/curly/test.ts.linttest rename to test/rules/curly/test.ts.lint diff --git a/test/rules/forin/test.ts.linttest b/test/rules/forin/test.ts.lint similarity index 100% rename from test/rules/forin/test.ts.linttest rename to test/rules/forin/test.ts.lint diff --git a/test/rules/indent/spaces/test.ts.linttest b/test/rules/indent/spaces/test.ts.lint similarity index 100% rename from test/rules/indent/spaces/test.ts.linttest rename to test/rules/indent/spaces/test.ts.lint diff --git a/test/rules/indent/tabs/test.ts.linttest b/test/rules/indent/tabs/test.ts.lint similarity index 100% rename from test/rules/indent/tabs/test.ts.linttest rename to test/rules/indent/tabs/test.ts.lint diff --git a/test/rules/interface-name/test.ts.linttest b/test/rules/interface-name/test.ts.lint similarity index 100% rename from test/rules/interface-name/test.ts.linttest rename to test/rules/interface-name/test.ts.lint diff --git a/test/rules/jsdoc-format/jsdoc-windows.ts.linttest b/test/rules/jsdoc-format/jsdoc-windows.ts.lint similarity index 100% rename from test/rules/jsdoc-format/jsdoc-windows.ts.linttest rename to test/rules/jsdoc-format/jsdoc-windows.ts.lint diff --git a/test/rules/jsdoc-format/jsdoc.ts.linttest b/test/rules/jsdoc-format/jsdoc.ts.lint similarity index 100% rename from test/rules/jsdoc-format/jsdoc.ts.linttest rename to test/rules/jsdoc-format/jsdoc.ts.lint diff --git a/test/rules/label-position/test.ts.linttest b/test/rules/label-position/test.ts.lint similarity index 100% rename from test/rules/label-position/test.ts.linttest rename to test/rules/label-position/test.ts.lint diff --git a/test/rules/label-undefined/test.ts.linttest b/test/rules/label-undefined/test.ts.lint similarity index 100% rename from test/rules/label-undefined/test.ts.linttest rename to test/rules/label-undefined/test.ts.lint diff --git a/test/rules/max-line-length/test.ts.linttest b/test/rules/max-line-length/test.ts.lint similarity index 100% rename from test/rules/max-line-length/test.ts.linttest rename to test/rules/max-line-length/test.ts.lint diff --git a/test/rules/member-access/accessor/test.ts.linttest b/test/rules/member-access/accessor/test.ts.lint similarity index 100% rename from test/rules/member-access/accessor/test.ts.linttest rename to test/rules/member-access/accessor/test.ts.lint diff --git a/test/rules/member-access/constructor/test.ts.linttest b/test/rules/member-access/constructor/test.ts.lint similarity index 100% rename from test/rules/member-access/constructor/test.ts.linttest rename to test/rules/member-access/constructor/test.ts.lint diff --git a/test/rules/member-access/default/test.ts.linttest b/test/rules/member-access/default/test.ts.lint similarity index 100% rename from test/rules/member-access/default/test.ts.linttest rename to test/rules/member-access/default/test.ts.lint diff --git a/test/rules/member-ordering/method/test.ts.linttest b/test/rules/member-ordering/method/test.ts.lint similarity index 100% rename from test/rules/member-ordering/method/test.ts.linttest rename to test/rules/member-ordering/method/test.ts.lint diff --git a/test/rules/member-ordering/private/test.ts.linttest b/test/rules/member-ordering/private/test.ts.lint similarity index 100% rename from test/rules/member-ordering/private/test.ts.linttest rename to test/rules/member-ordering/private/test.ts.lint diff --git a/test/rules/member-ordering/static/test.ts.linttest b/test/rules/member-ordering/static/test.ts.lint similarity index 100% rename from test/rules/member-ordering/static/test.ts.linttest rename to test/rules/member-ordering/static/test.ts.lint diff --git a/test/rules/no-any/test.ts.linttest b/test/rules/no-any/test.ts.lint similarity index 100% rename from test/rules/no-any/test.ts.linttest rename to test/rules/no-any/test.ts.lint diff --git a/test/rules/no-arg/test.ts.linttest b/test/rules/no-arg/test.ts.lint similarity index 100% rename from test/rules/no-arg/test.ts.linttest rename to test/rules/no-arg/test.ts.lint diff --git a/test/rules/no-bitwise/test.ts.linttest b/test/rules/no-bitwise/test.ts.lint similarity index 100% rename from test/rules/no-bitwise/test.ts.linttest rename to test/rules/no-bitwise/test.ts.lint diff --git a/test/rules/no-conditional-assignment/test.ts.linttest b/test/rules/no-conditional-assignment/test.ts.lint similarity index 100% rename from test/rules/no-conditional-assignment/test.ts.linttest rename to test/rules/no-conditional-assignment/test.ts.lint diff --git a/test/rules/no-consecutive-blank-lines/test.ts.linttest b/test/rules/no-consecutive-blank-lines/test.ts.lint similarity index 100% rename from test/rules/no-consecutive-blank-lines/test.ts.linttest rename to test/rules/no-consecutive-blank-lines/test.ts.lint diff --git a/test/rules/no-console/test.ts.linttest b/test/rules/no-console/test.ts.lint similarity index 100% rename from test/rules/no-console/test.ts.linttest rename to test/rules/no-console/test.ts.lint diff --git a/test/rules/no-construct/test.ts.linttest b/test/rules/no-construct/test.ts.lint similarity index 100% rename from test/rules/no-construct/test.ts.linttest rename to test/rules/no-construct/test.ts.lint diff --git a/test/rules/no-constructor-vars/test.ts.linttest b/test/rules/no-constructor-vars/test.ts.lint similarity index 100% rename from test/rules/no-constructor-vars/test.ts.linttest rename to test/rules/no-constructor-vars/test.ts.lint diff --git a/test/rules/no-debugger/test.ts.linttest b/test/rules/no-debugger/test.ts.lint similarity index 100% rename from test/rules/no-debugger/test.ts.linttest rename to test/rules/no-debugger/test.ts.lint diff --git a/test/rules/no-duplicate-key/test.ts.linttest b/test/rules/no-duplicate-key/test.ts.lint similarity index 100% rename from test/rules/no-duplicate-key/test.ts.linttest rename to test/rules/no-duplicate-key/test.ts.lint diff --git a/test/rules/no-duplicate-variable/test.ts.linttest b/test/rules/no-duplicate-variable/test.ts.lint similarity index 100% rename from test/rules/no-duplicate-variable/test.ts.linttest rename to test/rules/no-duplicate-variable/test.ts.lint diff --git a/test/rules/no-empty/test.ts.linttest b/test/rules/no-empty/test.ts.lint similarity index 100% rename from test/rules/no-empty/test.ts.linttest rename to test/rules/no-empty/test.ts.lint diff --git a/test/rules/no-eval/test.ts.linttest b/test/rules/no-eval/test.ts.lint similarity index 100% rename from test/rules/no-eval/test.ts.linttest rename to test/rules/no-eval/test.ts.lint diff --git a/test/rules/no-inferrable-types/test.ts.linttest b/test/rules/no-inferrable-types/test.ts.lint similarity index 100% rename from test/rules/no-inferrable-types/test.ts.linttest rename to test/rules/no-inferrable-types/test.ts.lint diff --git a/test/rules/no-internal-module/test.ts.linttest b/test/rules/no-internal-module/test.ts.lint similarity index 100% rename from test/rules/no-internal-module/test.ts.linttest rename to test/rules/no-internal-module/test.ts.lint diff --git a/test/rules/no-null-keyword/test.ts.linttest b/test/rules/no-null-keyword/test.ts.lint similarity index 100% rename from test/rules/no-null-keyword/test.ts.linttest rename to test/rules/no-null-keyword/test.ts.lint diff --git a/test/rules/no-require-imports/test.ts.linttest b/test/rules/no-require-imports/test.ts.lint similarity index 100% rename from test/rules/no-require-imports/test.ts.linttest rename to test/rules/no-require-imports/test.ts.lint diff --git a/test/rules/no-shadowed-variable/test.ts.linttest b/test/rules/no-shadowed-variable/test.ts.lint similarity index 100% rename from test/rules/no-shadowed-variable/test.ts.linttest rename to test/rules/no-shadowed-variable/test.ts.lint diff --git a/test/rules/no-string-literal/test.ts.linttest b/test/rules/no-string-literal/test.ts.lint similarity index 100% rename from test/rules/no-string-literal/test.ts.linttest rename to test/rules/no-string-literal/test.ts.lint diff --git a/test/rules/no-switch-case-fall-through/test.ts.linttest b/test/rules/no-switch-case-fall-through/test.ts.lint similarity index 100% rename from test/rules/no-switch-case-fall-through/test.ts.linttest rename to test/rules/no-switch-case-fall-through/test.ts.lint diff --git a/test/rules/no-trailing-whitespace/test.ts.linttest b/test/rules/no-trailing-whitespace/test.ts.lint similarity index 100% rename from test/rules/no-trailing-whitespace/test.ts.linttest rename to test/rules/no-trailing-whitespace/test.ts.lint diff --git a/test/rules/no-unreachable/test.ts.linttest b/test/rules/no-unreachable/test.ts.lint similarity index 100% rename from test/rules/no-unreachable/test.ts.linttest rename to test/rules/no-unreachable/test.ts.lint diff --git a/test/rules/no-unused-expression/test.ts.linttest b/test/rules/no-unused-expression/test.ts.lint similarity index 100% rename from test/rules/no-unused-expression/test.ts.linttest rename to test/rules/no-unused-expression/test.ts.lint diff --git a/test/rules/no-unused-variable/check-parameters/test.ts.linttest b/test/rules/no-unused-variable/check-parameters/test.ts.lint similarity index 100% rename from test/rules/no-unused-variable/check-parameters/test.ts.linttest rename to test/rules/no-unused-variable/check-parameters/test.ts.lint diff --git a/test/rules/no-unused-variable/default/class.ts.linttest b/test/rules/no-unused-variable/default/class.ts.lint similarity index 100% rename from test/rules/no-unused-variable/default/class.ts.linttest rename to test/rules/no-unused-variable/default/class.ts.lint diff --git a/test/rules/no-unused-variable/default/false-positives.ts.linttest b/test/rules/no-unused-variable/default/false-positives.ts.lint similarity index 100% rename from test/rules/no-unused-variable/default/false-positives.ts.linttest rename to test/rules/no-unused-variable/default/false-positives.ts.lint diff --git a/test/rules/no-unused-variable/default/function.ts.linttest b/test/rules/no-unused-variable/default/function.ts.lint similarity index 100% rename from test/rules/no-unused-variable/default/function.ts.linttest rename to test/rules/no-unused-variable/default/function.ts.lint diff --git a/test/rules/no-unused-variable/default/import.ts.linttest b/test/rules/no-unused-variable/default/import.ts.lint similarity index 100% rename from test/rules/no-unused-variable/default/import.ts.linttest rename to test/rules/no-unused-variable/default/import.ts.lint diff --git a/test/rules/no-unused-variable/default/react-addons1.tsx.linttest b/test/rules/no-unused-variable/default/react-addons1.tsx.lint similarity index 100% rename from test/rules/no-unused-variable/default/react-addons1.tsx.linttest rename to test/rules/no-unused-variable/default/react-addons1.tsx.lint diff --git a/test/rules/no-unused-variable/default/react-addons2.tsx.linttest b/test/rules/no-unused-variable/default/react-addons2.tsx.lint similarity index 100% rename from test/rules/no-unused-variable/default/react-addons2.tsx.linttest rename to test/rules/no-unused-variable/default/react-addons2.tsx.lint diff --git a/test/rules/no-unused-variable/default/react-addons3.tsx.linttest b/test/rules/no-unused-variable/default/react-addons3.tsx.lint similarity index 100% rename from test/rules/no-unused-variable/default/react-addons3.tsx.linttest rename to test/rules/no-unused-variable/default/react-addons3.tsx.lint diff --git a/test/rules/no-unused-variable/default/react1.tsx.linttest b/test/rules/no-unused-variable/default/react1.tsx.lint similarity index 100% rename from test/rules/no-unused-variable/default/react1.tsx.linttest rename to test/rules/no-unused-variable/default/react1.tsx.lint diff --git a/test/rules/no-unused-variable/default/react2.tsx.linttest b/test/rules/no-unused-variable/default/react2.tsx.lint similarity index 100% rename from test/rules/no-unused-variable/default/react2.tsx.linttest rename to test/rules/no-unused-variable/default/react2.tsx.lint diff --git a/test/rules/no-unused-variable/default/react3.tsx.linttest b/test/rules/no-unused-variable/default/react3.tsx.lint similarity index 100% rename from test/rules/no-unused-variable/default/react3.tsx.linttest rename to test/rules/no-unused-variable/default/react3.tsx.lint diff --git a/test/rules/no-unused-variable/default/react4.tsx.linttest b/test/rules/no-unused-variable/default/react4.tsx.lint similarity index 100% rename from test/rules/no-unused-variable/default/react4.tsx.linttest rename to test/rules/no-unused-variable/default/react4.tsx.lint diff --git a/test/rules/no-unused-variable/default/var.ts.linttest b/test/rules/no-unused-variable/default/var.ts.lint similarity index 100% rename from test/rules/no-unused-variable/default/var.ts.linttest rename to test/rules/no-unused-variable/default/var.ts.lint diff --git a/test/rules/no-unused-variable/react/react-addons1.tsx.linttest b/test/rules/no-unused-variable/react/react-addons1.tsx.lint similarity index 100% rename from test/rules/no-unused-variable/react/react-addons1.tsx.linttest rename to test/rules/no-unused-variable/react/react-addons1.tsx.lint diff --git a/test/rules/no-unused-variable/react/react-addons2.tsx.linttest b/test/rules/no-unused-variable/react/react-addons2.tsx.lint similarity index 100% rename from test/rules/no-unused-variable/react/react-addons2.tsx.linttest rename to test/rules/no-unused-variable/react/react-addons2.tsx.lint diff --git a/test/rules/no-unused-variable/react/react-addons3.tsx.linttest b/test/rules/no-unused-variable/react/react-addons3.tsx.lint similarity index 100% rename from test/rules/no-unused-variable/react/react-addons3.tsx.linttest rename to test/rules/no-unused-variable/react/react-addons3.tsx.lint diff --git a/test/rules/no-unused-variable/react/react1.tsx.linttest b/test/rules/no-unused-variable/react/react1.tsx.lint similarity index 100% rename from test/rules/no-unused-variable/react/react1.tsx.linttest rename to test/rules/no-unused-variable/react/react1.tsx.lint diff --git a/test/rules/no-unused-variable/react/react2.tsx.linttest b/test/rules/no-unused-variable/react/react2.tsx.lint similarity index 100% rename from test/rules/no-unused-variable/react/react2.tsx.linttest rename to test/rules/no-unused-variable/react/react2.tsx.lint diff --git a/test/rules/no-unused-variable/react/react3.tsx.linttest b/test/rules/no-unused-variable/react/react3.tsx.lint similarity index 100% rename from test/rules/no-unused-variable/react/react3.tsx.linttest rename to test/rules/no-unused-variable/react/react3.tsx.lint diff --git a/test/rules/no-unused-variable/react/react4.tsx.linttest b/test/rules/no-unused-variable/react/react4.tsx.lint similarity index 100% rename from test/rules/no-unused-variable/react/react4.tsx.linttest rename to test/rules/no-unused-variable/react/react4.tsx.lint diff --git a/test/rules/no-use-before-declare/test.ts.linttest b/test/rules/no-use-before-declare/test.ts.lint similarity index 100% rename from test/rules/no-use-before-declare/test.ts.linttest rename to test/rules/no-use-before-declare/test.ts.lint diff --git a/test/rules/no-var-keyword/test.ts.linttest b/test/rules/no-var-keyword/test.ts.lint similarity index 100% rename from test/rules/no-var-keyword/test.ts.linttest rename to test/rules/no-var-keyword/test.ts.lint diff --git a/test/rules/no-var-requires/test.ts.linttest b/test/rules/no-var-requires/test.ts.lint similarity index 100% rename from test/rules/no-var-requires/test.ts.linttest rename to test/rules/no-var-requires/test.ts.lint diff --git a/test/rules/object-literal-sort-keys/test.ts.linttest b/test/rules/object-literal-sort-keys/test.ts.lint similarity index 100% rename from test/rules/object-literal-sort-keys/test.ts.linttest rename to test/rules/object-literal-sort-keys/test.ts.lint diff --git a/test/rules/one-line/all/test.ts.linttest b/test/rules/one-line/all/test.ts.lint similarity index 100% rename from test/rules/one-line/all/test.ts.linttest rename to test/rules/one-line/all/test.ts.lint diff --git a/test/rules/one-line/none/test.ts.linttest b/test/rules/one-line/none/test.ts.lint similarity index 100% rename from test/rules/one-line/none/test.ts.linttest rename to test/rules/one-line/none/test.ts.lint diff --git a/test/rules/quotemark/double-avoid-escape/test.ts.linttest b/test/rules/quotemark/double-avoid-escape/test.ts.lint similarity index 100% rename from test/rules/quotemark/double-avoid-escape/test.ts.linttest rename to test/rules/quotemark/double-avoid-escape/test.ts.lint diff --git a/test/rules/quotemark/double/test.ts.linttest b/test/rules/quotemark/double/test.ts.lint similarity index 100% rename from test/rules/quotemark/double/test.ts.linttest rename to test/rules/quotemark/double/test.ts.lint diff --git a/test/rules/quotemark/jsx-double/test.tsx.linttest b/test/rules/quotemark/jsx-double/test.tsx.lint similarity index 100% rename from test/rules/quotemark/jsx-double/test.tsx.linttest rename to test/rules/quotemark/jsx-double/test.tsx.lint diff --git a/test/rules/quotemark/jsx-single/test.tsx.linttest b/test/rules/quotemark/jsx-single/test.tsx.lint similarity index 100% rename from test/rules/quotemark/jsx-single/test.tsx.linttest rename to test/rules/quotemark/jsx-single/test.tsx.lint diff --git a/test/rules/quotemark/single-avoid-escape/test.ts.linttest b/test/rules/quotemark/single-avoid-escape/test.ts.lint similarity index 100% rename from test/rules/quotemark/single-avoid-escape/test.ts.linttest rename to test/rules/quotemark/single-avoid-escape/test.ts.lint diff --git a/test/rules/quotemark/single/test.ts.linttest b/test/rules/quotemark/single/test.ts.lint similarity index 100% rename from test/rules/quotemark/single/test.ts.linttest rename to test/rules/quotemark/single/test.ts.lint diff --git a/test/rules/radix/test.ts.linttest b/test/rules/radix/test.ts.lint similarity index 100% rename from test/rules/radix/test.ts.linttest rename to test/rules/radix/test.ts.lint diff --git a/test/rules/semicolon/test.ts.linttest b/test/rules/semicolon/test.ts.lint similarity index 100% rename from test/rules/semicolon/test.ts.linttest rename to test/rules/semicolon/test.ts.lint diff --git a/test/rules/switch-default/test.ts.linttest b/test/rules/switch-default/test.ts.lint similarity index 100% rename from test/rules/switch-default/test.ts.linttest rename to test/rules/switch-default/test.ts.lint diff --git a/test/rules/trailing-comma/multiline-always/test.ts.linttest b/test/rules/trailing-comma/multiline-always/test.ts.lint similarity index 100% rename from test/rules/trailing-comma/multiline-always/test.ts.linttest rename to test/rules/trailing-comma/multiline-always/test.ts.lint diff --git a/test/rules/trailing-comma/multiline-never/test.ts.linttest b/test/rules/trailing-comma/multiline-never/test.ts.lint similarity index 100% rename from test/rules/trailing-comma/multiline-never/test.ts.linttest rename to test/rules/trailing-comma/multiline-never/test.ts.lint diff --git a/test/rules/trailing-comma/singleline-always/test.ts.linttest b/test/rules/trailing-comma/singleline-always/test.ts.lint similarity index 100% rename from test/rules/trailing-comma/singleline-always/test.ts.linttest rename to test/rules/trailing-comma/singleline-always/test.ts.lint diff --git a/test/rules/trailing-comma/singleline-never/test.ts.linttest b/test/rules/trailing-comma/singleline-never/test.ts.lint similarity index 100% rename from test/rules/trailing-comma/singleline-never/test.ts.linttest rename to test/rules/trailing-comma/singleline-never/test.ts.lint diff --git a/test/rules/triple-equals/test.ts.linttest b/test/rules/triple-equals/test.ts.lint similarity index 100% rename from test/rules/triple-equals/test.ts.linttest rename to test/rules/triple-equals/test.ts.lint diff --git a/test/rules/typedef-whitespace/none/test.ts.linttest b/test/rules/typedef-whitespace/none/test.ts.lint similarity index 100% rename from test/rules/typedef-whitespace/none/test.ts.linttest rename to test/rules/typedef-whitespace/none/test.ts.lint diff --git a/test/rules/typedef-whitespace/nospace/test.ts.linttest b/test/rules/typedef-whitespace/nospace/test.ts.lint similarity index 100% rename from test/rules/typedef-whitespace/nospace/test.ts.linttest rename to test/rules/typedef-whitespace/nospace/test.ts.lint diff --git a/test/rules/typedef-whitespace/space/test.ts.linttest b/test/rules/typedef-whitespace/space/test.ts.lint similarity index 100% rename from test/rules/typedef-whitespace/space/test.ts.linttest rename to test/rules/typedef-whitespace/space/test.ts.lint diff --git a/test/rules/typedef/all/test.ts.linttest b/test/rules/typedef/all/test.ts.lint similarity index 100% rename from test/rules/typedef/all/test.ts.linttest rename to test/rules/typedef/all/test.ts.lint diff --git a/test/rules/typedef/none/test.ts.linttest b/test/rules/typedef/none/test.ts.lint similarity index 100% rename from test/rules/typedef/none/test.ts.linttest rename to test/rules/typedef/none/test.ts.lint diff --git a/test/rules/use-strict/test.ts.linttest b/test/rules/use-strict/test.ts.lint similarity index 100% rename from test/rules/use-strict/test.ts.linttest rename to test/rules/use-strict/test.ts.lint diff --git a/test/rules/variable-name/allow-leading-trailing-underscore/test.ts.linttest b/test/rules/variable-name/allow-leading-trailing-underscore/test.ts.lint similarity index 100% rename from test/rules/variable-name/allow-leading-trailing-underscore/test.ts.linttest rename to test/rules/variable-name/allow-leading-trailing-underscore/test.ts.lint diff --git a/test/rules/variable-name/allow-leading-underscore/test.ts.linttest b/test/rules/variable-name/allow-leading-underscore/test.ts.lint similarity index 100% rename from test/rules/variable-name/allow-leading-underscore/test.ts.linttest rename to test/rules/variable-name/allow-leading-underscore/test.ts.lint diff --git a/test/rules/variable-name/allow-trailing-underscore/test.ts.linttest b/test/rules/variable-name/allow-trailing-underscore/test.ts.lint similarity index 100% rename from test/rules/variable-name/allow-trailing-underscore/test.ts.linttest rename to test/rules/variable-name/allow-trailing-underscore/test.ts.lint diff --git a/test/rules/variable-name/ban-keywords/test.ts.linttest b/test/rules/variable-name/ban-keywords/test.ts.lint similarity index 100% rename from test/rules/variable-name/ban-keywords/test.ts.linttest rename to test/rules/variable-name/ban-keywords/test.ts.lint diff --git a/test/rules/variable-name/default/test.ts.linttest b/test/rules/variable-name/default/test.ts.lint similarity index 100% rename from test/rules/variable-name/default/test.ts.linttest rename to test/rules/variable-name/default/test.ts.lint diff --git a/test/rules/whitespace/all/test.ts.linttest b/test/rules/whitespace/all/test.ts.lint similarity index 100% rename from test/rules/whitespace/all/test.ts.linttest rename to test/rules/whitespace/all/test.ts.lint diff --git a/test/rules/whitespace/none/test.ts.linttest b/test/rules/whitespace/none/test.ts.lint similarity index 100% rename from test/rules/whitespace/none/test.ts.linttest rename to test/rules/whitespace/none/test.ts.lint From 4af24b47fddaf90ee55b5e571b8cd48cc4cd57ca Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Tue, 26 Jan 2016 11:03:10 -0500 Subject: [PATCH 30/30] Tweak build options for quiter output, add newlines to the end of some files --- Gruntfile.js | 7 ++++--- test/rules/class-name/test.ts.lint | 2 +- test/rules/comment-format/lower/test.ts.lint | 2 +- test/rules/comment-format/upper/test.ts.lint | 2 +- test/rules/member-access/accessor/test.ts.lint | 2 +- test/rules/member-ordering/method/test.ts.lint | 2 +- test/rules/no-empty/test.ts.lint | 2 +- test/rules/no-shadowed-variable/test.ts.lint | 2 +- test/rules/no-string-literal/test.ts.lint | 2 +- test/rules/no-unused-variable/default/function.ts.lint | 2 +- test/rules/typedef-whitespace/nospace/tslint.json | 2 +- 11 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index d7cfc69c307..4a5ba7aa169 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -22,16 +22,17 @@ module.exports = function (grunt) { options: { reporter: "spec" }, - src: ["build/test/**/*Tests.js", "build/test/assert.js", "build/test/lint.js"] + src: ["build/test/**/*Tests.js", "build/test/assert.js"] } }, run: { testBin: { - exec: "./test/check-bin.sh" + cmd: "./test/check-bin.sh", + options: {quiet: Infinity} }, testRules: { - exec: "node ./build/test/ruleTestRunner.js" + args: ["./build/test/ruleTestRunner.js"] } }, diff --git a/test/rules/class-name/test.ts.lint b/test/rules/class-name/test.ts.lint index b186f4d2b9e..c32a2d6479d 100644 --- a/test/rules/class-name/test.ts.lint +++ b/test/rules/class-name/test.ts.lint @@ -14,4 +14,4 @@ export default class { // should not fail } -[0]: name must be in pascal case \ No newline at end of file +[0]: name must be in pascal case diff --git a/test/rules/comment-format/lower/test.ts.lint b/test/rules/comment-format/lower/test.ts.lint index 467d630bed5..42d2730a105 100644 --- a/test/rules/comment-format/lower/test.ts.lint +++ b/test/rules/comment-format/lower/test.ts.lint @@ -19,4 +19,4 @@ class Clazz { // this comment is correct `${location.protocol}//${location.hostname}` [lower]: comment must start with lowercase letter -[space]: comment must start with a space \ No newline at end of file +[space]: comment must start with a space diff --git a/test/rules/comment-format/upper/test.ts.lint b/test/rules/comment-format/upper/test.ts.lint index 109fcc2eb1e..9ed5955f23b 100644 --- a/test/rules/comment-format/upper/test.ts.lint +++ b/test/rules/comment-format/upper/test.ts.lint @@ -19,4 +19,4 @@ class Clazz { // This comment is correct `${location.protocol}//${location.hostname}` [upper]: comment must start with uppercase letter -[space]: comment must start with a space \ No newline at end of file +[space]: comment must start with a space diff --git a/test/rules/member-access/accessor/test.ts.lint b/test/rules/member-access/accessor/test.ts.lint index 9fe7c2a6ddf..2addb586696 100644 --- a/test/rules/member-access/accessor/test.ts.lint +++ b/test/rules/member-access/accessor/test.ts.lint @@ -18,4 +18,4 @@ const obj = { get g() { return 1; } -}; \ No newline at end of file +}; diff --git a/test/rules/member-ordering/method/test.ts.lint b/test/rules/member-ordering/method/test.ts.lint index f723f73ef38..d9cd26c7886 100644 --- a/test/rules/member-ordering/method/test.ts.lint +++ b/test/rules/member-ordering/method/test.ts.lint @@ -19,4 +19,4 @@ class Foo { ~~~~~~~~~~ [0] } -[0]: Declaration of public instance member variable not allowed to appear after declaration of public instance member function \ No newline at end of file +[0]: Declaration of public instance member variable not allowed to appear after declaration of public instance member function diff --git a/test/rules/no-empty/test.ts.lint b/test/rules/no-empty/test.ts.lint index d78423babb0..0bbc38c017a 100644 --- a/test/rules/no-empty/test.ts.lint +++ b/test/rules/no-empty/test.ts.lint @@ -39,4 +39,4 @@ class testClass3 { ~ } ~~~~~ [block is empty] -} \ No newline at end of file +} diff --git a/test/rules/no-shadowed-variable/test.ts.lint b/test/rules/no-shadowed-variable/test.ts.lint index 740fc097b73..0922484af53 100644 --- a/test/rules/no-shadowed-variable/test.ts.lint +++ b/test/rules/no-shadowed-variable/test.ts.lint @@ -151,4 +151,4 @@ function testParameterDestructuring( let pos = 3; // failure ~~~ [shadowed variable: 'pos'] } -} \ No newline at end of file +} diff --git a/test/rules/no-string-literal/test.ts.lint b/test/rules/no-string-literal/test.ts.lint index e262bc9114b..cf1665ec723 100644 --- a/test/rules/no-string-literal/test.ts.lint +++ b/test/rules/no-string-literal/test.ts.lint @@ -24,4 +24,4 @@ obj["a-2"]; obj["2a"]; obj["?a#$!$^&%&"]; -[0]: object access via string literals is disallowed \ No newline at end of file +[0]: object access via string literals is disallowed diff --git a/test/rules/no-unused-variable/default/function.ts.lint b/test/rules/no-unused-variable/default/function.ts.lint index 1ed63d3f839..b2d492a075c 100644 --- a/test/rules/no-unused-variable/default/function.ts.lint +++ b/test/rules/no-unused-variable/default/function.ts.lint @@ -20,4 +20,4 @@ declare function func5(): any; export default function () { return 0; -} \ No newline at end of file +} diff --git a/test/rules/typedef-whitespace/nospace/tslint.json b/test/rules/typedef-whitespace/nospace/tslint.json index 96ded7b8822..6153fe36a89 100644 --- a/test/rules/typedef-whitespace/nospace/tslint.json +++ b/test/rules/typedef-whitespace/nospace/tslint.json @@ -8,4 +8,4 @@ "variable-declaration": "nospace" }] } -} \ No newline at end of file +}