Skip to content

feat: Update pre-commit configuration, add CLAUDE.md, and implement JSON5 formatting features #5

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
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,4 @@ dmypy.json

# Pyre type checker
.pyre/
.claude/
9 changes: 5 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
repos:
- repo: https://github.com/asottile/reorder_python_imports
rev: v2.5.0
rev: v3.12.0
hooks:
- id: reorder-python-imports
- repo: https://github.com/psf/black
rev: 21.5b2
rev: 23.12.1
hooks:
- id: black
language_version: python3
files: pretty_format_json5.py
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v4.5.0
hooks:
- id: fix-byte-order-marker
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v2.3.1"
rev: "v3.1.0"
hooks:
- id: prettier
types: [file]
Expand Down
152 changes: 152 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
{
"[yaml]": {
"editor.tabSize": 2,
"editor.formatOnSave": false,
"editor.formatOnPaste": false,
"editor.formatOnType": false
},
"json.schemas": [
{
"fileMatch": ["Taskfile.yml"],
"url": "./hack/schemas/taskfile.json"
}
],
"yaml.schemas": {
"https://taskfile.dev/schema.json": "**/Taskfile.yml",
"hack/schemas/mkdocs-material/schema.json": "mkdocs.yml"
},
"files.associations": {
"*.cheat": "markdown",
"Makefile.ci": "makefile",
"pyproject.toml*": "toml",
"*.just": "just"
},
"pylint.interpreter": ["${workspaceFolder}/.venv/bin/python"],
"pylint.args": [
"--enable=F,E,E1101",
"--disable=C0111,E0401,C,W,E1205",
"--max-line-length=120",
"--load-plugins",
"pylint_pydantic,pylint_per_file_ignores"
],
"python.analysis.typeCheckingMode": "basic",
"python.analysis.autoFormatStrings": true,
"python.analysis.autoImportCompletions": true,
"python.analysis.inlayHints.functionReturnTypes": true,
"python.analysis.inlayHints.variableTypes": true,
"python.analysis.inlayHints.callArgumentNames": "all",
"python.terminal.activateEnvInCurrentTerminal": true,
"files.exclude": {
"**/__pycache__": true,
"**/*.pyc": true,
"**/pycache": true
},
// Editor settings for Python files
"editor.formatOnSave": true,
"python.pythonPath": "${workspaceFolder}/.venv/bin/python",
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
"python.analysis.inlayHints.pytestParameters": true,
"python.analysis.diagnosticSeverityOverrides": {
"reportUnusedImport": "none",
"reportMissingImports": "error",
"reportImportCycles": "error",
"reportUnusedVariable": "none",
"reportMissingTypeStubs": "none",
"reportUnknownMemberType": "none",
"reportUnusedFunction": "warning",
"reportUnusedClass": "warning",
"reportIncompatibleMethodOverride": "none",
"reportGeneralTypeIssues": "information"
},
"notebook.formatOnSave.enabled": false,
"[python]": {
"editor.formatOnSave": false,
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.tabSize": 4,
"editor.formatOnPaste": false,
"editor.formatOnType": false
},
"[makefile]": {
"editor.formatOnSave": true,
"editor.tabSize": 4
},
"editor.inlineSuggest.showToolbar": "onHover",
"editor.renderWhitespace": "all",
"python.analysis.packageIndexDepths": [
{
"name": "langchain",
"depth": 3,
"includeAllSymbols": true
},
{
"name": "langgraph",
"depth": 3,
"includeAllSymbols": true
},
{
"name": "langchain_core",
"depth": 3,
"includeAllSymbols": true
},
{
"name": "langchain_community",
"depth": 3,
"includeAllSymbols": true
},
{
"name": "discord",
"depth": 3,
"includeAllSymbols": true
},
{
"name": "discord.ext.test",
"depth": 5,
"includeAllSymbols": true
},
{
"name": "dpytest",
"depth": 5,
"includeAllSymbols": true
},
{
"name": "gallery_dl",
"depth": 5,
"includeAllSymbols": true
},
{
"name": "loguru",
"depth": 5,
"includeAllSymbols": true
}
],
"python.analysis.extraPaths": ["."],
"python.analysis.completeFunctionParens": true,
"python.analysis.indexing": true,
"python.languageServer": "Pylance",
"python.analysis.importFormat": "absolute",
"python.analysis.stubPath": "${workspaceFolder}/typings",
"python.analysis.autoSearchPaths": true,
"python.analysis.diagnosticMode": "openFilesOnly",
"python.analysis.includeAliasesFromUserFiles": true,
"python.analysis.inlayHints.parameterNames": true,
"python.analysis.inlayHints.parameterNamesStyle": "long",
"python.analysis.inlayHints.callArgumentNamesStyle": "long",
"python.analysis.enableEditableInstalls": true,
"editor.semanticHighlighting.enabled": true,
"workbench.editorAssociations": {
"*.mdc": "default"
},
// SOURCE: https://github.com/allthingslinux/tux/blob/7a7cd918d1c96ef11a8e65e11fee2bd8c692df67/.vscode/settings.json
"yaml.customTags": [
"!ENV scalar",
"!ENV sequence",
"!relative scalar",
"tag:yaml.org,2002:python/name:material.extensions.emoji.to_svg",
"tag:yaml.org,2002:python/name:material.extensions.emoji.twemoji",
"tag:yaml.org,2002:python/name:pymdownx.superfences.fence_code_format",
"tag:yaml.org,2002:python/name:mermaid2.fence_mermaid_custom",
"tag:yaml.org,2002:python/object/apply:pymdownx.slugs.slugify mapping"
],
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true
}
77 changes: 77 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

