forked from DataDog/integrations-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use codespell to check for typos * save list of allowed words * Test validation * don't change cisco key ex * Skip directories * add metric names that should not be corrected * try one line * split multiline * Use config file * Create a validation command for typos * Add annotations * catch none * Remove * Fix * Put ignore words in a file
- Loading branch information
1 parent
bc0b241
commit 48e7754
Showing
5 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
ACI | ||
aci | ||
creat | ||
hist | ||
idae | ||
Mor | ||
mor | ||
nd | ||
unparseable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[codespell] | ||
skip = *.txt,*.json,*/.tox/*,*.sql,*/site/*,*/metrics.yaml,*/CHANGELOG.md,*/.git/*,*/*.egg-info/*,*/build/*,*/vendor/*,*/tests/*,*/.tox/* | ||
count = | ||
quiet-level = 3 | ||
ignore-words = .codespell/ignore_words.txt | ||
ignore-regex = PullRequest|PostgresSQL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
datadog_checks_dev/datadog_checks/dev/tooling/commands/validate/typos.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# (C) Datadog, Inc. 2021-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
import os | ||
import re | ||
|
||
import click | ||
|
||
from datadog_checks.dev.tooling.annotations import annotate_warning | ||
from datadog_checks.dev.tooling.constants import get_root | ||
|
||
from ....subprocess import run_command | ||
from ...utils import complete_valid_checks | ||
from ..console import CONTEXT_SETTINGS, abort, echo_failure, echo_info, echo_success, echo_warning | ||
|
||
FILE_PATH_REGEX = r'(.+\/[^\/]+)\:(\d+)\:\s+(\w+\s+\=\=\>\s+\w+)' | ||
|
||
|
||
@click.command(context_settings=CONTEXT_SETTINGS, short_help='Validate spelling') | ||
@click.argument('check', autocompletion=complete_valid_checks, required=False) | ||
@click.option('--fix', is_flag=True, help='Apply suggested fix') | ||
@click.pass_context | ||
def typos(ctx, check, fix): | ||
"""Validate spelling in the source code. | ||
If `check` is specified, only the directory is validated. | ||
Use codespell command line tool to detect spelling errors. | ||
""" | ||
root = get_root() | ||
|
||
if check: | ||
path = os.path.join(root, check) | ||
else: | ||
path = root | ||
|
||
cmd = f"codespell {path} --config={root}/.codespell/setup.cfg" | ||
|
||
if fix: | ||
cmd += " -w" | ||
|
||
try: | ||
output, err, code = run_command(cmd, capture=True) | ||
if code == 0: | ||
echo_success("All files are valid!") | ||
abort() | ||
annotate_typos(output) | ||
except Exception as e: | ||
echo_info(f"Encountered error validating spell check: {e}") | ||
|
||
|
||
def annotate_typos(output): | ||
echo_failure("Typo validation failed, please fix typos") | ||
parse_errors = output.split('\n') | ||
for line in parse_errors: | ||
m = re.match(FILE_PATH_REGEX, line) | ||
if m is None: | ||
continue | ||
|
||
file, num, suggestion = m.groups() | ||
annotate_warning(file, f"Detected typo: {suggestion}", line=num) | ||
echo_warning(line) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters