Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1c5b68c

Browse files
first release
0 parents commit 1c5b68c

File tree

11 files changed

+312
-0
lines changed

11 files changed

+312
-0
lines changed

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
npm-debug.log
3+
tmp

‎.jshintrc‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"curly": true,
3+
"eqeqeq": true,
4+
"immed": true,
5+
"latedef": true,
6+
"newcap": true,
7+
"noarg": true,
8+
"sub": true,
9+
"undef": true,
10+
"boss": true,
11+
"eqnull": true,
12+
"node": true,
13+
"es5": true
14+
}

‎Gruntfile.js‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* grunt-htmlhint
3+
* https://github.com/yaniswang/grunt-htmlhint
4+
*
5+
* Copyright (c) 2013 Yanis Wang
6+
* Licensed under the MIT license.
7+
*/
8+
9+
'use strict';
10+
11+
module.exports = function(grunt) {
12+
13+
// Project configuration.
14+
grunt.initConfig({
15+
jshint: {
16+
all: [
17+
'Gruntfile.js',
18+
'tasks/*.js'
19+
],
20+
options: {
21+
jshintrc: '.jshintrc',
22+
},
23+
},
24+
25+
// Configuration to be run (and then tested).
26+
htmlhint: {
27+
all: {
28+
options: {
29+
'tag-pair': true,
30+
'htmlhintrc': 'test/.htmlhintrc'
31+
},
32+
src: 'test/fixtures/*.html'
33+
}
34+
}
35+
36+
});
37+
38+
// Actually load this plugin's task(s).
39+
grunt.loadTasks('tasks');
40+
41+
// These plugins provide necessary tasks.
42+
grunt.loadNpmTasks('grunt-contrib-jshint');
43+
44+
// By default, lint and run all tests.
45+
grunt.registerTask('default', ['jshint', 'htmlhint']);
46+
47+
};

‎LICENSE-MIT‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2013 Yanis Wang
2+
3+
Permission is hereby granted, free of charge, to any person
4+
obtaining a copy of this software and associated documentation
5+
files (the "Software"), to deal in the Software without
6+
restriction, including without limitation the rights to use,
7+
copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the
9+
Software is furnished to do so, subject to the following
10+
conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.

‎README.md‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# grunt-htmlhint
2+
3+
> Validate html files with htmlhint.
4+
5+
## Getting Started
6+
This plugin requires Grunt `~0.4.1`
7+
8+
If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
9+
10+
```shell
11+
npm install grunt-htmlhint --save-dev
12+
```
13+
14+
One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
15+
16+
```js
17+
grunt.loadNpmTasks('grunt-htmlhint');
18+
```
19+
20+
## The "htmlhint" task
21+
22+
### Overview
23+
In your project's Gruntfile, add a section named `htmlhint` to the data object passed into `grunt.initConfig()`.
24+
25+
### Options
26+
27+
See all rules here: [https://github.com/yaniswang/HTMLHint/wiki/Rules](https://github.com/yaniswang/HTMLHint/wiki/Rules)
28+
29+
#### options.htmlhintrc
30+
Type: `String`
31+
Default value: `null`
32+
33+
If this filename is specified, options and globals defined therein will be used. Task and target options override the options within the `htmlhintrc` file. The `htmlhintrc` file must be valid JSON and looks something like this:
34+
35+
```json
36+
{
37+
"tag-pair": true,
38+
}
39+
```
40+
41+
#### options.force
42+
Type: `Boolean`
43+
Default value: `false`
44+
45+
Report HTMLHint errors but dont fail the task
46+
47+
### Usage Examples
48+
49+
#### Direct options
50+
51+
```js
52+
htmlhint: {
53+
html1: {
54+
options: {
55+
'tag-pair': true
56+
},
57+
src: ['path/to/**/*.html']
58+
},
59+
html2: {
60+
options: {
61+
'tag-pair': true
62+
},
63+
src: ['path/to/**/*.html']
64+
}
65+
}
66+
```
67+
68+
#### Config file
69+
70+
```js
71+
htmlhint: {
72+
options: {
73+
htmllintrc: '.htmllintrc'
74+
},
75+
html1: {
76+
src: ['path/to/**/*.html']
77+
},
78+
html2: {
79+
src: ['path/to/**/*.html']
80+
}
81+
}
82+
```
83+
84+
## Release History
85+
86+
* 2013年4月6日 v0.4.0 First release

‎package.json‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "grunt-htmlhint",
3+
"description": "Validate html files with htmlhint.",
4+
"version": "0.4.0",
5+
"homepage": "https://github.com/yaniswang/grunt-htmlhint",
6+
"author": {
7+
"name": "Yanis Wang",
8+
"email": "yanis.wang@gmail.com",
9+
"url": "http://yaniswang.com/"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "git@github.com:yaniswang/grunt-htmlhint.git"
14+
},
15+
"bugs": {
16+
"url": "https://github.com/yaniswang/grunt-htmlhint/issues"
17+
},
18+
"licenses": [
19+
{
20+
"type": "MIT",
21+
"url": "https://github.com/yaniswang/grunt-htmlhint/blob/master/LICENSE-MIT"
22+
}
23+
],
24+
"main": "Gruntfile.js",
25+
"engines": {
26+
"node": ">= 0.8.0"
27+
},
28+
"scripts": {
29+
"test": "grunt test --force"
30+
},
31+
"devDependencies": {
32+
"grunt-contrib-jshint": "~0.1.1",
33+
"grunt": "~0.4.1"
34+
},
35+
"peerDependencies": {
36+
"grunt": "~0.4.1"
37+
},
38+
"keywords": [
39+
"gruntplugin"
40+
],
41+
"dependencies": {
42+
"htmlhint": "~0.9.2"
43+
}
44+
}

