Skip to content

Commit 4e78274

Browse files
committed
add gulp task to lint for closure warnings
1 parent 1478a06 commit 4e78274

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ before_script:
1919
- npm install -g bower gulp-cli@1
2020
- bower install
2121
- gulp lint
22+
- gulp lint-closure
2223
script:
2324
- xvfb-run wct
2425
- 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

gulpfile.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ class Log extends Transform {
8686
}
8787
}
8888

89+
let CLOSURE_LINT_ONLY = false;
90+
let EXPECTED_WARNING_COUNT = 503;
91+
8992
gulp.task('closure', ['clean'], () => {
9093

9194
let entry, splitRx, joinRx;
@@ -109,6 +112,25 @@ gulp.task('closure', ['clean'], () => {
109112
shell: `./${entry}`
110113
});
111114

115+
function closureLintLogger(log) {
116+
let result = log.split(/\n/).slice(-2)[0];
117+
let warnings = result.match(/(\d+) warning/);
118+
let chalk = require('chalk');
119+
if (warnings && Number(warnings[1]) > EXPECTED_WARNING_COUNT) {
120+
console.log(log);
121+
console.error(chalk.red(`closure linting: actual warning count ${warnings[1]} greater than expected warning count ${EXPECTED_WARNING_COUNT}`));
122+
process.exit(1);
123+
}
124+
}
125+
126+
let closurePluginOptions;
127+
128+
if (CLOSURE_LINT_ONLY) {
129+
closurePluginOptions = {
130+
logger: closureLintLogger
131+
}
132+
}
133+
112134
const closureStream = closure({
113135
compilation_level: 'ADVANCED',
114136
language_in: 'ES6_STRICT',
@@ -118,6 +140,7 @@ gulp.task('closure', ['clean'], () => {
118140
assume_function_wrapper: true,
119141
rewrite_polyfills: false,
120142
new_type_inf: true,
143+
checks_only: CLOSURE_LINT_ONLY,
121144
externs: [
122145
'externs/webcomponents-externs.js',
123146
'externs/polymer-externs.js',
@@ -128,7 +151,7 @@ gulp.task('closure', ['clean'], () => {
128151
'polymerMixinClass',
129152
'polymerElement'
130153
]
131-
});
154+
}, closurePluginOptions);
132155

133156
const closurePipeline = lazypipe()
134157
.pipe(() => closureStream)
@@ -186,6 +209,11 @@ gulp.task('closure', ['clean'], () => {
186209
.pipe(gulp.dest(COMPILED_DIR))
187210
});
188211

212+
gulp.task('lint-closure', (done) => {
213+
CLOSURE_LINT_ONLY = true;
214+
runseq('closure', done);
215+
})
216+
189217
gulp.task('build', ['clean'], () => {
190218
// process source files in the project
191219
const sources = project.sources();

0 commit comments

Comments
 (0)