-
Notifications
You must be signed in to change notification settings - Fork 411
feat: mdformat to match internal style #56
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
markmcd
wants to merge
4
commits into
main
Choose a base branch
from
mdformat
base: main
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 3 commits
Commits
Show all changes
4 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,23 @@ | ||
| name: Format Check | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ main ] | ||
| pull_request: | ||
| branches: [ main ] | ||
|
|
||
| jobs: | ||
| format: | ||
| name: Markdown Format Check | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout Code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.11' | ||
|
|
||
| - name: Run Format Check | ||
| run: bash scripts/format.sh --check |
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 |
|---|---|---|
|
|
@@ -202,3 +202,7 @@ poetry.toml | |
|
|
||
| # LSP config files | ||
| pyrightconfig.json | ||
|
|
||
| # Markdown formatter virtualenv | ||
| scripts/.venv/ | ||
|
|
||
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,73 @@ | ||
| #!/usr/bin/env python3 | ||
| import os | ||
| import subprocess | ||
| import sys | ||
|
|
||
| EXCLUDE_DIRS = { | ||
| '.git', | ||
| 'node_modules', | ||
| '.venv', | ||
| '.agents', | ||
| '.claude-plugin', | ||
| '.codex-plugin', | ||
| '.cursor-plugin', | ||
| '.jetskicli', | ||
| } | ||
|
|
||
| def main(): | ||
| # Determine the directory paths | ||
| script_dir = os.path.dirname(os.path.abspath(__file__)) | ||
| root_dir = os.path.dirname(script_dir) | ||
|
|
||
| # Separate options (starting with '-') from positional arguments (files) | ||
| options = [] | ||
| input_paths = [] | ||
| for arg in sys.argv[1:]: | ||
| if arg.startswith('-'): | ||
| options.append(arg) | ||
| else: | ||
| input_paths.append(arg) | ||
|
|
||
| if input_paths: | ||
| # User specified files/directories explicitly | ||
| md_files = [] | ||
| for path in input_paths: | ||
| abs_path = os.path.abspath(path) | ||
| if not os.path.exists(abs_path): | ||
| print(f"Error: Path '{path}' does not exist.", file=sys.stderr) | ||
| sys.exit(1) | ||
| elif os.path.isdir(abs_path): | ||
| # Walk the directory | ||
| for root, dirs, files in os.walk(abs_path): | ||
| dirs[:] = [d for d in dirs if d not in EXCLUDE_DIRS] | ||
| for file in files: | ||
| if file.endswith('.md'): | ||
| md_files.append(os.path.join(root, file)) | ||
| elif os.path.isfile(abs_path): | ||
| if abs_path.endswith('.md'): | ||
| md_files.append(abs_path) | ||
| else: | ||
| print(f"Error: File '{path}' is not a markdown file.", file=sys.stderr) | ||
| sys.exit(1) | ||
| else: | ||
| # Walk the entire repository | ||
| md_files = [] | ||
| for root, dirs, files in os.walk(root_dir): | ||
| dirs[:] = [d for d in dirs if d not in EXCLUDE_DIRS] | ||
| for file in files: | ||
| if file.endswith('.md'): | ||
| md_files.append(os.path.join(root, file)) | ||
|
|
||
| if not md_files: | ||
| print("No markdown files found to format.") | ||
| return | ||
|
|
||
| # Run mdformat | ||
| cmd = [sys.executable, '-m', 'mdformat', '--wrap', '80'] + options + md_files | ||
|
|
||
| # Run the command and propagate exit code | ||
| result = subprocess.run(cmd) | ||
| sys.exit(result.returncode) | ||
|
|
||
| if __name__ == '__main__': | ||
| main() |
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,26 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| # Get the directory of the script | ||
| DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
|
|
||
| # Check if python3 is installed | ||
| if ! command -v python3 &> /dev/null; then | ||
| echo "Error: python3 is not installed. Please install Python 3 to run the formatter." | ||
| exit 1 | ||
| fi | ||
|
|
||
| VENV_DIR="$DIR/.venv" | ||
|
|
||
| # Create virtual environment if it doesn't exist | ||
| if [ ! -d "$VENV_DIR" ]; then | ||
| echo "Creating Python virtual environment in $VENV_DIR..." | ||
| python3 -m venv "$VENV_DIR" | ||
| fi | ||
|
|
||
| # Install mdformat and plugins if not already installed, or ensure they are present | ||
| echo "Ensuring mdformat and plugins are installed..." | ||
| "$VENV_DIR/bin/pip" install -q mdformat mdformat-gfm mdformat-frontmatter | ||
|
|
||
| # Run the python formatter script, passing along all arguments | ||
| "$VENV_DIR/bin/python" "$DIR/format.py" "$@" | ||
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.
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.
Uh oh!
There was an error while loading. Please reload this page.