Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Validator rule ignores #99

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ class ConfidentialValidator(KomandPluginValidator):
# emails allowed
emails = ["[email protected]"]

# validator ignore signature
IGNORE = "<validator:confidential_validator:ignore>"

# validator ignore comments for Python and markdown
IGNORES = {f"# {IGNORE}", f"[//]: # {IGNORE}"}

# store violations per file
violations = []

Expand All @@ -26,7 +32,23 @@ def validate_help(plugin_path: str):
@staticmethod
def validate_emails(content: [str], path_to_file: str):
email_pattern = re.compile(r"([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+){0,}")

# Store previous line to check for validator ignore
ignore_next_line: bool = False

for i in range(0, len(content)):

# If this is found, continue looping through lines and ignore validation for the next line
checkable = set(content[i].strip().split(" "))
if ConfidentialValidator.IGNORES.intersection(checkable):
ignore_next_line = True
continue

# If ignore_next_line set to true then this current line was flagged to be ignore by validation
if ignore_next_line:
ignore_next_line = False
continue

matches = email_pattern.findall(content[i])
while "" in matches:
matches.remove("")
Expand Down