Tcl formatting

The formatter reads <workspace>/.linty/formatting.yml and formats the source file according to the rules below.

Note:

  • A file that does not parse is left unchanged.

  • After formatting, the original and formatted parse trees are compared. If they differ, the file is left unchanged.

Contents

Configuration

tcl:
  indentation: 2

indentation is the number of spaces in one level. If the file is missing, the key is missing, or the value is zero or not a positive integer, the indentation is 2.

vhdl:
  indentation: 4
verilog:
  indentation: 4
tcl:
  indentation: 4
proc foo {a} {
puts $a
if {$a} {
puts $a
}
}

becomes

proc foo {a} {
    puts $a
    if {$a} {
        puts $a
    }
}

Trailing spaces

Spaces at the end of a line are removed.

Tabs

Tabs are replaced with spaces.

Line endings

CRLF and CR line endings are written as LF.

Newline at the end of a file

A non-empty file ends with a newline.

Indentation

A command body is indented one level. The body of proc or namespace eval is a command body. So is each braced word of if, elseif, else, for, foreach, while, switch, eval, catch, and try. The line that opens the body stays at the current level. A line that starts with } is indented one level less for each such }, including } else { and } elseif.

proc foo {} {
if {1} {
puts a
} else {
puts b
}
}

becomes

proc foo {} {
  if {1} {
    puts a
  } else {
    puts b
  }
}

Comments

A # comment is indented with the code around it. The comment text is kept.

proc foo {} {
# comment
puts x
}

becomes

proc foo {} {
  # comment
  puts x
}