add gulp task to lint for closure warnings

This commit is contained in:
Daniel Freedman
2017-04-18 11:29:33 -07:00
parent 1478a0680a
commit 4e78274152
2 changed files with 30 additions and 1 deletions

View File

@@ -19,6 +19,7 @@ before_script:
- npm install -g bower gulp-cli@1
- bower install
- gulp lint
- gulp lint-closure
script:
- xvfb-run wct
- if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then wct -s 'windows 10/microsoftedge@14' -s 'windows 8.1/internet explorer@11' -s 'os x 10.11/safari@9' -s 'macos 10.12/safari@10' -s 'Linux/chrome@41'; fi

View File

@@ -86,6 +86,9 @@ class Log extends Transform {
}
}
let CLOSURE_LINT_ONLY = false;
let EXPECTED_WARNING_COUNT = 503;
gulp.task('closure', ['clean'], () => {
let entry, splitRx, joinRx;
@@ -109,6 +112,25 @@ gulp.task('closure', ['clean'], () => {
shell: `./${entry}`
});
function closureLintLogger(log) {
let result = log.split(/\n/).slice(-2)[0];
let warnings = result.match(/(\d+) warning/);
let chalk = require('chalk');
if (warnings && Number(warnings[1]) > EXPECTED_WARNING_COUNT) {
console.log(log);
console.error(chalk.red(`closure linting: actual warning count ${warnings[1]} greater than expected warning count ${EXPECTED_WARNING_COUNT}`));
process.exit(1);
}
}
let closurePluginOptions;
if (CLOSURE_LINT_ONLY) {
closurePluginOptions = {
logger: closureLintLogger
}
}
const closureStream = closure({
compilation_level: 'ADVANCED',
language_in: 'ES6_STRICT',
@@ -118,6 +140,7 @@ gulp.task('closure', ['clean'], () => {
assume_function_wrapper: true,
rewrite_polyfills: false,
new_type_inf: true,
checks_only: CLOSURE_LINT_ONLY,
externs: [
'externs/webcomponents-externs.js',
'externs/polymer-externs.js',
@@ -128,7 +151,7 @@ gulp.task('closure', ['clean'], () => {
'polymerMixinClass',
'polymerElement'
]
});
}, closurePluginOptions);
const closurePipeline = lazypipe()
.pipe(() => closureStream)
@@ -186,6 +209,11 @@ gulp.task('closure', ['clean'], () => {
.pipe(gulp.dest(COMPILED_DIR))
});
gulp.task('lint-closure', (done) => {
CLOSURE_LINT_ONLY = true;
runseq('closure', done);
})
gulp.task('build', ['clean'], () => {
// process source files in the project
const sources = project.sources();