-
Notifications
You must be signed in to change notification settings - Fork 5
Introduce check for special characters #92
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
Open
jwasikpsnc
wants to merge
3
commits into
iterorganization:develop
Choose a base branch
from
jwasikpsnc:feature/check_for_special_characters
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,152 @@ | ||
| #!/usr/bin/env bash | ||
| set -uo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
|
|
||
| CHARS=( | ||
| $'\u2013' $'\u2014' $'\u2212' $'\u2018' $'\u2019' | ||
| $'\u201C' $'\u201D' $'\u2026' $'\u00A0' $'\u200B' | ||
| $'\u200C' $'\u200D' $'\u2060' $'\uFEFF' $'\u00AD' | ||
| $'\u2022' $'\u00D7' $'\u00F7' $'\u2190' $'\u2192' | ||
| $'\u21D2' $'\u2260' $'\u2264' $'\u2265' | ||
| ) | ||
|
|
||
| DESCS=( | ||
| "EN DASH (–)" | ||
| "EM DASH (—)" | ||
| "UNICODE MINUS (−)" | ||
| "LEFT SINGLE QUOTATION MARK (‘)" | ||
| "RIGHT SINGLE QUOTATION MARK (’)" | ||
| "LEFT DOUBLE QUOTATION MARK (“)" | ||
| "RIGHT DOUBLE QUOTATION MARK (”)" | ||
| "HORIZONTAL ELLIPSIS (…)" | ||
| "NON-BREAKING SPACE (NBSP)" | ||
| "ZERO WIDTH SPACE" | ||
| "ZERO WIDTH NON-JOINER" | ||
| "ZERO WIDTH JOINER" | ||
| "WORD JOINER" | ||
| "ZERO WIDTH NO-BREAK SPACE (BOM)" | ||
| "SOFT HYPHEN" | ||
| "BULLET (•)" | ||
| "MULTIPLICATION SIGN (×)" | ||
| "DIVISION SIGN (÷)" | ||
| "LEFT ARROW (←)" | ||
| "RIGHT ARROW (→)" | ||
| "RIGHTWARDS DOUBLE ARROW (⇒)" | ||
| "NOT EQUAL TO (≠)" | ||
| "LESS-THAN OR EQUAL TO (≤)" | ||
| "GREATER-THAN OR EQUAL TO (≥)" | ||
| ) | ||
|
|
||
| EXCLUDED_DIRS=( | ||
| __pycache__ .pytest_cache .mypy_cache .ruff_cache | ||
| .tox .venv venv ibex_venv imaspy_venv imas_core_develop_venv | ||
| build dist node_modules .git .webpack out ci generated _build | ||
| ) | ||
|
|
||
| DIRS=() | ||
| EXTS=() | ||
| AFTER_EXT=false | ||
|
|
||
| for arg in "$@"; do | ||
| if [ "$arg" = "--help" ] || [ "$arg" = "-h" ]; then | ||
| echo "Usage: $(basename "$0") [directories...] [--ext extensions...]" | ||
| echo "" | ||
| echo "Scan source files for forbidden Unicode characters." | ||
| echo "" | ||
| echo "Arguments:" | ||
| echo " directories One or more directories to scan (default: ../ and ../../frontend)" | ||
| echo " --ext File extensions to check (default: all files)" | ||
| echo "" | ||
| echo "Examples:" | ||
| echo " $(basename "$0") Scan backend/ and frontend/" | ||
| echo " $(basename "$0") backend/ --ext .py Scan only .py files in backend/" | ||
| echo " $(basename "$0") frontend/ --ext .ts .tsx .js Scan only TS/JS files in frontend/" | ||
| echo " $(basename "$0") src/ docs/ --ext .py .md Scan custom dirs with custom extensions" | ||
| exit 0 | ||
| elif [ "$arg" = "--ext" ]; then | ||
| AFTER_EXT=true | ||
| elif [ "$AFTER_EXT" = true ]; then | ||
| EXTS+=("$arg") | ||
| else | ||
| DIRS+=("$arg") | ||
| fi | ||
| done | ||
|
|
||
| # checks for forbidden chars in ../. (backend), ../../docs, and ../../frontend by default | ||
| # if no --ext given, all files are checked | ||
| if [ ${#DIRS[@]} -eq 0 ]; then | ||
| DIRS=("$SCRIPT_DIR/../" "$SCRIPT_DIR/../../docs" "$SCRIPT_DIR/../../frontend") | ||
| fi | ||
|
|
||
| find_args=() | ||
|
|
||
| for dir in "${DIRS[@]}"; do | ||
| if [ ! -d "$dir" ]; then | ||
| echo "Directory not found: $dir" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| find_args+=("$(cd "$dir" && pwd)") | ||
| done | ||
|
|
||
| find_args=("${find_args[@]}" -type f) | ||
|
|
||
| if [ ${#EXTS[@]} -gt 0 ]; then | ||
| find_args+=("(") | ||
| find_args+=(-name "*${EXTS[0]}") | ||
| for ((i=1; i<${#EXTS[@]}; i++)); do | ||
| find_args+=(-o -name "*${EXTS[i]}") | ||
| done | ||
| find_args+=(")") | ||
| fi | ||
|
|
||
| for d in "${EXCLUDED_DIRS[@]}"; do | ||
| find_args+=(! -path "*/$d/*") | ||
| done | ||
|
|
||
| # Collect all matching files | ||
| all_files=() | ||
| while IFS= read -r -d '' file; do | ||
| all_files+=("$file") | ||
| done < <(find "${find_args[@]}" -print0 2>/dev/null) | ||
|
|
||
| file_count=${#all_files[@]} | ||
|
|
||
| if [ "$file_count" -eq 0 ]; then | ||
| echo "No files to check." | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "Checking $file_count files..." | ||
|
|
||
| errors=0 | ||
|
|
||
| for ((i=0; i<${#CHARS[@]}; i++)); do | ||
| char="${CHARS[i]}" | ||
| desc="${DESCS[i]}" | ||
|
|
||
| matches=$(printf '%s\0' "${all_files[@]}" | xargs -0 grep -In "$char" 2>/dev/null) || true | ||
| if [ -n "$matches" ]; then | ||
| while IFS= read -r grep_line; do | ||
| file="${grep_line%%:*}" | ||
| rest="${grep_line#*:}" | ||
| lineno="${rest%%:*}" | ||
| content="${rest#*:}" | ||
|
|
||
| prefix="${content%%$char*}" | ||
| col=$(( ${#prefix} + 1 )) | ||
|
|
||
| echo "$file:$lineno:$col: $desc" | ||
| done <<< "$matches" | ||
| ((errors++)) || true | ||
| fi | ||
| done | ||
|
|
||
| if [ "$errors" -gt 0 ]; then | ||
| echo "" | ||
| echo "❌ Forbidden Unicode characters found in $errors file(s)." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "✅ No forbidden Unicode characters found." |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to commit the script?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what the script is doing, but would this be captured by using RUFF preview rules like RUF001-3 (maybe in preview)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the script was in my .gitignore....
I will check tomorrow if we can use RUF001 for /docs and /frontend (.rst, .js etc...).
For now, short answer i get from the google is "no"