Skip to content

Commit

Permalink
Use parser.getMapAttrs instead of using custom for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
takenspc committed Jul 29, 2014
1 parent c0fb8fe commit dfb166f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
14 changes: 4 additions & 10 deletions src/rules/alt-not-empty.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,15 @@ HTMLHint.addRule({
var self = this;
parser.addListener('tagstart', function(event){
var tagName = event.tagName.toLowerCase(),
attrs = event.attrs,
attrMap = {},
attr,
mapAttrs = parser.getMapAttrs(event.attrs),
col = event.col + tagName.length + 1,
selector;
if (tagName !== 'area' && tagName !== 'input'){
return;
}
for(var i=0, l=attrs.length;i<l;i++){
attr = attrs[i];
attrMap[attr.name.toLowerCase()] = attr.value;
}
if ((tagName === 'area' && 'href' in attrMap) ||
(tagName === 'input' && attrMap['type'] === 'image')) {
if (!('alt' in attrMap) || attrMap['alt'] === '') {
if ((tagName === 'area' && 'href' in mapAttrs) ||
(tagName === 'input' && mapAttrs['type'] === 'image')) {
if (!('alt' in mapAttrs) || mapAttrs['alt'] === '') {
selector = tagName === 'area' ? 'area[href]' : 'input[type=image]';
reporter.warn('Alt of ' + selector + ' must be set value.', event.line, col, self, event.raw);
}
Expand Down
4 changes: 2 additions & 2 deletions test/rules/alt-not-empty.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('Rules: '+ruldId, function(){
expect(messages.length).to.be(0);
});

it('Area tag have not href and alt attribute should not result in an error', function(){
it('Area tag have not href and alt attributes should not result in an error', function(){
var code = '<area>';
var messages = HTMLHint.verify(code, ruleOptions);
expect(messages.length).to.be(0);
Expand Down Expand Up @@ -54,7 +54,7 @@ describe('Rules: '+ruldId, function(){
expect(messages.length).to.be(0);
});

it('Input tag have not type and alt attribute should not result in an error', function(){
it('Input tag have not type and alt attributes should not result in an error', function(){
var code = '<input>';
var messages = HTMLHint.verify(code, ruleOptions);
expect(messages.length).to.be(0);
Expand Down

0 comments on commit dfb166f

Please sign in to comment.