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.

Netzwerk
Try

Tcl 8.4 can load it. 0 errors, 7 warnings, 3 notes.

12 lines; the longest has 73 characters.

Events and priorities

  • HTTP_REQUEST line 1 no priority

The rule, lines marked

when HTTP_REQUEST {
⇥ if {[HTTP::uri] eq "/old"} { HTTP::redirect "https://[HTTP::host]/new" }
set n [expr $count + 1] ;# bump
switch [HTTP::path] {
"/a" { pool a_pool }
default { pool web_pool }
}
if { $a and $b } {
#log local0. "debug"
set static::flag 1
}
}

Findings

  1. 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.

  2. 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.

  3. 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.

  4. warningR6line 3Comments
    set n [expr $count + 1] ;# bump

    An end-of-line comment. Put comments on their own line, at the indent of the code.

  5. warningR12line 3Braced expressions
    set n [expr $count + 1] ;# bump

    An 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.

  6. 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).

  7. 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.

  8. 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.

  9. noteR20line 9No commented-out code
    #log local0. "debug"

    Commented-out code. Remove it before the rule goes to production.

  10. noteR18line 10Prefixed static:: names
    set static::flag 1

    static::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.

API endpointGEThttps://ronutz.com/api/v1/f5-irules-style-checkerDocumented, not served. Opens the specification.

Referenzen

Appears in these workflows