Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
Lint tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Nov 18, 2015
1 parent bca0887 commit f553832
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 64 deletions.
3 changes: 3 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
Expand All @@ -7,6 +8,8 @@
"noarg": true,
"node": true,
"nonbsp": true,
"noempty": true,
"quotmark": "single",
"strict": true,
"sub": true,
"undef": true,
Expand Down
49 changes: 20 additions & 29 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

});
Expand Down
13 changes: 6 additions & 7 deletions tasks/bootlint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -43,21 +42,21 @@ 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;
});

}

if (!output) {
grunt.log.warn(filepath + ":", lintId, lint.message);
grunt.log.warn(filepath + ':', lintId, lint.message);
totalErrCount++;
}

Expand All @@ -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.');
}
Expand Down
52 changes: 24 additions & 28 deletions test/bootlint_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand All @@ -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();
});
Expand All @@ -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();
});
Expand All @@ -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();
});
Expand All @@ -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();
});
Expand All @@ -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();
});
Expand All @@ -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();
});
Expand All @@ -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');
Expand Down

0 comments on commit f553832

Please sign in to comment.