Skip to content

Commit ae175d0

Browse files
committed
merge with master
2 parents 98ac805 + acef223 commit ae175d0

311 files changed

Lines changed: 5837 additions & 2971 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vscode/tasks.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,25 @@
1818
"problemMatcher": [
1919
"$tsc"
2020
]
21+
},
22+
{
23+
"taskName": "lint-server",
24+
"args": [],
25+
"problemMatcher": {
26+
"owner": "typescript",
27+
"fileLocation": ["relative", "${workspaceRoot}"],
28+
"pattern": {
29+
"regexp": "^(warning|error)\\s+([^(]+)\\s+\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\):\\s+(.*)$",
30+
"severity": 1,
31+
"file": 2,
32+
"location": 3,
33+
"message": 4
34+
},
35+
"watchedTaskBeginsRegExp": "^\\*\\*\\*Lint failure\\*\\*\\*$",
36+
"watchedTaskEndsRegExp": "^\\*\\*\\* Total \\d+ failures\\.$"
37+
},
38+
"showOutput": "always",
39+
"isWatching": true
2140
}
2241
]
2342
}

Jakefile.js

Lines changed: 85 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var fs = require("fs");
44
var os = require("os");
55
var path = require("path");
66
var child_process = require("child_process");
7+
var Linter = require("tslint");
78

89
// Variables
910
var compilerDirectory = "src/compiler/";
@@ -828,17 +829,93 @@ tslintRulesFiles.forEach(function(ruleFile, i) {
828829
compileFile(tslintRulesOutFiles[i], [ruleFile], [ruleFile], [], /*useBuiltCompiler*/ true, /*noOutFile*/ true, /*generateDeclarations*/ false, path.join(builtLocalDirectory, "tslint"));
829830
});
830831

