Skip to content

Commit 2368b54

Browse files
author
Nick Pape
committed
Fixup encoding per PR comments
1 parent 6356033 commit 2368b54

File tree

8 files changed

+33
-29
lines changed

8 files changed

+33
-29
lines changed

apps/api-documenter/src/markdown/MarkdownDocumenter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as path from 'path';
66
import {
77
PackageName,
88
FileSystem,
9-
NewlineConversion
9+
NewlineKind
1010
} from '@microsoft/node-core-library';
1111
import {
1212
IApiClass,
@@ -601,7 +601,7 @@ export class MarkdownDocumenter {
601601
});
602602

603603
FileSystem.writeFile(filename, content, {
604-
convertLineEndings: NewlineConversion.CrLf
604+
convertLineEndings: NewlineKind.CrLf
605605
});
606606
}
607607

apps/api-documenter/src/yaml/YamlDocumenter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
JsonSchema,
1111
PackageName,
1212
FileSystem,
13-
NewlineConversion
13+
NewlineKind
1414
} from '@microsoft/node-core-library';
1515
import {
1616
MarkupElement,
@@ -419,7 +419,7 @@ export class YamlDocumenter {
419419
}
420420

421421
FileSystem.writeFile(filePath, stringified, {
422-
convertLineEndings: NewlineConversion.CrLf,
422+
convertLineEndings: NewlineKind.CrLf,
423423
ensureFolder: true
424424
});
425425

apps/api-extractor/src/generators/dtsRollup/DtsRollupGenerator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/* tslint:disable:no-bitwise */
55

66
import * as ts from 'typescript';
7-
import { FileSystem, NewlineConversion } from '@microsoft/node-core-library';
7+
import { FileSystem, NewlineKind } from '@microsoft/node-core-library';
88

99
import { ExtractorContext } from '../../ExtractorContext';
1010
import { IndentedWriter } from '../../utils/IndentedWriter';
@@ -116,7 +116,7 @@ export class DtsRollupGenerator {
116116
this._generateTypingsFileContent(indentedWriter, dtsKind);
117117

118118
FileSystem.writeFile(dtsFilename, indentedWriter.toString(), {
119-
convertLineEndings: NewlineConversion.CrLf,
119+
convertLineEndings: NewlineKind.CrLf,
120120
ensureFolder: true
121121
});
122122
}

apps/rush-lib/src/api/ApprovedPackagesConfiguration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import * as path from 'path';
55
import * as os from 'os';
6-
import { JsonFile, JsonSchema, FileSystem, NewlineConversion } from '@microsoft/node-core-library';
6+
import { JsonFile, JsonSchema, FileSystem, NewlineKind } from '@microsoft/node-core-library';
77

88
import { Utilities } from '../utilities/Utilities';
99

@@ -162,7 +162,7 @@ export class ApprovedPackagesConfiguration {
162162
+ ' They will be lost when the Rush tool resaves it.\n' + body;
163163

164164
FileSystem.writeFile(this._jsonFilename, body, {
165-
convertLineEndings: NewlineConversion.CrLf
165+
convertLineEndings: NewlineKind.CrLf
166166
});
167167
}
168168

apps/rush-lib/src/cli/actions/ScanAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class ScanAction extends BaseRushAction {
8181

8282
for (const filename of glob.sync('{./*.{ts,js,tsx,jsx},./{src,lib}/**/*.{ts,js,tsx,jsx}}')) {
8383
try {
84-
const contents: string = FileSystem.readFile(filename, { encoding: 'utf8' });
84+
const contents: string = FileSystem.readFile(filename);
8585
const lines: string[] = contents.split('\n');
8686

8787
for (const line of lines) {

common/reviews/api/node-core-library.api.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ interface IProtectableMapParameters<K, V> {
150150

151151
// @public
152152
interface IReadFileOptions {
153-
convertLineEndings?: NewlineConversion;
153+
convertLineEndings?: NewlineKind;
154154
encoding?: Encoding;
155155
}
156156

@@ -161,7 +161,7 @@ interface IReadFolderOptions {
161161

162162
// @public
163163
interface IWriteFileOptions {
164-
convertLineEndings?: NewlineConversion;
164+
convertLineEndings?: NewlineKind;
165165
encoding?: Encoding;
166166
ensureFolder?: boolean;
167167
}
@@ -203,13 +203,11 @@ class MapExtensions {
203203
}
204204

205205
// @public
206-
enum NewlineConversion {
206+
enum NewlineKind {
207207
// (undocumented)
208208
CrLf = 0,
209209
// (undocumented)
210-
Lf = 1,
211-
// (undocumented)
212-
None = 2
210+
Lf = 1
213211
}
214212

215213
// @public

libraries/node-core-library/src/FileSystem.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@ export const enum Encoding {
1616
* Enumeration controlling conversion of newline characters.
1717
* @public
1818
*/
19-
export enum NewlineConversion {
20-
CrLf,
21-
Lf,
22-
None
19+
export const enum NewlineKind {
20+
/**
21+
* Windows-style newlines
22+
*/
23+
CrLf = '\r\n',
24+
25+
/**
26+
* Unix-style newlines
27+
*/
28+
Lf = '\n'
2329
}
2430

2531
/**
@@ -47,9 +53,9 @@ export interface IWriteFileOptions {
4753

4854
/**
4955
* If specified, will normalize line endings to the specified style of newline.
50-
* Defaults to `NewlineConversion.None`.
56+
* Defaults to `NewlineKind.None`.
5157
*/
52-
convertLineEndings?: NewlineConversion;
58+
convertLineEndings?: NewlineKind;
5359

5460
/**
5561
* If specified, will change the encoding of the file that will be written.
@@ -71,9 +77,9 @@ export interface IReadFileOptions {
7177

7278
/**
7379
* If specified, will normalize line endings to the specified style of newline.
74-
* Defaults to `NewlineConversion.None`.
80+
* Defaults to `NewlineKind.None`.
7581
*/
76-
convertLineEndings?: NewlineConversion;
82+
convertLineEndings?: NewlineKind;
7783
}
7884

7985
/**
@@ -246,7 +252,7 @@ export class FileSystem {
246252
public static writeFile(filePath: string, contents: string, options?: IWriteFileOptions): void {
247253
options = {
248254
ensureFolder: false,
249-
convertLineEndings: NewlineConversion.None,
255+
convertLineEndings: undefined,
250256
encoding: Encoding.Utf8,
251257
...options
252258
};
@@ -270,7 +276,7 @@ export class FileSystem {
270276
public static readFile(filePath: string, options?: IReadFileOptions): string {
271277
options = {
272278
encoding: Encoding.Utf8,
273-
convertLineEndings: NewlineConversion.None,
279+
convertLineEndings: undefined,
274280
...options
275281
};
276282

@@ -373,10 +379,10 @@ export class FileSystem {
373379
* @param text - The text to be normalized.
374380
* @param lineEndings - The style of line endings to use.
375381
*/
376-
private static _convertLineEndings(text: string, lineEndings: NewlineConversion | undefined): string {
377-
if (lineEndings === NewlineConversion.CrLf) {
382+
private static _convertLineEndings(text: string, lineEndings: NewlineKind | undefined): string {
383+
if (lineEndings === NewlineKind.CrLf) {
378384
return Text.convertToCrLf(text);
379-
} else if (lineEndings === NewlineConversion.Lf) {
385+
} else if (lineEndings === NewlineKind.Lf) {
380386
return Text.convertToLf(text);
381387
}
382388
return text;

libraries/node-core-library/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export {
5353
IReadFileOptions,
5454
IMoveOptions,
5555
IDeleteFileOptions,
56-
NewlineConversion
56+
NewlineKind
5757
} from './FileSystem';
5858
export {
5959
FileWriter,

0 commit comments

Comments
 (0)