]> source.dussan.org Git - jquery-ui.git/commitdiff
Build: Implement an asciilint task to verify content of ui files (ignore i18n). Fixes... 1007/head
authorJörn Zaefferer <joern.zaefferer@gmail.com>
Fri, 14 Jun 2013 07:01:02 +0000 (09:01 +0200)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Wed, 3 Jul 2013 14:01:51 +0000 (16:01 +0200)
Gruntfile.js
build/tasks/build.js

index 4eee9a1abe3d3343880519688f32c07c2f33c0a6..b35a4514d20a1602423f9cb6576130e45e468bb8 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;
+});
+
 };