Skip to main content

PR 的廉价 lint 解决方案。

项目描述

https://travis-ci.org/theochem/cardboardlint.svg?branch=master https://anaconda.org/theochem/cardboardlint/badges/version.svg https://codecov.io/gh/theochem/cardboardlint/branch/master/graph/badge.svg https://img.shields.io/pypi/v/cardboardlint.svg https://img.shields.io/pypi/pyversions/cardboardlint.svg https://img.shields.io/github/release/theochem/cardboardlint.svg

介绍

Cardboardlint 是一种用于拉取请求的廉价 lint 解决方案。

它是一种非托管和可定制的工具,类似于商业服务,例如:

对于更高级的分析,可以使用隐蔽扫描。( https://scan.coverity.com/ )

Cardboardlint 包装了一系列 linter,旨在用于 Git 存储库中的项目。Cardboardlint 能够仅报告与您的开发分支中已更改的行相关的消息,与另一个提交相比,例如主分支的 HEAD。这是为了让项目贡献者的生活更轻松:在他们的拉取请求中,他们只会看到与他们接触的代码相关的 linting 问题。对于某些 linters,cardboardlint 还支持自动修复 linting 问题,可选择限制在开发分支中已更改的代码。

一些使用 Cardboardlint 的示例项目:

用法

  • 安装 cardboardlint,它需要 python 3.6 或 3.7 和 PyYaml。您必须安装 Python 3,PyYaml 将按照以下说明自动为您安装。

    # Install cardboardlint with pip. Any of the following that works for you
    # is fine:
    pip install cardboardlint
    pip install cardboardlint --user
    python3 -m pip install cardboardlint
    python3 -m pip install cardboardlint --user
    # Or install cardboardlint with conda:
    conda install theochem::cardboardlint
  • .cardboardlint.yml添加到源代码树的根目录。它至少应该包含一个带有linter 列表的linter部分,例如

    linters:
    - pylint:
        pylintrc: tools/your_custom_pylintrc
    - cppcheck:
    - import:
    ...

    从源代码中很容易推导出支持的 linter 列表。只需查看cardboardlint/linter_*.py文件即可。这些文件中的每一个都有一个带有一些解释的模块文档字符串和一个带有可用配置变量的 DEFAULT_CONFIG 字典。

    您可以使用不同的配置设置多次重复任何 linter。这可能很有用,例如,当单元测试的 lint 必须与源代码的其余部分不同时。这是一个简单的示例,其中单元测试具有不同的 pylint 配置:

    pre_filefilter: [<s>'+</s> <s>tools/demo/*.py'</s>, <s>'-</s> <s>tools/*'</s>, <s>'+</s> <s>*'</s>]
    
    linters:
    - pylint:
        pylintrc: tools/pylintrc
        filefilter: [<s>'-</s> <s>test_*.py'</s>, <s>'+</s> <s>*.py'</s>]
        exclude:
    - pylint:
        pylintrc: tools/pylintrc_tests
        filefilter: [<s>'+</s> <s>test_*.py'</s>]
    - import:
    ...

    当 cardboardlint 启动时,它会列出当前存储库中 git 不会忽略的文件列表。这些文件名首先由所谓的pre_filefilter过滤。然后使用特定于 linter的文件过滤器对通过pre_filefilter的文件进行测试,最终得到要由给定 linter 检查的文件列表。

    pre_filefilterfilefilter包含一个规则列表,用于测试是否应考虑对文件进行 linting。每个规则都以可能的结果开头,+(包含)或-(排除),然后是一个全局模式。目前,该模式忽略了目录分隔符的存在,并将完整路径视为测试模式的单个字符串,使用 Python 的fnmatch内置模块。规则按顺序进行测试,当模式匹配时,会做出相应的决定(包括和排除),而不考虑后续规则。当没有模式匹配时,文件被排除。

    以下技巧可能有用:

    • 如果您想包含不匹配任何模式的文件,请添加 '+ *'作为最后一个模式,这通常对pre_filefilter有用。

    • 如果您想在所有目录中包含所有 python 文件,请使用 '+ *.py'。通配符还将匹配包含 Python 文件的目录。例如,它将匹配路径a/b.py中的a/b

  • 安装您打算运行的 linter(在本地或在您的 CI 环境中)。这些依赖项不会自动安装,因为您可能不想使用所有这些依赖项。

    所有支持的 linter 的 Conda 包都可以在 conda-forge 的主要 conda 通道中找到(https://anaconda.org/conda-forge)。我们为 conda-forge 添加了用于cppcheckcpplint的包。所有其他 linter 都已经可用。要安装所有这些,我们可以推荐以下命令:

    # Add conda-forga channel with lower priority as the default channels. This
    # prevents your conda env from being flooded by conda-forga packages.
    conda config --append channels conda-forge
    # Install all linters for which cardboardlint has wrappers:
    conda install pycodestyle pydocstyle cppcheck cpplint yamllint flake8 \
                  doxygen pylint autopep8, yapf, black
  • 运行 cardboardlinter,可以通过以下几种方式完成:

    # runs all linters and use multiple cpus
    cardboardlinter -n auto
    # runs all linters and only shows messages for changes relative to master
    cardboardlinter -r master
    # run only static linters
    cardboardlinter -f static
    # run only dynamic linters, which require in-place build
    cardboardlinter -f dynamic
    
    # run fixers, which automaticaly solve trivial problems
    cardboardlinter -F
    # run fixers, which automaticaly solve trivial problems, only on those
    # lines that have changed w.r.t. the master branch.
    cardboardlinter -F -r master
  • CI中的用法:

    • Travis-CI(在.travis.yml中)。这只会报告 PR 中已更改的行的消息。

      install:
      # Install the latest cardboardlinter
      - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
          pip install --upgrade cardboardlint
        fi
      
      script:
      # Run the cardboardlinter, in case of pull requests
      - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
          cardboardlinter --refspec $TRAVIS_BRANCH -n auto;
        fi
    • 还可以使用 Roberto 来驱动整个构建+测试+打包工作流程,其中包括使用 Cardboardlint 进行 linting。见https://theochem.github.io/roberto/

更改日志

  • 版本 1.3.1 2020 年 8 月 26 日

    • 改善与罗伯托的互动。

    • 隐藏重复的消息。

  • 1.3.0 版 2019 年 4 月 14 日

    • 更详细的输出。始终显示用于 linting 的选定文件列表。

    • 修复 Python 命令行脚本的默认位置是 ./bin,而不是 ./scripts。

    • 打印短绒的挂壁时间。

    • 很少清理。

  • 1.2.0 版 2019 年 4 月 12 日

    • 添加了对修复程序的支持。以下衬里也可以解决问题:header、whitespace、autopep8、yapf、black。后三个是新的。

    • 删除了一些 Python-2 兼容性代码。

    • 用 pytest 替换鼻子测试。

    • 在 README 中添加更多上下文。

    • 添加 RST 短绒。

  • 1.1.0 版 2019 年 4 月 3 日

    • 添加要使用的处理器数量的选项。

  • 1.0.1 版 2019 年 3 月 30 日

    • 为 cpplint 添加缺少的配置选项。

  • 1.0.0 版 2019 年 3 月 27 日

    第一次发布,主要是为了预测 API 的重大变化,这将导致主要版本的增加。通过发布,我们可以优雅地处理 API 中的这种变化。显着特点包括:

    • 支持以下 linter:cppcheck、ccplint、doxygen、flake8、header(内部)、import(内部)、namespace(内部)、pycodestyle、pydocstyle、pylint、whitespace(内部)、yamllint

    • 对于所有受支持的 linter,输出可以限制为在两次 git 提交之间发生更改的文件和(这些文件中的行)。在拉取请求中,这将只显示与 PR 中涉及的代码相关的错误。这是为了让贡献者的生活更轻松,即不用担心他们没有接触过的代码中的 linting 问题。

    • 灵活的文件过滤,本质上是rsync文件过滤规则的简化版。

    • 所有棉绒的一致和彩色输出,使处理棉绒问题变得容易。

下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

cardboardlint-1.3.1.tar.gz (28.2 kB 查看哈希

已上传 source