]> source.dussan.org Git - jquery-ui.git/commitdiff
Build: Implement an asciilint task to verify content of ui files (ignore i18n). Fixes...
authorJörn Zaefferer <joern.zaefferer@gmail.com>
Fri, 14 Jun 2013 07:01:02 +0000 (09:01 +0200)
committerScott González <scott.gonzalez@gmail.com>
Tue, 26 Nov 2013 16:18:32 +0000 (11:18 -0500)
(cherry picked from commit 7da828375afb20d58736bb1eb530f915c445d5b9)

Gruntfile.js
build/tasks/build.js

index d52e573ba39f657bbcb08b1413aae5d621fcb0ce..85088b279c64d91bd97e945f1270ffd70be90bbc 100644 (file)
@@ -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" ] );
index 4d803df77c5ddaf9e0db6f0d9bceeaf8db8c8c04..c50745899c0047308fde830f3ddfb1941b33e118 100644 (file)
@@ -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;
+});
+
 };