Skip to content

Commit

Permalink
Make cli logs more clear to people
Browse files Browse the repository at this point in the history
  • Loading branch information
yaniswang committed Oct 7, 2015
1 parent 83afc1d commit 8576cd4
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 23 deletions.
4 changes: 0 additions & 4 deletions .jshintrc → .jshintrc1
Expand Up @@ -13,7 +13,6 @@
"sub": true,

"browser": true,
"wsh": true,
"-W099": true,
"-W100": true,

Expand All @@ -22,9 +21,6 @@
"HTMLParser",
"require",
"exports",
"process",
"describe",
"it",
"console",
"JSHINT",
"CSSLint"
Expand Down
23 changes: 23 additions & 0 deletions .jshintrc2
@@ -0,0 +1,23 @@
{
"curly": true,
"expr": true,
"newcap": false,
"regexdash": true,
"trailing": true,
"undef": true,
"unused": true,
"maxerr": 100,

"eqnull": true,
"evil": true,
"sub": true,

"node": true,
"-W099": true,
"-W100": true,

"predef": [
"describe",
"it"
]
}
3 changes: 2 additions & 1 deletion CHANGE.md
Expand Up @@ -11,10 +11,11 @@ add:
4. Support json raw format in cli
5. tag-pair(rule): Show the line of the start tag
6. space-tab-mixed-disabled(rule): Support space and tab mode, for check only space or tab
7. Make cli logs more clear to people

fix:

1. fix issue: #77 `<link rel=icon><link rel=icon>`
1. Fix issue: #77 `<link rel=icon><link rel=icon>`
2. Made the descriptions and error messages of rules more clear to people

## ver 0.9.7 (2015-3-8)
Expand Down
14 changes: 10 additions & 4 deletions Gruntfile.js
Expand Up @@ -13,10 +13,16 @@ module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
all: {
src: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js', 'bin/*'],
browser: {
src: ['src/**/*.js'],
options: {
jshintrc: ".jshintrc"
jshintrc: ".jshintrc1"
}
},
node: {
src: ['Gruntfile.js', 'test/**/*.js', 'bin/*'],
options: {
jshintrc: ".jshintrc2"
}
}
},
Expand Down Expand Up @@ -74,7 +80,7 @@ module.exports = function(grunt) {
});

grunt.registerTask('build', ['jshint', 'clean', 'concat']);

grunt.registerTask('dev', ['build', 'exec:test']);

