【问题标题】:Use PyLint to calculate Cyclomatic Complexity使用 PyLint 计算圈复杂度
【发布时间】:2019-07-22 18:38:20
【问题描述】:

我想使用 PyLint 计算圈复杂度。我需要一个 python 脚本来一次计算许多模块的复杂性。

我尝试过使用命令以及通过 python 程序。

这是我正在使用的命令:

pylint shortQuestion.py --load-plugins=pylint.extensions.mccabe

这是我在 python 中使用的代码:

import pylint.lint

pylint_opts = ['basics.py','--load-plugins=pylint.extensions.mccabe','--rcfile=~/.pylintrc']

pylint.lint.Run(pylint_opts)

这是我从命令和代码中得到的结果:

Using config file /var/root/.pylintrc
************* Module shortQuestion
W:  5, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:  6, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:  7, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:  8, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C:  1, 0: Module name "shortQuestion" doesn't conform to snake_case naming style (invalid-name)
C:  1, 0: Missing module docstring (missing-docstring)
C:  4, 0: Function name "isContained" doesn't conform to snake_case naming style (invalid-name)
C:  4, 0: Missing function docstring (missing-docstring)
R:  5, 1: Unnecessary "else" after "return" (no-else-return)
W:  4,16: Unused argument 'cls' (unused-argument)

----------------------------------------------------------------------
Your code has been rated at -15.00/10 (previous run: 10.00/10, -25.00)

这里是 -15.00/10 圈复杂度吗?如果是,我怎样才能以格式化的方式获得输出?因为我需要一次计算许多 python 模块的复杂性。如果没有,我该如何计算?

【问题讨论】:

    标签: python pylint cyclomatic-complexity


    【解决方案1】:

    您在输出末尾看到的分数是基于 pylint 的代码质量总体分数。如果您修复所有这些警告,分数将达到 10 分(满分 10 分)。

    如果您的圈复杂度太高,您应该看到的消息是:

    R:1: 'function1' 太复杂了。 McCabe 评分为 11(太复杂)

    另见docs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-27
      • 2018-02-22
      • 2011-10-04
      • 1970-01-01
      • 2010-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多