diff --git a/.travis.yml b/.travis.yml index cdb0129741..6725fc9f5e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/gulpfile.js b/gulpfile.js index 97b6464987..25d15c02d6 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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();