-
Notifications
You must be signed in to change notification settings - Fork 3
docs: add GenLayer Linter API reference #336
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
MuncleUscles
wants to merge
3
commits into
main
Choose a base branch
from
docs/genvm-linter
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 all commits
Commits
Show all changes
3 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
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,237 @@ | ||
| # GenLayer Linter Reference | ||
|
|
||
| The GenLayer Linter (`genvm-linter`) is a command-line tool for validating Intelligent Contracts and extracting ABI schemas. It performs static analysis to catch common errors before deployment. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| pip install genvm-linter | ||
| ``` | ||
|
|
||
| ## Command Line Syntax | ||
|
|
||
| ```bash | ||
| genvm-lint <command> <contract.py> [options] | ||
| ``` | ||
|
|
||
| ## Commands | ||
|
|
||
| ### check | ||
|
|
||
| The default validation workflow that runs both lint and validate checks. | ||
|
|
||
| ```bash | ||
| USAGE: | ||
| genvm-lint check <contract.py> [options] | ||
|
|
||
| OPTIONS: | ||
| --json Output results in JSON format | ||
|
|
||
| EXAMPLES: | ||
| genvm-lint check my_contract.py | ||
| genvm-lint check my_contract.py --json | ||
| ``` | ||
|
|
||
| ### lint | ||
|
|
||
| Fast AST-based static analysis (~50ms). Checks for common issues without requiring the GenLayer SDK. | ||
|
|
||
| ```bash | ||
| USAGE: | ||
| genvm-lint lint <contract.py> [options] | ||
|
|
||
| OPTIONS: | ||
| --json Output results in JSON format | ||
|
|
||
| EXAMPLES: | ||
| genvm-lint lint my_contract.py | ||
| genvm-lint lint my_contract.py --json | ||
| ``` | ||
|
|
||
| **Checks performed:** | ||
| - Forbidden imports (`random`, `os`, `sys`, `subprocess`, etc.) | ||
| - Non-deterministic patterns (float usage) | ||
| - Contract header structure | ||
|
|
||
| ### validate | ||
|
|
||
| Semantic validation using the GenLayer SDK (~200ms). Requires downloading GenVM artifacts. | ||
|
|
||
| ```bash | ||
| USAGE: | ||
| genvm-lint validate <contract.py> [options] | ||
|
|
||
| OPTIONS: | ||
| --json Output results in JSON format | ||
|
|
||
| EXAMPLES: | ||
| genvm-lint validate my_contract.py | ||
| genvm-lint validate my_contract.py --json | ||
| ``` | ||
|
|
||
| **Validates:** | ||
| - Types exist in SDK | ||
| - Decorators correctly applied | ||
| - Storage fields have valid types | ||
| - Method signatures correct | ||
|
|
||
| ### schema | ||
|
|
||
| Extract the ABI schema from an Intelligent Contract. | ||
|
|
||
| ```bash | ||
| USAGE: | ||
| genvm-lint schema <contract.py> [options] | ||
|
|
||
| OPTIONS: | ||
| --json Output results in JSON format | ||
| --output <file> Write schema to file | ||
|
|
||
| EXAMPLES: | ||
| genvm-lint schema my_contract.py | ||
| genvm-lint schema my_contract.py --json | ||
| genvm-lint schema my_contract.py --output abi.json | ||
| ``` | ||
|
|
||
| ### download | ||
|
|
||
| Pre-download GenVM artifacts for offline validation. | ||
|
|
||
| ```bash | ||
| USAGE: | ||
| genvm-lint download [options] | ||
|
|
||
| OPTIONS: | ||
| --version <version> Download a specific version | ||
| --list Show cached versions | ||
|
|
||
| EXAMPLES: | ||
| genvm-lint download # Download latest | ||
| genvm-lint download --version v0.2.12 # Download specific version | ||
| genvm-lint download --list # Show cached versions | ||
| ``` | ||
|
|
||
| ## Output Formats | ||
|
|
||
| ### Human-readable (default) | ||
|
|
||
| ``` | ||
| ✓ Lint passed (3 checks) | ||
| ✓ Validation passed | ||
| Contract: MyContract | ||
| Methods: 26 (16 view, 10 write) | ||
| ``` | ||
|
|
||
| ### JSON (--json flag) | ||
|
|
||
| ```json | ||
| { | ||
| "ok": true, | ||
| "lint": { | ||
| "ok": true, | ||
| "passed": 3 | ||
| }, | ||
| "validate": { | ||
| "ok": true, | ||
| "contract": "MyContract", | ||
| "methods": 26, | ||
| "view_methods": 16, | ||
| "write_methods": 10, | ||
| "ctor_params": 5 | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Error Output (JSON) | ||
|
|
||
| When validation fails: | ||
|
|
||
| ```json | ||
| { | ||
| "ok": false, | ||
| "lint": { | ||
| "ok": false, | ||
| "errors": [ | ||
| { | ||
| "code": "E001", | ||
| "message": "Forbidden import: random", | ||
| "line": 3 | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Exit Codes | ||
|
|
||
| | Code | Description | | ||
| |------|-------------| | ||
| | `0` | All checks passed | | ||
| | `1` | Lint or validation errors | | ||
| | `2` | Contract file not found | | ||
| | `3` | SDK download failed | | ||
|
|
||
| ## Common Lint Errors | ||
|
|
||
| ### Forbidden Imports | ||
|
|
||
| The following modules are forbidden in Intelligent Contracts as they introduce non-determinism: | ||
|
|
||
| - `random` - Use `gl.random` instead | ||
| - `os`, `sys`, `subprocess` - System access not allowed | ||
| - `socket`, `urllib`, `requests` - Use `gl.get_webpage()` instead | ||
| - `time`, `datetime` - Use `gl.block_timestamp` instead | ||
|
|
||
| ### Non-deterministic Patterns | ||
|
|
||
| - **Float usage**: Floating-point arithmetic can produce different results across validators. Use `Decimal` or integer math. | ||
| - **Dictionary iteration**: In Python < 3.7, dict ordering was non-deterministic. Use `sorted()` when iterating. | ||
|
|
||
| ## Integration Examples | ||
|
|
||
| ### CI/CD Pipeline | ||
|
|
||
| ```yaml | ||
| # GitHub Actions example | ||
| - name: Validate contracts | ||
| run: | | ||
| pip install genvm-linter | ||
| genvm-lint check contracts/*.py --json | ||
| ``` | ||
|
|
||
| ### Pre-commit Hook | ||
|
|
||
| ```yaml | ||
| # .pre-commit-config.yaml | ||
| repos: | ||
| - repo: local | ||
| hooks: | ||
| - id: genvm-lint | ||
| name: GenVM Linter | ||
| entry: genvm-lint check | ||
| language: python | ||
| files: \.py$ | ||
| additional_dependencies: ['genvm-linter'] | ||
| ``` | ||
|
|
||
| ### Programmatic Usage | ||
|
|
||
| ```python | ||
| import subprocess | ||
| import json | ||
|
|
||
| result = subprocess.run( | ||
| ['genvm-lint', 'check', 'my_contract.py', '--json'], | ||
| capture_output=True, | ||
| text=True | ||
| ) | ||
|
|
||
| validation = json.loads(result.stdout) | ||
| if not validation['ok']: | ||
| print("Validation failed:", validation) | ||
| ``` | ||
|
|
||
| ## Related Tools | ||
|
|
||
| - [GenLayer Test](/api-references/genlayer-test) - Testing framework for Intelligent Contracts | ||
| - [GenLayer CLI](/api-references/genlayer-cli) - CLI for deploying and managing contracts | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
GenLayer SDK minimum Python version requirement💡 Result:
The GenLayer Python SDK published on PyPI as
genlayer-pyrequires Python >= 3.12 (so the minimum supported version is Python 3.12). [1]Note: there is also a PyPI package named
genlayer-sdk, but it’s described as a “minimal empty” placeholder package and lists Python >= 3.6. [2]Sources: [1] [2]
🏁 Script executed:
Repository: genlayerlabs/genlayer-docs
Length of output: 52
🏁 Script executed:
Repository: genlayerlabs/genlayer-docs
Length of output: 101
🏁 Script executed:
Repository: genlayerlabs/genlayer-docs
Length of output: 610
Remove outdated Python version reference.
Line 188 warns about dictionary ordering in Python < 3.7, but GenLayer SDK requires Python >= 3.12 and project boilerplate requires Python 3.8+. Dictionary ordering is guaranteed in Python 3.7 and later per PEP 468, making this warning irrelevant. Either remove this bullet point or replace it with guidance relevant to GenLayer's actual minimum Python version.
🤖 Prompt for AI Agents