Skip to content

Commit 63d2d65

Browse files
committed
Merge remote-tracking branch 'upstream/master'
* upstream/master: Remove setting python.formatting.formatOnSave in favor of the vs code setting (#312)
2 parents 966e516 + c1edd58 commit 63d2d65

31 files changed

+1743
-1825
lines changed

gulpfile.js

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const relative = require('relative');
1414
const ts = require('gulp-typescript');
1515
const watch = require('gulp-watch');
1616
const cp = require('child_process');
17+
const colors = require('colors/safe');
1718

1819
/**
1920
* Hygiene works by creating cascading subsets of all our files and
@@ -179,7 +180,7 @@ const hygiene = exports.hygiene = (some, options) => {
179180
}
180181
};
181182
}
182-
const tsProject = ts.createProject('tsconfig.json', { strict: true });
183+
const tsProject = ts.createProject('tsconfig.json', { strict: true, noImplicitAny: false });
183184
const reporter = customReporter();
184185
return tsProject(reporter);
185186
}
@@ -203,7 +204,7 @@ const hygiene = exports.hygiene = (some, options) => {
203204
return typescript
204205
.pipe(es.through(null, function () {
205206
if (errorCount > 0) {
206-
this.emit('error', 'Hygiene failed with ' + errorCount + ' errors. Check \'gulpfile.js\'.');
207+
this.emit('error', 'Hygiene failed with ' + errorCount + ' errors 👎. Check \'gulpfile.js\'.');
207208
} else {
208209
this.emit('end');
209210
}
@@ -214,18 +215,23 @@ gulp.task('hygiene', () => hygiene());
214215

215216
gulp.task('hygiene-watch', function () {
216217
return watch(all, function () {
218+
console.clear();
219+
console.log('Checking hygiene...');
217220
run(true, true);
218221
});
219222
});
220223

221224
function run(lintOnlyModifiedFiles, doNotExit) {
222225
function exitProcessOnError(ex) {
223226
console.error();
224-
console.error(ex);
227+
console.error(colors.red(ex));
225228
if (!doNotExit) {
226229
process.exit(1);
227230
}
228-
}
231+
if (lintOnlyModifiedFiles && doNotExit) {
232+
console.log('Watching for changes...');
233+
}
234+
}
229235
process.on('unhandledRejection', (reason, p) => {
230236
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
231237
exitProcessOnError();
@@ -239,20 +245,62 @@ function run(lintOnlyModifiedFiles, doNotExit) {
239245
}).on('error', exitProcessOnError);
240246
}
241247

242-
const cmd = lintOnlyModifiedFiles ? 'git diff --name-only' : 'git diff --cached --name-only';
243-
cp.exec(cmd, {
248+
let filesPromise;
249+
if (lintOnlyModifiedFiles) {
250+
filesPromise = Promise.all([getCachedFiles(), getModifiedFiles()]).then(filesList => {
251+
const files1 = filesList[0];
252+
const files2 = filesList[1];
253+
files2.forEach(file => {
254+
if (files1.indexOf(file) === -1) {
255+
files1.push(file);
256+
}
257+
});
258+
return files1;
259+
});
260+
} else {
261+
filesPromise = getCachedFiles();
262+
}
263+
filesPromise.then(files => {
264+
hygiene(files, {
265+
skipEOL: skipEOL
266+
})
267+
.on('end', () => {
268+
if (lintOnlyModifiedFiles && doNotExit) {
269+
console.log(colors.green('Hygiene passed with 0 errors 👍.'));
270+
console.log('Watching for changes...');
271+
}
272+
})
273+
.on('error', exitProcessOnError);
274+
}).catch(exitProcessOnError);
275+
});
276+
}
277+
function getCachedFiles() {
278+
return new Promise(resolve => {
279+
cp.exec('git diff --cached --name-only', {
244280
maxBuffer: 2000 * 1024
245281
}, (err, out) => {
246282
if (err) {
247-
exitProcessOnError(err);
283+
return reject(err);
248284
}
249285
const some = out
250286
.split(/\r?\n/)
251287
.filter(l => !!l);
252-
253-
hygiene(some, {
254-
skipEOL: skipEOL
255-
}).on('error', exitProcessOnError);
288+
resolve(some);
289+
});
290+
});
291+
}
292+
function getModifiedFiles() {
293+
return new Promise(resolve => {
294+
cp.exec('git diff --name-only', {
295+
maxBuffer: 2000 * 1024
296+
}, (err, out) => {
297+
if (err) {
298+
return reject(err);
299+
}
300+
const some = out
301+
.split(/\r?\n/)
302+
.filter(l => !!l);
303+
resolve(some);
256304
});
257305
});
258306
}

0 commit comments

Comments
 (0)