Skip to content

Commit ff92ab0

Browse files
RyanCavanaughjakebaileysheetalkamat
authored
Change default newLine, forceConsistentCasingInFileNames (#52298)
Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
1 parent 1447819 commit ff92ab0

File tree

219 files changed

+40758
-41182
lines changed

Some content is hidden

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

219 files changed

+40758
-41182
lines changed

src/compiler/commandLineParser.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
12851285
paramType: Diagnostics.NEWLINE,
12861286
category: Diagnostics.Emit,
12871287
description: Diagnostics.Set_the_newline_character_for_emitting_files,
1288-
defaultValueDescription: Diagnostics.Platform_specific
1288+
defaultValueDescription: "lf"
12891289
},
12901290
{
12911291
name: "noErrorTruncation",
@@ -1461,7 +1461,7 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
14611461
affectsModuleResolution: true,
14621462
category: Diagnostics.Interop_Constraints,
14631463
description: Diagnostics.Ensure_that_casing_is_correct_in_imports,
1464-
defaultValueDescription: false,
1464+
defaultValueDescription: true,
14651465
},
14661466
{
14671467
name: "maxNodeModuleJsDepth",

src/compiler/emitter.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFi
741741
const sourceMapDataList: SourceMapEmitResult[] | undefined = (compilerOptions.sourceMap || compilerOptions.inlineSourceMap || getAreDeclarationMapsEnabled(compilerOptions)) ? [] : undefined;
742742
const emittedFilesList: string[] | undefined = compilerOptions.listEmittedFiles ? [] : undefined;
743743
const emitterDiagnostics = createDiagnosticCollection();
744-
const newLine = getNewLineCharacter(compilerOptions, () => host.getNewLine());
744+
const newLine = getNewLineCharacter(compilerOptions);
745745
const writer = createTextWriter(newLine);
746746
const { enter, exit } = performance.createTimer("printTime", "beforePrint", "afterPrint");
747747
let bundleBuildInfo: BundleBuildInfo | undefined;
@@ -1271,7 +1271,6 @@ function emitUsingBuildInfoWorker(
12711271
getCommonSourceDirectory: () => getNormalizedAbsolutePath(buildInfo.bundle!.commonSourceDirectory, buildInfoDirectory),
12721272
getCompilerOptions: () => config.options,
12731273
getCurrentDirectory: () => host.getCurrentDirectory(),
1274-
getNewLine: () => host.getNewLine(),
12751274
getSourceFile: returnUndefined,
12761275
getSourceFileByPath: returnUndefined,
12771276
getSourceFiles: () => sourceFilesForJsEmit,

src/compiler/program.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ export function createCompilerHostWorker(options: CompilerOptions, setParentNode
463463
return getDirectoryPath(normalizePath(system.getExecutingFilePath()));
464464
}
465465

466-
const newLine = getNewLineCharacter(options, () => system.newLine);
466+
const newLine = getNewLineCharacter(options);
467467
const realpath = system.realpath && ((path: string) => system.realpath!(path));
468468
const compilerHost: CompilerHost = {
469469
getSourceFile: createGetSourceFile(fileName => compilerHost.readFile(fileName), () => options, setParentNodes),
@@ -2482,7 +2482,6 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
24822482
getCommonSourceDirectory: program.getCommonSourceDirectory,
24832483
getCompilerOptions: program.getCompilerOptions,
24842484
getCurrentDirectory: () => currentDirectory,
2485-
getNewLine: () => host.getNewLine(),
24862485
getSourceFile: program.getSourceFile,
24872486
getSourceFileByPath: program.getSourceFileByPath,
24882487
getSourceFiles: program.getSourceFiles,
@@ -3450,7 +3449,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
34503449
addFileIncludeReason(file || undefined, reason);
34513450
// try to check if we've already seen this file but with a different casing in path
34523451
// NOTE: this only makes sense for case-insensitive file systems, and only on files which are not redirected
3453-
if (file && options.forceConsistentCasingInFileNames) {
3452+
if (file && !(options.forceConsistentCasingInFileNames === false)) {
34543453
const checkedName = file.fileName;
34553454
const isRedirect = toPath(checkedName) !== toPath(fileName);
34563455
if (isRedirect) {

src/compiler/types.ts

-1
Original file line numberDiff line numberDiff line change
@@ -8008,7 +8008,6 @@ export interface EmitHost extends ScriptReferenceHost, ModuleSpecifierResolution
80088008

80098009
getCommonSourceDirectory(): string;
80108010
getCanonicalFileName(fileName: string): string;
8011-
getNewLine(): string;
80128011

80138012
isEmitBlocked(emitFileName: string): boolean;
80148013

src/compiler/utilities.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,6 @@ import {
490490
SymbolTable,
491491
SyntaxKind,
492492
SyntaxList,
493-
sys,
494493
TaggedTemplateExpression,
495494
TemplateLiteral,
496495
TemplateLiteralLikeNode,
@@ -6870,14 +6869,14 @@ export function directoryProbablyExists(directoryName: string, host: { directory
68706869
const carriageReturnLineFeed = "\r\n";
68716870
const lineFeed = "\n";
68726871
/** @internal */
6873-
export function getNewLineCharacter(options: CompilerOptions | PrinterOptions, getNewLine?: () => string): string {
6872+
export function getNewLineCharacter(options: CompilerOptions | PrinterOptions): string {
68746873
switch (options.newLine) {
68756874
case NewLineKind.CarriageReturnLineFeed:
68766875
return carriageReturnLineFeed;
68776876
case NewLineKind.LineFeed:
6878-
return lineFeed;
6877+
case undefined:
6878+
return lineFeed;
68796879
}
6880-
return getNewLine ? getNewLine() : sys ? sys.newLine : carriageReturnLineFeed;
68816880
}
68826881

68836882
/**

src/compiler/watch.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,6 @@ export function createWatchFactory<Y = undefined>(host: WatchFactoryHost & { tra
745745
/** @internal */
746746
export function createCompilerHostFromProgramHost(host: ProgramHost<any>, getCompilerOptions: () => CompilerOptions, directoryStructureHost: DirectoryStructureHost = host): CompilerHost {
747747
const useCaseSensitiveFileNames = host.useCaseSensitiveFileNames();
748-
const hostGetNewLine = memoize(() => host.getNewLine());
749748
const compilerHost: CompilerHost = {
750749
getSourceFile: createGetSourceFile(
751750
(fileName, encoding) => !encoding ? compilerHost.readFile(fileName) : host.readFile(fileName, encoding),
@@ -762,7 +761,7 @@ export function createCompilerHostFromProgramHost(host: ProgramHost<any>, getCom
762761
getCurrentDirectory: memoize(() => host.getCurrentDirectory()),
763762
useCaseSensitiveFileNames: () => useCaseSensitiveFileNames,
764763
getCanonicalFileName: createGetCanonicalFileName(useCaseSensitiveFileNames),
765-
getNewLine: () => getNewLineCharacter(getCompilerOptions(), hostGetNewLine),
764+
getNewLine: () => getNewLineCharacter(getCompilerOptions()),
766765
fileExists: f => host.fileExists(f),
767766
readFile: f => host.readFile(f),
768767
trace: maybeBind(host, host.trace),
@@ -867,7 +866,7 @@ function createWatchCompilerHost<T extends BuilderProgram = EmitAndSemanticDiagn
867866
copyProperties(result, createWatchHost(system, reportWatchStatus));
868867
result.afterProgramCreate = builderProgram => {
869868
const compilerOptions = builderProgram.getCompilerOptions();
870-
const newLine = getNewLineCharacter(compilerOptions, () => system.newLine);
869+
const newLine = getNewLineCharacter(compilerOptions);
871870

872871
emitFilesAndReportErrors(
873872
builderProgram,

src/compiler/watchPublic.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ export function createWatchProgram<T extends BuilderProgram>(host: WatchCompiler
441441
}
442442
reportWatchDiagnostic(Diagnostics.Starting_compilation_in_watch_mode);
443443
if (configFileName && !host.configFileParsingResult) {
444-
newLine = getNewLineCharacter(optionsToExtendForConfigFile, () => host.getNewLine());
444+
newLine = getNewLineCharacter(optionsToExtendForConfigFile);
445445
Debug.assert(!rootFileNames);
446446
parseConfigFile();
447447
newLine = updateNewLine();
@@ -668,7 +668,7 @@ export function createWatchProgram<T extends BuilderProgram>(host: WatchCompiler
668668
}
669669

670670
function updateNewLine() {
671-
return getNewLineCharacter(compilerOptions || optionsToExtendForConfigFile, () => host.getNewLine());
671+
return getNewLineCharacter(compilerOptions || optionsToExtendForConfigFile);
672672
}
673673

674674
function toPath(fileName: string) {

src/harness/fakesHosts.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ export class CompilerHost implements ts.CompilerHost {
243243
if (sys instanceof vfs.FileSystem) sys = new System(sys);
244244
this.sys = sys;
245245
this.defaultLibLocation = sys.vfs.meta.get("defaultLibLocation") || "";
246-
this._newLine = ts.getNewLineCharacter(options, () => this.sys.newLine);
246+
this._newLine = ts.getNewLineCharacter(options);
247247
this._sourceFiles = new collections.SortedMap<string, ts.SourceFile>({ comparer: sys.vfs.stringComparer, sort: "insertion" });
248248
this._setParentNodes = setParentNodes;
249249
this._outputsMap = new collections.SortedMap(this.vfs.stringComparer);

src/harness/fourslashImpl.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const enum MetadataOptionNames {
9898
const fileMetadataNames = [MetadataOptionNames.fileName, MetadataOptionNames.emitThisFile, MetadataOptionNames.resolveReference, MetadataOptionNames.symlink];
9999

100100
function convertGlobalOptionsToCompilerOptions(globalOptions: Harness.TestCaseParser.CompilerSettings): ts.CompilerOptions {
101-
const settings: ts.CompilerOptions = { target: ts.ScriptTarget.ES5 };
101+
const settings: ts.CompilerOptions = { target: ts.ScriptTarget.ES5, newLine: ts.NewLineKind.CarriageReturnLineFeed };
102102
Harness.Compiler.setCompilerOptionsFromHarnessSetting(globalOptions, settings);
103103
return settings;
104104
}

src/harness/harnessLanguageService.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import * as collections from "./_namespaces/collections";
55
import * as vpath from "./_namespaces/vpath";
66
import {
77
Compiler,
8-
harnessNewLine,
98
mockHash,
109
virtualFileSystemRoot,
1110
} from "./_namespaces/Harness";
11+
import { getNewLineCharacter } from "./_namespaces/ts";
1212

1313
export function makeDefaultProxy(info: ts.server.PluginCreateInfo): ts.LanguageService {
1414
const proxy = Object.create(/*prototype*/ null); // eslint-disable-line no-null/no-null
@@ -149,7 +149,7 @@ export abstract class LanguageServiceAdapterHost {
149149
}
150150

151151
public getNewLine(): string {
152-
return harnessNewLine;
152+
return getNewLineCharacter(this.settings);
153153
}
154154

155155
public getFilenames(): string[] {

src/services/completions.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ import {
9191
getNameTable,
9292
getNewLineCharacter,
9393
getNewLineKind,
94+
getNewLineOrDefaultFromHost,
9495
getPropertyNameForPropertyNameNode,
9596
getQuotePreference,
9697
getReplacementSpanForContextToken,
@@ -262,7 +263,6 @@ import {
262263
LiteralTypeNode,
263264
map,
264265
mapDefined,
265-
maybeBind,
266266
MemberOverrideStatus,
267267
memoize,
268268
memoizeOne,
@@ -1069,12 +1069,12 @@ function getExhaustiveCaseSnippets(
10691069
}
10701070

10711071
const newClauses = map(elements, element => factory.createCaseClause(element, []));
1072-
const newLineChar = getNewLineCharacter(options, maybeBind(host, host.getNewLine));
1072+
const newLineChar = getNewLineOrDefaultFromHost(host, formatContext?.options);
10731073
const printer = createSnippetPrinter({
10741074
removeComments: true,
10751075
module: options.module,
10761076
target: options.target,
1077-
newLine: getNewLineKind(newLineChar),
1077+
newLine: getNewLineKind(newLineChar)
10781078
});
10791079
const printNode = formatContext
10801080
? (node: Node) => printer.printAndFormatNode(EmitHint.Unspecified, node, sourceFile, formatContext)
@@ -1572,7 +1572,7 @@ function getEntryForMemberCompletion(
15721572
module: options.module,
15731573
target: options.target,
15741574
omitTrailingSemicolon: false,
1575-
newLine: getNewLineKind(getNewLineCharacter(options, maybeBind(host, host.getNewLine))),
1575+
newLine: getNewLineKind(getNewLineOrDefaultFromHost(host, formatContext?.options)),
15761576
});
15771577
const importAdder = codefix.createImportAdder(sourceFile, program, preferences, host);
15781578

@@ -1738,7 +1738,7 @@ function getEntryForObjectLiteralMethodCompletion(
17381738
module: options.module,
17391739
target: options.target,
17401740
omitTrailingSemicolon: false,
1741-
newLine: getNewLineKind(getNewLineCharacter(options, maybeBind(host, host.getNewLine))),
1741+
newLine: getNewLineKind(getNewLineOrDefaultFromHost(host, formatContext?.options)),
17421742
});
17431743
if (formatContext) {
17441744
insertText = printer.printAndFormatSnippetList(ListFormat.CommaDelimited | ListFormat.AllowTrailingComma, factory.createNodeArray([method], /*hasTrailingComma*/ true), sourceFile, formatContext);

src/services/services.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1643,7 +1643,7 @@ export function createLanguageService(
16431643
getCancellationToken: () => cancellationToken,
16441644
getCanonicalFileName,
16451645
useCaseSensitiveFileNames: () => useCaseSensitiveFileNames,
1646-
getNewLine: () => getNewLineCharacter(newSettings, () => getNewLineOrDefaultFromHost(host)),
1646+
getNewLine: () => getNewLineCharacter(newSettings),
16471647
getDefaultLibFileName: options => host.getDefaultLibFileName(options),
16481648
writeFile: noop,
16491649
getCurrentDirectory: () => currentDirectory,
@@ -2437,7 +2437,7 @@ export function createLanguageService(
24372437
}
24382438

24392439
function getDocCommentTemplateAtPosition(fileName: string, position: number, options?: DocCommentTemplateOptions): TextInsertion | undefined {
2440-
return JsDoc.getDocCommentTemplateAtPosition(getNewLineOrDefaultFromHost(host), syntaxTreeCache.getCurrentSourceFile(fileName), position, options);
2440+
return JsDoc.getDocCommentTemplateAtPosition(getNewLineOrDefaultFromHost(host, /*formatSettings*/ undefined), syntaxTreeCache.getCurrentSourceFile(fileName), position, options);
24412441
}
24422442

24432443
function isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean {

src/services/shims.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ class LanguageServiceShimObject extends ShimBase implements LanguageServiceShim
781781
}
782782

783783
private realizeDiagnostics(diagnostics: readonly Diagnostic[]): { message: string; start: number; length: number; category: string; }[] {
784-
const newLine = getNewLineOrDefaultFromHost(this.host);
784+
const newLine = getNewLineOrDefaultFromHost(this.host, /*formatSettings*/ undefined);
785785
return realizeDiagnostics(diagnostics, newLine);
786786
}
787787

src/services/utilities.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -2930,16 +2930,16 @@ function findLinkNameEnd(text: string) {
29302930
return 0;
29312931
}
29322932

2933-
const carriageReturnLineFeed = "\r\n";
2933+
const lineFeed = "\n";
29342934
/**
2935-
* The default is CRLF.
2935+
* The default is LF.
29362936
*
29372937
* @internal
29382938
*/
2939-
export function getNewLineOrDefaultFromHost(host: FormattingHost, formatSettings?: FormatCodeSettings) {
2939+
export function getNewLineOrDefaultFromHost(host: FormattingHost, formatSettings: FormatCodeSettings | undefined) {
29402940
return formatSettings?.newLineCharacter ||
29412941
host.getNewLine?.() ||
2942-
carriageReturnLineFeed;
2942+
lineFeed;
29432943
}
29442944

29452945
/** @internal */

src/testRunner/unittests/services/languageService.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function Component(x: Config): any;`
8282
diagnostics: ts.emptyArray,
8383
outputFiles: [{
8484
name: "foo.d.ts",
85-
text: "export {};\r\n",
85+
text: "export {};\n",
8686
writeByteOrderMark: false
8787
}],
8888
}

src/testRunner/unittests/tscWatch/programUpdates.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,7 @@ export function f(p: C) { return p; }`
14711471
};
14721472
const config: File = {
14731473
path: `/tsconfig.json`,
1474-
content: JSON.stringify({ compilerOptions: {} })
1474+
content: JSON.stringify({ compilerOptions: { forceConsistentCasingInFileNames: false } })
14751475
};
14761476
return createWatchedSystem([aFile, bFile, config, libFile], { useCaseSensitiveFileNames: false });
14771477
},

tests/baselines/reference/completionsClassMembers2.baseline

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@
199199
"kind": "method",
200200
"kindModifiers": "",
201201
"sortText": "17",
202-
"insertText": "method(): void {\r\n}",
202+
"insertText": "method(): void {\n}",
203203
"displayParts": [
204204
{
205205
"text": "(",
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
var X = /** @class */ (function () {
2-
function X() {
3-
}
4-
X.prototype.foobar = function (x) { return x; };
5-
return X;
6-
}());
1+
var X = /** @class */ (function () {
2+
function X() {
3+
}
4+
X.prototype.foobar = function (x) { return x; };
5+
return X;
6+
}());

0 commit comments

Comments
 (0)