This repository contains a pre-commit hook that checks and formats JSON5 files. It ensures JSON5 files are properly formatted according to specified configuration options.

## Code Structure

- `pretty_format_json5.py`: The main module containing the JSON5 formatting logic
- `setup.py`: Package configuration for installation
- `test_pretty_format_json5.py`: Test suite validating formatting behavior

## Development Commands

### Installation

```bash
# Install the package locally in development mode
pip install -e .

# Install development dependencies
pip install pre-commit pytest json5
```

### Testing

#### Run the Test Suite

```bash
# Run all tests
python -m pytest test_pretty_format_json5.py -v

# Run a specific test
python -m pytest test_pretty_format_json5.py::test_vscode_settings_formatting -v

# Run tests with coverage
python -m pytest test_pretty_format_json5.py --cov=pretty_format_json5
```

#### Manual Testing

Test the formatter with specific files:

```bash
# Run the formatter on specific files
python pretty_format_json5.py file1.json5 file2.json5

# Run with specific options
python pretty_format_json5.py --indent 4 --ensure-ascii --no-sort-keys file.json5

# Test without autofix to see diff
python pretty_format_json5.py --no-autofix file.json5
```

#### Example Test Cases

The test suite includes validation for:

- VS Code settings.json formatting (complete before/after example)
- Unquoted keys for valid JavaScript identifiers
- Trailing commas in JSON5 style
- Mixed quoted/unquoted key handling
- Nested object and array formatting

### Releasing

Update the version in `setup.py` and create a new git tag matching the version.

## Command Line Options

- `--no-autofix`: Don't automatically format JSON5 files
- `--indent ...`: Control indentation (number for spaces or string of whitespace), defaults to 2 spaces
- `--ensure-ascii`: Convert Unicode characters to escape sequences
- `--no-sort-keys`: Retain original key ordering when formatting
- `--top-keys comma,separated,keys`: Keys to keep at the top of mappings
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
test:
python -m pytest test_pretty_format_json5.py -v

fix:
pre-commit run -a --show-diff-on-failure

smoke-test:
python pretty_format_json5.py .vscode/settings.json
Loading