Skip to content

Commit e8cf2fe

Browse files
committed
hello world
0 parents  commit e8cf2fe

File tree

8 files changed

+454
-0
lines changed

8 files changed

+454
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
npm-debug.log
3+
tmp
4+
log

.htmlhintrc

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"tagname-lowercase": true,
3+
"attr-lowercase": true,
4+
"attr-value-double-quotes": true,
5+
"attr-value-not-empty": true,
6+
"attr-no-duplication": true,
7+
"doctype-first": true,
8+
"tag-pair": true,
9+
"tag-self-close": true,
10+
"spec-char-escape": true,
11+
"id-unique": true,
12+
"src-not-empty": true,
13+
"head-script-disabled": true,
14+
"img-alt-require": true,
15+
"doctype-html5": true,
16+
"id-class-value": true,
17+
"style-disabled": true,
18+
"space-tab-mixed-disabled": true,
19+
"id-class-ad-disabled": true,
20+
"href-abs-or-rel": true,
21+
"attr-unsafe-chars": true
22+
}

.jshintrc

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
}

Gruntfile.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* grunt-htmlhint-inline
3+
* https://github.com/kazu69/grunt-htmlhint-inline
4+
*
5+
* Copyright (c) 2015 kazu69
6+
* Licensed under the MIT license.
7+
*/
8+
9+
'use strict';
10+
11+
module.exports = function(grunt) {
12+
13+
grunt.initConfig({
14+
jshint: {
15+
all: [
16+
'Gruntfile.js'
17+
],
18+
options: {
19+
jshintrc: '.jshintrc'
20+
}
21+
},
22+
23+
htmlhint_inline: {
24+
options: {
25+
htmlhintrc: '.htmlhintrc',
26+
ignore: {
27+
'<?php': '?>'
28+
},
29+
patterns: [
30+
{
31+
match: /hoge/g,
32+
replacement: 'fuga'
33+
}
34+
],
35+
reporterOutput: './log/grunt.log',
36+
},
37+
dest: {
38+
src: ['./test/*.phtml']
39+
}
40+
}
41+
42+
});
43+
44+
grunt.loadTasks('tasks');
45+
grunt.loadNpmTasks('grunt-contrib-jshint');
46+
47+
grunt.registerTask('test', ['htmlhint_inline']);
48+
grunt.registerTask('default', ['jshint', 'test']);
49+
};

README.md

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# grunt-htmlhint-inline
2+
3+
> Grunt task for linting inline html
4+
5+
## Getting Started
6+
This plugin requires Grunt `~0.4.5`
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-inline --save-dev
12+
```
13+
14+
Once 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-inline');
18+
```
19+
20+
## The "htmlhint-inline" task
21+
22+
### Overview
23+
In your project's Gruntfile, add a section named `htmlhint-inline` to the data object passed into `grunt.initConfig()`.
24+
25+
```js
26+
grunt.initConfig({
27+
htmlhint_inline: {
28+
options: {
29+
htmlhintrc: '.htmlhintrc',
30+
ignore: {
31+
'<?php': '?>'
32+
}
33+
},
34+
dest: {
35+
src: ['./test/*.phtml']
36+
}
37+
},
38+
});
39+
```
40+
41+
### Options
42+
43+
#### htmlhintrc
44+
Type: String Default value: null
45+
46+
```htmlhintrc``` file must be a valid JSON.
47+
If you specify this file, options that have been defined in it will be used in the global.
48+
If there is specified in the task options, the options in this file will be overwritten.
49+
50+
```json
51+
{
52+
"tagname-lowercase": true
53+
}
54+
```
55+
56+
#### patterns
57+
Type: Array Default: []
58+
59+
Enable the replacement by the pattern
60+
61+
##### patterns.match
62+
63+
Type: RegExp|String
64+
65+
Indicates the matching expression.
66+
67+
##### patterns.replacement
68+
69+
Type: String|Function
70+
71+
#### reporterOutput
72+
73+
Type: String Default: null
74+
75+
Output the task execution results to a specified file.
76+
77+
#### force
78+
79+
Type: Boolean Default value: false
80+
81+
Report HTMLHint errors but dont fail the task
82+
83+
84+
### Usage Examples
85+
86+
#### Default Options
87+
In this example, the default options are used to do something with whatever. So if the `testing` file has the content `Testing` and the `123` file had the content `1 2 3`, the generated result would be `Testing, 1 2 3.`
88+
89+
```js
90+
grunt.initConfig({
91+
htmlhint_inline: {
92+
options: {
93+
"tagname-lowercase": true,
94+
"attr-lowercase": true,
95+
ignore: {
96+
'<?php': '?>'
97+
}
98+
},
99+
dest: {
100+
src: ['./test/*.phtml']
101+
}
102+
},
103+
});
104+
```
105+
106+
#### Custom Options
107+
In this example, custom options are used to do something else with whatever else. So if the `testing` file has the content `Testing` and the `123` file had the content `1 2 3`, the generated result in this case would be `Testing: 1 2 3 !!!`
108+
109+
```js
110+
grunt.initConfig({
111+
htmlhint_inline: {
112+
options: {
113+
htmlhintrc: '.htmlhintrc',
114+
ignore: {
115+
'<?php': '?>'
116+
},
117+
patterns: [
118+
{
119+
match: /hoge/g,
120+
replacement: 'fuga'
121+
}
122+
],
123+
reporterOutput: './log/grunt.log',
124+
},
125+
dest: {
126+
src: ['./test/*.phtml']
127+
}
128+
}
129+
});
130+
```
131+
## License
132+
133+
MIT

