设置gulp HTML linter的选项/规则

时间:2017-08-27 21:30:15

标签: javascript gulp lint

如何设置gulp-htmllint的选项?

我想排除任何与缩进样式和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;
  }
}

2 个答案:

答案 0 :(得分:1)

以下是.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

我目前正在享受为多种环境整理构建链。要传递开发版,可以使用常规的非功能性HTML注释。对于prod构建,应该删除那些不必要的注释......这是如何相关的是我对所有环境使用相同的构建链并根据需要指定不同的选项文件 - 您可以传递要使用的选项文件和它将覆盖默认的.htmllintrc文件。

  

options.config

     

类型:字符串默认值:.htmllintrc

     

包含htmllint选项的配置文件。

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

答案 1 :(得分:0)

从未使用gulp但只是通过阅读我可以看到的文档,您可以定义UserDetailsService文件并在那里添加选项。

    @Test
    @WithUserDetails( "myUserNameOnDatabase")
    public void contextLoads() {
        try {
            mockMvc.perform(get("/stores")).andExpect(status().isOk()).andDo(print());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }