Skip to content

Commit

Permalink
1. add rule: attr-no-duplication
Browse files Browse the repository at this point in the history
2. add rule: space-tab-mixed-disabled
2. add default rule: attr-no-duplication
  • Loading branch information
yaniswang committed Jun 14, 2014
1 parent 3f01f90 commit eddcca1
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 172 deletions.
1 change: 1 addition & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

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

"predef": [
"HTMLHint",
Expand Down
6 changes: 6 additions & 0 deletions CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
HTMLHint change log
====================

## ver 0.9.6 (2014-6-14)

1. add rule: attr-no-duplication
2. add rule: space-tab-mixed-disabled
2. add default rule: attr-no-duplication

## ver 0.9.4 (2013-9-27)

1. add rule: src-not-empty
Expand Down
3 changes: 1 addition & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ module.exports = function(grunt) {
replace: {
htmlhint: {
files: {
'lib/htmlhint.js':'lib/htmlhint.js',
'bin/htmlhint':'src/cli.js'
'lib/htmlhint.js':'lib/htmlhint.js'
},
options: {
prefix: '@',
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
The MIT License
================

Copyright (c) 2013 Yanis Wang \<[email protected]\>
Copyright (c) 2014 Yanis Wang \<[email protected]\>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 6 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
TODO
==================

1. reporter support
2. w3c rule
1. add rule: Relative path
2. add rule: Absolute path
3. add rule: adblock
4. add comment support: `<!-- htmlhint doctype-first:false-->`
4. reporter support
5. w3c rule
2 changes: 1 addition & 1 deletion coverage.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/htmlhint.js

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{
"name": "htmlhint",
"version": "0.9.5",
"version": "0.9.6",
"description": "A Static Code Analysis Tool for HTML",
"main": "./index",
"dependencies": {
"commander": "~1.1.1",
"colors": "~0.6.0-1",
"jshint": "~1.1.0",
"csslint": "~0.9.10"
"commander": "1.1.1",
"colors": "0.6.0-1",
"jshint": "1.1.0",
"csslint": "0.9.10"
},
"devDependencies": {
"grunt-cli": "~0.1.6",
"grunt": "~0.4.1",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-concat": "~0.1.3",
"grunt-contrib-uglify": "~0.2.0",
"grunt-contrib-watch": "~0.3.1",
"grunt-replace": "~0.4.0",
"grunt-contrib-jshint": "~0.3.0",
"grunt-cli": "0.1.6",
"grunt": "0.4.1",
"grunt-contrib-clean": "0.4.0",
"grunt-contrib-concat": "0.1.3",
"grunt-contrib-uglify": "0.2.0",
"grunt-contrib-watch": "0.3.1",
"grunt-replace": "0.4.0",
"grunt-contrib-jshint": "0.3.0",
"grunt-mocha-hack": "0.1.0",
"grunt-exec": "~0.4.0",
"mocha": "~1.8.2",
"expect.js": "~0.2.0",
"jscover": "~0.2.4"
"grunt-exec": "0.4.0",
"mocha": "1.8.2",
"expect.js": "0.2.0",
"jscover": "0.2.4"
},
"bin": {
"htmlhint": "./bin/htmlhint"
Expand Down
146 changes: 0 additions & 146 deletions src/cli.js

This file was deleted.

3 changes: 2 additions & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ var HTMLHint = (function (undefined) {
'tag-pair': true,
'spec-char-escape': true,
'id-unique': true,
'src-not-empty': true
'src-not-empty': true,
'attr-no-duplication': true // added: 2014-6-14
};

HTMLHint.addRule = function(rule){
Expand Down
27 changes: 27 additions & 0 deletions src/rules/attr-no-duplication.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) 2014, Yanis Wang <[email protected]>
* MIT Licensed
*/
HTMLHint.addRule({
id: 'attr-no-duplication',
description: 'Attribute name can not been duplication.',
init: function(parser, reporter){
var self = this;
parser.addListener('tagstart', function(event){
var attrs = event.attrs;
var attr;
var attrName;
var col = event.col + event.tagName.length + 1;

var mapAttrName = {};
for(var i=0, l=attrs.length;i<l;i++){
attr = attrs[i];
attrName = attr.name;
if(mapAttrName[attrName] === true){
reporter.error('The name of attribute [ '+attr.name+' ] been duplication.', event.line, col + attr.index, self, attr.raw);
}
mapAttrName[attrName] = true;
}
});
}
});
16 changes: 16 additions & 0 deletions src/rules/space-tab-mixed-disabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) 2014, Yanis Wang <[email protected]>
* MIT Licensed
*/
HTMLHint.addRule({
id: 'space-tab-mixed-disabled',
description: 'Spaces and tabs can not mixed in front of line.',
init: function(parser, reporter){
var self = this;
parser.addListener('text', function(event){
if(event.pos === 0 && /^( +\t|\t+ )/.test(event.raw) === true){
reporter.warn('Mixed spaces and tabs in front of line.', event.line, 0, self, event.raw);
}
});
}
});
32 changes: 32 additions & 0 deletions test/rules/attr-no-duplication.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright (c) 2014, Yanis Wang <[email protected]>
* MIT Licensed
*/

var expect = require("expect.js");

var HTMLHint = require("../../index").HTMLHint;

var ruldId = 'attr-no-duplication',
ruleOptions = {};

ruleOptions[ruldId] = true;

describe('Rules: '+ruldId, function(){

it('Attribute name been duplication should result in an error', function(){
var code = '<a href="a" href="b">bbb</a>';
var messages = HTMLHint.verify(code, ruleOptions);
expect(messages.length).to.be(1);
expect(messages[0].rule.id).to.be(ruldId);
expect(messages[0].line).to.be(1);
expect(messages[0].col).to.be(12);
});

it('Attribute name not been duplication should not result in an error', function(){
var code = '<a href="a">bbb</a>';
var messages = HTMLHint.verify(code, ruleOptions);
expect(messages.length).to.be(0);
});

});
46 changes: 46 additions & 0 deletions test/rules/space-tab-mixed-disabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright (c) 2014, Yanis Wang <[email protected]>
* MIT Licensed
*/

var expect = require("expect.js");

var HTMLHint = require("../../index").HTMLHint;

var ruldId = 'space-tab-mixed-disabled',
ruleOptions = {};

ruleOptions[ruldId] = true;

describe('Rules: '+ruldId, function(){

it('Spaces and tabs mixed in front of line should result in an error', function(){
// space before tab
var code = ' <a href="a">bbb</a>';
var messages = HTMLHint.verify(code, ruleOptions);
expect(messages.length).to.be(1);
expect(messages[0].rule.id).to.be(ruldId);
expect(messages[0].line).to.be(1);
expect(messages[0].col).to.be(0);
// tab before space
code = ' <a href="a">bbb</a>';
messages = HTMLHint.verify(code, ruleOptions);
expect(messages.length).to.be(1);
expect(messages[0].rule.id).to.be(ruldId);
expect(messages[0].line).to.be(1);
expect(messages[0].col).to.be(0);
});

it('Only spaces in front of line should not result in an error', function(){
var code = ' <a href="a">bbb</a>';
var messages = HTMLHint.verify(code, ruleOptions);
expect(messages.length).to.be(0);
});

it('Only tabs in front of line should not result in an error', function(){
var code = ' <a href="a">bbb</a>';
var messages = HTMLHint.verify(code, ruleOptions);
expect(messages.length).to.be(0);
});

});

0 comments on commit eddcca1

Please sign in to comment.