Skip to content

Commit

Permalink
Allow 'whitelisting' 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 whitelist.
  • Loading branch information
wpoely86 committed Oct 24, 2024
1 parent 7444382 commit 7c891c0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 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, whitelist_components=None):
"""Run lint checks against all lines of a file."""
if whitelist_components is None:
whitelist_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 whitelisted components
components_included.extend(whitelist_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('--whitelist-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,9 +515,13 @@ def main():
print('No files were provided, not doing anything')
return 0

whitelist_components = None
if args.whitelist_components:
whitelist_components = args.whitelist_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)
file_problem_lines, file_problem_count = lint_file(filename, args.allow_mvn_templates, whitelist_components)
problem_lines += file_problem_lines
problem_count += file_problem_count
problem_stats[filename] = file_problem_count
Expand Down

0 comments on commit 7c891c0

Please sign in to comment.