From fd9b7d3475870cff054b0b21a310fb21e05ed794 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=CC=88rn=20Zaefferer?= Date: Sat, 10 Mar 2012 13:45:16 +0100 Subject: [PATCH] Build/grunt: Integrate CSSLint --- grunt.js | 43 ++++++++++++++++++++++++++++++++++++++++++- package.json | 4 ++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/grunt.js b/grunt.js index fe840c15d..ae837d7fc 100644 --- a/grunt.js +++ b/grunt.js @@ -221,6 +221,15 @@ config.init({ grunt: 'grunt.js', tests: 'tests/unit/**/*.js' }, + csslint: { + base_theme: { + src: 'themes/base/*.css', + rules: { + 'import': false, + 'overqualified-elements': 2 + } + } + }, jshint: { options: { curly: true, @@ -333,6 +342,38 @@ task.registerBasicTask('zip', 'Create a zip file for release', function() { }); }); +task.registerBasicTask('csslint', 'Lint CSS files with csslint', function() { + var csslint = require('csslint').CSSLint; + var files = file.expand(this.file.src); + var ruleset = {}; + csslint.getRules().forEach(function(rule) { + ruleset[rule.id] = 1; + }); + for (var rule in this.data.rules) { + if (!this.data.rules[rule]) { + delete ruleset[rule]; + } else { + ruleset[rule] = this.data.rules[rule]; + } + } + var hadErrors = 0; + files.forEach(function(filepath) { + log.writeln('Linting ' + filepath); + var result = csslint.verify(file.read(filepath), ruleset); + result.messages.forEach(function(message) { + log.writeln('['.red + ('L' + message.line).yellow + ':'.red + ('C' + message.col).yellow + ']'.red); + log[message.type === 'error' ? 'error' : 'writeln'](message.message + ' ' + message.rule.desc + ' (' + message.rule.id + ')'); + }); + if (result.messages.length) { + hadErrors += 1; + } + }); + if (hadErrors) { + return false; + } + log.writeln('Lint free'); +}); + task.registerBasicTask( 'css_min', 'Minify CSS files with Sqwish.', function() { var files = file.expand( this.file.src ); // Get banner, if specified. It would be nice if UglifyJS supported ignoring @@ -498,7 +539,7 @@ task.registerHelper("lpad", function(str, len, chr) { return ( Array( len + 1 ).join( chr || " " ) + str ).substr( -len ); }); -task.registerTask('default', 'lint qunit build compare_size'); +task.registerTask('default', 'lint csslint qunit build compare_size'); task.registerTask('sizer', 'concat:ui min:dist/jquery-ui.min.js compare_size'); task.registerTask('build', 'concat min css_min'); task.registerTask('release', 'build copy:dist copy:dist_min copy:dist_min_images copy:dist_css_min md5:dist zip:dist'); diff --git a/package.json b/package.json index 2d473076a..cd0c9f78d 100644 --- a/package.json +++ b/package.json @@ -27,9 +27,9 @@ "dependencies": {}, "devDependencies": { "grunt": "0.2.x", - "adm-zip": "0.1.x", "sqwish": "0.2.x", - "request": "0.2.x" + "request": "2.9.x", + "csslint": "0.9.x" }, "keywords": [] } \ No newline at end of file -- 2.39.5