mirror of
https://github.com/kjanat/livegraphs-django.git
synced 2026-01-16 11:12:12 +01:00
Add configuration and scripts for linting, testing, and dependency management
- Introduced .pre-commit-config.yaml for pre-commit hooks using uv-pre-commit. - Created lint.sh script to run Ruff and Black for linting and formatting. - Added test.sh script to execute tests with coverage reporting. - Configured .uv file for uv settings including lockfile management and dependency resolution. - Updated Makefile with targets for virtual environment setup, dependency installation, linting, testing, formatting, and database migrations. - Established requirements.txt with main and development dependencies for the project.
This commit is contained in:
@ -1,37 +1,61 @@
|
||||
# Prettier for Django/Jinja Templates
|
||||
# Prettier for Django Templates
|
||||
|
||||
This project uses Prettier with the `prettier-plugin-jinja-template` plugin to format HTML templates with Django/Jinja syntax.
|
||||
This project uses Prettier with the `prettier-plugin-django-annotations` plugin to format HTML templates with Django template syntax.
|
||||
|
||||
## Setup
|
||||
|
||||
To use Prettier with your Django templates, you'll need to install Prettier and the Jinja template plugin:
|
||||
The project is already configured with Prettier integration in pre-commit hooks. The configuration includes:
|
||||
|
||||
1. `.prettierrc` - Configuration file with Django HTML support
|
||||
2. `.prettierignore` - Files to exclude from formatting
|
||||
3. Pre-commit hook for automatic formatting on commits
|
||||
|
||||
### Manual Installation
|
||||
|
||||
To use Prettier locally (outside of pre-commit hooks), you'll need to install the dependencies:
|
||||
|
||||
```bash
|
||||
# Using npm
|
||||
npm install --save-dev prettier prettier-plugin-jinja-template
|
||||
npm install
|
||||
|
||||
# Or using yarn
|
||||
yarn add --dev prettier prettier-plugin-jinja-template
|
||||
# Or install just the required packages
|
||||
npm install --save-dev prettier prettier-plugin-django-annotations
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Once installed, you can format your Django templates using:
|
||||
### With Pre-commit
|
||||
|
||||
Prettier will automatically run as part of the pre-commit hooks when you commit changes.
|
||||
|
||||
To manually run the pre-commit hooks on all files:
|
||||
|
||||
```bash
|
||||
pre-commit run prettier --all-files
|
||||
```
|
||||
|
||||
### Using npm Scripts
|
||||
|
||||
The package.json includes npm scripts for formatting:
|
||||
|
||||
```bash
|
||||
# Format all static files
|
||||
npm run format
|
||||
|
||||
# Check formatting without modifying files
|
||||
npm run format:check
|
||||
```
|
||||
|
||||
### Command Line
|
||||
|
||||
You can also run Prettier directly:
|
||||
|
||||
```bash
|
||||
# Format a specific file
|
||||
npx prettier --write path/to/template.html
|
||||
|
||||
# Format all HTML files
|
||||
npx prettier --write "**/*.html"
|
||||
```
|
||||
|
||||
### Without install
|
||||
|
||||
If you don't want to install the plugin, you can use the following command:
|
||||
|
||||
```bash
|
||||
npx prettier --plugin=prettier-plugin-jinja-template --parser=jinja-template --write **/*.html
|
||||
npx prettier --write "dashboard_project/templates/**/*.html"
|
||||
```
|
||||
|
||||
## VSCode Integration
|
||||
@ -40,12 +64,12 @@ For VSCode users, install the Prettier extension and add these settings to your
|
||||
|
||||
```json
|
||||
{
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"[html]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"editor.formatOnSave": true
|
||||
},
|
||||
"prettier.requireConfig": true
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"[html]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"editor.formatOnSave": true
|
||||
},
|
||||
"prettier.requireConfig": true
|
||||
}
|
||||
```
|
||||
|
||||
@ -62,3 +86,12 @@ If you need to prevent Prettier from formatting a section of your template:
|
||||
This works too.
|
||||
</div>
|
||||
```
|
||||
|
||||
## Django Template Support
|
||||
|
||||
The `prettier-plugin-django-annotations` plugin provides special handling for Django templates, including:
|
||||
|
||||
- Proper formatting of Django template tags (`{% %}`)
|
||||
- Support for Django template comments (`{# #}`)
|
||||
- Preservation of Django template variable output (`{{ }}`)
|
||||
- Special handling for Django template syntax inside HTML attributes
|
||||
|
||||
Reference in New Issue
Block a user