grunt.registerTask('default', ['build', 'exec:cover', 'uglify', 'replace:version']);
Expand Down
22 changes: 15 additions & 7 deletions bin/htmlhint
Expand Up @@ -95,7 +95,7 @@ function getAllFiles(arrTargets){
for(var i=0,l=arrTargets.length;i<l;i++){
var filepath = path.resolve(process.cwd(), arrTargets[i]);
if(fs.existsSync(filepath) !== false){
if(fs.statSync(filepath).isFile) {
if(fs.statSync(filepath).isFile()) {
arrAllFiles.push(filepath);
} else {
getFiles(arrTargets[i], arrAllFiles);
Expand Down Expand Up @@ -128,12 +128,15 @@ function getFiles(filepath, arrFiles){
}

function processFiles(arrFiles, ruleset, jsonOutput){
var exitcode = 0,
allHintCount = 0;
var exitcode = 0;
var allFileCount = 0;
var allHintCount = 0;
console.log('');
arrFiles.forEach(function(filepath){
var hintCount = hintFile(filepath, ruleset, jsonOutput);
if(hintCount > 0){
exitcode = 1;
allFileCount ++;
allHintCount += hintCount;
}
});
Expand All @@ -142,10 +145,10 @@ function processFiles(arrFiles, ruleset, jsonOutput){
}
else{
if(allHintCount > 0){
console.log('\r\n%d problems.'.red, allHintCount);
console.log('%d errors in %d files'.red, allHintCount, allFileCount);
}
else{
console.log('No problem.'.green);
console.log('Done, without errors.'.green);
}
}
return exitcode;
Expand All @@ -166,13 +169,18 @@ function hintFile(filepath, ruleset, jsonOutput){
}

function logPretty(filepath, messages){
console.log(filepath+':');
console.log(' '+path.relative(process.cwd(), filepath));
messages.forEach(function(hint){
console.log('[ %s ] line %d, col %d: %s', hint.rule.id.green, hint.line, hint.col, hint.message[hint.type === 'error'?'red':'yellow']);
console.log(' L%d |%s', hint.line, hint.evidence.replace(/\t/g, ' ').gray);
console.log(' %s^ %s', repeatStr(String(hint.line).length + 3 + hint.col - 1), (hint.message + ' (' + hint.rule.id+')')[hint.type === 'error'?'red':'yellow']);
});
console.log('');
}

function repeatStr(n, str){
return new Array(n + 1).join(str || ' ');
}

function logJson(filepath, messages, jsonOutput){
jsonOutput.push({'file': filepath, 'messages': messages});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/htmlhint.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -16,7 +16,7 @@
"grunt-cli": "0.1.6",
"grunt-contrib-clean": "0.4.0",
"grunt-contrib-concat": "0.1.3",
"grunt-contrib-jshint": "0.3.0",
"grunt-contrib-jshint": "0.11.3",
"grunt-contrib-uglify": "0.2.0",
"grunt-contrib-watch": "0.3.1",
"grunt-exec": "0.4.0",
Expand Down
3 changes: 2 additions & 1 deletion src/core.js
@@ -1,3 +1,4 @@
/* jshint -W079 */
/**
* Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com>
* MIT Licensed
Expand Down Expand Up @@ -72,4 +73,4 @@ var HTMLHint = (function (undefined) {

if (typeof exports === 'object' && exports){
exports.HTMLHint = HTMLHint;
}
}
5 changes: 3 additions & 2 deletions src/htmlparser.js
@@ -1,3 +1,4 @@
/* jshint -W079 */
/**
* Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com>
* MIT Licensed
Expand Down Expand Up @@ -31,8 +32,8 @@ var HTMLParser = (function(undefined){
var self = this,
mapCdataTags = self._mapCdataTags;

var regTag=/<(?:\/([^\s>]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:\s+[\w\-:]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'\/>]*))?)*?)\s*(\/?))>/g,
regAttr = /\s*([\w\-:]+)(?:\s*=\s*(?:(")([^"]*)"|(')([^']*)'|([^\s"'\/>]*)))?/g,
var regTag=/<(?:\/([^\s>]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:\s+[\w\-:]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]*))?)*?)\s*(\/?))>/g,
regAttr = /\s*([\w\-:]+)(?:\s*=\s*(?:(")([^"]*)"|(')([^']*)'|([^\s"'>]*)))?/g,
regLine = /\r?\n/g;

var match, matchIndex, lastIndex = 0, tagName, arrAttrs, tagCDATA, attrsCDATA, arrCDATA, lastCDATAIndex = 0, text;
Expand Down
7 changes: 5 additions & 2 deletions test/htmlparser.spec.js
Expand Up @@ -446,9 +446,12 @@ describe('HTMLParser: Case parse', function(){
expect(arrEvents[1]).to.event('tagstart',
{
tagName: 'img',
close: '/'
close: ''
});
expect(arrEvents[1].attrs.length).to.be(2);
var attrs = arrEvents[1].attrs;
expect(attrs.length).to.be(2);
expect(attrs[1].name).to.be('alt');
expect(attrs[1].value).to.be('/');
done();
});
parser.parse('<img src="aaa" alt= />');
Expand Down

2 comments on commit 8576cd4

@DragorWW
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really .jshintrc1 .jshintrc2 ??
please name them as:
.jshintrc-borwsers
.jshintrc-node

@yaniswang
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

Please sign in to comment.