[Grunt & Yeoman] grunt-html-hint で html の lint/hint/validation をする
grunt-html-hint おすすめかも、というお話し。
[markdown]
“`prettyprinted
% grunt -version
grunt-cli v0.1.10
grunt v0.4.1
“`
2013/11/15 現在で、先月のダウンロード数が多い順。
## grunt-html
> * [grunt-html](https://npmjs.org/package/grunt-html)
### インストール
“`prettyprinted
% npm install –save-dev grunt-html
“`
### Gruntfile
一部のみ抜粋。
“`
# grunt-html
htmllint:
all: [
‘src/**/*.html’
]
“`
### 実行
成功
“`prettyprinted
% grunt htmllint
Running “htmllint:all” (htmllint) task
>> 2 files lint free.
Done, without errors.
“`
失敗
“`prettyprinted
% grunt htmllint
Running “htmllint:all” (htmllint) task
Linting src/index.html”… ERROR
[L10:C3] Saw “<" when expecting an attribute name. Probable cause
Linting src/index.html"... ERROR
[L10:C6] End tag had attributes.
Linting src/index.html"... ERROR
[L10:C27] Stray end tag "h2".
Warning: Task "htmllint:all" failed. Use --force to continue.
Aborted due to warnings.
``` ## grunt-html-validation > * [grunt-html-validation](https://npmjs.org/package/grunt-html-validation)
### インストール
“`prettyprinted
% npm install –save-dev grunt-html-validation
“`
### Gruntfile
一部のみ抜粋。
“`
# grunt-html-validation
validation:
# options:
target: [
‘src/**/*.html’
]
“`
### 実行
成功
“`prettyprinted
% grunt validation
Running “validation:target” (validation) task
Validation started for.. src/index.html
>> Validation successful..
Validated skipping..src/sample.html
“`
失敗
“`prettyprinted
% grunt validation
Running “validation:target” (validation) task
Validation started for.. src/index.html
1=> “Saw < when expecting an attribute name. Probable cause: Missing > immediately before.” Line no: 10
2=> “End tag had attributes.” Line no: 10
3=> “Stray end tag h2.” Line no: 10
No of errors: 3
Validation started for.. src/sample.html
>> Validation successful..
Validation report generated: validation-report.json
Done, without errors.
“`
ファイルが生成されていました。
* validation-status.json
* validation-report.json
## grunt-html-hint
> * [grunt-htmlhint](https://npmjs.org/package/grunt-htmlhint)
### インストール
“`prettyprinted
% npm install –save-dev grunt-htmlhint
“`
### Gruntfile
一部のみ抜粋。
“`
# grunt-htmlhint
htmlhint:
options:
‘tag-pair’: true
# htmlhintrc: ‘.htmlhintrc’
html1:
src: [‘src/**/*.html’]
“`
### 実行
.htmlhintrc がうまくパースされないので、上記の通りダイレクトで書き込んでみた。
> * [Rules · yaniswang/HTMLHint Wiki · GitHub](https://github.com/yaniswang/HTMLHint/wiki/Rules)
“`prettyprinted
% grunt htmlhint
Running “htmlhint:html1” (htmlhint) task
Warning: Unable to parse “.htmlhintrc” file (Unexpected token ‘). Use –force to continue.
Aborted due to warnings.
“`
成功
“`prettyprinted
% grunt htmlhint
>> Local Npm module “grunt-lib-phantomjs” not found. Is it installed?
Running “htmlhint:html1” (htmlhint) task
>> 2 files lint free.
Done, without errors.
“`
失敗
“`prettyprinted
% grunt htmlhint
Running “htmlhint:html1” (htmlhint) task
Linting src/index.html…ERROR
[L12:C1] Tag must be paired, Missing: [
]