【问题标题】:How to generate a checkstyle.xml for Jenkins with stylelint?如何使用 stylelint 为 Jenkins 生成 checkstyle.xml?
【发布时间】:2018-10-14 15:24:54
【问题描述】:

我想知道如何使用 stylelint 为 Jenkins 生成 checkstyle.xml。在网上搜索并遗憾地找到了stylelint-checkstyle-formatter,但只有以下“说明”:

只需阅读有关使用格式化程序的 stylelint 文档并按照这些说明进行操作。

再次遗憾的是,我在documentation 中什么也没找到...

【问题讨论】:

    标签: css jenkins sass checkstyle stylelint


    【解决方案1】:

    我终于找到了一种方法(使用 gulp)并希望它在 StackOverflow 上分享。

    首先安装以下依赖项:

    yarn add -D stylelint gulp-stylelint stylelint-checkstyle-formatter stylelint-scss stylelint-config-recommended-scss
    

    然后使用下面的 gulp 任务:

    gulp.task("scss-lint", function() {
        const gulpStylelint = require('gulp-stylelint');
        const stylelintCheckstyleFormatter = require('stylelint-checkstyle-formatter');
    
        return gulp
            .src('src/**/*.scss')
            .pipe(gulpStylelint({
                reportOutputDir: 'build/reports/scss-checkstyle',
                reporters: [
                    {formatter: 'verbose', console: true},
                    {formatter: stylelintCheckstyleFormatter, save: 'checkstyle.xml'},
                ],
            }));
    });
    

    最后是我的.stylelint

    {
        "extends": "stylelint-config-recommended-scss",
        "defaultSeverity": "warning",
        "formatter": "stylelint-checkstyle-formatter",
        "plugins": [
            "stylelint-scss"
        ],
            "rules": {
            "indentation": 4,
                "color-hex-length": null,
                "shorthand-property-no-redundant-values": null,
                "no-missing-end-of-source-newline": null,
                "declaration-empty-line-before": null,
                "at-rule-empty-line-before": null,
                "selector-type-no-unknown": [
                true,
                {
                    "ignore": ["custom-elements"],
                    "ignoreTypes": ["tooltip"]
                }
            ]
        }
    }
    

    【讨论】:

      【解决方案2】:

      我通过 CLI 安装了 stylelint-checkstyle-formatter 插件,然后使用 --custom-formatter 选项将其传递给 stylelint:

      npm install stylelint-checkstyle-formatter --save-dev
      stylelint --custom-formatter ./node_modules/stylelint-checkstyle-formatter ....
      

      【讨论】:

        猜你喜欢
        • 2016-08-03
        • 1970-01-01
        • 2014-02-21
        • 2015-10-22
        • 2020-05-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-02
        相关资源
        最近更新 更多