Files
inliver233 a1ada96cc3 Lint clean: adopt the PR's type/style gate, apply it to the current tree, and drop its path filter
PR #3 proposed adding mypy and flake8 to CI, with configurations for both. The idea is right and the
configurations are kept. Three things about the PR itself needed correcting, and all three were found
by running the gate rather than reading the diff:

  1. It was written against an older tree. Its own edits reference code that no longer exists there
     (`unknown, positions, warnings = ...`, a `struct` import at line 857 that is used 600 lines
     later), so merging it as-is would have removed a live import. The fixes were re-derived against
     the current tree instead, and the PR is superseded.
  2. It added a `paths:` filter to the workflow, watching only `*.py` plus the two lint configs. That
     would stop `check_refs.py` and `check_routing.py` -- documentation gates -- from running on a
     documentation-only commit, which is exactly the change they exist to catch. The workflow keeps
     the PR's `actions/*@v7` bump and gains no filter; the reason is written next to the trigger.
  3. `pip install --upgrade pip pytest` was dropped to just the packages, because upgrading pip in CI
     is not a goal and can fail for reasons unrelated to this repository.

What the gate found on the current tree, and what was done about it -- 70 flake8 findings and 3 mypy
errors, none of which were cosmetic-only:

  F401 (23)  unused imports, removed. These were safe to delete because the import statement itself
             cannot have a side effect that matters here.
  F841 (12)  unused bindings, handled three ways rather than one. Dead code was deleted
             (`mt_mcp_probe.print_waiting_help`'s `host`, `repack.py`'s `signer_jar`); a computed
             value that was then forgotten was **wired up** (`rasc_build.py` now names the linker
             target in its build-failure hint instead of discarding it); and a binding that is
             intentional kept its place with `# noqa: F841` and the reason -- `java2c_probe` reads
             dex header fields one by one against the format spec, and deleting three of them to
             please a linter would have made the parser stop lining up with the format it implements.
  E741 (14)  the ambiguous loop name `l`, renamed with an AST pass that resolves each binding to its
             own scope. A regex rename would have been wrong: several scopes bind their own `l`.
             That pass had a defect of its own -- it treated a comprehension target as living in the
             comprehension scope while leaving references to it in the enclosing one -- which
             produced seven `undefined name 'l'`. Found by running flake8, fixed, and the counting
             bug is documented in `check_routing.py`, whose own `tables()` had the same class of
             error in the other direction.
  style      continuation indents, blank lines between top-level definitions, and lines over length.
             The line limit is 160, not 120, and the number is a **measurement**: this repository's
             secret-scanner rule table holds raw regex source of 148 and 156 characters, which cannot
             be split without changing the pattern.
  mypy (3)   two missing annotations on module-level containers, and one optional-dependency rebind
             (`dexutil = None` after `except ImportError`) that is the repository's own idiom and
             now says so with a `type: ignore[assignment]` and the reason. No code was reordered to
             satisfy the checker.

Verified on a venv containing only `mypy` and `flake8` -- the poorest environment the configuration
must work in, and the one CI uses: **flake8 reports 0, mypy reports "Success: no issues found in 55
source files"**. Behaviour is unchanged: 625 passed / 163 skipped / 25 xfailed, the same five gates
green (check_repo 0 problem, check_refs 0 dangling, check_routing coherent, check_budget 0 failure,
check_commands 0 drift), and every key script still prints help.

  .flake8        new, with the line-length and complexity numbers and their reasons
  mypy.ini       new; optional imports declared, nothing excluded from the analysis
  ci.yml         `actions/*@v7`; new `lint` job on one interpreter; no path filter
  30 files       the findings above
2026-09-22 19:56:34 +08:00

35 lines
1.8 KiB
INI

# flake8 configuration for this repository.
#
# Three settings, each with the measurement behind it rather than a preference.
#
# max-line-length = 160
# 120 was tried first and two lines still exceeded it: the secret-scanner rule table in
# scan_leaks.py holds raw regex source of 148 and 156 characters. Splitting a regex inside a raw
# string either changes the pattern or forces concatenation that is harder to read than the long
# line, so the limit is set from what a real string in this repository needs (156) with a little
# room, and a line over 160 is a genuine defect rather than a style disagreement.
#
# max-complexity is not set, and C901 is excluded below with the measurement: this repository's
# parsers and dispatchers reach 21-41 (check_commands.command_findings is 41, a flat if/elif chain
# over finding kinds). Setting a threshold above the maximum would be a number chosen to pass rather
# than a standard; splitting them into one function per case would move the shape of the format away
# from the code that reads it, and looking like the specification is this repository's argument.
# The numbers are recorded here so a future pass can decide to refactor with them in hand.
#
# extend-ignore:
# C901 see above -- reported here as a measurement, not enforced
# E203 slice whitespace (`data[start : end]`); flake8 and every autoformatter disagree, and the
# repository has no autoformatter
#
# Run from the repository root:
# flake8 *.py skills/apk-reverse/scripts/*.py
#
# Enforced in CI: the `lint` job in .github/workflows/ci.yml runs this exact command alongside mypy,
# on a bare interpreter, so the configuration is exercised in the poorest environment it must keep
# working in.
[flake8]
max-line-length = 160
extend-ignore = C901,E203
exclude = .git,__pycache__,tools,build,dist