832+
function getLinterOptions() {
833+
return {
834+
configuration: require("./tslint.json"),
835+
formatter: "prose",
836+
formattersDirectory: undefined,
837+
rulesDirectory: "built/local/tslint"
838+
};
839+
}
840+
841+
function lintFileContents(options, path, contents) {
842+
var ll = new Linter(path, contents, options);
843+
return ll.lint();
844+
}
845+
846+
function lintFile(options, path) {
847+
var contents = fs.readFileSync(path, "utf8");
848+
return lintFileContents(options, path, contents);
849+
}
850+
851+
function lintFileAsync(options, path, cb) {
852+
fs.readFile(path, "utf8", function(err, contents) {
853+
if (err) {
854+
return cb(err);
855+
}
856+
var result = lintFileContents(options, path, contents);
857+
cb(undefined, result);
858+
});
859+
}
860+
861+
var lintTargets = compilerSources.concat(harnessCoreSources);
862+
831863
// if the codebase were free of linter errors we could make jake runtests
832864
// run this task automatically
833865
desc("Runs tslint on the compiler sources");
834866
task("lint", ["build-rules"], function() {
835-
function success(f) { return function() { console.log('SUCCESS: No linter errors in ' + f + '\n'); }};
836-
function failure(f) { return function() { console.log('FAILURE: Please fix linting errors in ' + f + '\n') }};
837-
838-
var lintTargets = compilerSources.concat(harnessCoreSources);
867+
var lintOptions = getLinterOptions();
839868
for (var i in lintTargets) {
840-
var f = lintTargets[i];
841-
var cmd = 'tslint --rules-dir built/local/tslint -c tslint.json ' + f;
842-
exec(cmd, success(f), failure(f));
869+
var result = lintFile(lintOptions, lintTargets[i]);
870+
if (result.failureCount > 0) {
871+
console.log(result.output);
872+
fail('Linter errors.', result.failureCount);
873+
}
843874
}
844-
}, { async: true });
875+
});
876+
877+
/**
878+
* This is required because file watches on Windows get fires _twice_
879+
* when a file changes on some node/windows version configuations
880+
* (node v4 and win 10, for example). By not running a lint for a file
881+
* which already has a pending lint, we avoid duplicating our work.
882+
* (And avoid printing duplicate results!)
883+
*/
884+
var lintSemaphores = {};
885+
886+
function lintWatchFile(filename) {
887+
fs.watch(filename, {persistent: true}, function(event) {
888+
if (event !== "change") {
889+
return;
890+
}
891+
892+
if (!lintSemaphores[filename]) {
893+
lintSemaphores[filename] = true;
894+
lintFileAsync(getLinterOptions(), filename, function(err, result) {
895+
delete lintSemaphores[filename];
896+
if (err) {
897+
console.log(err);
898+
return;
899+
}
900+
if (result.failureCount > 0) {
901+
console.log("***Lint failure***");
902+
for (var i = 0; i < result.failures.length; i++) {
903+
var failure = result.failures[i];
904+
var start = failure.startPosition.lineAndCharacter;
905+
var end = failure.endPosition.lineAndCharacter;
906+
console.log("warning " + filename + " (" + (start.line + 1) + "," + (start.character + 1) + "," + (end.line + 1) + "," + (end.character + 1) + "): " + failure.failure);
907+
}
908+
console.log("*** Total " + result.failureCount + " failures.");
909+
}
910+
});
911+
}
912+
});
913+
}
914+
915+
desc("Watches files for changes to rerun a lint pass");
916+
task("lint-server", ["build-rules"], function() {
917+
console.log("Watching ./src for changes to linted files");
918+
for (var i = 0; i < lintTargets.length; i++) {
919+
lintWatchFile(lintTargets[i]);
920+
}
921+
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@
4040
},
4141
"scripts": {
4242
"pretest": "jake tests",
43-
"test": "jake runtests",
43+
"test": "jake runtests && npm run lint",
4444
"build": "npm run build:compiler && npm run build:tests",
4545
"build:compiler": "jake local",
4646
"build:tests": "jake tests",
4747
"clean": "jake clean",
4848
"jake": "jake",
49+
"lint": "jake lint",
4950
"setup-hooks": "node scripts/link-hooks.js"
5051
},
5152
"browser": {

scripts/tslint/nextLineRule.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const OPTION_CATCH = "check-catch";
55
const OPTION_ELSE = "check-else";
66

77
export class Rule extends Lint.Rules.AbstractRule {
8-
public static CATCH_FAILURE_STRING = "'catch' should be on the line following the previous block's ending curly brace";
9-
public static ELSE_FAILURE_STRING = "'else' should be on the line following the previous block's ending curly brace";
8+
public static CATCH_FAILURE_STRING = "'catch' should not be on the same line as the preceeding block's curly brace";
9+
public static ELSE_FAILURE_STRING = "'else' should not be on the same line as the preceeding block's curly brace";
1010

1111
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
1212
return this.applyWithWalker(new NextLineWalker(sourceFile, this.getOptions()));
@@ -25,7 +25,7 @@ class NextLineWalker extends Lint.RuleWalker {
2525
if (this.hasOption(OPTION_ELSE) && !!elseKeyword) {
2626
const thenStatementEndLoc = sourceFile.getLineAndCharacterOfPosition(thenStatement.getEnd());
2727
const elseKeywordLoc = sourceFile.getLineAndCharacterOfPosition(elseKeyword.getStart(sourceFile));
28-
if (thenStatementEndLoc.line !== (elseKeywordLoc.line - 1)) {
28+
if (thenStatementEndLoc.line === elseKeywordLoc.line) {
2929
const failure = this.createFailure(elseKeyword.getStart(sourceFile), elseKeyword.getWidth(sourceFile), Rule.ELSE_FAILURE_STRING);
3030
this.addFailure(failure);
3131
}
@@ -47,7 +47,7 @@ class NextLineWalker extends Lint.RuleWalker {
4747
const catchKeyword = catchClause.getFirstToken(sourceFile);
4848
const tryClosingBraceLoc = sourceFile.getLineAndCharacterOfPosition(tryClosingBrace.getEnd());
4949
const catchKeywordLoc = sourceFile.getLineAndCharacterOfPosition(catchKeyword.getStart(sourceFile));
50-
if (tryClosingBraceLoc.line !== (catchKeywordLoc.line - 1)) {
50+
if (tryClosingBraceLoc.line === catchKeywordLoc.line) {
5151
const failure = this.createFailure(catchKeyword.getStart(sourceFile), catchKeyword.getWidth(sourceFile), Rule.CATCH_FAILURE_STRING);
5252
this.addFailure(failure);
5353
}
@@ -58,4 +58,4 @@ class NextLineWalker extends Lint.RuleWalker {
5858

5959
function getFirstChildOfKind(node: ts.Node, kind: ts.SyntaxKind) {
6060
return node.getChildren().filter((child) => child.kind === kind)[0];
61-
}
61+
}

src/compiler/binder.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ namespace ts {
103103
let container: Node;
104104
let blockScopeContainer: Node;
105105
let lastContainer: Node;
106+
let seenThisKeyword: boolean;
106107

107108
// state used by reachability checks
108109
let hasExplicitReturn: boolean;
@@ -351,7 +352,14 @@ namespace ts {
351352
blockScopeContainer.locals = undefined;
352353
}
353354

354-
bindWithReachabilityChecks(node);
355+
if (node.kind === SyntaxKind.InterfaceDeclaration) {
356+
seenThisKeyword = false;
357+
bindWithReachabilityChecks(node);
358+
node.flags = seenThisKeyword ? node.flags | NodeFlags.ContainsThis : node.flags & ~NodeFlags.ContainsThis;
359+
}
360+
else {
361+
bindWithReachabilityChecks(node);
362+
}
355363

356364
container = saveContainer;
357365
parent = saveParent;
@@ -1135,6 +1143,9 @@ namespace ts {
11351143
return checkStrictModePrefixUnaryExpression(<PrefixUnaryExpression>node);
11361144
case SyntaxKind.WithStatement:
11371145
return checkStrictModeWithStatement(<WithStatement>node);
1146+
case SyntaxKind.ThisKeyword:
1147+
seenThisKeyword = true;
1148+
return;
11381149

11391150
case SyntaxKind.TypeParameter:
11401151
return declareSymbolAndAddToSymbolTable(<Declaration>node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes);

0 commit comments

Comments
 (0)