forked from htmllint/htmllint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
M26656 Create linter rule for id/name checking
- Loading branch information
Christoph Krautz
committed
Jan 25, 2017
1 parent
c2f722a
commit 088ab44
Showing
5 changed files
with
3,887 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
var knife = require('../knife'), | ||
Issue = require('../issue'), | ||
proc = require('../processOption'); | ||
|
||
module.exports = { | ||
name: 'tag-req-name', | ||
on: ['dom'], | ||
filter: ['tag', 'style', 'script'], | ||
desc: [ | ||
'The value of this option is a list of strings, each of which is a tag', | ||
'name. Tags with any of the given names are disallowed.' | ||
].join('\n'), | ||
process: proc.arrayOfStr | ||
}; | ||
|
||
module.exports.lint = function (element, opts) { | ||
var format = opts[this.name]; | ||
if (format.indexOf(element.name) < 0) { | ||
return []; | ||
} | ||
|
||
if (knife.hasNonEmptyAttr(element, 'id') || knife.hasNonEmptyAttr(element, 'name')) { | ||
return []; | ||
} | ||
|
||
return new Issue('E016', element.openLineCol, { tag: element.name }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
module.exports = [ | ||
{ | ||
desc: 'should pass when set to false', | ||
input: '<input type="radio">', | ||
opts: { 'tag-req-name': false }, | ||
output: 0 | ||
}, | ||
{ | ||
desc: 'should pass when tag not listed in options', | ||
input: '<input type="radio">', | ||
opts: { 'tag-req-name': ['div'] }, | ||
output: 0 | ||
}, | ||
{ | ||
desc: 'should fail when input has no type', | ||
input: '<input>', | ||
opts: { 'tag-req-name': ['input'] }, | ||
output: 1 | ||
}, | ||
{ | ||
desc: 'should fail when input has no type value', | ||
input: '<input type>', | ||
opts: { 'tag-req-name': ['input'] }, | ||
output: 1 | ||
}, | ||
{ | ||
desc: 'should fail when input has type text', | ||
input: '<input type="text">', | ||
opts: { 'tag-req-name': ['input'] }, | ||
output: 1 | ||
}, | ||
{ | ||
desc: 'should fail when radio input has no id or name', | ||
input: '<input type="radio" >', | ||
opts: { 'tag-req-name': ['input'] }, | ||
output: 1 | ||
}, | ||
{ | ||
desc: 'should fail when button has no id or name', | ||
input: '<button>', | ||
opts: { 'tag-req-name': ['button'] }, | ||
output: 1 | ||
}, | ||
{ | ||
desc: 'should fail when anchor has no id or name', | ||
input: '<a></a>', | ||
opts: { 'tag-req-name': ['a'] }, | ||
output: 1 | ||
}, | ||
{ | ||
desc: 'should fail when form has no id or name', | ||
input: '<form></form>', | ||
opts: { 'tag-req-name': ['form'] }, | ||
output: 1 | ||
}, | ||
{ | ||
desc: 'should fail when radio input has empty name', | ||
input: '<input type="radio" name>', | ||
opts: { 'tag-req-name': ['input'] }, | ||
output: 1 | ||
}, | ||
{ | ||
desc: 'should fail when radio input has name with no length', | ||
input: '<input type="radio" name="">', | ||
opts: { 'tag-req-name': ['input'] }, | ||
output: 1 | ||
}, | ||
{ | ||
desc: 'should pass when input has a name', | ||
input: '<input type="radio" name="hello">', | ||
opts: { 'tag-req-name': ['input'] }, | ||
output: 0 | ||
}, | ||
{ | ||
desc: 'should pass when button has a name', | ||
input: '<button name="hello">', | ||
opts: { 'tag-req-name': ['button'] }, | ||
output: 0 | ||
}, | ||
{ | ||
desc: 'should pass when form has a name', | ||
input: '<form name="hello"></form>', | ||
opts: { 'tag-req-name': ['form'] }, | ||
output: 0 | ||
}, | ||
{ | ||
desc: 'should pass when anchor has a name', | ||
input: '<a name="hello"></a>', | ||
opts: { 'tag-req-name': ['a'] }, | ||
output: 0 | ||
} | ||
]; |
Oops, something went wrong.