This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 889
Check for newly introduced diagnostics before reporting failures (for unused import) #1608
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1b4dac8
allow type-checked rules to be tested with multiple input files in th…
alexeagle af2e841
allow typechecked tests to specify a tsconfig
alexeagle bba39e0
no-unused-variable optionally type-checks
alexeagle ecaa31f
WIP: try to check fixes against language service
alexeagle f836dc1
WIP: optimize by checking whole file first
alexeagle 9e1c647
Always pass a language service to rule.apply*
alexeagle 131aec3
cleanup
alexeagle 6d333a4
add test
alexeagle bcc86a2
Merge branch 'master' of github.com:palantir/tslint into alex
dbbe1e4
Fix merge issues
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,6 @@ import * as path from "path"; | |
import * as ts from "typescript"; | ||
|
||
import {Fix} from "./language/rule/rule"; | ||
import {createCompilerOptions} from "./language/utils"; | ||
import * as Linter from "./linter"; | ||
import {LintError} from "./test/lintError"; | ||
import * as parse from "./test/parse"; | ||
|
@@ -48,6 +47,21 @@ export interface TestResult { | |
export function runTest(testDirectory: string, rulesDirectory?: string | string[]): TestResult { | ||
const filesToLint = glob.sync(path.join(testDirectory, `**/*${MARKUP_FILE_EXTENSION}`)); | ||
const tslintConfig = Linter.findConfiguration(path.join(testDirectory, "tslint.json"), null).results; | ||
const tsConfig = path.join(testDirectory, "tsconfig.json"); | ||
let compilerOptions: ts.CompilerOptions = { allowJs: true }; | ||
if (fs.existsSync(tsConfig)) { | ||
const {config, error} = ts.readConfigFile(tsConfig, ts.sys.readFile); | ||
if (error) { | ||
throw new Error(JSON.stringify(error)); | ||
} | ||
|
||
const parseConfigHost = { | ||
fileExists: fs.existsSync, | ||
readDirectory: ts.sys.readDirectory, | ||
useCaseSensitiveFileNames: true, | ||
}; | ||
compilerOptions = ts.parseJsonConfigFileContent(config, parseConfigHost, testDirectory).options; | ||
} | ||
const results: TestResult = { directory: testDirectory, results: {} }; | ||
|
||
for (const fileToLint of filesToLint) { | ||
|
@@ -59,7 +73,6 @@ export function runTest(testDirectory: string, rulesDirectory?: string | string[ | |
|
||
let program: ts.Program; | ||
if (tslintConfig.linterOptions && tslintConfig.linterOptions.typeCheck) { | ||
const compilerOptions = createCompilerOptions(); | ||
const compilerHost: ts.CompilerHost = { | ||
fileExists: () => true, | ||
getCanonicalFileName: (filename: string) => filename, | ||
|
@@ -73,6 +86,9 @@ export function runTest(testDirectory: string, rulesDirectory?: string | string[ | |
return ts.createSourceFile(filenameToGet, fileText, compilerOptions.target); | ||
} else if (filenameToGet === fileCompileName) { | ||
return ts.createSourceFile(fileBasename, fileTextWithoutMarkup, compilerOptions.target, true); | ||
} else if (fs.existsSync(path.resolve(path.dirname(fileToLint), filenameToGet))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just curious, what's this case for? |
||
const text = fs.readFileSync(path.resolve(path.dirname(fileToLint), filenameToGet), {encoding: "utf-8"}); | ||
return ts.createSourceFile(filenameToGet, text, compilerOptions.target, true); | ||
} | ||
}, | ||
readFile: () => null, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export class A {} | ||
export var a: A; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {a, A} from './a'; | ||
|
||
export class B { | ||
static thing = a; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"compilerOptions": { | ||
"declaration": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"linterOptions": { | ||
"typeCheck": true | ||
}, | ||
"rules": { | ||
"no-unused-variable": true | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typeguard function would be nice here