2017-08-27 61 views
0

如何設置gulp-htmllint的選項?爲gulp設置選項/規則HTML linter

我想排除任何有關縮進樣式和id或類樣式的規則。然而,它的文檔顯示那些有破折號的鍵,ex indent-style或id-class-style,但破折號破壞了代碼。我試圖將字符串作爲字符串來寫,但這似乎沒有什麼區別。

據我瞭解,這是什麼定義的任務,而這正是我試圖定義規則選項:

gulp.task('default', function() { 
return gulp.src('src/index.html') 
    .pipe(htmllint({ 
     indent-style: false, 
     id-class-style: false 
    }, htmllintReporter)); 
}); 

這是定義你將在終端看到的功能:

function htmllintReporter(filepath, issues) { 
if (issues.length > 0) { 
    issues.forEach(function (issue) { 
    gutil.log(gutil.colors.cyan('[gulp-htmllint] ') + 
    gutil.colors.white(filepath + ' [' + issue.line + ',' + 
    issue.column + ']: ') + gutil.colors.red('(' + issue.code + ') ' + 
    issue.msg)); 
    }); 
    process.exitCode = 1; 
    } 
} 

回答

0

從未使用過一口,但只是從閱讀文檔,我可以看到你可以定義一個.htmllintrc文件,並添加選項那裏。

{ 
    "indent-style": false, 
    "id-class-style": false 
} 
+0

如何定義的.htmllintrc文件?我可以在gulp-htmllint文件夾中找到.eslintrc文件,但仍然無法添加適當的選項。 –

+0

我會在你的項目的根目錄中定義它 – ricardoNava

0

下面是一個.htmllintrc文件的內容的一個示例:

{ 
    "attr-name-style": "dash", 
    "attr-quote-style": "double", 
    "id-class-style": "dash", 
    "indent-style": "spaces", 
    "indent-width": 2, 
    "line-end-style": "lf", 
    "attr-req-value": false, 
    "html-req-lang": true, 
    "title-max-length": 120, 
    "img-req-src": false, 
    "tag-bans": ["!style"] 
} 

,從字面上去在相同的目錄中gulpfile.js或Gruntfile.js--相同的目錄中的package.json。 (鑑於這些文件的超常見放置......)將上述選項放入純文本文件中並將其命名爲「.htmllintrc」。沒有文件擴展名,它實際上被命名爲「.htmllintrc」。

被盜來源:https://github.com/thisissoon/angular-start/blob/master/.htmllintrc

我目前享受組建一個buildchain多個環境。要傳遞開發版本,可以使用常規的非功能html註釋。對於prod build,這些不必要的註釋應該被刪除......這與如何相關的是,我對所有環境使用相同的構建鏈,並根據需要指定不同的選項文件 - 您可以傳遞要使用的選項文件和它將覆蓋默認的.htmllintrc文件。

options.config

類型:String默認值:.htmllintrc含htmllint選項

配置文件。

https://github.com/yvanavermaet/gulp-htmllint#optionsconfig