MCPcopy Create free account
hub / github.com/crisxuan/bestJavaer / check_files

Function check_files

scripts/check_article_quality.py:404–451  ·  view source on GitHub ↗
(args: argparse.Namespace)

Source from the content-addressed store, hash-verified

402
403
404def check_files(args: argparse.Namespace) -> list[Failure]:
405 paths, use_staged_content = collect_paths(args)
406 article_paths = sorted({path for path in paths if is_article_path(path)})
407 failures: list[Failure] = []
408 root = repo_root()
409
410 for path in article_paths:
411 if not use_staged_content and not path.exists():
412 continue
413
414 text = read_path(path, staged=use_staged_content)
415 metrics = measure(text)
416 image_count, image_issues = check_images(
417 path,
418 text,
419 staged=use_staged_content,
420 args=args,
421 root=root,
422 )
423 metrics = replace(
424 metrics,
425 images=image_count,
426 broken_images=len(image_issues),
427 )
428 issues: list[str] = []
429 if metrics.chars < args.min_chars:
430 issues.append(f"body has {metrics.chars} meaningful chars; expected >= {args.min_chars}")
431 if metrics.paragraphs < args.min_paragraphs:
432 issues.append(f"has {metrics.paragraphs} developed paragraphs; expected >= {args.min_paragraphs}")
433 if metrics.sentences < args.min_sentences:
434 issues.append(f"has {metrics.sentences} developed sentences; expected >= {args.min_sentences}")
435 if metrics.broken_images > args.max_broken_images:
436 issues.append(
437 f"has {metrics.broken_images} broken image references; "
438 f"expected <= {args.max_broken_images}"
439 )
440
441 if issues:
442 failures.append(
443 Failure(
444 path=path,
445 metrics=metrics,
446 issues=tuple(issues),
447 image_issues=image_issues,
448 )
449 )
450
451 return failures
452
453
454def build_parser() -> argparse.ArgumentParser:

Callers 1

mainFunction · 0.85

Calls 8

collect_pathsFunction · 0.85
is_article_pathFunction · 0.85
repo_rootFunction · 0.85
read_pathFunction · 0.85
measureFunction · 0.85
check_imagesFunction · 0.85
replaceFunction · 0.85
FailureClass · 0.85

Tested by

no test coverage detected