Keywords return and throw should be immediately followed by a semicolon or a single space

# T006

# Keywords return and throw should be immediately followed by a semicolon or a single space

Description:

The `return` and `throw` keywords should be immediately followed by a semicolon or a single space:

    void fun()
    {
         if (...)
         {
              return;
         }
         // ...
    }

    int add(int a, int b)
    {
         return a + b;
    }

An exception to this rule is allowed for exeption specifications:

    void fun() throw();

Compliance: Inspirel

Show source code for this rule

Hide source code

    # Keywords return and throw should be immediately followed by a semicolon or a single space

    foreach f [getSourceFileNames] {
        foreach t [getTokens $f 1 0 -1 -1 {return throw}] {
            set keyword [lindex $t 0]
            set line [lindex $t 1]
            set column [lindex $t 2]
            set followingTokens [getTokens $f $line [expr $column + [string length $keyword]] [expr $line + 1] 0 {}]
            if {$followingTokens == {}} {
                report $f $line "keyword '${keyword}' not immediately followed by a semicolon or a single space"
            } else {
                set first [lindex [lindex $followingTokens 0] 0]
                if {$first != ";" && $first != " " && !($keyword == "throw" && $first == "(")} {
                    report $f $line "keyword '${keyword}' not immediately followed by a semicolon or a single space"
                }
            }
        }
    }

Rule index