我是Grunt的新手-csslint插件,运行并完成cssLint任务后,有很多我无法遵循的错误和警告。那么如何配置任务只是打印出错误,而不是警告?

最佳答案

如果使用grunt-contrib-csslint,则可以在.csslintrc文件中指定选项。

从grunt-contrib-csslint自述文件中:



假设您具有这样的结构:

├── .csslintrc
├── Gruntfile.js
├── css
│   └── foo.css
├── node_modules
└── package.json

.csslintrc
{ "ignore": [ "adjoining-classes", "box-model", "box-sizing", "bulletproof-font-face", "compatible-vendor-prefixes", "display-property-grouping", "duplicate-background-images", "duplicate-properties", "empty-rules", "fallback-colors", "floats", "font-faces", "font-sizes", "gradients", "ids", "import", "import-ie-limit", "important", "known-properties", "non-link-hover", "order-alphabetical", "outline-none", "overqualified-elements", "qualified-headings", "regex-selectors", "rules-count", "selector-max", "selector-max-approaching", "selector-newline", "shorthand", "star-property-hack", "text-indent", "underscore-property-hack", "unique-headings", "universal-selector", "unqualified-attributes", "vendor-prefix", "zero-units" ]}
引用:https://github.com/CSSLint/csslint/wiki/Command-line-interface

Gruntfile

module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    csslint: {
      strict: {
        src: ['css/*.css']
      },
      lax: {
        options: {
          csslintrc: '.csslintrc'
        },
        src: ['css/*.css']
      }
    }
  });

  grunt.loadNpmTasks('grunt-contrib-csslint');

  grunt.registerTask('default', ['csslint:lax']);
};

然后grunt将仅报告错误,而grunt csslint:strict将报告警告和错误。

09-17 09:00