Skip to content

Commit

Permalink
Issue #34: Add a way to filter errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
agi authored and agi90 committed Dec 5, 2018
1 parent d7d9211 commit 3f20f44
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
19 changes: 18 additions & 1 deletion apilint/src/main/resources/apilint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,12 @@ def dump_result_json(args, compat_fail, api_changes, failures):

json.dump(result, args['result_json'])

def matches_filter(filter_, failure):
for f in filter_:
if failure.rule is not None and failure.rule.startswith(f):
return True
return False

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Enforces common Android public API design \
patterns. It ignores lint messages from a previous API level, if provided.")
Expand All @@ -1566,6 +1572,9 @@ def dump_result_json(args, compat_fail, api_changes, failures):
help="Show API changes noticed")
parser.add_argument("--show-deprecations-at-birth", action='store_const', const=True,
help="Show API deprecations at birth")
parser.add_argument("--filter-errors", nargs='*',
help="Provide a list of erorr codes to consider. Filter will "
"select only error codes that starts with the codes specified.")
parser.add_argument("--result-json", help="Put result in JSON file.", type=argparse.FileType('w'))
args = vars(parser.parse_args())

Expand All @@ -1586,7 +1595,7 @@ def dump_result_json(args, compat_fail, api_changes, failures):
show_deprecations_at_birth(cur, prev)
sys.exit()

compat_fail = None
compat_fail = []

with current_file as f:
cur_fail, cur_noticed, cur = examine_stream(f)
Expand All @@ -1607,6 +1616,14 @@ def dump_result_json(args, compat_fail, api_changes, failures):
# look for compatibility issues
compat_fail = verify_compat(cur, prev)

# filter errors if filter was specified
if args['filter_errors'] is not None:
filtered_fail = {}
for p in cur_fail:
if matches_filter(args['filter_errors'], cur_fail[p]):
filtered_fail[p] = cur_fail[p]
cur_fail = filtered_fail

dump_result_json(args, compat_fail, cur_noticed, cur_fail)

if compat_fail and len(compat_fail) != 0:
Expand Down
4 changes: 3 additions & 1 deletion apilint/src/test/resources/apilint_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
json_file = "{}/{}-result.json".format(args.build_dir, t["test"])
test = ["python", "src/main/resources/apilint.py",
"--result-json", json_file,
after_api, before_api, "--show-noticed"]
after_api, before_api,
"--filter-errors", t["filter"] if "filter" in t else "NONE",
"--show-noticed"]

error_code = sp.call(test)

Expand Down
2 changes: 2 additions & 0 deletions apilint/src/test/resources/apilint_test/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@
},{
"test": "test-fields-only-class",
"expected": "API_ERROR",
"filter": "GV",
"rule": "GV1"
},{
"test": "test-fields-only-class-final",
"expected": "API_ERROR",
"filter": "GV",
"rule": "GV2"
},{
"test": "test-whitespace-change",
Expand Down

0 comments on commit 3f20f44

Please sign in to comment.