tasks/htmlhintinline.js

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* grunt-htmlhint-inline
3+
* https://github.com/kazu69/grunt-htmlhint-inline
4+
*
5+
* Copyright (c) 2015 kazu69
6+
* Licensed under the MIT license.
7+
*/
8+
9+
'use strict';
10+
11+
module.exports = function (grunt) {
12+
13+
var lintinline = require('./lib/inlinehint'),
14+
HTMLHint = require("htmlhint").HTMLHint,
15+
path = require('path');
16+
17+
grunt.registerMultiTask('htmlhint_inline', 'Validate inline html with htmlhint', function () {
18+
var done = this.async(),
19+
log = grunt.log,
20+
output = '';
21+
22+
var options = this.options({
23+
force: false,
24+
reporterOutput: null,
25+
patterns: [],
26+
htmlhintrc: null
27+
});
28+
29+
var force = options.force;
30+
delete options.force;
31+
32+
var reporterOutput = options.reporterOutput;
33+
delete options.reporterOutput;
34+
35+
var patterns = options.patterns;
36+
delete options.patterns;
37+
38+
var htmlhintrc = options.htmlhintrc
39+
delete options.htmlhintrc
40+
41+
var ignore = options.ignore;
42+
delete options.ignore;
43+
44+
if (htmlhintrc) {
45+
var _htmlhintrc = grunt.file.readJSON(htmlhintrc);
46+
// set to the default options value
47+
grunt.util._.defaults(options, _htmlhintrc);
48+
}
49+
50+
// output pre hook
51+
if (reporterOutput) {
52+
grunt.util.hooker.hook(process.stdout, 'write', {
53+
pre: function(stdout) {
54+
output += stdout;
55+
// https://github.com/cowboy/javascript-hooker#hookerpreempt
56+
return grunt.util.hooker.preempt();
57+
}
58+
});
59+
}
60+
61+
var tempFiles = lintinline.wrapReporter(options, this.filesSrc, ignore, patterns),
62+
tempFilesLength = Object.keys(tempFiles).length,
63+
hintCount = 0, eachCount = 0;
64+
65+
Object.keys(tempFiles).forEach(function( file ) {
66+
var realFilePath = tempFiles[file]['filepath'],
67+
file = grunt.file.read( file ),
68+
msg = "Linting " + realFilePath + "...",
69+
messages;
70+
71+
if (file.length) {
72+
messages = HTMLHint.verify(file, options);
73+
74+
log.write(msg);
75+
76+
(messages.length > 0)? log.error() : log.ok();
77+
78+
messages.forEach(function( message ) {
79+
log.writeln(
80+
"[".red + ( "L" + message.line ).yellow +":".red +
81+
( "C" + message.col ).yellow + "]".red + ' ' + message.message.yellow
82+
);
83+
84+
var evidence = message.evidence,
85+
col = message.col;
86+
if (col === 0) {
87+
evidence = '?'.red + evidence;
88+
} else if(col > evidence.length) {
89+
evidence = evidence + ' '.red;
90+
} else {
91+
evidence = evidence.slice(0, col - 1) + evidence[col - 1].red + evidence.slice(col);
92+
}
93+
log.writeln(evidence);
94+
hintCount ++;
95+
});
96+
}
97+
else { log.writeln( "Skipping empty file " + file); }
98+
99+
if (reporterOutput) {
100+
var destDir = path.dirname(reporterOutput);
101+
if (eachCount >= tempFilesLength) {
102+
grunt.util.hooker.unhook(process.stdout, 'write');
103+
}
104+
105+
if (!grunt.file.exists(destDir)) {
106+
grunt.file.mkdir(destDir);
107+
grunt.file.write(options.filePath, '');
108+
}
109+
110+
reporterOutput = grunt.template.process(reporterOutput);
111+
grunt.file.write(reporterOutput, output);
112+
}
113+
114+
eachCount++;
115+
116+
if ( hintCount > 0 ) return force;
117+
118+
log.ok(
119+
tempFilesLength + ' file' +
120+
(tempFilesLength === 1 ? '' : 's') + ' lint free.'
121+
);
122+
});
123+
});
124+
};

0 commit comments

Comments
 (0)