From 93755fef532ee34a957c29df6167e42e1d16360a Mon Sep 17 00:00:00 2001 From: Sam El-Husseini Date: Thu, 31 Oct 2019 15:49:28 -0700 Subject: [PATCH] Treat compiler warnings as errors and run on travis (#3378) * Enable compiler warnings as errors and run on travis --- core/field_variable.js | 3 +- core/insertion_marker_manager.js | 7 +-- core/renderers/geras/path_object.js | 3 +- core/theme.js | 8 ++-- gulpfile.js | 68 +++++++++++++++++++++++++++-- package.json | 3 +- tests/run_all_tests.sh | 5 ++- 7 files changed, 83 insertions(+), 14 deletions(-) diff --git a/core/field_variable.js b/core/field_variable.js index 5ac85d736..850e2c378 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -63,7 +63,8 @@ Blockly.FieldVariable = function(varName, opt_validator, opt_variableTypes, /** * An array of options for a dropdown list, * or a function which generates these options. - * @type {!function(this:Blockly.FieldVariable): !Array.} + * @type {(!Array.| + * !function(this:Blockly.FieldDropdown): !Array.)} * @protected */ this.menuGenerator_ = Blockly.FieldVariable.dropdownCreate; diff --git a/core/insertion_marker_manager.js b/core/insertion_marker_manager.js index bdf208181..2be5213a0 100644 --- a/core/insertion_marker_manager.js +++ b/core/insertion_marker_manager.js @@ -570,8 +570,8 @@ Blockly.InsertionMarkerManager.prototype.highlightBlock_ = function() { closest.targetBlock().highlightForReplacement(true); } else if (local.type == Blockly.OUTPUT_VALUE) { this.highlightedBlock_ = closest.getSourceBlock(); - // TODO: remove? - closest.getSourceBlock().highlightShapeForInput(closest, true); + // TODO: Bring this back for zelos rendering. + // closest.getSourceBlock().highlightShapeForInput(closest, true); } this.highlightingBlock_ = true; }; @@ -585,7 +585,8 @@ Blockly.InsertionMarkerManager.prototype.unhighlightBlock_ = function() { // If there's no block in place, but we're still connecting to a value input, // then we must have been highlighting an input shape. if (closest.type == Blockly.INPUT_VALUE && !closest.isConnected()) { - this.highlightedBlock_.highlightShapeForInput(closest, false); + // TODO: Bring this back for zelos rendering. + // this.highlightedBlock_.highlightShapeForInput(closest, false); } else { this.highlightedBlock_.highlightForReplacement(false); } diff --git a/core/renderers/geras/path_object.js b/core/renderers/geras/path_object.js index 42e995b85..701bc324a 100644 --- a/core/renderers/geras/path_object.js +++ b/core/renderers/geras/path_object.js @@ -137,5 +137,6 @@ Blockly.geras.PathObject.prototype.applyColour = function(isShadow) { Blockly.geras.PathObject.prototype.setStyle = function(blockStyle) { this.style = blockStyle; this.colourDark = - Blockly.utils.colour.blend('#000', this.style.colourPrimary, 0.2); + Blockly.utils.colour.blend('#000', this.style.colourPrimary, 0.2) || + this.colourDark; }; diff --git a/core/theme.js b/core/theme.js index c086d3714..bad41cffb 100644 --- a/core/theme.js +++ b/core/theme.js @@ -163,7 +163,7 @@ Blockly.Theme.createBlockStyle = function(colour) { */ Blockly.Theme.validatedBlockStyle = function(blockStyle) { // Make a new object with all of the same properties. - var valid = {}; + var valid = /** @type {!Blockly.Theme.BlockStyle} */ ({}); if (blockStyle) { Blockly.utils.object.mixin(valid, blockStyle); } @@ -174,10 +174,12 @@ Blockly.Theme.validatedBlockStyle = function(blockStyle) { valid.colourPrimary = parsedColour.hex; valid.colourSecondary = valid.colourSecondary ? Blockly.utils.colour.parseBlockColour(valid.colourSecondary).hex : - Blockly.utils.colour.blend('#fff', valid.colourPrimary, 0.6); + Blockly.utils.colour.blend('#fff', valid.colourPrimary, 0.6) || + valid.colourPrimary; valid.colourTertiary = valid.colourTertiary ? Blockly.utils.colour.parseBlockColour(valid.colourTertiary).hex : - Blockly.utils.colour.blend('#fff', valid.colourPrimary, 0.3); + Blockly.utils.colour.blend('#fff', valid.colourPrimary, 0.3) || + valid.colourPrimary; valid.hat = valid.hat || ''; return valid; diff --git a/gulpfile.js b/gulpfile.js index f57d6a33c..645efb57f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -79,12 +79,71 @@ function prependHeader() { return gulp.insert.prepend(`// Do not edit this file; automatically generated by gulp.\n`); } +/** + * Closure compiler warning groups used to treat warnings as errors. + */ +var JSCOMP_ERROR = [ + 'accessControls', + 'ambiguousFunctionDecl', + 'checkPrototypalTypes', + 'checkRegExp', + 'checkTypes', + 'checkVars', + 'conformanceViolations', + 'const', + 'constantProperty', + 'deprecated', + 'deprecatedAnnotations', + 'duplicateMessage', + // 'es3', + 'es5Strict', + 'externsValidation', + 'fileoverviewTags', + 'functionParams', + 'globalThis', + 'internetExplorerChecks', + 'invalidCasts', + 'misplacedTypeAnnotation', + 'missingGetCssName', + // 'missingOverride', + 'missingPolyfill', + 'missingProperties', + 'missingProvide', + 'missingRequire', + 'missingReturn', + // 'missingSourcesWarnings', + 'moduleLoad', + 'msgDescriptions', + 'newCheckTypes', + 'nonStandardJsDocs', + // 'polymer', + // 'reportUnknownTypes', + // 'strictCheckTypes', + // 'strictMissingProperties', + 'strictModuleDepCheck', + // 'strictPrimitiveOperators', + 'suspiciousCode', + 'typeInvalidation', + 'undefinedNames', + 'undefinedVars', + 'underscore', + 'unknownDefines', + 'unusedLocalVariables', + // 'unusedPrivateMembers', + 'useOfGoogBase', + 'uselessCode', + 'untranspilableFeatures', + 'visibility' +]; + /** * Helper method for calling the Closure compiler. * @param {*} compilerOptions * @param {boolean=} opt_verbose Optional option for verbose logging + * @param {boolean=} opt_warnings_as_error Optional option for treating warnings + * as errors. */ -function compile(compilerOptions, opt_verbose) { +function compile(compilerOptions, opt_verbose, opt_warnings_as_error) { if (!compilerOptions) compilerOptions = {}; compilerOptions.compilation_level = 'SIMPLE_OPTIMIZATIONS'; compilerOptions.warning_level = opt_verbose ? 'VERBOSE' : 'DEFAULT'; @@ -92,6 +151,7 @@ function compile(compilerOptions, opt_verbose) { compilerOptions.language_out = 'ECMASCRIPT5_STRICT'; compilerOptions.rewrite_polyfills = false; compilerOptions.hide_warnings_for = 'node_modules'; + if (opt_warnings_as_error) compilerOptions.jscomp_error = JSCOMP_ERROR; const platform = ['native', 'java', 'javascript']; @@ -125,7 +185,7 @@ gulp.task('build-core', function () { js_output_file: 'blockly_compressed.js', externs: './externs/svg-externs.js', define: defines - }, argv.verbose)) + }, argv.verbose, argv.strict)) .pipe(prependHeader()) .pipe(gulp.dest('./')); }); @@ -157,7 +217,7 @@ goog.provide('Blockly.Mutator');`; .pipe(compile({ dependency_mode: 'NONE', js_output_file: 'blocks_compressed.js' - }, argv.verbose)) + }, argv.verbose, argv.strict)) .pipe(gulp.replace('\'use strict\';', '\'use strict\';\n\n\n')) // Remove Blockly.Blocks to be compatible with Blockly. .pipe(gulp.replace(/var Blockly=\{[^;]*\};\n?/, '')) @@ -185,7 +245,7 @@ goog.provide('Blockly.utils.string');`; .pipe(compile({ dependency_mode: 'NONE', js_output_file: `${language}_compressed.js` - }, argv.verbose)) + }, argv.verbose, argv.strict)) .pipe(gulp.replace('\'use strict\';', '\'use strict\';\n\n\n')) // Remove Blockly.Generator and Blockly.utils.string to be compatible with Blockly. .pipe(gulp.replace(/var Blockly=\{[^;]*\};\s*Blockly.utils.global={};\s*Blockly.utils.string={};\n?/, '')) diff --git a/package.json b/package.json index da8364912..98962932a 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,8 @@ "build": "gulp build", "build:blocks": "gulp build-blocks", "build:core": "gulp build-core", - "build:debug": "gulp build-core --verbose > build-debug.log 2>&1 && tail -3 -r build-debug.log", + "build:debug": "gulp build-core --verbose --strict", + "build:debug:log": "npm run build:debug > build-debug.log 2>&1 && tail -3 build-debug.log", "build:langfiles": "gulp build-langfiles", "build:uncompressed": "gulp build-uncompressed", "bump": "npm version 3.$(date +'%Y%m%d').0", diff --git a/tests/run_all_tests.sh b/tests/run_all_tests.sh index cb8349674..dffd9d1cc 100755 --- a/tests/run_all_tests.sh +++ b/tests/run_all_tests.sh @@ -64,6 +64,9 @@ run_test_command "node" "./node_modules/.bin/mocha tests/node --opts tests/node/ # Run generator tests inside a browser and check the results. run_test_command "generators" "tests/scripts/run_generators.sh" +# Run the closure compiler ensuring there are no errors. +run_test_command "compile" "npm run build:debug" + # Generate TypeScript typings and ensure there are no errors. run_test_command "typings" "tests/scripts/compile_typings.sh" @@ -71,7 +74,7 @@ run_test_command "typings" "tests/scripts/compile_typings.sh" run_test_command "metadata" "tests/scripts/check_metadata.sh" # # Attempt advanced compilation of a Blockly app. -# run_test_command "compile" "tests/compile/compile.sh" +# run_test_command "advanced_compile" "tests/compile/compile.sh" # End of tests.