Skip to content
Snippets Groups Projects
Select Git revision
  • Dev
  • cdce-writing
  • ModuleNoiseAnalyzer
  • add_requirements
  • uplegger
  • 2s_cmnoise_multi_sigma
  • disable_stubs_for_pedestal_2S
  • fix_lpgbt_setting
  • croc_scc_tuning
  • fravera-Dev-patch-21673
  • fravera-Dev-patch-19658
  • ci/devPipeline
  • cmsinnertracker
  • fravera-Dev-patch-31094
  • atTB
  • PSv2
  • Dev_Merge_lpGBT_2S_PS
  • ProtoModule_Developments
  • daqSchool2021
  • daqSchool2021Solutions
  • v6-18
  • v6-17
  • v6-16
  • v6-15
  • v6-14
  • v6-13
  • v6-12
  • v6-11
  • v6-10
  • v6-09
  • v6-08
  • v6-07
  • v6-06
  • v6-05
  • v6-04
  • v6-03
  • v6-02
  • v6-01
  • v6-00
  • v5-04
40 results

runcpplint.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    runcpplint.py 1.81 KiB
    #!/usr/bin/env python3
    
    # Adapted from https://github.com/code-freak/codeclimate-cpplint.git
    
    import subprocess
    import json
    import re
    import argparse
    import linecache
    import hashlib
    
    
    ECLIPSE_REGEX = re.compile(r'^(.*):([0-9]+):\s+(.*?)\s+\[([^\]]+)\]\s+\[([0-9]+)\]')
    
    parser = argparse.ArgumentParser()
    parser.add_argument('--files', nargs='+')
    args = parser.parse_args()
    
    
    def get_issue(line):
        matches = ECLIPSE_REGEX.match(line)
        print(line)
        if matches is None:
            return None
        (fname, line, message, check, level) = matches.group(1, 2, 3, 4, 5)
        codeline = linecache.getline(fname, int(line))
        issue = {
            "fingerprint": f"{hashlib.md5(str(check+message+fname+codeline).encode()).hexdigest()}",
            "type": "issue",
            "severity": "minor",
            "check_name": check,
            "description": message,
            "categories": ["Style"],
            "location": {
                "path": fname,
                "lines": {
                    "begin": int(line),
                    "end": int(line)
                }
            }
        }
        return issue
    
    
    def run_cpplint(files):
        cmd = ["cpplint", "--linelength=120", "--filter=-legal", "--recursive"]
        cmd.extend(files)
        try:
            output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
            print(output)
        except subprocess.CalledProcessError as e:
            output = e.output
    
        if len(output):
            output = output.decode('utf-8')
            issues = []
            for line in output.splitlines():
                result = get_issue(line)
                if result:
                    issues.append(result)
    
            print(">>> Writing JSON report to cpplint-report.json")
            with open('cpplint-report.json', 'w') as f:
                json.dump(issues, f, indent=4)
    
    def main():
        run_cpplint(args.files)
        print("\0")
        pass
    
    if __name__ == "__main__":
        main()