SILENT KILLERPanel

Current Path: > > opt > cloudlinux > venv > lib64 > python3.11 > site-packages > pylint > checkers


Operation   : Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
Software     : Apache
Server IP    : 162.0.232.56 | Your IP: 216.73.216.111
Domains      : 1034 Domain(s)
Permission   : [ 0755 ]

Files and Folders in: //opt/cloudlinux/venv/lib64/python3.11/site-packages/pylint/checkers

NameTypeSizeLast ModifiedActions
__pycache__ Directory - -
base Directory - -
classes Directory - -
refactoring Directory - -
__init__.py File 4367 bytes April 17 2025 13:10:59.
async.py File 3923 bytes April 17 2025 13:10:59.
bad_chained_comparison.py File 2228 bytes April 17 2025 13:10:59.
base_checker.py File 10931 bytes April 17 2025 13:10:59.
deprecated.py File 9661 bytes April 17 2025 13:10:59.
design_analysis.py File 22139 bytes April 17 2025 13:10:59.
dunder_methods.py File 3513 bytes April 17 2025 13:10:59.
ellipsis_checker.py File 2014 bytes April 17 2025 13:10:59.
exceptions.py File 26673 bytes April 17 2025 13:10:59.
format.py File 27558 bytes April 17 2025 13:10:59.
imports.py File 42302 bytes April 17 2025 13:10:59.
lambda_expressions.py File 3462 bytes April 17 2025 13:10:59.
logging.py File 16221 bytes April 17 2025 13:10:59.
mapreduce_checker.py File 1111 bytes April 17 2025 13:10:59.
method_args.py File 4790 bytes April 17 2025 13:10:59.
misc.py File 4987 bytes April 17 2025 13:10:59.
modified_iterating_checker.py File 7859 bytes April 17 2025 13:10:59.
nested_min_max.py File 3720 bytes April 17 2025 13:10:59.
newstyle.py File 4567 bytes April 17 2025 13:10:59.
non_ascii_names.py File 7146 bytes April 17 2025 13:10:59.
raw_metrics.py File 3900 bytes April 17 2025 13:10:59.
similar.py File 34091 bytes April 17 2025 13:10:59.
spelling.py File 16556 bytes April 17 2025 13:10:59.
stdlib.py File 32028 bytes April 17 2025 13:10:59.
strings.py File 41242 bytes April 17 2025 13:10:59.
threading_checker.py File 1941 bytes April 17 2025 13:10:59.
typecheck.py File 88917 bytes April 17 2025 13:10:59.
unicode.py File 18480 bytes April 17 2025 13:10:59.
unsupported_version.py File 2999 bytes April 17 2025 13:10:59.
utils.py File 79111 bytes April 17 2025 13:10:59.
variables.py File 129607 bytes April 17 2025 13:10:59.

Reading File: //opt/cloudlinux/venv/lib64/python3.11/site-packages/pylint/checkers/raw_metrics.py

# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt

from __future__ import annotations

import sys
import tokenize
from typing import TYPE_CHECKING, Any, cast

from pylint.checkers import BaseTokenChecker
from pylint.reporters.ureports.nodes import Paragraph, Section, Table, Text
from pylint.utils import LinterStats, diff_string

if sys.version_info >= (3, 8):
    from typing import Literal
else:
    from typing_extensions import Literal

if TYPE_CHECKING:
    from pylint.lint import PyLinter


def report_raw_stats(
    sect: Section,
    stats: LinterStats,
    old_stats: LinterStats | None,
) -> None:
    """Calculate percentage of code / doc / comment / empty."""
    total_lines = stats.code_type_count["total"]
    sect.insert(0, Paragraph([Text(f"{total_lines} lines have been analyzed\n")]))
    lines = ["type", "number", "%", "previous", "difference"]
    for node_type in ("code", "docstring", "comment", "empty"):
        node_type = cast(Literal["code", "docstring", "comment", "empty"], node_type)
        total = stats.code_type_count[node_type]
        percent = float(total * 100) / total_lines if total_lines else None
        old = old_stats.code_type_count[node_type] if old_stats else None
        diff_str = diff_string(old, total) if old else None
        lines += [
            node_type,
            str(total),
            f"{percent:.2f}" if percent is not None else "NC",
            str(old) if old else "NC",
            diff_str if diff_str else "NC",
        ]
    sect.append(Table(children=lines, cols=5, rheaders=1))


class RawMetricsChecker(BaseTokenChecker):
    """Checker that provides raw metrics instead of checking anything.

    Provides:
    * total number of lines
    * total number of code lines
    * total number of docstring lines
    * total number of comments lines
    * total number of empty lines
    """

    # configuration section name
    name = "metrics"
    # configuration options
    options = ()
    # messages
    msgs: Any = {}
    # reports
    reports = (("RP0701", "Raw metrics", report_raw_stats),)

    def open(self) -> None:
        """Init statistics."""
        self.linter.stats.reset_code_count()

    def process_tokens(self, tokens: list[tokenize.TokenInfo]) -> None:
        """Update stats."""
        i = 0
        tokens = list(tokens)
        while i < len(tokens):
            i, lines_number, line_type = get_type(tokens, i)
            self.linter.stats.code_type_count["total"] += lines_number
            self.linter.stats.code_type_count[line_type] += lines_number


JUNK = (tokenize.NL, tokenize.INDENT, tokenize.NEWLINE, tokenize.ENDMARKER)


def get_type(
    tokens: list[tokenize.TokenInfo], start_index: int
) -> tuple[int, int, Literal["code", "docstring", "comment", "empty"]]:
    """Return the line type : docstring, comment, code, empty."""
    i = start_index
    start = tokens[i][2]
    pos = start
    line_type = None
    while i < len(tokens) and tokens[i][2][0] == start[0]:
        tok_type = tokens[i][0]
        pos = tokens[i][3]
        if line_type is None:
            if tok_type == tokenize.STRING:
                line_type = "docstring"
            elif tok_type == tokenize.COMMENT:
                line_type = "comment"
            elif tok_type in JUNK:
                pass
            else:
                line_type = "code"
        i += 1
    if line_type is None:
        line_type = "empty"
    elif i < len(tokens) and tokens[i][0] == tokenize.NEWLINE:
        i += 1
    # Mypy fails to infer the literal of line_type
    return i, pos[0] - start[0] + 1, line_type  # type: ignore[return-value]


def register(linter: PyLinter) -> None:
    linter.register_checker(RawMetricsChecker(linter))

SILENT KILLER Tool