gulp hygiene
This commit is contained in:
parent
f6e57602af
commit
9b5899187d
120
build/gulpfile.hygiene.js
Normal file
120
build/gulpfile.hygiene.js
Normal file
|
@ -0,0 +1,120 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
var gulp = require('gulp');
|
||||
var filter = require('gulp-filter');
|
||||
var es = require('event-stream');
|
||||
var path = require('path');
|
||||
|
||||
var eolFilter = [
|
||||
'build/**/*',
|
||||
'extensions/**/*',
|
||||
'scripts/**/*',
|
||||
'src/**/*',
|
||||
'test/**/*',
|
||||
'!extensions/csharp-o/bin/**',
|
||||
'!extensions/**/out/**',
|
||||
'!**/node_modules/**',
|
||||
'!**/fixtures/**',
|
||||
'!**/*.{svg,exe,png,scpt,bat,cur,ttf,woff,eot}',
|
||||
];
|
||||
|
||||
var indentationFilter = [
|
||||
'**',
|
||||
'!**/lib/**',
|
||||
'!**/*.d.ts',
|
||||
'!extensions/typescript/server/**',
|
||||
'!test/assert.js',
|
||||
'!**/package.json',
|
||||
'!**/octicons/**',
|
||||
'!**/vs/languages/sass/test/common/example.scss',
|
||||
'!**/vs/languages/less/common/parser/less.grammar.txt',
|
||||
'!**/vs/languages/css/common/buildscripts/css-schema.xml',
|
||||
'!**/vs/languages/markdown/common/raw.marked.js',
|
||||
'!**/vs/base/common/winjs.base.raw.js',
|
||||
'!**/vs/base/node/terminateProcess.sh',
|
||||
'!extensions/csharp-o/gulpfile.js',
|
||||
'!**/vs/base/node/terminateProcess.sh',
|
||||
'!**/vs/text.js',
|
||||
'!**/vs/nls.js',
|
||||
'!**/vs/css.js',
|
||||
'!**/vs/loader.js',
|
||||
'!extensions/**/snippets/**',
|
||||
'!extensions/**/syntaxes/**',
|
||||
'!extensions/**/themes/**',
|
||||
];
|
||||
|
||||
var copyrightFilterList = [
|
||||
'**',
|
||||
'!**/*.json',
|
||||
'!**/*.html',
|
||||
'!**/test/**',
|
||||
'!**/*.md',
|
||||
'!**/*.sh',
|
||||
'!**/*.txt',
|
||||
'!src/vs/editor/standalone-languages/swift.ts',
|
||||
];
|
||||
|
||||
var copyrightHeader = [
|
||||
'/*---------------------------------------------------------------------------------------------',
|
||||
' * Copyright (c) Microsoft Corporation. All rights reserved.',
|
||||
' * Licensed under the MIT License. See License.txt in the project root for license information.',
|
||||
' *--------------------------------------------------------------------------------------------*/'
|
||||
].join('\n');
|
||||
|
||||
gulp.task('hygiene', function() {
|
||||
var errorCount = 0;
|
||||
|
||||
var eol = es.through(function (file) {
|
||||
if (/\r\n?/g.test(file.contents.toString('utf8'))) {
|
||||
console.error(file.path + ': Bad EOL found');
|
||||
errorCount++;
|
||||
}
|
||||
|
||||
this.emit('data', file);
|
||||
});
|
||||
|
||||
var indentation = es.through(function (file) {
|
||||
file.contents
|
||||
.toString('utf8')
|
||||
.split(/\r\n|\r|\n/)
|
||||
.forEach(function(line, i) {
|
||||
if (line.length === 0) {
|
||||
// empty lines are OK
|
||||
} else if (/^[\t]*[^\s]/.test(line)) {
|
||||
// good indent
|
||||
} else if (/^[\t]* \*/.test(line)) {
|
||||
// block comment using an extra space
|
||||
} else {
|
||||
console.error(file.path + '(' + (i + 1) + ',1): Bad whitespace indentation');
|
||||
errorCount++;
|
||||
}
|
||||
});
|
||||
|
||||
this.emit('data', file);
|
||||
});
|
||||
|
||||
var copyrights = es.through(function (file) {
|
||||
if (file.contents.toString('utf8').indexOf(copyrightHeader) !== 0) {
|
||||
console.error(file.path + ': Missing or bad copyright statement');
|
||||
errorCount++;
|
||||
}
|
||||
});
|
||||
|
||||
return gulp.src(eolFilter, { base: '.' })
|
||||
.pipe(filter(function (f) { return !f.stat.isDirectory(); }))
|
||||
.pipe(eol)
|
||||
.pipe(filter(indentationFilter))
|
||||
.pipe(indentation)
|
||||
.pipe(filter(copyrightFilterList))
|
||||
.pipe(copyrights)
|
||||
.pipe(es.through(null, function () {
|
||||
if (errorCount > 0) {
|
||||
this.emit('error', 'Hygiene failed with ' + errorCount + ' errors.\nCheck build/gulpfile.hygiene.js for the hygiene rules.');
|
||||
} else {
|
||||
this.emit('end');
|
||||
}
|
||||
}));
|
||||
});
|
|
@ -1,36 +0,0 @@
|
|||
var es = require('event-stream');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
var copyright = [
|
||||
'/*---------------------------------------------------------------------------------------------',
|
||||
' * Copyright (c) Microsoft Corporation. All rights reserved.',
|
||||
' * Licensed under the MIT License. See License.txt in the project root for license information.',
|
||||
' *--------------------------------------------------------------------------------------------*/'
|
||||
].join('\n');
|
||||
|
||||
|
||||
exports.copyrights = function () {
|
||||
return es.mapSync(function (file) {
|
||||
if (file.contents) {
|
||||
var contents = file.contents.toString('utf8');
|
||||
|
||||
if (contents.indexOf(copyright) !== 0) {
|
||||
throw new Error('File ' + file.path + ' does not contain copyright statement.');
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
exports.insertCopyrights = function() {
|
||||
return es.mapSync(function (file) {
|
||||
if (file.contents) {
|
||||
var contents = file.contents.toString('utf8');
|
||||
|
||||
if (contents.indexOf(copyright) !== 0) {
|
||||
contents = copyright + '\n\n' + contents;
|
||||
fs.writeFileSync(file.path, contents, 'utf8');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
var es = require('event-stream');
|
||||
var path = require('path');
|
||||
|
||||
module.exports = function (opts) {
|
||||
return es.mapSync(function (file) {
|
||||
if (file.stat.isDirectory()) {
|
||||
return file;
|
||||
}
|
||||
var contents = file.contents.toString('utf8');
|
||||
|
||||
if (opts.complain) {
|
||||
if (contents.indexOf('\r\n') >= 0) {
|
||||
console.log(file.path + ' uses \\r\\n');
|
||||
}
|
||||
|
||||
if (opts.whitespace) {
|
||||
var lines = contents.split(/\r\n|\r|\n/);
|
||||
for (var i = 0, len = lines.length; i < len; i++) {
|
||||
var line = lines[i];
|
||||
if (line.length === 0) {
|
||||
// empty lines are OK
|
||||
continue;
|
||||
}
|
||||
|
||||
if (/^[\t]*[^\s]/.test(line)) {
|
||||
// good indent
|
||||
continue;
|
||||
} else if (/^[\t]* \*/.test(line)) {
|
||||
// block comment using an extra space
|
||||
continue;
|
||||
} else if (/^[\t]+$/.test(line)) {
|
||||
// empty line
|
||||
continue;
|
||||
} else {
|
||||
console.log(file.path + '(' + (i + 1) + ',1): Mixed whitespace indentation');
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var lines = contents.split(/\r\n|\r|\n/);
|
||||
|
||||
if (opts.whitespace) {
|
||||
for (var i = 0, len = lines.length; i < len; i++) {
|
||||
var line = lines[i];
|
||||
line = line.replace(/^\ {28}/, '\t\t\t\t\t\t\t');
|
||||
line = line.replace(/^\ {24}/, '\t\t\t\t\t\t');
|
||||
line = line.replace(/^\ {20}/, '\t\t\t\t\t');
|
||||
line = line.replace(/^\ {16}/, '\t\t\t\t');
|
||||
line = line.replace(/^\ {12}/, '\t\t\t');
|
||||
line = line.replace(/^\ {8}/, '\t\t');
|
||||
line = line.replace(/^\ {4}/, '\t');
|
||||
lines[i] = line;
|
||||
}
|
||||
}
|
||||
|
||||
file.contents = new Buffer(lines.join('\n'), 'utf8');
|
||||
}
|
||||
return file;
|
||||
});
|
||||
};
|
68
gulpfile.js
68
gulpfile.js
|
@ -13,8 +13,6 @@ var mocha = require('gulp-mocha');
|
|||
var es = require('event-stream');
|
||||
var watch = require('./build/lib/watch');
|
||||
var nls = require('./build/lib/nls');
|
||||
var style = require('./build/lib/style');
|
||||
var copyrights = require('./build/lib/copyrights');
|
||||
var util = require('./build/lib/util');
|
||||
var reporter = require('./build/lib/reporter')();
|
||||
var remote = require('gulp-remote-src');
|
||||
|
@ -115,71 +113,6 @@ gulp.task('clean', ['clean-client', 'clean-plugins']);
|
|||
gulp.task('compile', ['compile-client', 'compile-plugins']);
|
||||
gulp.task('watch', ['watch-client', 'watch-plugins']);
|
||||
|
||||
var LINE_FEED_FILES = [
|
||||
'build/**/*',
|
||||
'extensions/**/*',
|
||||
'scripts/**/*',
|
||||
'src/**/*',
|
||||
'test/**/*',
|
||||
'!extensions/csharp-o/bin/**',
|
||||
'!extensions/**/out/**',
|
||||
'!**/node_modules/**',
|
||||
'!**/fixtures/**',
|
||||
'!**/*.{svg,exe,png,scpt,bat,cur,ttf,woff,eot}',
|
||||
];
|
||||
|
||||
gulp.task('eol-style', function() {
|
||||
return gulp.src(LINE_FEED_FILES).pipe(style({complain:true}));
|
||||
});
|
||||
gulp.task('fix-eol-style', function() {
|
||||
return gulp.src(LINE_FEED_FILES, { base: '.' }).pipe(style({})).pipe(gulp.dest('.'));
|
||||
});
|
||||
var WHITESPACE_FILES = LINE_FEED_FILES.concat([
|
||||
'!**/lib/**',
|
||||
'!**/*.d.ts',
|
||||
'!extensions/typescript/server/**',
|
||||
'!test/assert.js',
|
||||
'!**/octicons/**',
|
||||
'!**/vs/languages/sass/test/common/example.scss',
|
||||
'!**/vs/languages/less/common/parser/less.grammar.txt',
|
||||
'!**/vs/languages/css/common/buildscripts/css-schema.xml',
|
||||
'!**/vs/languages/markdown/common/raw.marked.js',
|
||||
'!**/vs/base/common/winjs.base.raw.js',
|
||||
'!**/vs/base/node/terminateProcess.sh',
|
||||
'!extensions/csharp-o/gulpfile.js',
|
||||
'!**/vs/base/node/terminateProcess.sh',
|
||||
'!**/vs/text.js',
|
||||
'!**/vs/nls.js',
|
||||
'!**/vs/css.js',
|
||||
'!**/vs/loader.js',
|
||||
'!extensions/**/snippets/**',
|
||||
'!extensions/**/syntaxes/**',
|
||||
'!extensions/**/themes/**',
|
||||
]);
|
||||
gulp.task('whitespace-style', function() {
|
||||
return gulp.src(WHITESPACE_FILES).pipe(style({complain:true, whitespace:true}));
|
||||
});
|
||||
gulp.task('fix-whitespace-style', function() {
|
||||
return gulp.src(WHITESPACE_FILES, { base: '.' }).pipe(style({whitespace:true})).pipe(gulp.dest('.'));
|
||||
});
|
||||
|
||||
var COPYRIGHTS_FILES = WHITESPACE_FILES.concat([
|
||||
'!**/*.json',
|
||||
'!**/*.html',
|
||||
'!**/test/**',
|
||||
'!**/*.md',
|
||||
'!**/*.sh',
|
||||
'!**/*.txt',
|
||||
'!src/vs/editor/standalone-languages/swift.ts',
|
||||
]);
|
||||
gulp.task('copyrights', function() {
|
||||
return gulp.src(COPYRIGHTS_FILES, { base: '.' }).pipe(copyrights.copyrights());
|
||||
});
|
||||
|
||||
gulp.task('insert-copyrights', function() {
|
||||
return gulp.src(COPYRIGHTS_FILES, { base: '.' }).pipe(copyrights.insertCopyrights());
|
||||
});
|
||||
|
||||
gulp.task('test', function () {
|
||||
return gulp.src('test/all.js')
|
||||
.pipe(mocha({ ui: 'tdd', delay: true }))
|
||||
|
@ -215,6 +148,7 @@ gulp.task('mixin', function () {
|
|||
.pipe(gulp.dest('.'));
|
||||
});
|
||||
|
||||
require('./build/gulpfile.hygiene');
|
||||
require('./build/gulpfile.vscode');
|
||||
require('./build/gulpfile.editor');
|
||||
require('./build/gulpfile.plugins');
|
||||
|
|
Loading…
Reference in a new issue