mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
enforce triple-equals
This commit is contained in:
parent
9bfba73418
commit
7e03429a8e
@ -338,7 +338,7 @@ namespace ts {
|
||||
TypeofNEHostObject = 1 << 13, // typeof x !== "xxx"
|
||||
EQUndefined = 1 << 14, // x === undefined
|
||||
EQNull = 1 << 15, // x === null
|
||||
EQUndefinedOrNull = 1 << 16, // x == undefined / x == null
|
||||
EQUndefinedOrNull = 1 << 16, // x === undefined / x === null
|
||||
NEUndefined = 1 << 17, // x !== undefined
|
||||
NENull = 1 << 18, // x !== null
|
||||
NEUndefinedOrNull = 1 << 19, // x != undefined / x != null
|
||||
@ -17506,7 +17506,7 @@ namespace ts {
|
||||
function checkObjectTypeForDuplicateDeclarations(node: TypeLiteralNode | InterfaceDeclaration) {
|
||||
const names = createMap<boolean>();
|
||||
for (const member of node.members) {
|
||||
if (member.kind == SyntaxKind.PropertySignature) {
|
||||
if (member.kind === SyntaxKind.PropertySignature) {
|
||||
let memberName: string;
|
||||
switch (member.name.kind) {
|
||||
case SyntaxKind.StringLiteral:
|
||||
|
||||
@ -378,7 +378,7 @@ namespace ts {
|
||||
directoryPathMap.set(parent, result);
|
||||
current = parent;
|
||||
|
||||
if (current == commonPrefix) {
|
||||
if (current === commonPrefix) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -557,7 +557,7 @@ namespace ts {
|
||||
// combine results of resolutions and predicted results
|
||||
let j = 0;
|
||||
for (let i = 0; i < result.length; i++) {
|
||||
if (result[i] == predictedToResolveToAmbientModuleMarker) {
|
||||
if (result[i] === predictedToResolveToAmbientModuleMarker) {
|
||||
result[i] = undefined;
|
||||
}
|
||||
else {
|
||||
@ -1364,7 +1364,7 @@ namespace ts {
|
||||
|
||||
// If the file was previously found via a node_modules search, but is now being processed as a root file,
|
||||
// then everything it sucks in may also be marked incorrectly, and needs to be checked again.
|
||||
if (file && sourceFilesFoundSearchingNodeModules.get(file.path) && currentNodeModulesDepth == 0) {
|
||||
if (file && sourceFilesFoundSearchingNodeModules.get(file.path) && currentNodeModulesDepth === 0) {
|
||||
sourceFilesFoundSearchingNodeModules.set(file.path, false);
|
||||
if (!options.noResolve) {
|
||||
processReferencedFiles(file, isDefaultLib);
|
||||
|
||||
@ -30,7 +30,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function reportEmittedFiles(files: string[]): void {
|
||||
if (!files || files.length == 0) {
|
||||
if (!files || files.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -282,7 +282,7 @@ namespace ts {
|
||||
// When the configFileName is just "tsconfig.json", the watched directory should be
|
||||
// the current directory; if there is a given "project" parameter, then the configFileName
|
||||
// is an absolute file name.
|
||||
directory == "" ? "." : directory,
|
||||
directory === "" ? "." : directory,
|
||||
watchedDirectoryChanged, /*recursive*/ true);
|
||||
}
|
||||
}
|
||||
@ -334,7 +334,7 @@ namespace ts {
|
||||
// When the configFileName is just "tsconfig.json", the watched directory should be
|
||||
// the current directory; if there is a given "project" parameter, then the configFileName
|
||||
// is an absolute file name.
|
||||
directory == "" ? "." : directory,
|
||||
directory === "" ? "." : directory,
|
||||
watchedDirectoryChanged, /*recursive*/ true);
|
||||
};
|
||||
}
|
||||
|
||||
@ -4658,7 +4658,7 @@ namespace ts {
|
||||
*/
|
||||
export function getParseTreeNode<T extends Node>(node: Node, nodeTest?: (node: Node) => node is T): T;
|
||||
export function getParseTreeNode(node: Node, nodeTest?: (node: Node) => boolean): Node {
|
||||
if (node == undefined || isParseTreeNode(node)) {
|
||||
if (node === undefined || isParseTreeNode(node)) {
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
@ -2275,13 +2275,13 @@ namespace FourSlash {
|
||||
|
||||
public verifyImportFixAtPosition(expectedTextArray: string[], errorCode?: number) {
|
||||
const ranges = this.getRanges();
|
||||
if (ranges.length == 0) {
|
||||
if (ranges.length === 0) {
|
||||
this.raiseError("At least one range should be specified in the testfile.");
|
||||
}
|
||||
|
||||
const codeFixes = this.getCodeFixActions(this.activeFile.fileName, errorCode);
|
||||
|
||||
if (!codeFixes || codeFixes.length == 0) {
|
||||
if (!codeFixes || codeFixes.length === 0) {
|
||||
this.raiseError("No codefixes returned.");
|
||||
}
|
||||
|
||||
@ -2646,7 +2646,7 @@ namespace FourSlash {
|
||||
private assertItemInCompletionList(items: ts.CompletionEntry[], name: string, text?: string, documentation?: string, kind?: string, spanIndex?: number) {
|
||||
for (const item of items) {
|
||||
if (item.name === name) {
|
||||
if (documentation != undefined || text !== undefined) {
|
||||
if (documentation !== undefined || text !== undefined) {
|
||||
const details = this.getCompletionEntryDetails(item.name);
|
||||
|
||||
if (documentation !== undefined) {
|
||||
@ -2899,7 +2899,7 @@ ${code}
|
||||
}
|
||||
// TODO: should be '==='?
|
||||
}
|
||||
else if (line == "" || lineLength === 0) {
|
||||
else if (line === "" || lineLength === 0) {
|
||||
// Previously blank lines between fourslash content caused it to be considered as 2 files,
|
||||
// Remove this behavior since it just causes errors now
|
||||
}
|
||||
|
||||
@ -1933,7 +1933,7 @@ namespace Harness {
|
||||
}
|
||||
|
||||
const parentDirectory = IO.directoryName(dirName);
|
||||
if (parentDirectory != "") {
|
||||
if (parentDirectory !== "") {
|
||||
createDirectoryStructure(parentDirectory);
|
||||
}
|
||||
IO.createDirectory(dirName);
|
||||
|
||||
@ -112,7 +112,7 @@ class ProjectRunner extends RunnerBase {
|
||||
// Replace the disk specific path into the project root path
|
||||
url = url.substr(diskProjectPath.length);
|
||||
// TODO: should be '!=='?
|
||||
if (url.charCodeAt(0) != ts.CharacterCodes.slash) {
|
||||
if (url.charCodeAt(0) !== ts.CharacterCodes.slash) {
|
||||
url = "/" + url;
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,11 +50,11 @@ namespace Harness.SourceMapRecorder {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sourceMapMappings.charAt(decodingIndex) == ",") {
|
||||
if (sourceMapMappings.charAt(decodingIndex) === ",") {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sourceMapMappings.charAt(decodingIndex) == ";") {
|
||||
if (sourceMapMappings.charAt(decodingIndex) === ";") {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -117,7 +117,7 @@ namespace Harness.SourceMapRecorder {
|
||||
}
|
||||
|
||||
while (decodingIndex < sourceMapMappings.length) {
|
||||
if (sourceMapMappings.charAt(decodingIndex) == ";") {
|
||||
if (sourceMapMappings.charAt(decodingIndex) === ";") {
|
||||
// New line
|
||||
decodeOfEncodedMapping.emittedLine++;
|
||||
decodeOfEncodedMapping.emittedColumn = 1;
|
||||
@ -125,7 +125,7 @@ namespace Harness.SourceMapRecorder {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sourceMapMappings.charAt(decodingIndex) == ",") {
|
||||
if (sourceMapMappings.charAt(decodingIndex) === ",") {
|
||||
// Next entry is on same line - no action needed
|
||||
decodingIndex++;
|
||||
continue;
|
||||
|
||||
@ -3144,7 +3144,7 @@ namespace ts.projectSystem {
|
||||
checkNumberOfInferredProjects(projectService, 1);
|
||||
|
||||
const configuredProject = projectService.configuredProjects[0];
|
||||
assert.isTrue(configuredProject.getFileNames().length == 0);
|
||||
assert.isTrue(configuredProject.getFileNames().length === 0);
|
||||
|
||||
const inferredProject = projectService.inferredProjects[0];
|
||||
assert.isTrue(inferredProject.containsFile(<server.NormalizedPath>file1.path));
|
||||
|
||||
@ -278,7 +278,7 @@ and grew 1cm per day`;
|
||||
const insertString = testContent.substring(rsa[i], rsa[i] + las[i]);
|
||||
svc.edit(ersa[i], elas[i], insertString);
|
||||
checkText = editFlat(ersa[i], elas[i], insertString, checkText);
|
||||
if (0 == (i % 4)) {
|
||||
if (0 === (i % 4)) {
|
||||
const snap = svc.getSnapshot();
|
||||
const snapText = snap.getText(0, checkText.length);
|
||||
assert.equal(checkText, snapText);
|
||||
|
||||
@ -204,7 +204,7 @@ namespace ts.server {
|
||||
startWatchingContainingDirectoriesForFile(fileName: string, project: InferredProject, callback: (fileName: string) => void) {
|
||||
let currentPath = getDirectoryPath(fileName);
|
||||
let parentPath = getDirectoryPath(currentPath);
|
||||
while (currentPath != parentPath) {
|
||||
while (currentPath !== parentPath) {
|
||||
if (!this.directoryWatchersForTsconfig.has(currentPath)) {
|
||||
this.projectService.logger.info(`Add watcher for: ${currentPath}`);
|
||||
this.directoryWatchersForTsconfig.set(currentPath, this.projectService.host.watchDirectory(currentPath, callback));
|
||||
@ -540,7 +540,7 @@ namespace ts.server {
|
||||
*/
|
||||
private onConfigFileAddedForInferredProject(fileName: string) {
|
||||
// TODO: check directory separators
|
||||
if (getBaseFileName(fileName) != "tsconfig.json") {
|
||||
if (getBaseFileName(fileName) !== "tsconfig.json") {
|
||||
this.logger.info(`${fileName} is not tsconfig.json`);
|
||||
return;
|
||||
}
|
||||
@ -950,7 +950,7 @@ namespace ts.server {
|
||||
const scriptKind = propertyReader.getScriptKind(f);
|
||||
const hasMixedContent = propertyReader.hasMixedContent(f, this.hostConfiguration.extraFileExtensions);
|
||||
if (this.host.fileExists(rootFilename)) {
|
||||
const info = this.getOrCreateScriptInfoForNormalizedPath(toNormalizedPath(rootFilename), /*openedByClient*/ clientFileName == rootFilename, /*fileContent*/ undefined, scriptKind, hasMixedContent);
|
||||
const info = this.getOrCreateScriptInfoForNormalizedPath(toNormalizedPath(rootFilename), /*openedByClient*/ clientFileName === rootFilename, /*fileContent*/ undefined, scriptKind, hasMixedContent);
|
||||
project.addRoot(info);
|
||||
}
|
||||
else {
|
||||
|
||||
@ -643,7 +643,7 @@ namespace ts.server {
|
||||
// check if requested version is the same that we have reported last time
|
||||
if (this.lastReportedFileNames && lastKnownVersion === this.lastReportedVersion) {
|
||||
// if current structure version is the same - return info without any changes
|
||||
if (this.projectStructureVersion == this.lastReportedVersion && !updatedFileNames) {
|
||||
if (this.projectStructureVersion === this.lastReportedVersion && !updatedFileNames) {
|
||||
return { info, projectErrors: this.projectErrors };
|
||||
}
|
||||
// compute and return the difference
|
||||
|
||||
@ -79,7 +79,7 @@ namespace ts.server {
|
||||
const lm = LineIndex.linesFromText(insertedText);
|
||||
const lines = lm.lines;
|
||||
if (lines.length > 1) {
|
||||
if (lines[lines.length - 1] == "") {
|
||||
if (lines[lines.length - 1] === "") {
|
||||
lines.length--;
|
||||
}
|
||||
}
|
||||
@ -570,7 +570,7 @@ namespace ts.server {
|
||||
}
|
||||
if (this.checkEdits) {
|
||||
const updatedText = this.getText(0, this.root.charCount());
|
||||
Debug.assert(checkText == updatedText, "buffer edit mismatch");
|
||||
Debug.assert(checkText === updatedText, "buffer edit mismatch");
|
||||
}
|
||||
return walker.lineIndex;
|
||||
}
|
||||
|
||||
@ -367,7 +367,7 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
this.projectService.updateTypingsForProject(response);
|
||||
if (response.kind == ActionSet && this.socket) {
|
||||
if (response.kind === ActionSet && this.socket) {
|
||||
this.sendEvent(0, "setTypings", response);
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ namespace ts.server {
|
||||
if (a.file < b.file) {
|
||||
return -1;
|
||||
}
|
||||
else if (a.file == b.file) {
|
||||
else if (a.file === b.file) {
|
||||
const n = compareNumber(a.start.line, b.start.line);
|
||||
if (n === 0) {
|
||||
return compareNumber(a.start.offset, b.start.offset);
|
||||
@ -1084,7 +1084,7 @@ namespace ts.server {
|
||||
// getFormattingEditsAfterKeystroke either empty or pertaining
|
||||
// only to the previous line. If all this is true, then
|
||||
// add edits necessary to properly indent the current line.
|
||||
if ((args.key == "\n") && ((!edits) || (edits.length === 0) || allEditsBeforePos(edits, position))) {
|
||||
if ((args.key === "\n") && ((!edits) || (edits.length === 0) || allEditsBeforePos(edits, position))) {
|
||||
const lineInfo = scriptInfo.getLineInfo(args.line);
|
||||
if (lineInfo && (lineInfo.leaf) && (lineInfo.leaf.text)) {
|
||||
const lineText = lineInfo.leaf.text;
|
||||
@ -1093,10 +1093,10 @@ namespace ts.server {
|
||||
let hasIndent = 0;
|
||||
let i: number, len: number;
|
||||
for (i = 0, len = lineText.length; i < len; i++) {
|
||||
if (lineText.charAt(i) == " ") {
|
||||
if (lineText.charAt(i) === " ") {
|
||||
hasIndent++;
|
||||
}
|
||||
else if (lineText.charAt(i) == "\t") {
|
||||
else if (lineText.charAt(i) === "\t") {
|
||||
hasIndent += formatOptions.tabSize;
|
||||
}
|
||||
else {
|
||||
@ -1499,7 +1499,7 @@ namespace ts.server {
|
||||
const normalizedFileName = toNormalizedPath(fileName);
|
||||
const project = this.projectService.getDefaultProjectForFile(normalizedFileName, /*refreshInferredProjects*/ true);
|
||||
for (const fileNameInProject of fileNamesInProject) {
|
||||
if (this.getCanonicalFileName(fileNameInProject) == this.getCanonicalFileName(fileName))
|
||||
if (this.getCanonicalFileName(fileNameInProject) === this.getCanonicalFileName(fileName))
|
||||
highPriorityFiles.push(fileNameInProject);
|
||||
else {
|
||||
const info = this.projectService.getScriptInfo(fileNameInProject);
|
||||
@ -1520,7 +1520,7 @@ namespace ts.server {
|
||||
const checkList = fileNamesInProject.map(fileName => ({ fileName, project }));
|
||||
// Project level error analysis runs on background files too, therefore
|
||||
// doesn't require the file to be opened
|
||||
this.updateErrorCheck(next, checkList, this.changeSeq, (n) => n == this.changeSeq, delay, 200, /*requireOpen*/ false);
|
||||
this.updateErrorCheck(next, checkList, this.changeSeq, (n) => n === this.changeSeq, delay, 200, /*requireOpen*/ false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -61,7 +61,7 @@ namespace ts.server {
|
||||
|
||||
function compilerOptionsChanged(opt1: CompilerOptions, opt2: CompilerOptions): boolean {
|
||||
// TODO: add more relevant properties
|
||||
return opt1.allowJs != opt2.allowJs;
|
||||
return opt1.allowJs !== opt2.allowJs;
|
||||
}
|
||||
|
||||
function unresolvedImportsChanged(imports1: SortedReadonlyArray<string>, imports2: SortedReadonlyArray<string>): boolean {
|
||||
|
||||
@ -31,7 +31,7 @@ namespace ts.server.typingsInstaller {
|
||||
}
|
||||
|
||||
function getNPMLocation(processName: string) {
|
||||
if (path.basename(processName).indexOf("node") == 0) {
|
||||
if (path.basename(processName).indexOf("node") === 0) {
|
||||
return `"${path.join(path.dirname(process.argv[0]), "npm")}"`;
|
||||
}
|
||||
else {
|
||||
|
||||
@ -219,7 +219,7 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
public scheduleCollect() {
|
||||
if (!this.host.gc || this.timerId != undefined) {
|
||||
if (!this.host.gc || this.timerId !== undefined) {
|
||||
// no global.gc or collection was already scheduled - skip this request
|
||||
return;
|
||||
}
|
||||
|
||||
@ -264,7 +264,7 @@ namespace ts.BreakpointResolver {
|
||||
// a or ...c or d: x from
|
||||
// [a, b, ...c] or { a, b } or { d: x } from destructuring pattern
|
||||
if ((node.kind === SyntaxKind.Identifier ||
|
||||
node.kind == SyntaxKind.SpreadElement ||
|
||||
node.kind === SyntaxKind.SpreadElement ||
|
||||
node.kind === SyntaxKind.PropertyAssignment ||
|
||||
node.kind === SyntaxKind.ShorthandPropertyAssignment) &&
|
||||
isArrayLiteralOrObjectLiteralDestructuringPattern(node.parent)) {
|
||||
|
||||
@ -14,7 +14,7 @@ namespace ts.codefix {
|
||||
// ^^^^^^^
|
||||
const token = getTokenAtPosition(sourceFile, start);
|
||||
|
||||
if (token.kind != SyntaxKind.Identifier) {
|
||||
if (token.kind !== SyntaxKind.Identifier) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ namespace ts.codefix {
|
||||
|
||||
// figure out if the `this` access is actually inside the supercall
|
||||
// i.e. super(this.a), since in that case we won't suggest a fix
|
||||
if (superCall.expression && superCall.expression.kind == SyntaxKind.CallExpression) {
|
||||
if (superCall.expression && superCall.expression.kind === SyntaxKind.CallExpression) {
|
||||
const arguments = (<CallExpression>superCall.expression).arguments;
|
||||
for (let i = 0; i < arguments.length; i++) {
|
||||
if ((<PropertyAccessExpression>arguments[i]).expression === token) {
|
||||
|
||||
@ -125,7 +125,7 @@ namespace ts.codefix {
|
||||
|
||||
case SyntaxKind.NamespaceImport:
|
||||
const namespaceImport = <NamespaceImport>token.parent;
|
||||
if (namespaceImport.name == token && !(<ImportClause>namespaceImport.parent).name) {
|
||||
if (namespaceImport.name === token && !(<ImportClause>namespaceImport.parent).name) {
|
||||
const importDecl = getAncestor(namespaceImport, SyntaxKind.ImportDeclaration);
|
||||
return deleteNode(importDecl);
|
||||
}
|
||||
|
||||
@ -1311,7 +1311,7 @@ namespace ts.Completions {
|
||||
}
|
||||
|
||||
function isEqualityOperatorKind(kind: SyntaxKind) {
|
||||
return kind == SyntaxKind.EqualsEqualsToken ||
|
||||
return kind === SyntaxKind.EqualsEqualsToken ||
|
||||
kind === SyntaxKind.ExclamationEqualsToken ||
|
||||
kind === SyntaxKind.EqualsEqualsEqualsToken ||
|
||||
kind === SyntaxKind.ExclamationEqualsEqualsToken;
|
||||
|
||||
@ -293,7 +293,7 @@ namespace ts {
|
||||
const oldSnapshotShim = <ScriptSnapshotShimAdapter>oldSnapshot;
|
||||
const encoded = this.scriptSnapshotShim.getChangeRange(oldSnapshotShim.scriptSnapshotShim);
|
||||
// TODO: should this be '==='?
|
||||
if (encoded == null) {
|
||||
if (encoded === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -382,7 +382,7 @@ namespace ts {
|
||||
public getCompilationSettings(): CompilerOptions {
|
||||
const settingsJson = this.shimHost.getCompilationSettings();
|
||||
// TODO: should this be '==='?
|
||||
if (settingsJson == null || settingsJson == "") {
|
||||
if (settingsJson === null || settingsJson === "") {
|
||||
throw Error("LanguageServiceShimHostAdapter.getCompilationSettings: empty compilationSettings");
|
||||
}
|
||||
const compilerOptions = <CompilerOptions>JSON.parse(settingsJson);
|
||||
@ -416,7 +416,7 @@ namespace ts {
|
||||
|
||||
public getLocalizedDiagnosticMessages(): any {
|
||||
const diagnosticMessagesJson = this.shimHost.getLocalizedDiagnosticMessages();
|
||||
if (diagnosticMessagesJson == null || diagnosticMessagesJson == "") {
|
||||
if (diagnosticMessagesJson === null || diagnosticMessagesJson === "") {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@ -56,7 +56,7 @@ namespace ts.SignatureHelp {
|
||||
// break;
|
||||
|
||||
// case TypeScript.SyntaxKind.CommaToken:
|
||||
// if (stack == 0) {
|
||||
// if (stack === 0) {
|
||||
// argumentIndex++;
|
||||
// }
|
||||
|
||||
|
||||
@ -465,7 +465,7 @@ namespace ts.textChanges {
|
||||
change.options.indentation !== undefined
|
||||
? change.options.indentation
|
||||
: change.useIndentationFromFile
|
||||
? formatting.SmartIndenter.getIndentation(change.range.pos, sourceFile, formatOptions, posStartsLine || (change.options.prefix == this.newLineCharacter))
|
||||
? formatting.SmartIndenter.getIndentation(change.range.pos, sourceFile, formatOptions, posStartsLine || (change.options.prefix === this.newLineCharacter))
|
||||
: 0;
|
||||
const delta =
|
||||
change.options.delta !== undefined
|
||||
|
||||
@ -911,10 +911,10 @@ namespace ts {
|
||||
// Internally, we represent the end of the comment at the newline and closing '/', respectively.
|
||||
return predicate ?
|
||||
forEach(commentRanges, c => c.pos < position &&
|
||||
(c.kind == SyntaxKind.SingleLineCommentTrivia ? position <= c.end : position < c.end) &&
|
||||
(c.kind === SyntaxKind.SingleLineCommentTrivia ? position <= c.end : position < c.end) &&
|
||||
predicate(c)) :
|
||||
forEach(commentRanges, c => c.pos < position &&
|
||||
(c.kind == SyntaxKind.SingleLineCommentTrivia ? position <= c.end : position < c.end));
|
||||
(c.kind === SyntaxKind.SingleLineCommentTrivia ? position <= c.end : position < c.end));
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@ -59,6 +59,7 @@
|
||||
"no-increment-decrement": true,
|
||||
"object-literal-surrounding-space": true,
|
||||
"no-type-assertion-whitespace": true,
|
||||
"no-in-operator": true
|
||||
"no-in-operator": true,
|
||||
"triple-equals": true
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user