Skip to content

Commit cd9dbe6

Browse files
author
Andy
authored
Enable 'only-arrow-functions' lint rule (microsoft#19717)
1 parent ae87cd2 commit cd9dbe6

9 files changed

Lines changed: 77 additions & 89 deletions

File tree

Gulpfile.ts

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,13 @@ const es2015LibrarySources = [
123123
"es2015.symbol.wellknown.d.ts"
124124
];
125125

126-
const es2015LibrarySourceMap = es2015LibrarySources.map(function(source) {
127-
return { target: "lib." + source, sources: ["header.d.ts", source] };
128-
});
126+
const es2015LibrarySourceMap = es2015LibrarySources.map(source =>
127+
({ target: "lib." + source, sources: ["header.d.ts", source] }));
129128

130129
const es2016LibrarySource = ["es2016.array.include.d.ts"];
131130

132-
const es2016LibrarySourceMap = es2016LibrarySource.map(function(source) {
133-
return { target: "lib." + source, sources: ["header.d.ts", source] };
134-
});
131+
const es2016LibrarySourceMap = es2016LibrarySource.map(source =>
132+
({ target: "lib." + source, sources: ["header.d.ts", source] }));
135133

136134
const es2017LibrarySource = [
137135
"es2017.object.d.ts",
@@ -140,17 +138,15 @@ const es2017LibrarySource = [
140138
"es2017.intl.d.ts",
141139
];
142140

143-
const es2017LibrarySourceMap = es2017LibrarySource.map(function(source) {
144-
return { target: "lib." + source, sources: ["header.d.ts", source] };
145-
});
141+
const es2017LibrarySourceMap = es2017LibrarySource.map(source =>
142+
({ target: "lib." + source, sources: ["header.d.ts", source] }));
146143

147144
const esnextLibrarySource = [
148145
"esnext.asynciterable.d.ts"
149146
];
150147

151-
const esnextLibrarySourceMap = esnextLibrarySource.map(function (source) {
152-
return { target: "lib." + source, sources: ["header.d.ts", source] };
153-
});
148+
const esnextLibrarySourceMap = esnextLibrarySource.map(source =>
149+
({ target: "lib." + source, sources: ["header.d.ts", source] }));
154150

155151
const hostsLibrarySources = ["dom.generated.d.ts", "webworker.importscripts.d.ts", "scripthost.d.ts"];
156152

@@ -176,9 +172,8 @@ const librarySourceMap = [
176172
{ target: "lib.esnext.full.d.ts", sources: ["header.d.ts", "esnext.d.ts"].concat(hostsLibrarySources, "dom.iterable.d.ts") },
177173
].concat(es2015LibrarySourceMap, es2016LibrarySourceMap, es2017LibrarySourceMap, esnextLibrarySourceMap);
178174

179-
const libraryTargets = librarySourceMap.map(function(f) {
180-
return path.join(builtLocalDirectory, f.target);
181-
});
175+
const libraryTargets = librarySourceMap.map(f =>
176+
path.join(builtLocalDirectory, f.target));
182177

183178
/**
184179
* .lcg file is what localization team uses to know what messages to localize.
@@ -193,22 +188,19 @@ const generatedLCGFile = path.join(builtLocalDirectory, "enu", "diagnosticMessag
193188
* 2. 'src\compiler\diagnosticMessages.generated.json' => 'built\local\ENU\diagnosticMessages.generated.json.lcg'
194189
* generate the lcg file (source of messages to localize) from the diagnosticMessages.generated.json
195190
*/
196-
const localizationTargets = ["cs", "de", "es", "fr", "it", "ja", "ko", "pl", "pt-BR", "ru", "tr", "zh-CN", "zh-TW"].map(function (f) {
197-
return path.join(builtLocalDirectory, f, "diagnosticMessages.generated.json");
198-
}).concat(generatedLCGFile);
191+
const localizationTargets = ["cs", "de", "es", "fr", "it", "ja", "ko", "pl", "pt-BR", "ru", "tr", "zh-CN", "zh-TW"]
192+
.map(f => path.join(builtLocalDirectory, f, "diagnosticMessages.generated.json"))
193+
.concat(generatedLCGFile);
199194

200195
for (const i in libraryTargets) {
201196
const entry = librarySourceMap[i];
202197
const target = libraryTargets[i];
203-
const sources = [copyright].concat(entry.sources.map(function(s) {
204-
return path.join(libraryDirectory, s);
205-
}));
206-
gulp.task(target, /*help*/ false, [], function() {
207-
return gulp.src(sources)
198+
const sources = [copyright].concat(entry.sources.map(s => path.join(libraryDirectory, s)));
199+
gulp.task(target, /*help*/ false, [], () =>
200+
gulp.src(sources)
208201
.pipe(newer(target))
209202
.pipe(concat(target, { newLine: "\n\n" }))
210-
.pipe(gulp.dest("."));
211-
});
203+
.pipe(gulp.dest(".")));
212204
}
213205

214206
const configureNightlyJs = path.join(scriptsDirectory, "configureNightly.js");
@@ -575,9 +567,7 @@ gulp.task(specMd, /*help*/ false, [word2mdJs], (done) => {
575567
const specMDFullPath = path.resolve(specMd);
576568
const cmd = "cscript //nologo " + word2mdJs + " \"" + specWordFullPath + "\" " + "\"" + specMDFullPath + "\"";
577569
console.log(cmd);
578-
cp.exec(cmd, function() {
579-
done();
580-
});
570+
cp.exec(cmd, done);
581571
});
582572

583573
gulp.task("generate-spec", "Generates a Markdown version of the Language Specification", [specMd]);
@@ -714,17 +704,13 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
714704
}
715705
args.push(run);
716706
setNodeEnvToDevelopment();
717-
exec(mocha, args, lintThenFinish, function(e, status) {
718-
finish(e, status);
719-
});
707+
exec(mocha, args, lintThenFinish, finish);
720708

721709
}
722710
else {
723711
// run task to load all tests and partition them between workers
724712
setNodeEnvToDevelopment();
725-
exec(host, [run], lintThenFinish, function(e, status) {
726-
finish(e, status);
727-
});
713+
exec(host, [run], lintThenFinish, finish);
728714
}
729715
});
730716