‎tasks/htmlhint.js‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* grunt-htmlhint
3+
* https://github.com/yaniswang/grunt-htmlhint
4+
*
5+
* Copyright (c) 2013 Yanis Wang
6+
* Licensed under the MIT license.
7+
*/
8+
9+
'use strict';
10+
11+
module.exports = function(grunt) {
12+
13+
grunt.registerMultiTask('htmlhint', 'Validate html files with htmlhint.', function() {
14+
15+
var HTMLHint = require("htmlhint").HTMLHint;
16+
var options = this.options({
17+
force: false
18+
}),
19+
arrFilesSrc = this.filesSrc,
20+
verbose = grunt.verbose;
21+
22+
if (options.htmlhintrc) {
23+
var rc = grunt.file.readJSON(options.htmlhintrc);
24+
grunt.util._.defaults(options, rc);
25+
delete options.htmlhintrc;
26+
}
27+
28+
var force = options.force;
29+
delete options.force;
30+
31+
var hintCount = 0;
32+
arrFilesSrc.forEach(function( filepath ) {
33+
var file = grunt.file.read( filepath ),
34+
msg = "Linting " + filepath + "...",
35+
messages;
36+
if (file.length) {
37+
messages = HTMLHint.verify(file, options);
38+
verbose.write( msg );
39+
if (messages.length > 0) {
40+
verbose.or.write( msg );
41+
grunt.log.error();
42+
} else {
43+
verbose.ok();
44+
}
45+
messages.forEach(function( message ) {
46+
grunt.log.writeln( "[".red + ( "L" + message.line ).yellow + ":".red + ( "C" + message.col ).yellow + "]".red + ' ' + message.message.yellow );
47+
var evidence = message.evidence,
48+
col = message.col;
49+
if (col === 0) {
50+
evidence = '?'.inverse.red + evidence;
51+
} else if (col > evidence.length) {
52+
evidence = evidence + ' '.inverse.red;
53+
} else {
54+
evidence = evidence.slice(0, col - 1) + evidence[col - 1].inverse.red + evidence.slice(col);
55+
}
56+
grunt.log.writeln(evidence);
57+
hintCount ++;
58+
});
59+
}
60+
else{
61+
grunt.log.writeln( "Skipping empty file " + filepath);
62+
}
63+
});
64+
65+
if ( hintCount > 0 ) {
66+
return force;
67+
}
68+
69+
grunt.log.ok(arrFilesSrc.length + ' file' + (arrFilesSrc.length === 1 ? '' : 's') + ' lint free.');
70+
71+
});
72+
73+
};

‎test/.htmlhintrc‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"doctype-first": true
3+
}

‎test/fixtures/empty.html‎

Whitespace-only changes.

‎test/fixtures/invalid.html‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<html>
2+
<head>
3+
<meta charset="UTF-8">
4+
<title></title>
5+
</head>
6+
<body>
7+
<ul><li></ul>
8+
<div>
9+
</body>
10+
</html>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /