pre-commit-bigfix 2.2.0__py3-none-any.whl → 2.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pre_commit_bigfix/__init__.py +1 -1
- pre_commit_bigfix/bes_relevance_lint.py +214 -43
- pre_commit_bigfix/run_all.py +2 -1
- {pre_commit_bigfix-2.2.0.dist-info → pre_commit_bigfix-2.3.0.dist-info}/METADATA +31 -7
- {pre_commit_bigfix-2.2.0.dist-info → pre_commit_bigfix-2.3.0.dist-info}/RECORD +9 -9
- {pre_commit_bigfix-2.2.0.dist-info → pre_commit_bigfix-2.3.0.dist-info}/WHEEL +0 -0
- {pre_commit_bigfix-2.2.0.dist-info → pre_commit_bigfix-2.3.0.dist-info}/entry_points.txt +0 -0
- {pre_commit_bigfix-2.2.0.dist-info → pre_commit_bigfix-2.3.0.dist-info}/licenses/LICENSE +0 -0
- {pre_commit_bigfix-2.2.0.dist-info → pre_commit_bigfix-2.3.0.dist-info}/top_level.txt +0 -0
pre_commit_bigfix/__init__.py
CHANGED
|
@@ -44,13 +44,15 @@ Checks:
|
|
|
44
44
|
E614 a BES file that is not well-formed XML, so nothing in it was linted.
|
|
45
45
|
Off by default -- bes-schema-validate owns file validity -- and
|
|
46
46
|
switched back on with --enable E614
|
|
47
|
+
E615 an --auto-fix was not written, because it would turn a BES.xsd-valid
|
|
48
|
+
file invalid; fix by hand, or --disable E615 to write it anyway
|
|
47
49
|
W600 a name no inspector dump defines. A warning rather than an error
|
|
48
50
|
because a repo running a newer client than the analyzer's snapshot
|
|
49
51
|
legitimately uses names it has never heard of
|
|
50
52
|
W601 a property written singular over an object that may be plural.
|
|
51
|
-
Disabled by default
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
Disabled by default: it fires ~6 times per file across real content,
|
|
54
|
+
which drowns everything else. Enable it deliberately with
|
|
55
|
+
--enable W601
|
|
54
56
|
W602 a singular spelling mid-chain -- under a `whose` filter, or where a
|
|
55
57
|
plural is built from it -- where the plural reads safer
|
|
56
58
|
W603 two version-looking strings compared as strings, not as versions
|
|
@@ -84,38 +86,62 @@ anywhere in it, the same marker the sibling hooks honor. There is no per-rule
|
|
|
84
86
|
marker: --disable takes the code repo-wide, and a single file that legitimately
|
|
85
87
|
needs relevance this complex is what --max-score is for.
|
|
86
88
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
finding as `suggested fix:
|
|
91
|
-
|
|
89
|
+
Where the analyzer can work out a safe rewrite of a statement (the singular
|
|
90
|
+
spellings behind W602, and the `unique value of` / singular-aggregate rewrites
|
|
91
|
+
behind E611), the fixed statement is printed once under that statement's first
|
|
92
|
+
finding as `suggested fix: ...`. Everything else needs a human to decide what
|
|
93
|
+
the relevance was meant to say.
|
|
94
|
+
|
|
95
|
+
--auto-fix=yes writes those fixes in place. It defaults to no in every mode,
|
|
96
|
+
files given or auto-discovering -- unlike the sibling hooks, because a
|
|
97
|
+
relevance fix changes what a statement says, not just how it is formatted, so
|
|
98
|
+
a repo opts in with `args: [--auto-fix=yes]`. The analyzer plans each file
|
|
99
|
+
(plan_fix): every fix is written as the smallest edit that makes it, and
|
|
100
|
+
one it cannot prove safe -- one that would add a finding, or one under a rule
|
|
101
|
+
--disable turned off -- is refused, site by site, so a file can come back
|
|
102
|
+
partly fixed. The plan is written (write_fix) unless it would turn a
|
|
103
|
+
BES.xsd-valid file invalid, which is reported as E615 with the original
|
|
104
|
+
findings; a file no schema applies to (.rel, .bsr, ...) is written unchecked.
|
|
105
|
+
Each written edit prints `path:line: [CODE] auto-fixed: old -> new (rule)`; a
|
|
106
|
+
fix not written keeps its `suggested fix:` line, with `(not auto-fixed:
|
|
107
|
+
<reason>)`. An auto-fixed file fails the hook so the change is reviewed and
|
|
108
|
+
re-staged.
|
|
92
109
|
|
|
93
110
|
Usage:
|
|
94
|
-
bes-relevance-lint [--strict] [--
|
|
111
|
+
bes-relevance-lint [--strict] [--auto-fix=yes|no] [--disable E604]
|
|
112
|
+
[--enable W601] [FILES...]
|
|
95
113
|
|
|
96
114
|
Exit status:
|
|
97
|
-
0 no E-code findings (and, without --strict, no
|
|
98
|
-
interpreter is older than 3.11, where the
|
|
99
|
-
and the hook skips with a notice rather
|
|
100
|
-
no way to go green
|
|
101
|
-
1 an E-code fired, a
|
|
102
|
-
missing on a 3.11+ interpreter, where it
|
|
115
|
+
0 no E-code findings and nothing auto-fixed (and, without --strict, no
|
|
116
|
+
warnings either), or the interpreter is older than 3.11, where the
|
|
117
|
+
analyzer cannot be installed and the hook skips with a notice rather
|
|
118
|
+
than failing a build that has no way to go green
|
|
119
|
+
1 an E-code fired, a file was auto-fixed, a warning fired under
|
|
120
|
+
--strict, or the analyzer is missing on a 3.11+ interpreter, where it
|
|
121
|
+
should have been installed
|
|
103
122
|
"""
|
|
104
123
|
|
|
105
124
|
import argparse
|
|
125
|
+
import itertools
|
|
126
|
+
import re
|
|
106
127
|
import sys
|
|
107
128
|
|
|
129
|
+
from pre_commit_bigfix import bes_common
|
|
130
|
+
|
|
108
131
|
try:
|
|
109
132
|
from bigfix_relevance_analyzer import (
|
|
110
133
|
LintConfig,
|
|
111
134
|
Severity,
|
|
112
135
|
lint_directory,
|
|
113
136
|
lint_paths,
|
|
137
|
+
plan_fix,
|
|
138
|
+
write_fix,
|
|
114
139
|
)
|
|
115
140
|
|
|
116
141
|
IMPORT_ERROR = None
|
|
117
142
|
except ImportError as exc: # pragma: no cover - exercised only on an old Python
|
|
118
143
|
LintConfig = lint_directory = lint_paths = Severity = None
|
|
144
|
+
plan_fix = write_fix = None
|
|
119
145
|
IMPORT_ERROR = exc
|
|
120
146
|
|
|
121
147
|
__all__ = ["main"]
|
|
@@ -155,7 +181,12 @@ CODES = {
|
|
|
155
181
|
"unterminated-code-fence": "W607",
|
|
156
182
|
}
|
|
157
183
|
|
|
158
|
-
|
|
184
|
+
# The hook's own code, not an analyzer rule: an --auto-fix the analyzer
|
|
185
|
+
# planned that was not written because it would turn a BES.xsd-valid file
|
|
186
|
+
# invalid -- the guard every rewriting sibling hook has under its own code.
|
|
187
|
+
GUARD_CODE = "E615"
|
|
188
|
+
|
|
189
|
+
KNOWN_CODES = frozenset(CODES.values()) | {GUARD_CODE}
|
|
159
190
|
|
|
160
191
|
# The reverse direction, for --disable/--enable: a repo names an E-code, the
|
|
161
192
|
# analyzer's LintConfig wants its own.
|
|
@@ -163,8 +194,12 @@ ANALYZER_CODES = {code: name for name, code in CODES.items()}
|
|
|
163
194
|
|
|
164
195
|
# Off unless a repo names them in --enable. E614 is a BES file that is not
|
|
165
196
|
# well-formed XML: bes-schema-validate already reports that, and this hook must
|
|
166
|
-
# not duplicate its findings, so unparsable XML stays skipped here.
|
|
167
|
-
|
|
197
|
+
# not duplicate its findings, so unparsable XML stays skipped here. W601 fires
|
|
198
|
+
# ~6 times per file across real content, which drowns everything else. It is
|
|
199
|
+
# off here rather than as `args: [--disable, W601]` in .pre-commit-hooks.yaml
|
|
200
|
+
# because a repo's `args:` replaces the manifest's: one writing
|
|
201
|
+
# `args: [--auto-fix=yes]` would have silently switched it back on.
|
|
202
|
+
DEFAULT_DISABLED = frozenset({"E614", "W601"})
|
|
168
203
|
|
|
169
204
|
|
|
170
205
|
MIN_ANALYZER_PYTHON = (3, 11)
|
|
@@ -209,13 +244,14 @@ def _split_codes(raw):
|
|
|
209
244
|
def _severities(disabled, enabled):
|
|
210
245
|
"""Per-code overrides for LintConfig, in the analyzer's own vocabulary."""
|
|
211
246
|
severities = {}
|
|
212
|
-
|
|
247
|
+
# GUARD_CODE is the hook's own, with no analyzer rule behind it
|
|
248
|
+
for code in disabled & set(ANALYZER_CODES):
|
|
213
249
|
severities[ANALYZER_CODES[code]] = Severity.IGNORE
|
|
214
|
-
for code in enabled:
|
|
250
|
+
for code in enabled & set(ANALYZER_CODES):
|
|
215
251
|
# Restore the analyzer's own default rather than forcing a severity:
|
|
216
|
-
# --enable exists to undo
|
|
217
|
-
#
|
|
218
|
-
#
|
|
252
|
+
# --enable exists to undo one of this hook's DEFAULT_DISABLED, not to
|
|
253
|
+
# promote a warning into an error. --strict is what does that, for
|
|
254
|
+
# every warning at once.
|
|
219
255
|
severities.pop(ANALYZER_CODES[code], None)
|
|
220
256
|
return severities
|
|
221
257
|
|
|
@@ -238,11 +274,36 @@ def _opted_out(path):
|
|
|
238
274
|
return False
|
|
239
275
|
|
|
240
276
|
|
|
241
|
-
def
|
|
277
|
+
def _drop_opted_out(findings):
|
|
278
|
+
"""`findings` without those from files carrying the skip marker.
|
|
279
|
+
|
|
280
|
+
For files the analyzer found itself -- auto-discovering, or walking a
|
|
281
|
+
folder named on the command line -- so the marker holds for them too.
|
|
282
|
+
Each file is read once, however many findings it has.
|
|
283
|
+
"""
|
|
284
|
+
opted_out = {}
|
|
285
|
+
kept = []
|
|
286
|
+
for finding in findings:
|
|
287
|
+
if finding.path not in opted_out:
|
|
288
|
+
opted_out[finding.path] = _opted_out(finding.path)
|
|
289
|
+
if not opted_out[finding.path]:
|
|
290
|
+
kept.append(finding)
|
|
291
|
+
return kept
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def _fix_key(path, line, original):
|
|
295
|
+
"""What ties a statement's findings to its fix: (path, site line, text)."""
|
|
296
|
+
return (str(path), line, original)
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def _report(findings, not_fixed=None):
|
|
242
300
|
"""Print each finding in this repo's format.
|
|
243
301
|
|
|
244
|
-
|
|
302
|
+
`not_fixed` maps a statement's _fix_key to why --auto-fix did not write
|
|
303
|
+
its fix, which is added to its `suggested fix:` line. Returns (errors,
|
|
304
|
+
warnings).
|
|
245
305
|
"""
|
|
306
|
+
not_fixed = not_fixed or {}
|
|
246
307
|
errors = warnings = 0
|
|
247
308
|
# Every fixable finding from one statement carries the same whole-statement
|
|
248
309
|
# rewrite, so print it once per statement rather than once per finding.
|
|
@@ -255,10 +316,12 @@ def _report(findings):
|
|
|
255
316
|
fix = getattr(finding, "autofix", None)
|
|
256
317
|
if fix is not None:
|
|
257
318
|
site_line = finding.site.line if finding.site is not None else None
|
|
258
|
-
key = (
|
|
319
|
+
key = _fix_key(finding.path, site_line, fix.original)
|
|
259
320
|
if key not in suggested:
|
|
260
321
|
suggested.add(key)
|
|
261
|
-
|
|
322
|
+
reason = not_fixed.get(key)
|
|
323
|
+
tail = f" (not auto-fixed: {reason})" if reason else ""
|
|
324
|
+
print(f" suggested fix: {fix.fixed}{tail}")
|
|
262
325
|
if finding.severity is Severity.WARNING:
|
|
263
326
|
warnings += 1
|
|
264
327
|
else:
|
|
@@ -266,6 +329,86 @@ def _report(findings):
|
|
|
266
329
|
return errors, warnings
|
|
267
330
|
|
|
268
331
|
|
|
332
|
+
_LINE_BREAK = re.compile(r"\r\n|\r|\n")
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def _auto_fix(path, findings, config, guard):
|
|
336
|
+
"""Write the analyzer's safe fixes into one file, unless BES.xsd forbids it.
|
|
337
|
+
|
|
338
|
+
`findings` are the file's lint findings; a file none of them offers a fix
|
|
339
|
+
for is not read again. Otherwise the analyzer plans every fix (plan_fix,
|
|
340
|
+
which writes nothing and refuses what is unsafe, site by site), and the
|
|
341
|
+
plan is written (write_fix) unless, with `guard`, it would turn a
|
|
342
|
+
schema-valid file invalid. Returns (findings, fixed, refused, not_fixed):
|
|
343
|
+
the findings to report, which are the fixed file's when it was written;
|
|
344
|
+
`fixed` and `refused` as (line, code, message) for bes_common.report; and
|
|
345
|
+
`not_fixed`, each unwritten fix's reason by _fix_key.
|
|
346
|
+
"""
|
|
347
|
+
if not any(getattr(finding, "autofix", None) for finding in findings):
|
|
348
|
+
return findings, [], [], {}
|
|
349
|
+
plan = plan_fix(path, config)
|
|
350
|
+
applied, unapplied, findings = plan.applied, plan.unapplied, plan.findings
|
|
351
|
+
refused = []
|
|
352
|
+
not_fixed = {}
|
|
353
|
+
if plan.changed:
|
|
354
|
+
# [] for a file no schema applies to (.rel, .bsr, ...), and for one
|
|
355
|
+
# that was not schema-valid to begin with: both are written unchecked.
|
|
356
|
+
errors = (
|
|
357
|
+
bes_common.schema_regression(plan.original, plan.fixed, str(path))
|
|
358
|
+
if guard
|
|
359
|
+
else []
|
|
360
|
+
)
|
|
361
|
+
if errors:
|
|
362
|
+
codes = ", ".join(
|
|
363
|
+
sorted(
|
|
364
|
+
{CODES[edit.rule] for fix in applied for edit in fix.autofix.edits}
|
|
365
|
+
)
|
|
366
|
+
)
|
|
367
|
+
refused.append(
|
|
368
|
+
(
|
|
369
|
+
1,
|
|
370
|
+
GUARD_CODE,
|
|
371
|
+
(
|
|
372
|
+
f"auto-fix ({codes}) not written: it would make the file fail "
|
|
373
|
+
f"BES.xsd validation ({errors[0]}); fix by hand, or --disable "
|
|
374
|
+
f"{GUARD_CODE} to write it anyway"
|
|
375
|
+
),
|
|
376
|
+
)
|
|
377
|
+
)
|
|
378
|
+
for fix in applied:
|
|
379
|
+
key = _fix_key(fix.path, fix.line, fix.autofix.original)
|
|
380
|
+
not_fixed[key] = f"it would fail BES.xsd validation ({GUARD_CODE})"
|
|
381
|
+
applied, findings = (), plan.original_findings
|
|
382
|
+
else:
|
|
383
|
+
result = write_fix(plan)
|
|
384
|
+
applied, unapplied, findings = (
|
|
385
|
+
result.applied,
|
|
386
|
+
result.unapplied,
|
|
387
|
+
result.findings,
|
|
388
|
+
)
|
|
389
|
+
for fix in unapplied:
|
|
390
|
+
not_fixed.setdefault(
|
|
391
|
+
_fix_key(fix.path, fix.line, fix.autofix.original), fix.reason
|
|
392
|
+
)
|
|
393
|
+
# One line per edit, not per statement: a statement can hold several
|
|
394
|
+
# fixes, each under its own rule (a respelling and a `unique value of`).
|
|
395
|
+
# Each is reported on its own line, as its finding was: a site's `line` is
|
|
396
|
+
# where the statement starts, and its text keeps its line breaks.
|
|
397
|
+
fixed = [
|
|
398
|
+
(
|
|
399
|
+
fix.line + len(_LINE_BREAK.findall(fix.autofix.original, 0, edit.start)),
|
|
400
|
+
CODES[edit.rule],
|
|
401
|
+
(
|
|
402
|
+
f"{fix.autofix.original[edit.start : edit.end]} -> {edit.replacement} "
|
|
403
|
+
f"({edit.rule})"
|
|
404
|
+
),
|
|
405
|
+
)
|
|
406
|
+
for fix in applied
|
|
407
|
+
for edit in fix.autofix.edits
|
|
408
|
+
]
|
|
409
|
+
return findings, fixed, refused, not_fixed
|
|
410
|
+
|
|
411
|
+
|
|
269
412
|
def main(argv=None):
|
|
270
413
|
"""Execution starts here.
|
|
271
414
|
|
|
@@ -282,6 +425,15 @@ def main(argv=None):
|
|
|
282
425
|
action="store_true",
|
|
283
426
|
help="treat warnings as failures (non-zero exit); default: advisory",
|
|
284
427
|
)
|
|
428
|
+
parser.add_argument(
|
|
429
|
+
"--auto-fix",
|
|
430
|
+
choices=["yes", "no"],
|
|
431
|
+
default="no",
|
|
432
|
+
help=(
|
|
433
|
+
"write the analyzer's safe fixes into the files in place (default: "
|
|
434
|
+
"no, in every mode -- unlike the sibling hooks, a repo opts in)"
|
|
435
|
+
),
|
|
436
|
+
)
|
|
285
437
|
parser.add_argument(
|
|
286
438
|
"--disable",
|
|
287
439
|
default="",
|
|
@@ -293,8 +445,8 @@ def main(argv=None):
|
|
|
293
445
|
default="",
|
|
294
446
|
metavar="CODES",
|
|
295
447
|
help=(
|
|
296
|
-
"comma-separated check IDs to switch back on, undoing
|
|
297
|
-
"
|
|
448
|
+
"comma-separated check IDs to switch back on, undoing one this "
|
|
449
|
+
"hook disables by default, e.g. --enable W601"
|
|
298
450
|
),
|
|
299
451
|
)
|
|
300
452
|
parser.add_argument(
|
|
@@ -374,28 +526,47 @@ def main(argv=None):
|
|
|
374
526
|
|
|
375
527
|
config = LintConfig(**config_kwargs)
|
|
376
528
|
|
|
529
|
+
# Filter after the walk rather than before it: the analyzer owns
|
|
530
|
+
# discovery, and re-walking here to drop opted-out files first would mean
|
|
531
|
+
# two definitions of what counts as a file to check. A named file is still
|
|
532
|
+
# dropped before it is linted, which is all pre-commit ever passes.
|
|
377
533
|
if args.files:
|
|
378
|
-
findings =
|
|
379
|
-
[path for path in args.files if not _opted_out(path)], config
|
|
534
|
+
findings = _drop_opted_out(
|
|
535
|
+
lint_paths([path for path in args.files if not _opted_out(path)], config)
|
|
380
536
|
)
|
|
381
537
|
else:
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
findings = [
|
|
386
|
-
finding
|
|
387
|
-
for finding in lint_directory(".", config, max_depth=args.max_depth)
|
|
388
|
-
if not _opted_out(finding.path)
|
|
389
|
-
]
|
|
390
|
-
|
|
391
|
-
error_count, warning_count = _report(findings)
|
|
538
|
+
findings = _drop_opted_out(
|
|
539
|
+
lint_directory(".", config, max_depth=args.max_depth)
|
|
540
|
+
)
|
|
392
541
|
|
|
542
|
+
if args.auto_fix != "yes":
|
|
543
|
+
error_count, warning_count = _report(findings)
|
|
544
|
+
fix_count = 0
|
|
545
|
+
else:
|
|
546
|
+
error_count = warning_count = fix_count = 0
|
|
547
|
+
guard = GUARD_CODE not in disabled
|
|
548
|
+
# The analyzer reports each file's findings together, in path order.
|
|
549
|
+
# A path named twice comes back as two runs, or one when adjacent:
|
|
550
|
+
# either way it is planned again from what is on disk, so a fix is
|
|
551
|
+
# written once.
|
|
552
|
+
for path, linted in itertools.groupby(findings, key=lambda f: f.path):
|
|
553
|
+
reported, fixed, refused, not_fixed = _auto_fix(
|
|
554
|
+
path, list(linted), config, guard
|
|
555
|
+
)
|
|
556
|
+
issues, _warnings, fixes = bes_common.report([(path, refused, fixed)])
|
|
557
|
+
errors, warnings = _report(reported, not_fixed)
|
|
558
|
+
error_count += issues + errors
|
|
559
|
+
warning_count += warnings
|
|
560
|
+
fix_count += fixes
|
|
561
|
+
|
|
562
|
+
if fix_count:
|
|
563
|
+
print(f"\nauto-fixed {fix_count} issue(s); review and re-stage the changes.")
|
|
393
564
|
if warning_count:
|
|
394
565
|
print(f"{warning_count} warning(s).")
|
|
395
566
|
if error_count:
|
|
396
567
|
print(f"{error_count} issue(s).")
|
|
397
|
-
# E-codes always fail; warnings fail only under --strict
|
|
398
|
-
return 1 if (error_count or (warning_count and args.strict)) else 0
|
|
568
|
+
# E-codes and any fix always fail; warnings fail only under --strict
|
|
569
|
+
return 1 if (error_count or fix_count or (warning_count and args.strict)) else 0
|
|
399
570
|
|
|
400
571
|
|
|
401
572
|
if __name__ == "__main__":
|
pre_commit_bigfix/run_all.py
CHANGED
|
@@ -109,7 +109,8 @@ HOOKS = (
|
|
|
109
109
|
"bes-relevance-lint",
|
|
110
110
|
"bes_relevance_lint",
|
|
111
111
|
r"\.(bes|bes\.xml|ojo|besrpt|beswrpt|webreport|bsr|rel)$",
|
|
112
|
-
|
|
112
|
+
# --auto-fix is already off by default; say so anyway
|
|
113
|
+
read_only=("--auto-fix=no",),
|
|
113
114
|
),
|
|
114
115
|
Hook(
|
|
115
116
|
"bes-relevance-convert-group",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pre-commit-bigfix
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.3.0
|
|
4
4
|
Summary: pre-commit hooks for BigFix content
|
|
5
5
|
Home-page: https://github.com/jgstew/pre-commit-bigfix
|
|
6
6
|
Author: JGStew
|
|
@@ -25,7 +25,7 @@ License-File: LICENSE
|
|
|
25
25
|
Requires-Dist: bigfix_prefetch>=1.1.5
|
|
26
26
|
Requires-Dist: lxml
|
|
27
27
|
Requires-Dist: validate_bes_xml<3,>=2.4.1
|
|
28
|
-
Requires-Dist: bigfix-relevance-analyzer<2,>=1.
|
|
28
|
+
Requires-Dist: bigfix-relevance-analyzer<2,>=1.26.0; python_version >= "3.11"
|
|
29
29
|
Provides-Extra: test
|
|
30
30
|
Requires-Dist: pytest; extra == "test"
|
|
31
31
|
Dynamic: license-file
|
|
@@ -624,6 +624,7 @@ of the file.
|
|
|
624
624
|
| `E612` | an ActionScript `{` with anything after it on its line and no `}` to close it there, which fails the action |
|
|
625
625
|
| `E613` | a `<?Relevance` with no closing `?>`, so its relevance was not linted |
|
|
626
626
|
| `E614` | a BES file that is not well-formed XML, so nothing in it was linted (**off by default**; `--enable E614`) |
|
|
627
|
+
| `E615` | an `--auto-fix` was not written because it would turn a BES.xsd-valid file invalid; fix by hand, or `--disable E615` to write it anyway |
|
|
627
628
|
| `W600` | a name no inspector dump defines |
|
|
628
629
|
| `W601` | a property written singular over an object that may be plural |
|
|
629
630
|
| `W602` | a singular spelling mid-chain (under a `whose` filter, or where a plural is built from it), where the plural reads safer |
|
|
@@ -635,7 +636,7 @@ of the file.
|
|
|
635
636
|
|
|
636
637
|
`W600` is a warning rather than an error because a repo running a newer client
|
|
637
638
|
than the analyzer's dump snapshot legitimately uses names it has never heard
|
|
638
|
-
of. `W601` is **disabled by default
|
|
639
|
+
of. `W601` is **disabled by default**: across 1,108
|
|
639
640
|
`.bes` files of real content it fires 6,127 times, which drowns everything
|
|
640
641
|
else. Switch it back on with `--enable W601`.
|
|
641
642
|
|
|
@@ -646,12 +647,35 @@ says the relevance that could be extracted is sound, not that the file parses.
|
|
|
646
647
|
A file opts out of every check here with
|
|
647
648
|
`<!-- pre-commit-skip: bes-relevance-lint -->` anywhere in it. There is no
|
|
648
649
|
per-rule marker: `--disable` takes a code repo-wide, and a single file that
|
|
649
|
-
legitimately needs relevance this complex is what `--max-score` is for.
|
|
650
|
-
are never rewritten, but where the analyzer can work out a safe rewrite of a
|
|
651
|
-
whole statement (today, the singular spellings behind `W602`) the fixed
|
|
652
|
-
statement is printed once under its first finding as `suggested fix: ...`.
|
|
650
|
+
legitimately needs relevance this complex is what `--max-score` is for.
|
|
653
651
|
E-codes fail the hook; pass `--strict` to also fail on warnings.
|
|
654
652
|
|
|
653
|
+
Where the analyzer can work out a safe rewrite of a statement (the singular
|
|
654
|
+
spellings behind `W602`, and the `unique value of` / singular-aggregate
|
|
655
|
+
rewrites behind `E611`), the fixed statement is printed once under its first
|
|
656
|
+
finding as `suggested fix: ...`. By default that is all: **unlike the sibling
|
|
657
|
+
hooks, this one never rewrites a file unless the repo opts in**, because a
|
|
658
|
+
relevance fix changes what a statement says, not just how it is formatted:
|
|
659
|
+
|
|
660
|
+
```yaml
|
|
661
|
+
- id: bes-relevance-lint
|
|
662
|
+
args: [--auto-fix=yes]
|
|
663
|
+
```
|
|
664
|
+
|
|
665
|
+
With `--auto-fix=yes`, each safe fix is written in place as the smallest
|
|
666
|
+
edit that makes it (`setting` gains an `s`; a wrap inserts
|
|
667
|
+
`unique value of `), so entities, CDATA and line endings around it are kept.
|
|
668
|
+
The analyzer refuses a fix it cannot prove safe - one that would add a finding
|
|
669
|
+
(a wrap that pushes a statement over `--max-score`, say), or one under a rule
|
|
670
|
+
you `--disable` - and refuses site by site, so a file can come back partly
|
|
671
|
+
fixed. Each written edit is reported as
|
|
672
|
+
`path:line: [W602] auto-fixed: setting -> settings (plural-preferred)`; a fix
|
|
673
|
+
that was not written keeps its `suggested fix:` line with
|
|
674
|
+
`(not auto-fixed: <reason>)`. A fix that would turn a BES.xsd-valid file
|
|
675
|
+
invalid is not written, and is reported as `E615`; files no schema applies to
|
|
676
|
+
(`.rel`, `.bsr`, ...) are written unchecked, as every sibling hook does. Any
|
|
677
|
+
auto-fix fails the hook so the change is reviewed and re-staged.
|
|
678
|
+
|
|
655
679
|
This hook needs **Python 3.11 or newer** - the analyzer requires it, while the
|
|
656
680
|
rest of this package still runs on 3.8. No specific interpreter is pinned, since
|
|
657
681
|
`language_version` names an exact executable and pinning `python3.11` would
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
pre_commit_bigfix/__init__.py,sha256=
|
|
1
|
+
pre_commit_bigfix/__init__.py,sha256=sF3yyO6plLbnxHNJvOF9Ytt1TbKtUfJrlBNEXR_bV1o,82
|
|
2
2
|
pre_commit_bigfix/bes_actionscript_lint_schclass.py,sha256=3H2oFIv9ENkuDXVD8YnV_3BqveV2YrGQEK9BDw8h5zE,37287
|
|
3
3
|
pre_commit_bigfix/bes_actionscript_validate_prefetch.py,sha256=5GYGloS3BiVS_wT5xI1DH6Tu4C_i-M4csyvc_MJRT58,52239
|
|
4
4
|
pre_commit_bigfix/bes_actionscript_validate_script.py,sha256=s9T4iYPilw0HSwh1HWdIimQXDtaaNv6KwvMtlC2Mj9w,126377
|
|
@@ -6,17 +6,17 @@ pre_commit_bigfix/bes_common.py,sha256=rxQy0c4zjsMAw1q6J4BrEj8etDjs2-qMjnUxjDtc4
|
|
|
6
6
|
pre_commit_bigfix/bes_content_score_risk.py,sha256=Z4m6peMJNyCyEwJ5kRIn91XcblYdR3WHwGCt3Duy4Og,54926
|
|
7
7
|
pre_commit_bigfix/bes_conventions_check.py,sha256=O3DZAjXby4eBSk9sQKOkb9vtrwuWVcP5lV1vyE9Lk_A,140941
|
|
8
8
|
pre_commit_bigfix/bes_relevance_convert_group.py,sha256=rWVcyAc3UsMS5zGQH9NQRPipC8wt589WHR2KU8LQai4,15606
|
|
9
|
-
pre_commit_bigfix/bes_relevance_lint.py,sha256=
|
|
9
|
+
pre_commit_bigfix/bes_relevance_lint.py,sha256=mzdyaVyqWMnFRuqi_n3tie2lNy-2U15slwE17quP63M,24350
|
|
10
10
|
pre_commit_bigfix/bes_schema_validate.py,sha256=HZkbrRTCpVzLkuMPXZ4l7ooDk3o_TrrTIFyRCjC5w0c,2835
|
|
11
11
|
pre_commit_bigfix/bes_siterepo_validate_layout.py,sha256=V3Q7sXq1EOzkZTLngkl6CF7GIXVvWcxZ33SRpdrgAAg,48356
|
|
12
|
-
pre_commit_bigfix/run_all.py,sha256=
|
|
12
|
+
pre_commit_bigfix/run_all.py,sha256=52mZI-HGAmSnmRGiQnaDmScXI1pfITpiPaRm18HSyUU,21194
|
|
13
13
|
pre_commit_bigfix/schclass.py,sha256=ZX8-lInTcI9O4sjeAoPFbI42r9r2xI85aiL-dWzatmw,11196
|
|
14
14
|
pre_commit_bigfix/schclass_tokenizer.py,sha256=GoP1SLcUJhlsBE55peCUXxss87maFqCrrgLSwZaHYS4,13011
|
|
15
15
|
pre_commit_bigfix/schclass_data/ExpandedActionScript.schclass,sha256=CjOZg7kBWBEeTKTZpdrlbpZml2LeS1wDqxTL58wpuiQ,12679
|
|
16
16
|
pre_commit_bigfix/schclass_data/bigfix_overrides.schclass,sha256=IWDXIhVZCoiS5Wj1vcUsJ0-qIuiH4hBAG3s7o71FuLE,1816
|
|
17
|
-
pre_commit_bigfix-2.
|
|
18
|
-
pre_commit_bigfix-2.
|
|
19
|
-
pre_commit_bigfix-2.
|
|
20
|
-
pre_commit_bigfix-2.
|
|
21
|
-
pre_commit_bigfix-2.
|
|
22
|
-
pre_commit_bigfix-2.
|
|
17
|
+
pre_commit_bigfix-2.3.0.dist-info/licenses/LICENSE,sha256=lf357oKwpEyV-sKYHQCzsqS-5wvE1qf1pgIbMaGUZFg,1063
|
|
18
|
+
pre_commit_bigfix-2.3.0.dist-info/METADATA,sha256=FlOgc3cVmIkFMqY0F5UH3XGh0SY2zi9OlHQe2pCSYM8,58516
|
|
19
|
+
pre_commit_bigfix-2.3.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
20
|
+
pre_commit_bigfix-2.3.0.dist-info/entry_points.txt,sha256=41Xki1Mw9LL5naLPdMiGuOUoeGjS5GITM2M1aZl2Bpc,774
|
|
21
|
+
pre_commit_bigfix-2.3.0.dist-info/top_level.txt,sha256=kcFl7WT3ydTOOVAhZeXh2s3t-z3ZWxVafQCcyE121a4,18
|
|
22
|
+
pre_commit_bigfix-2.3.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|