pyjslint - JSLint Wrapper
pyjslint is a Python wrapper for JSLint, designed to integrate JavaScript linting into Python projects. It bundles an old version of JSLint and appears to be unmaintained. The current version is 0.3.4, released in 2013, indicating an abandoned project.
Common errors
-
ModuleNotFoundError: No module named 'pyjslint.pyjslint'
cause Incorrect import path used for the `PyJsLint` class.fixThe class is nested within a submodule. Change `from pyjslint import PyJsLint` to `from pyjslint.pyjslint import PyJsLint`. -
SyntaxError: Missing parentheses in call to 'print'
cause This error typically occurs when running Python 2 code on a Python 3 interpreter, as `print` became a function in Python 3.fixThis specific `SyntaxError` (and others) indicate fundamental incompatibility with Python 3. The library is unmaintained and not updated for Python 3. There is no simple fix other than to abandon `pyjslint` for a modern alternative or run it in a Python 2 environment (not recommended for new projects). -
AttributeError: 'NoneType' object has no attribute 'get'
cause Attempting to access attributes on the result of `linter.lint()` without checking if it returned `None`.fixThe `lint()` method returns `None` if no errors are found, or a list of dictionaries if errors are present. Always check for `None` before attempting to iterate or access elements: `result = linter.lint(code); if result: for error in result: ...`.
Warnings
- breaking Project is abandoned and unmaintained since 2013. Expect no new features, bug fixes, or compatibility updates.
- gotcha The bundled JSLint version is severely outdated (from 2013 or earlier). It will not understand modern JavaScript syntax (ES6+, ES2015+) and its linting rules are not configurable to modern standards.
- gotcha Potential Python 3 compatibility issues. The package was released when Python 2 was prevalent, and it has `requires_python: None`.
Install
-
pip install pyjslint
Imports
- PyJsLint
from pyjslint import PyJsLint
from pyjslint.pyjslint import PyJsLint
Quickstart
from pyjslint.pyjslint import PyJsLint
# Example JavaScript code to lint
code_to_lint = """
var a = 1;
var b = 2;
var c = a + b // Missing semicolon, will be flagged
"""
# Initialize the linter
linter = PyJsLint()
# Lint the code
result = linter.lint(code_to_lint)
if result:
print("Linting errors found:")
for error in result:
print(f" Line {error.get('line')}, Character {error.get('character')}: {error.get('reason')}")
else:
print("No linting errors.")