MCPcopy Create free account
hub / github.com/dmlc/xgboost / Lint

Class Lint

ops/script/lint_cpp.py:57–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55
56
57class Lint:
58 def __init__(self) -> None:
59 self.project_name = "xgboost"
60 self.cpp_header_map: dict[str, dict[str, int]] = {}
61 self.cpp_src_map: dict[str, dict[str, int]] = {}
62
63 self.pylint_cats = set(["error", "warning", "convention", "refactor"])
64 # setup cpp lint
65 cpplint_args = ["--quiet", "--extensions=" + (",".join(CXX_SUFFIX)), "."]
66 _ = cpplint.ParseArguments(cpplint_args)
67 cpplint._SetFilters(
68 ",".join(
69 [
70 "-build/c++11",
71 "-build/include,",
72 "+build/namespaces",
73 ]
74 )
75 )
76 cpplint._SetCountingStyle("toplevel")
77 cpplint._line_length = 100
78
79 def process_cpp(self, path: str, suffix: str) -> None:
80 """Process a cpp file."""
81 _cpplint_state.ResetErrorCounts()
82 cpplint.ProcessFile(str(path), _cpplint_state.verbose_level)
83 _cpplint_state.PrintErrorCounts()
84 errors = _cpplint_state.errors_by_category.copy()
85
86 if suffix == "h":
87 self.cpp_header_map[str(path)] = errors
88 else:
89 self.cpp_src_map[str(path)] = errors
90
91 @staticmethod
92 def _print_summary_map(
93 strm: TextIO, result_map: dict[str, dict[str, int]], ftype: str
94 ) -> int:
95 """Print summary of certain result map."""
96 if len(result_map) == 0:
97 return 0
98 npass = sum(1 for x in result_map.values() if len(x) == 0)
99 strm.write(f"====={npass}/{len(result_map)} {ftype} files passed check=====\n")
100 for fname, emap in result_map.items():
101 if len(emap) == 0:
102 continue
103 strm.write(
104 f"{fname}: {sum(emap.values())} Errors of {len(emap)} Categories map={str(emap)}\n"
105 )
106 return len(result_map) - npass
107
108 def print_summary(self, strm: TextIO) -> int:
109 """Print summary of lint."""
110 nerr = 0
111 nerr += Lint._print_summary_map(strm, self.cpp_header_map, "cpp-header")
112 nerr += Lint._print_summary_map(strm, self.cpp_src_map, "cpp-source")
113 if nerr == 0:
114 strm.write("All passed!\n")

Callers 1

lint_cpp.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected