fix lint errors

上级 448115e4
...@@ -3,40 +3,38 @@ ...@@ -3,40 +3,38 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
"use strict"; const gulp = require('gulp');
const filter = require('gulp-filter');
const es = require('event-stream');
const gulpeslint = require('gulp-eslint');
const vfs = require('vinyl-fs');
const path = require('path');
const task = require('./lib/task');
const { all, jsHygieneFilter, tsHygieneFilter, hygiene } = require('./hygiene');
const gulp = require("gulp"); gulp.task('eslint', () => {
const filter = require("gulp-filter");
const es = require("event-stream");
const gulpeslint = require("gulp-eslint");
const vfs = require("vinyl-fs");
const path = require("path");
const task = require("./lib/task");
const { all, jsHygieneFilter, tsHygieneFilter, hygiene } = require("./hygiene");
gulp.task("eslint", () => {
return vfs return vfs
.src(all, { base: ".", follow: true, allowEmpty: true }) .src(all, { base: '.', follow: true, allowEmpty: true })
.pipe(filter(jsHygieneFilter.concat(tsHygieneFilter))) .pipe(filter(jsHygieneFilter.concat(tsHygieneFilter)))
.pipe( .pipe(
gulpeslint({ gulpeslint({
configFile: ".eslintrc.json", configFile: '.eslintrc.json',
rulePaths: ["./build/lib/eslint"], rulePaths: ['./build/lib/eslint'],
}) })
) )
.pipe(gulpeslint.formatEach("compact")) .pipe(gulpeslint.formatEach('compact'))
.pipe( .pipe(
gulpeslint.results((results) => { gulpeslint.results((results) => {
if (results.warningCount > 0 || results.errorCount > 0) { if (results.warningCount > 0 || results.errorCount > 0) {
throw new Error("eslint failed with warnings and/or errors"); throw new Error('eslint failed with warnings and/or errors');
} }
}) })
); );
}); });
function checkPackageJSON(actualPath) { function checkPackageJSON(actualPath) {
const actual = require(path.join(__dirname, "..", actualPath)); const actual = require(path.join(__dirname, '..', actualPath));
const rootPackageJSON = require("../package.json"); const rootPackageJSON = require('../package.json');
for (let depName in actual.dependencies) { for (let depName in actual.dependencies) {
const depVersion = actual.dependencies[depName]; const depVersion = actual.dependencies[depName];
...@@ -47,24 +45,24 @@ function checkPackageJSON(actualPath) { ...@@ -47,24 +45,24 @@ function checkPackageJSON(actualPath) {
} }
if (depVersion !== rootDepVersion) { if (depVersion !== rootDepVersion) {
this.emit( this.emit(
"error", 'error',
`The dependency ${depName} in '${actualPath}' (${depVersion}) is different than in the root package.json (${rootDepVersion})` `The dependency ${depName} in '${actualPath}' (${depVersion}) is different than in the root package.json (${rootDepVersion})`
); );
} }
} }
} }
const checkPackageJSONTask = task.define("check-package-json", () => { const checkPackageJSONTask = task.define('check-package-json', () => {
return gulp.src("package.json").pipe( return gulp.src('package.json').pipe(
es.through(function () { es.through(function () {
checkPackageJSON.call(this, "remote/package.json"); checkPackageJSON.call(this, 'remote/package.json');
checkPackageJSON.call(this, "remote/web/package.json"); checkPackageJSON.call(this, 'remote/web/package.json');
}) })
); );
}); });
gulp.task(checkPackageJSONTask); gulp.task(checkPackageJSONTask);
gulp.task( gulp.task(
"hygiene", 'hygiene',
task.series(checkPackageJSONTask, () => hygiene()) task.series(checkPackageJSONTask, () => hygiene())
); );
...@@ -3,17 +3,15 @@ ...@@ -3,17 +3,15 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
"use strict"; const filter = require('gulp-filter');
const es = require('event-stream');
const filter = require("gulp-filter"); const gulpeslint = require('gulp-eslint');
const es = require("event-stream"); const tsfmt = require('typescript-formatter');
const gulpeslint = require("gulp-eslint"); const VinylFile = require('vinyl');
const tsfmt = require("typescript-formatter"); const vfs = require('vinyl-fs');
const VinylFile = require("vinyl"); const path = require('path');
const vfs = require("vinyl-fs"); const fs = require('fs');
const path = require("path"); const pall = require('p-all');
const fs = require("fs");
const pall = require("p-all");
/** /**
* Hygiene works by creating cascading subsets of all our files and * Hygiene works by creating cascading subsets of all our files and
...@@ -25,159 +23,159 @@ const pall = require("p-all"); ...@@ -25,159 +23,159 @@ const pall = require("p-all");
*/ */
const all = [ const all = [
"*", '*',
"build/**/*", 'build/**/*',
"extensions/**/*", 'extensions/**/*',
"scripts/**/*", 'scripts/**/*',
"src/**/*", 'src/**/*',
"test/**/*", 'test/**/*',
"!test/**/out/**", '!test/**/out/**',
"!**/node_modules/**", '!**/node_modules/**',
]; ];
module.exports.all = all; module.exports.all = all;
const indentationFilter = [ const indentationFilter = [
"**", '**',
// except specific files // except specific files
"!**/ThirdPartyNotices.txt", '!**/ThirdPartyNotices.txt',
"!**/LICENSE.{txt,rtf}", '!**/LICENSE.{txt,rtf}',
"!LICENSES.chromium.html", '!LICENSES.chromium.html',
"!**/LICENSE", '!**/LICENSE',
"!src/vs/nls.js", '!src/vs/nls.js',
"!src/vs/nls.build.js", '!src/vs/nls.build.js',
"!src/vs/css.js", '!src/vs/css.js',
"!src/vs/css.build.js", '!src/vs/css.build.js',
"!src/vs/loader.js", '!src/vs/loader.js',
"!src/vs/base/common/insane/insane.js", '!src/vs/base/common/insane/insane.js',
"!src/vs/base/common/marked/marked.js", '!src/vs/base/common/marked/marked.js',
"!src/vs/base/node/terminateProcess.sh", '!src/vs/base/node/terminateProcess.sh',
"!src/vs/base/node/cpuUsage.sh", '!src/vs/base/node/cpuUsage.sh',
"!test/unit/assert.js", '!test/unit/assert.js',
// except specific folders // except specific folders
"!test/automation/out/**", '!test/automation/out/**',
"!test/smoke/out/**", '!test/smoke/out/**',
"!extensions/typescript-language-features/test-workspace/**", '!extensions/typescript-language-features/test-workspace/**',
"!extensions/vscode-api-tests/testWorkspace/**", '!extensions/vscode-api-tests/testWorkspace/**',
"!extensions/vscode-api-tests/testWorkspace2/**", '!extensions/vscode-api-tests/testWorkspace2/**',
"!build/monaco/**", '!build/monaco/**',
"!build/win32/**", '!build/win32/**',
// except multiple specific files // except multiple specific files
"!**/package.json", '!**/package.json',
"!**/yarn.lock", '!**/yarn.lock',
"!**/yarn-error.log", '!**/yarn-error.log',
// except multiple specific folders // except multiple specific folders
"!**/codicon/**", '!**/codicon/**',
"!**/fixtures/**", '!**/fixtures/**',
"!**/lib/**", '!**/lib/**',
"!extensions/**/out/**", '!extensions/**/out/**',
"!extensions/**/snippets/**", '!extensions/**/snippets/**',
"!extensions/**/syntaxes/**", '!extensions/**/syntaxes/**',
"!extensions/**/themes/**", '!extensions/**/themes/**',
"!extensions/**/colorize-fixtures/**", '!extensions/**/colorize-fixtures/**',
// except specific file types // except specific file types
"!src/vs/*/**/*.d.ts", '!src/vs/*/**/*.d.ts',
"!src/typings/**/*.d.ts", '!src/typings/**/*.d.ts',
"!extensions/**/*.d.ts", '!extensions/**/*.d.ts',
"!**/*.{svg,exe,png,bmp,scpt,bat,cmd,cur,ttf,woff,eot,md,ps1,template,yaml,yml,d.ts.recipe,ico,icns,plist}", '!**/*.{svg,exe,png,bmp,scpt,bat,cmd,cur,ttf,woff,eot,md,ps1,template,yaml,yml,d.ts.recipe,ico,icns,plist}',
"!build/{lib,download,darwin}/**/*.js", '!build/{lib,download,darwin}/**/*.js',
"!build/**/*.sh", '!build/**/*.sh',
"!build/azure-pipelines/**/*.js", '!build/azure-pipelines/**/*.js',
"!build/azure-pipelines/**/*.config", '!build/azure-pipelines/**/*.config',
"!**/Dockerfile", '!**/Dockerfile',
"!**/Dockerfile.*", '!**/Dockerfile.*',
"!**/*.Dockerfile", '!**/*.Dockerfile',
"!**/*.dockerfile", '!**/*.dockerfile',
"!extensions/markdown-language-features/media/*.js", '!extensions/markdown-language-features/media/*.js',
]; ];
const copyrightFilter = [ const copyrightFilter = [
"**", '**',
"!**/*.desktop", '!**/*.desktop',
"!**/*.json", '!**/*.json',
"!**/*.html", '!**/*.html',
"!**/*.template", '!**/*.template',
"!**/*.md", '!**/*.md',
"!**/*.bat", '!**/*.bat',
"!**/*.cmd", '!**/*.cmd',
"!**/*.ico", '!**/*.ico',
"!**/*.icns", '!**/*.icns',
"!**/*.xml", '!**/*.xml',
"!**/*.sh", '!**/*.sh',
"!**/*.txt", '!**/*.txt',
"!**/*.xpm", '!**/*.xpm',
"!**/*.opts", '!**/*.opts',
"!**/*.disabled", '!**/*.disabled',
"!**/*.code-workspace", '!**/*.code-workspace',
"!**/*.js.map", '!**/*.js.map',
"!build/**/*.init", '!build/**/*.init',
"!resources/linux/snap/snapcraft.yaml", '!resources/linux/snap/snapcraft.yaml',
"!resources/linux/snap/electron-launch", '!resources/linux/snap/electron-launch',
"!resources/win32/bin/code.js", '!resources/win32/bin/code.js',
"!resources/web/code-web.js", '!resources/web/code-web.js',
"!resources/completions/**", '!resources/completions/**',
"!extensions/markdown-language-features/media/highlight.css", '!extensions/markdown-language-features/media/highlight.css',
"!extensions/html-language-features/server/src/modes/typescript/*", '!extensions/html-language-features/server/src/modes/typescript/*',
"!extensions/*/server/bin/*", '!extensions/*/server/bin/*',
"!src/vs/editor/test/node/classification/typescript-test.ts", '!src/vs/editor/test/node/classification/typescript-test.ts',
]; ];
const jsHygieneFilter = [ const jsHygieneFilter = [
"src/**/*.js", 'src/**/*.js',
"build/gulpfile.*.js", 'build/gulpfile.*.js',
"!src/vs/loader.js", '!src/vs/loader.js',
"!src/vs/css.js", '!src/vs/css.js',
"!src/vs/nls.js", '!src/vs/nls.js',
"!src/vs/css.build.js", '!src/vs/css.build.js',
"!src/vs/nls.build.js", '!src/vs/nls.build.js',
"!src/**/insane.js", '!src/**/insane.js',
"!src/**/marked.js", '!src/**/marked.js',
"!**/test/**", '!**/test/**',
]; ];
module.exports.jsHygieneFilter = jsHygieneFilter; module.exports.jsHygieneFilter = jsHygieneFilter;
const tsHygieneFilter = [ const tsHygieneFilter = [
"src/**/*.ts", 'src/**/*.ts',
"test/**/*.ts", 'test/**/*.ts',
"extensions/**/*.ts", 'extensions/**/*.ts',
"!**/fixtures/**", '!**/fixtures/**',
"!**/typings/**", '!**/typings/**',
"!**/node_modules/**", '!**/node_modules/**',
"!extensions/typescript-basics/test/colorize-fixtures/**", '!extensions/typescript-basics/test/colorize-fixtures/**',
"!extensions/vscode-api-tests/testWorkspace/**", '!extensions/vscode-api-tests/testWorkspace/**',
"!extensions/vscode-api-tests/testWorkspace2/**", '!extensions/vscode-api-tests/testWorkspace2/**',
"!extensions/**/*.test.ts", '!extensions/**/*.test.ts',
"!extensions/html-language-features/server/lib/jquery.d.ts", '!extensions/html-language-features/server/lib/jquery.d.ts',
]; ];
module.exports.tsHygieneFilter = tsHygieneFilter; module.exports.tsHygieneFilter = tsHygieneFilter;
const copyrightHeaderLines = [ const copyrightHeaderLines = [
"/*---------------------------------------------------------------------------------------------", '/*---------------------------------------------------------------------------------------------',
" * Copyright (c) Microsoft Corporation. All rights reserved.", ' * Copyright (c) Microsoft Corporation. All rights reserved.',
" * Licensed under the MIT License. See License.txt in the project root for license information.", ' * Licensed under the MIT License. See License.txt in the project root for license information.',
" *--------------------------------------------------------------------------------------------*/", ' *--------------------------------------------------------------------------------------------*/',
]; ];
function hygiene(some) { function hygiene(some) {
let errorCount = 0; let errorCount = 0;
const productJson = es.through(function (file) { const productJson = es.through(function (file) {
const product = JSON.parse(file.contents.toString("utf8")); const product = JSON.parse(file.contents.toString('utf8'));
if (product.extensionsGallery) { if (product.extensionsGallery) {
console.error('product.json: Contains "extensionsGallery"'); console.error(`product.json: Contains 'extensionsGallery'`);
errorCount++; errorCount++;
} }
this.emit("data", file); this.emit('data', file);
}); });
const indentation = es.through(function (file) { const indentation = es.through(function (file) {
const lines = file.contents.toString("utf8").split(/\r\n|\r|\n/); const lines = file.contents.toString('utf8').split(/\r\n|\r|\n/);
file.__lines = lines; file.__lines = lines;
lines.forEach((line, i) => { lines.forEach((line, i) => {
...@@ -189,13 +187,13 @@ function hygiene(some) { ...@@ -189,13 +187,13 @@ function hygiene(some) {
// block comment using an extra space // block comment using an extra space
} else { } else {
console.error( console.error(
file.relative + "(" + (i + 1) + ",1): Bad whitespace indentation" file.relative + '(' + (i + 1) + ',1): Bad whitespace indentation'
); );
errorCount++; errorCount++;
} }
}); });
this.emit("data", file); this.emit('data', file);
}); });
const copyrights = es.through(function (file) { const copyrights = es.through(function (file) {
...@@ -203,18 +201,18 @@ function hygiene(some) { ...@@ -203,18 +201,18 @@ function hygiene(some) {
for (let i = 0; i < copyrightHeaderLines.length; i++) { for (let i = 0; i < copyrightHeaderLines.length; i++) {
if (lines[i] !== copyrightHeaderLines[i]) { if (lines[i] !== copyrightHeaderLines[i]) {
console.error(file.relative + ": Missing or bad copyright statement"); console.error(file.relative + ': Missing or bad copyright statement');
errorCount++; errorCount++;
break; break;
} }
} }
this.emit("data", file); this.emit('data', file);
}); });
const formatting = es.map(function (file, cb) { const formatting = es.map(function (file, cb) {
tsfmt tsfmt
.processString(file.path, file.contents.toString("utf8"), { .processString(file.path, file.contents.toString('utf8'), {
verify: false, verify: false,
tsfmt: true, tsfmt: true,
// verbose: true, // verbose: true,
...@@ -229,12 +227,12 @@ function hygiene(some) { ...@@ -229,12 +227,12 @@ function hygiene(some) {
}) })
.then( .then(
(result) => { (result) => {
let original = result.src.replace(/\r\n/gm, "\n"); let original = result.src.replace(/\r\n/gm, '\n');
let formatted = result.dest.replace(/\r\n/gm, "\n"); let formatted = result.dest.replace(/\r\n/gm, '\n');
if (original !== formatted) { if (original !== formatted) {
console.error( console.error(
"File not formatted. Run the 'Format Document' command to fix it:", `File not formatted. Run the 'Format Document' command to fix it:`,
file.relative file.relative
); );
errorCount++; errorCount++;
...@@ -249,8 +247,8 @@ function hygiene(some) { ...@@ -249,8 +247,8 @@ function hygiene(some) {
let input; let input;
if (Array.isArray(some) || typeof some === "string" || !some) { if (Array.isArray(some) || typeof some === 'string' || !some) {
const options = { base: ".", follow: true, allowEmpty: true }; const options = { base: '.', follow: true, allowEmpty: true };
if (some) { if (some) {
input = vfs.src(some, options).pipe(filter(all)); // split this up to not unnecessarily filter all a second time input = vfs.src(some, options).pipe(filter(all)); // split this up to not unnecessarily filter all a second time
} else { } else {
...@@ -260,12 +258,12 @@ function hygiene(some) { ...@@ -260,12 +258,12 @@ function hygiene(some) {
input = some; input = some;
} }
const productJsonFilter = filter("product.json", { restore: true }); const productJsonFilter = filter('product.json', { restore: true });
const result = input const result = input
.pipe(filter((f) => !f.stat.isDirectory())) .pipe(filter((f) => !f.stat.isDirectory()))
.pipe(productJsonFilter) .pipe(productJsonFilter)
.pipe(process.env["BUILD_SOURCEVERSION"] ? es.through() : productJson) .pipe(process.env['BUILD_SOURCEVERSION'] ? es.through() : productJson)
.pipe(productJsonFilter.restore) .pipe(productJsonFilter.restore)
.pipe(filter(indentationFilter)) .pipe(filter(indentationFilter))
.pipe(indentation) .pipe(indentation)
...@@ -278,11 +276,11 @@ function hygiene(some) { ...@@ -278,11 +276,11 @@ function hygiene(some) {
.pipe(filter(jsHygieneFilter.concat(tsHygieneFilter))) .pipe(filter(jsHygieneFilter.concat(tsHygieneFilter)))
.pipe( .pipe(
gulpeslint({ gulpeslint({
configFile: ".eslintrc.json", configFile: '.eslintrc.json',
rulePaths: ["./build/lib/eslint"], rulePaths: ['./build/lib/eslint'],
}) })
) )
.pipe(gulpeslint.formatEach("compact")) .pipe(gulpeslint.formatEach('compact'))
.pipe( .pipe(
gulpeslint.results((results) => { gulpeslint.results((results) => {
errorCount += results.warningCount; errorCount += results.warningCount;
...@@ -295,22 +293,22 @@ function hygiene(some) { ...@@ -295,22 +293,22 @@ function hygiene(some) {
es.through( es.through(
function (data) { function (data) {
count++; count++;
if (process.env["TRAVIS"] && count % 10 === 0) { if (process.env['TRAVIS'] && count % 10 === 0) {
process.stdout.write("."); process.stdout.write('.');
} }
this.emit("data", data); this.emit('data', data);
}, },
function () { function () {
process.stdout.write("\n"); process.stdout.write('\n');
if (errorCount > 0) { if (errorCount > 0) {
this.emit( this.emit(
"error", 'error',
"Hygiene failed with " + 'Hygiene failed with ' +
errorCount + errorCount +
" errors. Check 'build/gulpfile.hygiene.js'." ` errors. Check 'build / gulpfile.hygiene.js'.`
); );
} else { } else {
this.emit("end"); this.emit('end');
} }
} }
) )
...@@ -320,7 +318,7 @@ function hygiene(some) { ...@@ -320,7 +318,7 @@ function hygiene(some) {
module.exports.hygiene = hygiene; module.exports.hygiene = hygiene;
function createGitIndexVinyls(paths) { function createGitIndexVinyls(paths) {
const cp = require("child_process"); const cp = require('child_process');
const repositoryPath = process.cwd(); const repositoryPath = process.cwd();
const fns = paths.map((relativePath) => () => const fns = paths.map((relativePath) => () =>
...@@ -328,7 +326,7 @@ function createGitIndexVinyls(paths) { ...@@ -328,7 +326,7 @@ function createGitIndexVinyls(paths) {
const fullPath = path.join(repositoryPath, relativePath); const fullPath = path.join(repositoryPath, relativePath);
fs.stat(fullPath, (err, stat) => { fs.stat(fullPath, (err, stat) => {
if (err && err.code === "ENOENT") { if (err && err.code === 'ENOENT') {
// ignore deletions // ignore deletions
return c(null); return c(null);
} else if (err) { } else if (err) {
...@@ -337,7 +335,7 @@ function createGitIndexVinyls(paths) { ...@@ -337,7 +335,7 @@ function createGitIndexVinyls(paths) {
cp.exec( cp.exec(
`git show :${relativePath}`, `git show :${relativePath}`,
{ maxBuffer: 2000 * 1024, encoding: "buffer" }, { maxBuffer: 2000 * 1024, encoding: 'buffer' },
(err, out) => { (err, out) => {
if (err) { if (err) {
return e(err); return e(err);
...@@ -362,22 +360,22 @@ function createGitIndexVinyls(paths) { ...@@ -362,22 +360,22 @@ function createGitIndexVinyls(paths) {
// this allows us to run hygiene as a git pre-commit hook // this allows us to run hygiene as a git pre-commit hook
if (require.main === module) { if (require.main === module) {
const cp = require("child_process"); const cp = require('child_process');
process.on("unhandledRejection", (reason, p) => { process.on('unhandledRejection', (reason, p) => {
console.log("Unhandled Rejection at: Promise", p, "reason:", reason); console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
process.exit(1); process.exit(1);
}); });
if (process.argv.length > 2) { if (process.argv.length > 2) {
hygiene(process.argv.slice(2)).on("error", (err) => { hygiene(process.argv.slice(2)).on('error', (err) => {
console.error(); console.error();
console.error(err); console.error(err);
process.exit(1); process.exit(1);
}); });
} else { } else {
cp.exec( cp.exec(
"git diff --cached --name-only", 'git diff --cached --name-only',
{ maxBuffer: 2000 * 1024 }, { maxBuffer: 2000 * 1024 },
(err, out) => { (err, out) => {
if (err) { if (err) {
...@@ -389,15 +387,15 @@ if (require.main === module) { ...@@ -389,15 +387,15 @@ if (require.main === module) {
const some = out.split(/\r?\n/).filter((l) => !!l); const some = out.split(/\r?\n/).filter((l) => !!l);
if (some.length > 0) { if (some.length > 0) {
console.log("Reading git index versions..."); console.log('Reading git index versions...');
createGitIndexVinyls(some) createGitIndexVinyls(some)
.then( .then(
(vinyls) => (vinyls) =>
new Promise((c, e) => new Promise((c, e) =>
hygiene(es.readArray(vinyls)) hygiene(es.readArray(vinyls))
.on("end", () => c()) .on('end', () => c())
.on("error", e) .on('error', e)
) )
) )
.catch((err) => { .catch((err) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册