iRules style checker
Paste an iRule and read it against the DevCentral iRules Style Guide: indentation, braces, comments, braced expressions, switch --, event priorities, static:: names and more, plus a real Tcl 8.4 syntax check. Parsed, never run. Local, no network.
NetzwerkTcl 8.4 can load it. 0 errors, 7 warnings, 3 notes.
12 lines; the longest has 73 characters.
Events and priorities
HTTP_REQUESTline 1 no priority
The rule, lines marked
Findings
- warningR16line 1Event priority
when HTTP_REQUEST {The event HTTP_REQUEST has no priority. The guide asks for one on every event; the default is 500.
- warningE1line 2Indentation
if {[HTTP::uri] eq "/old"} { HTTP::redirect "https://[HTTP::host]/new" }A tab character. The guide asks for 4-space indents and no tabs.
- warningR8line 2No single-line if
if {[HTTP::uri] eq "/old"} { HTTP::redirect "https://[HTTP::host]/new" }A single-line if. Spread it over several lines, even for a debug log.
- warningR6line 3Comments
set n [expr $count + 1] ;# bumpAn end-of-line comment. Put comments on their own line, at the indent of the code.
- warningR12line 3Braced expressions
set n [expr $count + 1] ;# bumpAn expression that is not braced: $count + 1. An unbraced expression is substituted twice (an injection risk, F5 K57410758) and cannot be compiled ahead; brace it.
- warningR15line 4Option terminator --
switch [HTTP::path] {switch without -- before its value. A value that starts with a dash would be read as an option (F5 K15650046).
- warningR10line 8Tcl logical operators
if { $a and $b } {One of F5's word operators (and, or, not). Use the Tcl operators &&, || and !, with parentheses to make the grouping plain.
- noteR14line 8Braced variable names
if { $a and $b } {A variable in an expression written without braces around its name. The guide writes the name in braces after the dollar sign.
- noteR20line 9No commented-out code
#log local0. "debug"Commented-out code. Remove it before the rule goes to production.
- noteR18line 10Prefixed static:: names
set static::flag 1static::flag has no prefix. Prefix static:: names, for example with the rule's name, so two rules cannot collide.
The checker reads structure and text, never runs the rule. Where it cannot be sure (for example whether a line starting with a hash is code or a comment missing its space) the finding is a note, not a warning. D1 and D2 come from the guide's comment thread, and characters are named from the Unicode Character Database 18.0.0.
Referenzen
- F5 DevCentral: iRules Style Guide (JRahm with Jim_Deucker, 2022-12-22)
- F5 K15650046: Tcl code injection security exposure
- F5 K57410758: warning [use curly braces to avoid double substitution]
- F5 iRules reference: priority
- F5 iRules reference: table
- F5 iRules reference: How To Write Fast Rules
- F5 K9204: iRules are limited to 65,520 characters
- F5 iRules reference: return
- Tcl 8.4 manual: break
- Tcl 8.4 manual: continue
- Tcl 8.4 manual: switch
- F5 K6091: The version of Tcl used to develop iRules
- Tcl 8.4.6 source code, tag core-8-4-6 on GitHub
- Unicode Character Database 18.0.0: UnicodeData.txt
- Unicode Character Database 18.0.0: PropList.txt
- Unicode Character Database 18.0.0: DerivedCoreProperties.txt