-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
Description
Description
Implements native code formatting functionality similar to gofmt/gofumpt as a built-in feature.
Commands
Basic Format Command
tlin fmt [flags] [path...]
Formats the code in the specified paths. If no path is specified, it reads from stdin.
Flags
General Options
-l, --list- List files that would be reformatted
- Does not actually format the files
-w, --write- Write formatted content to source files
- Without this flag, prints to stdout
-d, --diff- Display diffs of formatting changes
-s, --simplify- Simplify code where possible (like gofumpt)
Style Options
--indent-style=<tab|space>- Indentation style (default: tab)
--indent-width=<n>- Number of spaces per indentation level when using spaces (default: 4)
--line-length=<n>- Maximum line length (default: 100)
--no-rewrite-imports- Disable import block rewriting/reordering
Examples
# Format a single file
tlin fmt file.gno
# Format and overwrite multiple files
tlin fmt -w file1.gno file2.gno
# Format all Go files in current directory and subdirectories
tlin fmt -w .
# Show formatting changes without applying them
tlin fmt -d file.gno
# List files that need formatting
tlin fmt -l .
# Format using spaces instead of tabs
tlin fmt --indent-style=space file.gno
# Format with simplified code style
tlin fmt -s file.gnoBehavior
Code Simplification (-s flag)
Integrate with auto fixer
When the -s flag is used, the formatter will apply additional simplifications similar to gofumpt:
-
Standardize empty lines
- Single empty line between functions
- No empty lines at start/end of block
- Group related blocks with empty lines
-
Import blocks
- Sort imports into groups (standard library, external, internal. related with: RFC: suggested import organization: separate by network or by purpose? gnolang/gno#3521)
- Remove unnecessary parentheses in import blocks
- Standardize import aliases
-
Code patterns
- Remove redundant type declarations
- Simplify redundant boolean expressions
- Use short variable declarations where possible
Exit Codes
- 0: Success (no formatting changes needed or changes applied successfully)
- 1: Syntax errors in input
- 2: Usage error (invalid flags, etc.)
Configuration
The formatter can be configured through .tlin.yaml configuration file:
formatter:
indent-style: tab
indent-width: 4
line-length: 100
simplify: false
rewrite-imports: trueCommand line flags take precedence over configuration file settings.