https://github.com/xian-network/xian-linter
A FastAPI service that provides Python code linting specifically designed for Xian smart contracts
https://github.com/xian-network/xian-linter
contracting fastapi linting python xian
Last synced: 2 days ago
JSON representation
A FastAPI service that provides Python code linting specifically designed for Xian smart contracts
- Host: GitHub
- URL: https://github.com/xian-network/xian-linter
- Owner: xian-network
- Created: 2024-12-26T00:16:55.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-01-16T01:07:31.000Z (9 months ago)
- Last Synced: 2025-06-11T14:44:07.183Z (4 months ago)
- Topics: contracting, fastapi, linting, python, xian
- Language: Python
- Homepage:
- Size: 45.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Xian Contract Linter
[](https://badge.fury.io/py/xian-linter)
[](https://pypi.org/project/xian-linter/)A FastAPI service that provides Python code linting specifically designed for Xian smart contracts. It combines PyFlakes for general Python linting with a custom Contracting linter to ensure contract code follows specific rules and patterns.
## Features
- Base64 and Gzip encoded code input support
- Parallel execution of linters
- Deduplication of error messages
- Configurable whitelist patterns for ignored errors
- Standardized error reporting format
- Input validation and size limits## Installation
You can install the linter in two ways:
### 1. Using pip
```bash
pip install xian-linter
```### 2. From source
```bash
# Clone the repository
git clone https://github.com/xian-network/xian-linter.git
cd xian-linter# Install dependencies using Poetry
poetry install
```## Usage
There are several ways to run the linter server:
### If installed via pip:
1. Using the command-line script:
```bash
xian-linter
```2. Using Python's module syntax:
```bash
python -m xian_linter
```3. Using uvicorn directly:
```bash
uvicorn xian_linter.linter:app --host 0.0.0.0 --port 8000
```### If installed from source using Poetry:
```bash
poetry run python xian_linter/linter.py
```The server will start on `http://localhost:8000` by default.
### API Endpoints
#### POST /lint_base64
Expects base64-encoded Python code in the request body.```bash
# Example using curl
base64 < contract.py > contract.py.b64
curl -X POST "http://localhost:8000/lint_base64" --data-binary "@contract.py.b64"
```#### POST /lint_gzip
Expects gzipped Python code in the request body.```bash
# Example using curl
gzip -c contract.py > contract.py.gz
curl -X POST "http://localhost:8000/lint_gzip" -H "Content-Type: application/gzip" --data-binary "@contract.py.gz"
```### Query Parameters
- `whitelist_patterns`: Comma-separated list of patterns to ignore in lint errors. Default patterns are provided for common Contracting keywords.
### Response Format
```json
{
"success": false,
"errors": [
{
"message": "Error description",
"severity": "error",
"position": {
"line": 3,
"column": 1
}
}
]
}
```The `position` field is optional and may not be present for global errors.