AstuteSource / chasten

:dizzy: Chasten Uses XML and XPATH to Check a Python Program's AST for Specified Patterns!
https://pypi.org/project/chasten/
GNU General Public License v2.0
7 stars 8 forks source link

Provide Summaries for the Counts of Checks Across All Matched Files #8

Open gkapfham opened 1 year ago

gkapfham commented 1 year ago

When the chasten tool is run on a program with multiple files, it will produce output like this:

🎉 Performing 12 check(s):

  ✓ id: 'CLS001', name: 'class-definition', pattern: './/ClassDef', min=None, max=None
    • /home/gkapfham/working/source/astute-subjects/subject-forks/lazytracker/lazytracker/lazytracker.py - 1 matches
  ✓ id: 'FUNC001', name: 'all-function-definition', pattern: '//FunctionDef/body/Expr[value/Constant]/following-sibling::*[1] |
//FunctionDef/body[not(Expr/value/Constant)]/*[1]', min=None, max=None
    • /home/gkapfham/working/source/astute-subjects/subject-forks/lazytracker/tests/test_lazytracker.py - 6 matches
    • /home/gkapfham/working/source/astute-subjects/subject-forks/lazytracker/tests/test_tracked.py - 2 matches
    • /home/gkapfham/working/source/astute-subjects/subject-forks/lazytracker/lazytracker/lazytracker.py - 6 matches
    • /home/gkapfham/working/source/astute-subjects/subject-forks/lazytracker/lazytracker/tracked.py - 3 matches
  ✓ id: 'FUNC002', name: 'all-function-definition-with-docstring', pattern: '//FunctionDef/body/Expr[value/Constant]/following-sibling::*[1]',
min=None, max=None
    • /home/gkapfham/working/source/astute-subjects/subject-forks/lazytracker/lazytracker/lazytracker.py - 6 matches
    • /home/gkapfham/working/source/astute-subjects/subject-forks/lazytracker/lazytracker/tracked.py - 1 matches
  ✓ id: 'FUNC003', name: 'all-function-definition-with-no-docstring', pattern: '//FunctionDef/body[not(Expr/value/Constant)]/*[1]', min=None,
max=None
    • /home/gkapfham/working/source/astute-subjects/subject-forks/lazytracker/tests/test_lazytracker.py - 6 matches
    • /home/gkapfham/working/source/astute-subjects/subject-forks/lazytracker/tests/test_tracked.py - 2 matches
    • /home/gkapfham/working/source/astute-subjects/subject-forks/lazytracker/lazytracker/tracked.py - 2 matches
  ✓ id: 'FUNC004', name: 'all-non-test-function-definition', pattern: '//FunctionDef[not(contains(@name,
"test_"))]/body/Expr[value/Constant]/following-sibling::*[1] | //FunctionDef[not(contains(@name, "test_"))]/body[not(Expr/value/Constant)]/*[1]',
min=None, max=None
    • /home/gkapfham/working/source/astute-subjects/subject-forks/lazytracker/tests/test_lazytracker.py - 2 matches
    • /home/gkapfham/working/source/astute-subjects/subject-forks/lazytracker/lazytracker/lazytracker.py - 6 matches
    • /home/gkapfham/working/source/astute-subjects/subject-forks/lazytracker/lazytracker/tracked.py - 3 matches
  ✗ id: 'FUNC004', name: 'all-test-function-definition', pattern: '//FunctionDef[starts-with(@name,
"test_")]/body/Expr[value/Constant]/following-sibling::*[1] | //AsyncFunctionDef[starts-with(@name,
"test_")]/body/Expr[value/Constant]/following-sibling::*[1] | //FunctionDef[starts-with(@name, "test_")]/body[not(Expr/value/Constant)]/*[1] |
//AsyncFunctionDef[starts-with(@name, "test_")]/body[not(Expr/value/Constant)]/*[1]', min=7, max=22
    • /home/gkapfham/working/source/astute-subjects/subject-forks/lazytracker/tests/test_lazytracker.py - 4 matches
    • /home/gkapfham/working/source/astute-subjects/subject-forks/lazytracker/tests/test_tracked.py - 2 matches
  ✓ id: 'CTRL001', name: 'single-nested-if-in-function', pattern: './/FunctionDef/body//If', min=None, max=None
    • /home/gkapfham/working/source/astute-subjects/subject-forks/lazytracker/lazytracker/lazytracker.py - 1 matches
    • /home/gkapfham/working/source/astute-subjects/subject-forks/lazytracker/lazytracker/tracked.py - 7 matches
  ✓ id: 'CTRL002', name: 'single-nested-if-anywhere-in-module', pattern: './/If', min=None, max=None
    • /home/gkapfham/working/source/astute-subjects/subject-forks/lazytracker/lazytracker/lazytracker.py - 1 matches
    • /home/gkapfham/working/source/astute-subjects/subject-forks/lazytracker/lazytracker/tracked.py - 7 matches
  ✓ id: 'CTRL003', name: 'double-nested-if-in-function', pattern: './/FunctionDef/body//If[ancestor::If and not(parent::orelse)]', min=None,
max=None
  ✓ id: 'CTRL004', name: 'double-nested-if-anywhere-in-module', pattern: './/If[ancestor::If and not(parent::orelse)]', min=None, max=None
  ✓ id: 'CTRL005', name: 'single-nested-for-target', pattern: './/For/target/Name', min=None, max=None
    • /home/gkapfham/working/source/astute-subjects/subject-forks/lazytracker/lazytracker/lazytracker.py - 3 matches
  ✓ id: 'CTRL006', name: 'single-nested-for-target-no-count', pattern: './/For/target/Name', min=None, max=None
    • /home/gkapfham/working/source/astute-subjects/subject-forks/lazytracker/lazytracker/lazytracker.py - 3 matches

✨ Saved the file 'chasten-results-lazytracker-20230823214805-7c28a9801c25437f981cb7e2a51926f0.json'

😓 At least one check did not pass.

This example is small enough that it is easy to tell that, for instance, single-nested-for-target-no-count has a total of 6 matches. However, it would be useful if the tool's command-line output has sub-totals for the number of matches for a specific check.