From 7396460c765395b97b9a1da125384903a62c1a2e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=CC=88rn=20Zaefferer?= Date: Fri, 14 Jun 2013 09:01:02 +0200 Subject: [PATCH] Build: Implement an asciilint task to verify content of ui files (ignore i18n). Fixes #9037 - Build: Verify characters in output (cherry picked from commit 7da828375afb20d58736bb1eb530f915c445d5b9) --- Gruntfile.js | 2 +- build/tasks/build.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Gruntfile.js b/Gruntfile.js index d52e573ba..85088b279 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -244,7 +244,7 @@ grunt.initConfig({ }); grunt.registerTask( "default", [ "lint", "test" ] ); -grunt.registerTask( "lint", [ "jshint", "csslint", "htmllint" ] ); +grunt.registerTask( "lint", [ "asciilint", "jshint", "csslint", "htmllint" ] ); grunt.registerTask( "test", [ "qunit" ] ); grunt.registerTask( "sizer", [ "concat:ui", "uglify:main", "compare_size:all" ] ); grunt.registerTask( "sizer_all", [ "concat:ui", "uglify", "compare_size" ] ); diff --git a/build/tasks/build.js b/build/tasks/build.js index 4d803df77..c50745899 100644 --- a/build/tasks/build.js +++ b/build/tasks/build.js @@ -135,4 +135,37 @@ grunt.registerTask( "clean", function() { require( "rimraf" ).sync( "dist" ); }); +grunt.registerTask( "asciilint", function() { + var valid = true, + files = grunt.file.expand({ filter: "isFile" }, "ui/*.js" ); + files.forEach(function( filename ) { + var i, c, + text = grunt.file.read( filename ); + + // Ensure files use only \n for line endings, not \r\n + if ( /\x0d\x0a/.test( text ) ) { + grunt.log.error( filename + ": Incorrect line endings (\\r\\n)" ); + valid = false; + } + + // Ensure only ASCII chars so script tags don't need a charset attribute + if ( text.length !== Buffer.byteLength( text, "utf8" ) ) { + grunt.log.error( filename + ": Non-ASCII characters detected:" ); + for ( i = 0; i < text.length; i++ ) { + c = text.charCodeAt( i ); + if ( c > 127 ) { + grunt.log.error( "- position " + i + ": " + c ); + grunt.log.error( "-- " + text.substring( i - 20, i + 20 ) ); + break; + } + } + valid = false; + } + }); + if ( valid ) { + grunt.log.ok( files.length + " files lint free." ); + } + return valid; +}); + }; -- 2.39.5