2015-11-24 18:09:31 +00:00
|
|
|
|
/*---------------------------------------------------------------------------------------------
|
|
|
|
|
* 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');
|
2016-01-18 08:50:41 +00:00
|
|
|
|
var tslint = require('gulp-tslint');
|
2015-11-24 18:09:31 +00:00
|
|
|
|
|
2015-11-25 21:01:45 +00:00
|
|
|
|
var all = [
|
2015-12-17 15:04:06 +00:00
|
|
|
|
'*',
|
2015-11-24 18:09:31 +00:00
|
|
|
|
'build/**/*',
|
|
|
|
|
'extensions/**/*',
|
|
|
|
|
'scripts/**/*',
|
|
|
|
|
'src/**/*',
|
2015-11-25 21:01:45 +00:00
|
|
|
|
'test/**/*'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
var eolFilter = [
|
|
|
|
|
'**',
|
2015-12-17 15:04:06 +00:00
|
|
|
|
'!ThirdPartyNotices.txt',
|
|
|
|
|
'!LICENSE.txt',
|
2015-11-24 18:09:31 +00:00
|
|
|
|
'!extensions/**/out/**',
|
|
|
|
|
'!**/node_modules/**',
|
|
|
|
|
'!**/fixtures/**',
|
2015-12-18 08:21:11 +00:00
|
|
|
|
'!**/*.{svg,exe,png,scpt,bat,cmd,cur,ttf,woff,eot}',
|
2015-11-24 18:09:31 +00:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
var indentationFilter = [
|
|
|
|
|
'**',
|
2015-12-17 15:04:06 +00:00
|
|
|
|
'!ThirdPartyNotices.txt',
|
|
|
|
|
'!**/*.md',
|
|
|
|
|
'!**/*.yml',
|
2015-12-10 17:38:31 +00:00
|
|
|
|
'!**/lib/**',
|
2015-11-24 18:09:31 +00:00
|
|
|
|
'!**/*.d.ts',
|
|
|
|
|
'!extensions/typescript/server/**',
|
|
|
|
|
'!test/assert.js',
|
|
|
|
|
'!**/package.json',
|
2015-11-30 15:27:47 +00:00
|
|
|
|
'!**/npm-shrinkwrap.json',
|
2015-11-24 18:09:31 +00:00
|
|
|
|
'!**/octicons/**',
|
|
|
|
|
'!**/vs/languages/sass/test/common/example.scss',
|
|
|
|
|
'!**/vs/languages/less/common/parser/less.grammar.txt',
|
|
|
|
|
'!**/vs/languages/css/common/buildscripts/css-schema.xml',
|
2016-01-21 15:15:42 +00:00
|
|
|
|
'!**/vs/base/common/marked/raw.marked.js',
|
2015-11-24 18:09:31 +00:00
|
|
|
|
'!**/vs/base/common/winjs.base.raw.js',
|
|
|
|
|
'!**/vs/base/node/terminateProcess.sh',
|
|
|
|
|
'!**/vs/base/node/terminateProcess.sh',
|
|
|
|
|
'!**/vs/text.js',
|
|
|
|
|
'!**/vs/nls.js',
|
|
|
|
|
'!**/vs/css.js',
|
|
|
|
|
'!**/vs/loader.js',
|
|
|
|
|
'!extensions/**/snippets/**',
|
|
|
|
|
'!extensions/**/syntaxes/**',
|
|
|
|
|
'!extensions/**/themes/**',
|
|
|
|
|
];
|
|
|
|
|
|
2016-01-18 08:50:41 +00:00
|
|
|
|
var copyrightFilter = [
|
2015-11-24 18:09:31 +00:00
|
|
|
|
'**',
|
|
|
|
|
'!**/*.json',
|
|
|
|
|
'!**/*.html',
|
|
|
|
|
'!**/test/**',
|
|
|
|
|
'!**/*.md',
|
2015-12-18 08:21:11 +00:00
|
|
|
|
'!**/*.bat',
|
|
|
|
|
'!**/*.cmd',
|
2016-01-05 15:32:49 +00:00
|
|
|
|
'!resources/win32/bin/code.js',
|
2015-11-24 18:09:31 +00:00
|
|
|
|
'!**/*.sh',
|
|
|
|
|
'!**/*.txt',
|
|
|
|
|
'!src/vs/editor/standalone-languages/swift.ts',
|
|
|
|
|
];
|
|
|
|
|
|
2016-01-18 08:50:41 +00:00
|
|
|
|
var tslintFilter = [
|
|
|
|
|
'src/**/*.ts',
|
|
|
|
|
'extensions/**/*.ts',
|
|
|
|
|
'!**/*.d.ts',
|
|
|
|
|
'!**/typings/**',
|
|
|
|
|
'!**/*.test.ts',
|
|
|
|
|
'!src/vs/editor/standalone-languages/test/**'
|
|
|
|
|
];
|
|
|
|
|
|
2015-11-24 18:09:31 +00:00
|
|
|
|
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');
|
|
|
|
|
|
2016-01-18 08:50:41 +00:00
|
|
|
|
/**
|
|
|
|
|
* Reports tslint erros in the format:
|
|
|
|
|
* src/helloWorld.c:5:3: warning: implicit declaration of function ‘prinft’
|
|
|
|
|
*/
|
|
|
|
|
var lintReporter = function (output, file, options) {
|
|
|
|
|
var relativeBase = file.base.substring(file.cwd.length + 1).replace('\\', '/');
|
|
|
|
|
output.forEach(function (e) {
|
|
|
|
|
var message = relativeBase + e.name + ':' + (e.startPosition.line + 1) + ':' + (e.startPosition.character + 1) + ': ' + e.failure;
|
|
|
|
|
console.log('[tslint] ' + message);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
gulp.task('tslint', function () {
|
|
|
|
|
return gulp.src(all, { base: '.' })
|
|
|
|
|
.pipe(filter(tslintFilter))
|
|
|
|
|
.pipe(tslint({ rulesDirectory: 'node_modules/tslint-microsoft-contrib' }))
|
|
|
|
|
.pipe(tslint.report(lintReporter, {
|
|
|
|
|
summarizeFailureOutput: false,
|
|
|
|
|
emitError: false
|
|
|
|
|
}));
|
|
|
|
|
});
|
|
|
|
|
|
2015-11-25 21:01:45 +00:00
|
|
|
|
var hygiene = exports.hygiene = function (some) {
|
2015-11-24 18:09:31 +00:00
|
|
|
|
var errorCount = 0;
|
|
|
|
|
|
|
|
|
|
var eol = es.through(function (file) {
|
|
|
|
|
if (/\r\n?/g.test(file.contents.toString('utf8'))) {
|
2015-11-25 21:01:45 +00:00
|
|
|
|
console.error(file.relative + ': Bad EOL found');
|
2015-11-24 18:09:31 +00:00
|
|
|
|
errorCount++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.emit('data', file);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var indentation = es.through(function (file) {
|
|
|
|
|
file.contents
|
|
|
|
|
.toString('utf8')
|
|
|
|
|
.split(/\r\n|\r|\n/)
|
2016-01-18 08:50:41 +00:00
|
|
|
|
.forEach(function (line, i) {
|
2015-11-25 08:47:15 +00:00
|
|
|
|
if (/^\s*$/.test(line)) {
|
|
|
|
|
// empty or whitespace lines are OK
|
2015-11-24 18:09:31 +00:00
|
|
|
|
} else if (/^[\t]*[^\s]/.test(line)) {
|
|
|
|
|
// good indent
|
|
|
|
|
} else if (/^[\t]* \*/.test(line)) {
|
|
|
|
|
// block comment using an extra space
|
|
|
|
|
} else {
|
2015-11-25 21:01:45 +00:00
|
|
|
|
console.error(file.relative + '(' + (i + 1) + ',1): Bad whitespace indentation');
|
2015-11-24 18:09:31 +00:00
|
|
|
|
errorCount++;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.emit('data', file);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var copyrights = es.through(function (file) {
|
|
|
|
|
if (file.contents.toString('utf8').indexOf(copyrightHeader) !== 0) {
|
2015-11-25 21:01:45 +00:00
|
|
|
|
console.error(file.relative + ': Missing or bad copyright statement');
|
2015-11-24 18:09:31 +00:00
|
|
|
|
errorCount++;
|
|
|
|
|
}
|
2015-11-25 08:47:15 +00:00
|
|
|
|
|
2015-11-25 08:29:48 +00:00
|
|
|
|
this.emit('data', file);
|
2015-11-24 18:09:31 +00:00
|
|
|
|
});
|
|
|
|
|
|
2015-11-25 21:01:45 +00:00
|
|
|
|
return gulp.src(some || all, { base: '.' })
|
2015-11-24 18:09:31 +00:00
|
|
|
|
.pipe(filter(function (f) { return !f.stat.isDirectory(); }))
|
2015-11-25 21:01:45 +00:00
|
|
|
|
.pipe(filter(eolFilter))
|
2015-11-24 18:09:31 +00:00
|
|
|
|
.pipe(eol)
|
|
|
|
|
.pipe(filter(indentationFilter))
|
|
|
|
|
.pipe(indentation)
|
2016-01-18 08:50:41 +00:00
|
|
|
|
.pipe(filter(copyrightFilter))
|
2015-11-24 18:09:31 +00:00
|
|
|
|
.pipe(copyrights)
|
|
|
|
|
.pipe(es.through(null, function () {
|
|
|
|
|
if (errorCount > 0) {
|
2015-11-26 08:57:29 +00:00
|
|
|
|
this.emit('error', 'Hygiene failed with ' + errorCount + ' errors. Check \'build/gulpfile.hygiene.js\'.');
|
2015-11-24 18:09:31 +00:00
|
|
|
|
} else {
|
|
|
|
|
this.emit('end');
|
|
|
|
|
}
|
|
|
|
|
}));
|
2015-11-25 21:01:45 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
gulp.task('hygiene', function () {
|
|
|
|
|
return hygiene();
|
2015-11-24 18:09:31 +00:00
|
|
|
|
});
|
2015-11-25 21:01:45 +00:00
|
|
|
|
|
|
|
|
|
// this allows us to run this as a git pre-commit hook
|
|
|
|
|
if (require.main === module) {
|
|
|
|
|
var cp = require('child_process');
|
|
|
|
|
cp.exec('git diff --cached --name-only', function (err, out) {
|
|
|
|
|
if (err) {
|
2015-11-26 08:57:29 +00:00
|
|
|
|
console.error();
|
|
|
|
|
console.error(err);
|
2015-11-25 21:01:45 +00:00
|
|
|
|
process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var some = out
|
|
|
|
|
.split(/\r?\n/)
|
|
|
|
|
.filter(function (l) { return !!l; });
|
|
|
|
|
|
|
|
|
|
hygiene(some).on('error', function (err) {
|
2015-11-26 08:57:29 +00:00
|
|
|
|
console.error();
|
|
|
|
|
console.error(err);
|
2015-11-25 21:01:45 +00:00
|
|
|
|
process.exit(1);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|