-
Notifications
You must be signed in to change notification settings - Fork 0
LP Linter
HuyHAP edited this page Mar 19, 2026
·
3 revisions
LP Linter is a static analysis tool for LP language, similar to pylint, flake8, mypy for Python.
# Check LP file
python tools/lp_linter.py myfile.lp
# Or use wrapper script
./tools/lp-check myfile.lp| Flag | Description |
|---|---|
--strict |
Enable strict mode (check style) |
--json |
Output results as JSON |
--quiet |
Show only errors (no warnings) |
--no-color |
Disable colored output |
# Strict mode
python tools/lp_linter.py myfile.lp --strict
# JSON output
python tools/lp_linter.py myfile.lp --json
# Only errors
python tools/lp_linter.py myfile.lp --quiet| Code | Description | Example |
|---|---|---|
| E001 | Unknown module | import unknown_module |
| E002 | Unknown type | x: foobar = 1 |
| E003 | Missing type annotation | def f(x): pass |
| E004 | Using None instead of null
|
x = None |
| E005 | Type ptr not allowed |
x: ptr = ... |
| E006 | Missing : after keyword |
if x > 5 |
| E007 | Common typo | printl("hi") |
| E008 | Missing dsa.flush()
|
When using dsa.write_*
|
| E009 | DSA output without flush | When using dsa module |
| Code | Description |
|---|---|
| W001 | Assignment in if (did you mean ==?) |
| W002 | Function defined but never called |
| Code | Description |
|---|---|
| S001 | Line too long (> 100 chars) |
| S002 | Trailing whitespace |
| S003 | Multiple spaces around operator |
π Found 3 issue(s): 2 error(s), 1 warning(s), 0 style
β [E004] Line 5:7: Use 'null' instead of 'None' in LP
π‘ Suggestion: Replace 'None' with 'null'
β [E008] Line 10:1: dsa module requires dsa.flush() before program exit
π‘ Suggestion: Add 'dsa.flush()' at the end of your program
β οΈ [W002] Line 3:1: Function 'main/solve' defined but never called
π‘ Suggestion: Add 'main()' or 'solve()' at the end of the file
[
{
"line": 5,
"col": 7,
"code": "E004",
"severity": "ERROR",
"message": "Use 'null' instead of 'None' in LP",
"suggestion": "Replace 'None' with 'null'"
}
]import dsa
def solve() -> int:
n: int = dsa.read_int()
dsa.write_int_ln(n * 2)
dsa.flush() # β Correct: has flush()
return 0
solve() # β Correct: calls functionimport dsa
def solve() -> int:
n: int = dsa.read_int()
arr: list = None # β E004: Using None
dsa.write_int_ln(n * 2)
# β E008: Missing dsa.flush()
return 0
# β W002: Not calling solve()Add to settings.json:
{
"files.associations": {
"*.lp": "lp"
},
"terminal.integrated.commandsToRun": [
"python tools/lp_linter.py ${file}"
]
}" Add to .vimrc
autocmd BufWritePost *.lp :!python tools/lp_linter.py %Create file .git/hooks/pre-commit:
#!/bin/bash
for file in $(git diff --cached --name-only | grep '\.lp$'); do
python tools/lp_linter.py "$file" --quiet
if [ $? -ne 0 ]; then
echo "Linter found errors in $file"
exit 1
fi
done-
Always run linter before compiling
python tools/lp_linter.py myfile.lp && lp myfile.lp -
Use
--strictfor production codepython tools/lp_linter.py myfile.lp --strict
-
Integrate into CI/CD
# GitHub Actions - name: Lint LP files run: python tools/lp_linter.py src/*.lp --strict
| Python | LP |
|---|---|
pylint file.py |
python tools/lp_linter.py file.lp |
flake8 file.py |
python tools/lp_linter.py file.lp --strict |
mypy file.py |
Type checking built into linter |
black file.py |
No formatter yet |
# 1. Write code
vim solution.lp
# 2. Run linter
python tools/lp_linter.py solution.lp --strict
# 3. Fix errors
# 4. Compile
lp solution.lp -c solution
# 5. Test
./solution < input.txt
# 6. Commit
git add solution.lp
git commit -m "Add solution"Back to Home | GitHub Repo | Issues
- Home
- Installation and Setup
- First Programs
- Language Basics
- Quick Reference
- Troubleshooting
- Known Limitations
- Language Reference
- Expressions and Collections
- Object-Oriented Programming
- Error Handling
- Feature Overview
- Feature Status
- Runtime Modules
- Concurrency and Parallelism
- Parallel and GPU Computing
- Security Overview
- Security Reference
- Security Calling Patterns
- Native ASM is the default backend.
- On Windows, prefer
--gccfor verification. - Docs are written against verified current behavior.