Skip to content

Commit

Permalink
Build: Implement an asciilint task to verify content of ui files (ign…
Browse files Browse the repository at this point in the history
…ore i18n). Fixes #9037 - Build: Verify characters in output

(cherry picked from commit 7da8283)
  • Loading branch information
jzaefferer authored and scottgonzalez committed Nov 26, 2013
1 parent c02eef9 commit 7396460
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Gruntfile.js
Expand Up @@ -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" ] );
Expand Down
33 changes: 33 additions & 0 deletions build/tasks/build.js
Expand Up @@ -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;
});

};

0 comments on commit 7396460

Please sign in to comment.