Features

  • Written in pure Tcl/Tk. No compilation. If you can run Tcl you can run Nagelfar.

  • Extendible. You can add to the syntax database, or let the tool use Tcl’s introspection to extract syntax information from any Tcl interpreter. Thus you can test scripts for applications using Tcl as script language.

  • Plugins. Even more extendible through plugins that can hook up at certain points in the check flow and do custom checking.

  • Severity level filter and glob matching filters to remove errors known to be OK.

  • View and edit the checked source directly in Nagelfar.

  • Inline comments can help Nagelfar do a better job.

  • Code coverage instrumentation. Provides help for simple code coverage analysis.

Example

To get a feeling of what it can do, here is a test script that is part of the distribution with errors it can detect, and the output from the tool.

Test File The result of checking it:
  1  proc apa {} {
  2  
  3      set bepa 1
  4      # Detect missing $
  5      set cepa bepa
  6      # Detect unknown or misspelled variable
  7      set depa $cep
  8      set epa
  9      # Detect bad $
 10      set $depa apa
 11      if {[info exists $cepa]} {
 12          # Detect wrong number of args
 13          set apa bepa cepa
 14      }
 15      # Detect ugly if
 16      if {$bepa == $cepa} {
 17          set hej 1
 18      } elsif {$bepa == $cepa} {
 19          set hej 2
 20      } else {
 21          set hej 3
 22      }
 23      # Detect bad subcommand
 24      info gurka
 25  
 26      # Detect bad switch comment
 27      switch $bepa {
 28          hej {
 29              set hej hopp
 30          }
 31          # This is bad
 32          hopp {
 33              # Detect a missing command
 34              miffo
 35          }
 36      }
 37  }
 38  
 39  # Test call-by-name handling
 40  # The syntax of this proc is described in
 41  # the file test.syntax
 42  proc copy {srcName dstName} {
 43      upvar $srcName src $dstName dst
 44      set dst $src
 45  }
 46  
 47  proc testCopy {} {
 48      set apa 1
 49      # It should not warn about apa below
 50      copy apa bepa
 51      # Bepa should be known now
 52      set cepa $bepa
 53  
 54      # Detect $ mistake
 55      copy apa $bepa
 56      copy $apa bepa
 57  }
 58  
 59  proc bepa {} {
 60      # Missing quote
 61      set apa "hej hopp
 62  }
 63  # A quote just to fix syntax coloring "
 64  
 65  proc cepa {} {
 66      # Missing bracket
 67      set apa [hej hopp
 68  }
 69  
 70  proc epa {} {
 71      # Extra close brace
 72      if {[string length apa}} {
 73          set bepa 1
 74      }
 75  }
 76  
 77  proc fepa {} {
 78      # Commented brace {
 79      if {[string length apa]} {
 80          set bepa 1
 81      }
 82  }
 83  }
 84  
 85  # This should be last in the file, since
 86  # the missing close brace disturbs anything
 87  # after it
 88  proc depa {} {
 89      # Missing close brace
 90      if {[string length apa] {
 91          set bepa 1
 92      }
 93  }
Parsing file test.syntax
Checking file test.tcl


Line   5: W Found constant "bepa" which is also a variable.

Line   7: E Unknown variable "cep"
Line   8: E Unknown variable "epa"

Line  10: N Suspicious variable name "$depa"
Line  11: N Suspicious variable name "$cepa"

Line  13: E Wrong number of arguments (3) to "set"
Line  13: W Found constant "bepa" which is also a variable.
Line  13: W Found constant "cepa" which is also a variable.


Line  18: E Badly formed if statement
            Found argument 'elsif' where else/elseif was expected.




Line  24: E Unknown subcommand "gurka" to "info"






Line  31: W Switch pattern starting with #. This could be a bad comment.
Line  31: W Unknown command "This"
Line  31: W Unknown command "bad"
Line  34: W Unknown command "miffo"




















Line  55: N Suspicious variable name "$bepa"
Line  56: N Suspicious variable name "$apa"




Line  61: E Could not complete statement.
            One double quote would complete the first line
            One double quote would complete the script body at line 62.



Line  67: E Could not complete statement.
            One close bracket would complete the first line
            One close bracket would complete the script body at line 68.
Line  70: E Wrong number of arguments (4) to "proc"
            Argument 4 at line 72
Line  72: E Wrong number of arguments (1) to "if"


Line  75: E Unbalanced close brace found






Line  82: E Unbalanced close brace found
            Unbalanced brace in comment in line 78.




Line  88: E Could not complete statement.
            One close brace would complete the first line
            One close brace would complete at end of line 93.
            One close brace would complete the script body at line 94.
            Assuming completeness for further processing.
Line  90: E Wrong number of arguments (1) to "if"
Line  93: N Close brace not aligned with line 90 (4 0)