diff options
author | XhmikosR <xhmikosr@gmail.com> | 2015-11-21 09:51:38 +0300 |
---|---|---|
committer | XhmikosR <xhmikosr@gmail.com> | 2015-11-21 09:51:38 +0300 |
commit | 276f23d0c001b38c40914c138fde0ed1b0c81efb (patch) | |
tree | 0fdb73dafeaed4f182f9f503010a82f2181c6477 | |
parent | bca08873b0003882cb8f9a6be11765e8e268d816 (diff) | |
parent | f553832f830447f636cb701a1dfca64411348274 (diff) |
Merge pull request #60 from twbs/lint
Lint tweaks.
-rw-r--r-- | .jshintrc | 3 | ||||
-rw-r--r-- | Gruntfile.js | 49 | ||||
-rw-r--r-- | tasks/bootlint.js | 13 | ||||
-rw-r--r-- | test/bootlint_test.js | 52 |
4 files changed, 53 insertions, 64 deletions
@@ -1,4 +1,5 @@ { + "camelcase": true, "curly": true, "eqeqeq": true, "immed": true, @@ -7,6 +8,8 @@ "noarg": true, "node": true, "nonbsp": true, + "noempty": true, + "quotmark": "single", "strict": true, "sub": true, "undef": true, diff --git a/Gruntfile.js b/Gruntfile.js index 5f0361a..f3fa1b6 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -25,108 +25,99 @@ module.exports = function(grunt) { // Before generating any new files, remove any previously-created files. clean: { - tests: ['tmp'] + tests: 'tmp' }, // Configuration to be run (and then tested). bootlint: { - default_options: { - options: { - }, + defaultOptions: { files: { - 'tmp/default_options': [ - 'test/fixtures/**.html', - ] + 'tmp/defaultOptions': 'test/fixtures/**.html' } }, relaxerror: { options: { relaxerror: { 'E001': [], - 'W005': [ - 'test/fixtures/missing-jquery.html' - ] - }, + 'W005': 'test/fixtures/missing-jquery.html' + } }, files: { 'tmp/relaxerror': [ 'test/fixtures/missing-doctype.html', 'test/fixtures/missing-charset.html', - 'test/fixtures/missing-jquery.html', + 'test/fixtures/missing-jquery.html' ] } }, - stoponerror: { + stoponerror: { options: { - stoponerror: true, + stoponerror: true }, files: { 'tmp/stoponerror': [ 'test/fixtures/missing-doctype.html', 'test/fixtures/missing-charset.html', - 'test/fixtures/cols-redundant.html', + 'test/fixtures/cols-redundant.html' ] } }, stoponwarning: { options: { - stoponwarning: true, + stoponwarning: true }, files: { 'tmp/stoponwarning': [ 'test/fixtures/missing-doctype.html', 'test/fixtures/missing-charset.html', - 'test/fixtures/cols-redundant.html', + 'test/fixtures/cols-redundant.html' ] } }, showallerrors: { options: { - showallerrors: true, + showallerrors: true }, files: { 'tmp/stoponwarning': [ 'test/fixtures/missing-doctype.html', 'test/fixtures/missing-charset.html', - 'test/fixtures/cols-redundant.html', + 'test/fixtures/cols-redundant.html' ] } }, showallerrorswithstop: { options: { showallerrors: true, - stoponwarning: true, + stoponwarning: true }, files: { 'tmp/stoponwarning': [ 'test/fixtures/missing-doctype.html', 'test/fixtures/missing-charset.html', - 'test/fixtures/cols-redundant.html', + 'test/fixtures/cols-redundant.html' ] } }, stoponboth: { options: { stoponwarning: true, - stoponerror: true, + stoponerror: true }, files: { - 'tmp/stoponboth': [ - 'test/fixtures/**.html', - ] + 'tmp/stoponboth': 'test/fixtures/**.html' } }, pass: { - options: {}, files: { 'tmp/pass': 'test/fixtures/pass.html' - }, - }, + } + } }, // Unit tests. nodeunit: { - tests: ['test/*_test.js'] + tests: 'test/*_test.js' } }); diff --git a/tasks/bootlint.js b/tasks/bootlint.js index 71f7595..1b881b1 100644 --- a/tasks/bootlint.js +++ b/tasks/bootlint.js @@ -32,9 +32,8 @@ module.exports = function(grunt) { if (!grunt.file.exists(filepath)) { grunt.log.warn('Source file "' + filepath + '" not found.'); return false; - } else { - return true; } + return true; }) .forEach(function(filepath) { @@ -43,13 +42,13 @@ module.exports = function(grunt) { var reporter = function (lint) { var isError = (lint.id[0] === 'E'); var isWarning = (lint.id[0] === 'W'); - var lintId = (isError) ? chalk.bgGreen.white(lint.id) : chalk.bgRed.white(lint.id); + var lintId = isError ? chalk.bgGreen.white(lint.id) : chalk.bgRed.white(lint.id); var output = false; if (lint.elements) { lint.elements.each(function (_, element) { var loc = element.startLocation; - grunt.log.warn(filepath + ":" + (loc.line + 1) + ":" + (loc.column + 1), lintId, lint.message); + grunt.log.warn(filepath + ':' + (loc.line + 1) + ':' + (loc.column + 1), lintId, lint.message); totalErrCount++; output = true; }); @@ -57,7 +56,7 @@ module.exports = function(grunt) { } if (!output) { - grunt.log.warn(filepath + ":", lintId, lint.message); + grunt.log.warn(filepath + ':', lintId, lint.message); totalErrCount++; } @@ -75,10 +74,10 @@ module.exports = function(grunt) { }); if (totalErrCount > 0 && !options.showallerrors) { - grunt.log.writeln().fail(totalErrCount + " lint error(s) found across " + totalFileCount + " file(s)."); + grunt.log.writeln().fail(totalErrCount + ' lint error(s) found across ' + totalFileCount + ' file(s).'); grunt.log.writeln().fail('For details, look up the lint problem IDs in the Bootlint wiki: https://github.com/twbs/bootlint/wiki'); } else if (totalErrCount > 0 && options.showallerrors) { - grunt.fail.warn(totalErrCount + " lint error(s) found across " + totalFileCount + " file(s)."); + grunt.fail.warn(totalErrCount + ' lint error(s) found across ' + totalFileCount + ' file(s).'); } else { grunt.log.ok(totalFileCount + ' file(s) lint free.'); } diff --git a/test/bootlint_test.js b/test/bootlint_test.js index eaccdc5..c5667f3 100644 --- a/test/bootlint_test.js +++ b/test/bootlint_test.js @@ -23,21 +23,17 @@ var grunt = require('grunt'); */ exports.bootlint = { - setUp: function(done) { - // setup here if necessary - done(); - }, - default_options: function(test) { + defaultOptions: function(test) { test.expect(3); grunt.util.spawn({ grunt: true, - args: ['bootlint:default_options', '--no-color'], + args: ['bootlint:defaultOptions', '--no-color'] }, function(err, result) { - test.ok(result.stdout.indexOf("test/fixtures/missing-doctype.html") >= 0, + test.ok(result.stdout.indexOf('test/fixtures/missing-doctype.html') >= 0, 'Should print file path'); - test.ok(result.stdout.indexOf("Document is missing a DOCTYPE declaration") >= 0, + test.ok(result.stdout.indexOf('Document is missing a DOCTYPE declaration') >= 0, 'Should warn about missing a DOCTYPE'); - test.ok(result.stdout.indexOf("9 lint error(s) found across 5 file(s)") >= 0, + test.ok(result.stdout.indexOf('9 lint error(s) found across 5 file(s)') >= 0, 'Should print number of lint errors and files'); test.done(); }); @@ -46,15 +42,15 @@ exports.bootlint = { test.expect(4); grunt.util.spawn({ grunt: true, - args: ['bootlint:relaxerror', '--no-color'], + args: ['bootlint:relaxerror', '--no-color'] }, function(err, result) { - test.ok(result.stdout.indexOf("E001") === -1, + test.ok(result.stdout.indexOf('E001') === -1, 'Should not warn about missing a DOCTYPE'); - test.ok(result.stdout.indexOf("W001") >= 0, + test.ok(result.stdout.indexOf('W001') >= 0, 'Should warn about missing charset'); - test.ok(result.stdout.indexOf("W005") === -1, + test.ok(result.stdout.indexOf('W005') === -1, 'Should not warn about missing jQuery'); - test.ok(result.stdout.indexOf("1 lint error(s) found across 3 file(s)") >= 0, + test.ok(result.stdout.indexOf('1 lint error(s) found across 3 file(s)') >= 0, 'Should print correct number of lint errors and files'); test.done(); }); @@ -63,11 +59,11 @@ exports.bootlint = { test.expect(2); grunt.util.spawn({ grunt: true, - args: ['bootlint:stoponerror', '--no-color'], + args: ['bootlint:stoponerror', '--no-color'] }, function(err, result) { - test.ok(result.stdout.indexOf("E001") >= 0, + test.ok(result.stdout.indexOf('E001') >= 0, 'Should warn about missing a DOCTYPE'); - test.ok(result.stdout.indexOf("W001") === -1, + test.ok(result.stdout.indexOf('W001') === -1, 'Should not warn about anything after E001'); test.done(); }); @@ -76,13 +72,13 @@ exports.bootlint = { test.expect(3); grunt.util.spawn({ grunt: true, - args: ['bootlint:stoponwarning', '--no-color'], + args: ['bootlint:stoponwarning', '--no-color'] }, function(err, result) { - test.ok(result.stdout.indexOf("E001") >= 0, + test.ok(result.stdout.indexOf('E001') >= 0, 'Should display error of missing a DOCTYPE'); - test.ok(result.stdout.indexOf("W001") >= 0, + test.ok(result.stdout.indexOf('W001') >= 0, 'Should warn about W001'); - test.ok(result.stdout.indexOf("E029") === -1, + test.ok(result.stdout.indexOf('E029') === -1, 'Should not warn about anything after W001'); test.done(); }); @@ -91,9 +87,9 @@ exports.bootlint = { test.expect(1); grunt.util.spawn({ grunt: true, - args: ['bootlint:stoponboth', '--no-color'], + args: ['bootlint:stoponboth', '--no-color'] }, function(err, result) { - test.ok(result.stdout.indexOf("E001") === -1, + test.ok(result.stdout.indexOf('E001') === -1, 'Should not warn about E001'); test.done(); }); @@ -102,9 +98,9 @@ exports.bootlint = { test.expect(1); grunt.util.spawn({ grunt: true, - args: ['bootlint:showallerrors', '--no-color'], + args: ['bootlint:showallerrors', '--no-color'] }, function(err, result) { - test.ok(result.stdout.indexOf("8 lint error(s) found across 3 file(s). Use --force to continue.") >= 0, + test.ok(result.stdout.indexOf('8 lint error(s) found across 3 file(s). Use --force to continue.') >= 0, 'Should show all errors before hard fail.'); test.done(); }); @@ -113,9 +109,9 @@ exports.bootlint = { test.expect(1); grunt.util.spawn({ grunt: true, - args: ['bootlint:showallerrorswithstop', '--no-color'], + args: ['bootlint:showallerrorswithstop', '--no-color'] }, function(err, result) { - test.ok(result.stdout.indexOf("8 lint error(s) found across 3 file(s). Use --force to continue.") >= 0, + test.ok(result.stdout.indexOf('8 lint error(s) found across 3 file(s). Use --force to continue.') >= 0, 'Should show all errors before hard fail even if stopon* is set.'); test.done(); }); @@ -124,7 +120,7 @@ exports.bootlint = { test.expect(1); grunt.util.spawn({ grunt: true, - args: ['bootlint:pass', '--no-color'], + args: ['bootlint:pass', '--no-color'] }, function(err, result) { test.ok(result.stdout.indexOf('1 file(s) lint free.') >= 0, 'Should print correct number of lint free files'); |