@@ -1082,7 +1068,7 @@ function sendNextFile(files: {path: string}[], child: cp.ChildProcess, callback:
10821068
function spawnLintWorker(files: {path: string}[], callback: (failures: number) => void) {
10831069
const child = cp.fork("./scripts/parallel-lint");
10841070
let failures = 0;
1085-
child.on("message", function(data) {
1071+
child.on("message", data => {
10861072
switch (data.kind) {
10871073
case "result":
10881074
if (data.failures > 0) {

src/compiler/sys.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ namespace ts {
124124
getEnvironmentVariable?(name: string): string;
125125
};
126126

127-
export let sys: System = (function() {
127+
export let sys: System = (() => {
128128
function getNodeSystem(): System {
129129
const _fs = require("fs");
130130
const _path = require("path");
@@ -594,7 +594,7 @@ namespace ts {
594594
if (sys) {
595595
// patch writefile to create folder before writing the file
596596
const originalWriteFile = sys.writeFile;
597-
sys.writeFile = function(path, data, writeBom) {
597+
sys.writeFile = (path, data, writeBom) => {
598598
const directoryPath = getDirectoryPath(normalizeSlashes(path));
599599
if (directoryPath && !sys.directoryExists(directoryPath)) {
600600
recursiveCreateDirectory(directoryPath, sys);

src/harness/harnessLanguageService.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@ namespace Harness.LanguageService {
757757
create(info: ts.server.PluginCreateInfo) {
758758
const proxy = makeDefaultProxy(info);
759759
const langSvc: any = info.languageService;
760+
// tslint:disable-next-line only-arrow-functions
760761
proxy.getQuickInfoAtPosition = function () {
761762
const parts = langSvc.getQuickInfoAtPosition.apply(langSvc, arguments);
762763
if (parts.displayParts.length > 0) {
@@ -789,7 +790,7 @@ namespace Harness.LanguageService {
789790
module: () => ({
790791
create(info: ts.server.PluginCreateInfo) {
791792
const proxy = makeDefaultProxy(info);
792-
proxy.getSemanticDiagnostics = function (filename: string) {
793+
proxy.getSemanticDiagnostics = filename => {
793794
const prev = info.languageService.getSemanticDiagnostics(filename);
794795
const sourceFile: ts.SourceFile = info.languageService.getSourceFile(filename);
795796
prev.push({
@@ -815,11 +816,12 @@ namespace Harness.LanguageService {
815816
};
816817
}
817818

818-
function makeDefaultProxy(info: ts.server.PluginCreateInfo) {
819+
function makeDefaultProxy(info: ts.server.PluginCreateInfo): ts.LanguageService {
819820
// tslint:disable-next-line:no-null-keyword
820821
const proxy = Object.create(/*prototype*/ null);
821822
const langSvc: any = info.languageService;
822823
for (const k of Object.keys(langSvc)) {
824+
// tslint:disable-next-line only-arrow-functions
823825
proxy[k] = function () {
824826
return langSvc[k].apply(langSvc, arguments);
825827
};

src/harness/loggedIO.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ namespace Playback {
366366

367367
function recordReplay<T extends Function>(original: T, underlying: any) {
368368
function createWrapper(record: T, replay: T): T {
369+
// tslint:disable-next-line only-arrow-functions
369370
return <any>(function () {
370371
if (replayLog !== undefined) {
371372
return replay.apply(undefined, arguments);

0 commit comments

Comments
 (0)