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

Fix incorrect script for no-pylint-disable #178

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
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
12 changes: 7 additions & 5 deletions .github/workflows/no-cheat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ jobs:

- name: Verify no lint is disabled in the new code
run: |
NEW_CODE=$(git diff origin/main..$(git branch --show-current) | grep -e '^+')
CHEAT=$(echo "${NEW_CODE}" | grep '# pylint: disable' | grep -v "CHEAT" | wc -c)
if [ "${CHEAT}" -ne 0 ]; then
echo "Do not cheat the linter: ${CHEAT}"
git fetch origin $GITHUB_BASE_REF:$GITHUB_BASE_REF
git diff $GITHUB_BASE_REF...$(git branch --show-current) >> diff_data.txt
python tests/unit/no_cheat.py diff_data.txt >> cheats.txt
COUNT=$(cat cheats.txt | wc -c)
if [ ${COUNT} -gt 1 ]; then
cat cheats.txt
exit 1
fi
fi
37 changes: 37 additions & 0 deletions tests/unit/no_cheat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import sys
from pathlib import Path

DISABLE_TAG = '# pylint: disable='


def no_cheat(diff_text: str) -> str:
lines = diff_text.split('\n')
removed: dict[str, int] = {}
added: dict[str, int] = {}
for line in lines:
if not (line.startswith("-") or line.startswith("+")):
continue
idx = line.find(DISABLE_TAG)
if idx < 0:
continue
codes = line[idx + len(DISABLE_TAG) :].split(',')
for code in codes:
code = code.strip().strip('\n').strip('"').strip("'")
if line.startswith("-"):
removed[code] = removed.get(code, 0) + 1
continue
added[code] = added.get(code, 0) + 1
results: list[str] = []
for code, count in added.items():
count -= removed.get(code, 0)
if count > 0:
results.append(f"Do not cheat the linter: found {count} additional {DISABLE_TAG}{code}")
return '\n'.join(results)


if __name__ == "__main__":
diff_data = sys.argv[1]
path = Path(diff_data)
if path.exists():
diff_data = path.read_text("utf-8")
print(no_cheat(diff_data))
Loading