|
| 1 | +gulp-htmlhint-inline |
| 2 | +================ |
| 3 | + |
| 4 | +## Usage |
| 5 | + |
| 6 | +First, install `gulp-htmlhint-inline` as a development dependency: |
| 7 | + |
| 8 | +```shell |
| 9 | +npm install --save-dev gulp-htmlhint-inline |
| 10 | +``` |
| 11 | + |
| 12 | +Then, add it to your `gulpfile.js`: |
| 13 | + |
| 14 | +```javascript |
| 15 | +var gulp = require('gulp'), |
| 16 | + htmlhint_inline = require('gulp-htmlhint-inline'); |
| 17 | + |
| 18 | +gulp.task('htmlhint', function () { |
| 19 | + var options = { |
| 20 | + htmlhintrc: './.htmlhintrc', |
| 21 | + ignores: { |
| 22 | + '<?php': '?>' |
| 23 | + }, |
| 24 | + patterns: [ |
| 25 | + { |
| 26 | + match: /hoge/g, |
| 27 | + replacement: 'fuga' |
| 28 | + } |
| 29 | + ] |
| 30 | + }; |
| 31 | + |
| 32 | + gulp.src('test/*.phtml') |
| 33 | + .pipe(htmlhint_inline(options)) |
| 34 | + .pipe(htmlhint_inline.reporter()) |
| 35 | + .pipe(htmlhint_inline.reporter('fail')); |
| 36 | +}); |
| 37 | +``` |
| 38 | + |
| 39 | +## Options |
| 40 | + |
| 41 | +#### htmlhintrc |
| 42 | +Type: String Default value: null |
| 43 | + |
| 44 | +```htmlhintrc``` file must be a valid JSON. |
| 45 | +If you specify this file, options that have been defined in it will be used in the global. |
| 46 | +If there is specified in the task options, the options in this file will be overwritten. |
| 47 | + |
| 48 | +```json |
| 49 | +{ |
| 50 | + "tagname-lowercase": true |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +#### ignores |
| 55 | +Type: Object Default: {} |
| 56 | + |
| 57 | +Remove program tag pairs. |
| 58 | + |
| 59 | +#### patterns |
| 60 | +Type: Array Default: [] |
| 61 | + |
| 62 | +Enable the replacement by the pattern |
| 63 | + |
| 64 | +##### patterns.match |
| 65 | + |
| 66 | +Type: RegExp|String |
| 67 | + |
| 68 | +Indicates the matching expression. |
| 69 | + |
| 70 | +##### patterns.replacement |
| 71 | + |
| 72 | +Type: String | Function |
| 73 | + |
| 74 | +#### reporter |
| 75 | + |
| 76 | +##### Default Reporter |
| 77 | + |
| 78 | +```js |
| 79 | +var gulp = require('gulp'), |
| 80 | + htmlhint_inline = require('gulp-htmlhint-inline'); |
| 81 | + |
| 82 | +gulp.task('htmlhint', function () { |
| 83 | + var options = { |
| 84 | + htmlhintrc: './.htmlhintrc', |
| 85 | + ignores: { |
| 86 | + '<?php': '?>' |
| 87 | + } |
| 88 | + }; |
| 89 | + |
| 90 | + gulp.src('test/*.phtml') |
| 91 | + .pipe(htmlhint_inline(options)) |
| 92 | + .pipe(htmlhint_inline.reporter()); |
| 93 | +}); |
| 94 | +``` |
| 95 | + |
| 96 | +##### Fail Reporter |
| 97 | + |
| 98 | +In order to end the task when your task happened error of HTMLHint, please use this reporter. |
| 99 | + |
| 100 | +```js |
| 101 | +var gulp = require('gulp'), |
| 102 | + htmlhint_inline = require('gulp-htmlhint-inline'); |
| 103 | + |
| 104 | +gulp.task('htmlhint', function () { |
| 105 | + var options = { |
| 106 | + htmlhintrc: './.htmlhintrc', |
| 107 | + ignores: { |
| 108 | + '<?php': '?>' |
| 109 | + } |
| 110 | + }; |
| 111 | + |
| 112 | + gulp.src('test/*.phtml') |
| 113 | + .pipe(htmlhint_inline(options)) |
| 114 | + .pipe(htmlhint_inline.reporter('fail')); |
| 115 | +}); |
| 116 | +``` |
| 117 | + |
| 118 | +##### Custom Reporter |
| 119 | + |
| 120 | +You can also use the custom reporter that you have created. |
| 121 | + |
| 122 | +```js |
| 123 | + |
| 124 | +var gulp = require('gulp'), |
| 125 | + htmlhint_inline = require('gulp-htmlhint-inline'); |
| 126 | + |
| 127 | +gulp.task('htmlhint', function () { |
| 128 | + var options = { |
| 129 | + htmlhintrc: './.htmlhintrc', |
| 130 | + ignores: { |
| 131 | + '<?php': '?>' |
| 132 | + } |
| 133 | + }; |
| 134 | + |
| 135 | + var cutomReporter = function (file) { |
| 136 | + if (!file.htmlhint_inline.success) { |
| 137 | + console.log('custom reporter: htmlhint-inline fail in '+ file.path); |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + return gulp.src('test/*.phtml') |
| 142 | + .pipe(htmlhint_inline(options)) |
| 143 | + .pipe(htmlhint_inline.reporter()) |
| 144 | + .pipe(htmlhint_inline.reporter(cutomReporter)); |
| 145 | +}); |
| 146 | + |
| 147 | +``` |
| 148 | + |
| 149 | +## License |
| 150 | + |
| 151 | +[MIT License](http://en.wikipedia.org/wiki/MIT_License) |
| 152 | + |
| 153 | +[npm-url]: https://npmjs.org/package/gulp-htmlhint-inline |
| 154 | +[npm-image]: https://badge.fury.io/js/gulp-htmlhint-inline.png |
0 commit comments