Skip to content

Commit

Permalink
Allow ignoring errors of components in panlint
Browse files Browse the repository at this point in the history
Panlint will not issue errors about the missing include for any component in the ignore list.
  • Loading branch information
wpoely86 committed Oct 27, 2024
1 parent 7444382 commit 2a818aa
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions panc/src/main/scripts/panlint/panlint.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,12 @@ def lint_line(line, components_included, first_line=False, allow_mvn_templates=F
return (line, first_line)


def lint_file(filename, allow_mvn_templates=False):
def lint_file(filename, allow_mvn_templates=False, ignore_components=None):
"""Run lint checks against all lines of a file."""
if ignore_components is None:
ignore_components = []

reports = []
problem_lines = []
file_problem_count = 0

Expand All @@ -455,6 +459,8 @@ def lint_file(filename, allow_mvn_templates=False):

# Get list of all component configs included in template
components_included = RE_COMPONENT_INCLUDE.findall(raw_text)
# add ignored components
components_included.extend(ignore_components)

# Is the current file part of the source tree of a component?
# If so, regard the component config as being included
Expand Down Expand Up @@ -489,6 +495,8 @@ def main():
parser.add_argument('--allow_mvn_templates', action='store_true', help='Allow use of maven templates')
parser.add_argument('--always_exit_success', action='store_true',
help='Always exit cleanly even if problems are found')
parser.add_argument('--ignore-components', type=str,
help='List of component to ignore when checking included components')
group_output = parser.add_mutually_exclusive_group()
group_output.add_argument('--debug', action='store_true', help='Enable debug output')
group_output.add_argument('--ide', action='store_true', help='Output machine-readable results for use by IDEs')
Expand All @@ -507,12 +515,16 @@ def main():
print('No files were provided, not doing anything')
return 0

ignore_components = None
if args.ignore_components:
ignore_components = args.ignore_components.split(',')

for path in args.paths:
for filename in glob(path):
file_problem_lines, file_problem_count = lint_file(filename, args.allow_mvn_templates)
problem_lines += file_problem_lines
problem_count += file_problem_count
problem_stats[filename] = file_problem_count
file_reports, file_problems = lint_file(filename, args.allow_mvn_templates, ignore_components)
reports += file_reports
problems_found += file_problems
problem_stats[filename] = file_problems

for line in problem_lines:
print_report(line, vi=args.vi)
Expand Down

0 comments on commit 2a818aa

Please sign in to comment.