Skip to content

Commit

Permalink
add gulp task to lint for closure warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dfreedm committed Apr 18, 2017
1 parent 1478a06 commit 4e78274
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 29 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -128,7 +151,7 @@ gulp.task('closure', ['clean'], () => {
'polymerMixinClass',
'polymerElement'
]
});
}, closurePluginOptions);

const closurePipeline = lazypipe()
.pipe(() => closureStream)
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 4e78274

Please sign in to comment.