-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(infra): block curly quotes #2414
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| name: Check Curly Quotes | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| check-curly-quotes: | ||
| name: Check for curly quotes | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Check for curly quotes | ||
| run: | | ||
| chmod +x scripts/check_curly_quotes.sh | ||
| ./scripts/check_curly_quotes.sh | ||
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,10 @@ | ||
| repos: | ||
| - repo: local | ||
| hooks: | ||
| - id: check-curly-quotes | ||
| name: Check for curly quotes | ||
| entry: bash scripts/check_curly_quotes.sh | ||
| language: system | ||
| pass_filenames: false | ||
| types: [text] | ||
| description: "Detect curly/smart quotes that should be straight quotes" |
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,70 @@ | ||
| #!/bin/bash | ||
| # Check for curly/smart quotes in source files | ||
| # | ||
| # Detects: | ||
| # " (U+201C) - Left double quotation mark | ||
| # " (U+201D) - Right double quotation mark | ||
| # ' (U+2018) - Left single quotation mark | ||
| # ' (U+2019) - Right single quotation mark | ||
|
|
||
| set -e | ||
|
|
||
| # Colors for output | ||
| RED='\033[0;31m' | ||
| GREEN='\033[0;32m' | ||
| NC='\033[0m' # No Color | ||
|
|
||
| # Default to src/ if no arguments provided | ||
| if [ $# -eq 0 ]; then | ||
| SEARCH_PATHS="src/" | ||
| else | ||
| SEARCH_PATHS="$@" | ||
| fi | ||
|
|
||
| # Pattern for curly quotes | ||
| CURLY_QUOTE_PATTERN='[""'']' | ||
|
|
||
| # Find files with curly quotes | ||
| # Exclude reference directories (auto-generated) and build artifacts | ||
| FOUND_FILES=$(grep -r -l -E "$CURLY_QUOTE_PATTERN" $SEARCH_PATHS \ | ||
| --include="*.md" \ | ||
| --include="*.mdx" \ | ||
| --include="*.py" \ | ||
| --include="*.js" \ | ||
| --include="*.ts" \ | ||
| --include="*.jsx" \ | ||
| --include="*.tsx" \ | ||
| --include="*.json" \ | ||
| --include="*.yaml" \ | ||
| --include="*.yml" \ | ||
| --exclude-dir=reference \ | ||
| --exclude-dir=build \ | ||
| --exclude-dir=node_modules \ | ||
| --exclude-dir=.git \ | ||
| --exclude-dir=.venv \ | ||
| --exclude-dir=__pycache__ \ | ||
| 2>/dev/null || true) | ||
|
|
||
| if [ -n "$FOUND_FILES" ]; then | ||
| echo -e "${RED}Error: Curly quotes found in the following files:${NC}" | ||
| echo "" | ||
|
|
||
| for file in $FOUND_FILES; do | ||
| echo -e "${RED}$file:${NC}" | ||
| # Show line numbers and content with curly quotes | ||
| grep -n -E "$CURLY_QUOTE_PATTERN" "$file" | head -10 | ||
| echo "" | ||
| done | ||
|
|
||
| echo "Please replace curly quotes with straight quotes:" | ||
| echo ' " -> " (left double quote)' | ||
| echo ' " -> " (right double quote)' | ||
| echo " ' -> ' (left single quote)" | ||
| echo " ' -> ' (right single quote)" | ||
| echo "" | ||
| echo "Tip: You can use 'make fix-curly-quotes' to automatically fix these." | ||
| exit 1 | ||
| else | ||
| echo -e "${GREEN}No curly quotes found.${NC}" | ||
| exit 0 | ||
| fi |
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,57 @@ | ||
| #!/bin/bash | ||
| # Fix curly/smart quotes by replacing them with straight quotes | ||
| # | ||
| # Replaces: | ||
| # " (U+201C) → " - Left double quotation mark | ||
| # " (U+201D) → " - Right double quotation mark | ||
| # ' (U+2018) → ' - Left single quotation mark | ||
| # ' (U+2019) → ' - Right single quotation mark | ||
|
|
||
| set -e | ||
|
|
||
| # Colors for output | ||
| GREEN='\033[0;32m' | ||
| YELLOW='\033[0;33m' | ||
| NC='\033[0m' # No Color | ||
|
|
||
| # Default to src/ if no arguments provided | ||
| if [ $# -eq 0 ]; then | ||
| SEARCH_PATHS="src/" | ||
| else | ||
| SEARCH_PATHS="$@" | ||
| fi | ||
|
|
||
| # Find all relevant files | ||
| FILES=$(find $SEARCH_PATHS \ | ||
| -type f \ | ||
| \( -name "*.md" -o -name "*.mdx" -o -name "*.py" -o -name "*.js" -o -name "*.ts" -o -name "*.jsx" -o -name "*.tsx" -o -name "*.json" -o -name "*.yaml" -o -name "*.yml" \) \ | ||
| -not -path "*/reference/*" \ | ||
| -not -path "*/build/*" \ | ||
| -not -path "*/node_modules/*" \ | ||
| -not -path "*/.git/*" \ | ||
| -not -path "*/.venv/*" \ | ||
| -not -path "*/__pycache__/*" \ | ||
| 2>/dev/null || true) | ||
|
|
||
| FIXED_COUNT=0 | ||
|
|
||
| for file in $FILES; do | ||
| if grep -q -E '[""'']' "$file" 2>/dev/null; then | ||
| echo -e "${YELLOW}Fixing: $file${NC}" | ||
| # Use sed to replace curly quotes with straight quotes | ||
| # macOS and Linux compatible | ||
| if [[ "$OSTYPE" == "darwin"* ]]; then | ||
| sed -i '' -e 's/[""]/"/g' -e "s/['']/'/g" "$file" | ||
| else | ||
| sed -i -e 's/[""]/"/g' -e "s/['']/'/g" "$file" | ||
| fi | ||
| FIXED_COUNT=$((FIXED_COUNT + 1)) | ||
| fi | ||
| done | ||
|
|
||
| if [ $FIXED_COUNT -gt 0 ]; then | ||
| echo "" | ||
| echo -e "${GREEN}Fixed curly quotes in $FIXED_COUNT file(s).${NC}" | ||
| else | ||
| echo -e "${GREEN}No curly quotes found. Nothing to fix.${NC}" | ||
| fi |
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.
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Copilot Autofix
AI 3 months ago
In general, the fix is to add an explicit
permissionsblock to the workflow (either at the top level so it applies to all jobs, or directly under the specific job) and restrictGITHUB_TOKENto the least privileges required. This workflow only checks out the repository and runs a script, socontents: readis sufficient.The best minimally invasive fix here is to add a job-level
permissionsblock undercheck-curly-quotes:specifyingcontents: read. This keeps the change tightly scoped to the job that CodeQL flagged and avoids assumptions about other jobs (none are shown). Concretely, in.github/workflows/check-curly-quotes.yml, underjobs: check-curly-quotes: name: Check for curly quotes, insert apermissions:mapping withcontents: readat the standard indentation level. No imports or other definitions are needed; this is pure workflow configuration.