SCR001: syntax-error
Script does not parse with Jython 2.7
| Code | SCR001 |
| Name | syntax-error |
| Category | Scripts (SCR) |
| Default severity | error |
| Enabled by default | yes |
| Fix available | no |
| ign-lint equivalent | none |
What it does
Section titled “What it does”Reports scripts that Jython 2.7 (Ignition 8.3's interpreter) refuses to
parse, at the first error, with Jython's message. Python 3-only syntax
(print(x, end="") without the future import, f"..." strings, nonlocal,
except E as e is fine but raise ... from ... is not) gets a hint.
The script is checked as Ignition compiles it: Perspective scripts inside
their generated def header (def runAction(self, event): and so on),
gateway event files with their canonical header, library modules as
written.
Two Ignition-specific cases, verified on an 8.3 gateway:
- An encoding declaration (
# -*- coding: utf-8 -*-) in the first two lines of the compiled source is a syntax error, because Ignition compiles scripts from text (SyntaxError: encoding declaration in Unicode string). In Perspective scripts and event files the first body line is line 2 of the compiled source. - A UTF-8 byte order mark at the start of a library module or event file is
not skipped (
no viable alternative at character '\ufeff').
Empty Perspective scripts are reported by VIEW008 instead. Empty
disabled scripts are not reported: the Designer writes a header-only
do<Method>.py stub for every disabled WebDev method, and Ignition does
not compile disabled scripts. A WebDev handler linted outside its project
is still read with its resource's config.json; without one, whether the
method is enabled is unknown and a header-only stub is not reported.
Why is this bad?
Section titled “Why is this bad?”A script that does not parse never runs: the event does nothing, the transform yields an error quality, the library module cannot be imported by anything.
Example
Section titled “Example”def onStartup(session): print "starting", session.props.id if session.props.auth.authenticated system.perspective.navigate("/home")Use instead:
def onStartup(session): print "starting", session.props.id if session.props.auth.authenticated: system.perspective.navigate("/home")Generated from the rule metadata by iglint generate-docs; iglint rule SCR001 prints the same page in the terminal. Source: docs/rules/SCR001.md.