FedericoCeratto / nimfmt

Nim code formatter / linter / style checker

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nim code formatter / style checker

Features
  • ✓ Detect inconsistent variable and proc naming

  • ✓ Fix inconsistent variable and proc naming

  • ✓ Add/remove whitespaces and commas in function calls

  • ❏ Sort imports

  • ❏ Enforce variable/function naming style

  • Enforce whitelines (in fixed number or a range):

    • ❏ before functions

    • ❏ on closing blocks

    • ❏ end of file

    • ❏ around imports

  • ❏ Optional # to close blocks

One of the main features is to detect and correct inconsistent variable and function naming.

Using proc_naming_style = most_popular, if the same identifier appears within a file as myName more frequently and my_name and myname less frequently, nimfmt will pick the first one. This is the recommended setting to ensure consistency without having to explicitly configure nimfmt with a preferred style.

Using proc_naming_style = snake_case, if the same identifier appears as myName, my_name and myname, nimfmt will pick the second one.

Configuration

nimfmt looks for configuration files is the following order:
  • current directory

  • ~/.config/nimfmt.cfg

  • ~/.nimfmt.cfg

  • /etc/nimfmt.cfg

Configuration example:

# Fix inconsistent naming
# auto     - fix automatically
# no       - print warning only
fix_naming_style = "auto"

# Choose the correct naming
# most_popular  - pick the most frequently used naming style for a given identifier
# snake_case    - prefer snake_case naming if possible
proc_naming_style = most_popular

Examples

Input:

proc my_foo( a: string,  b:string,c:int, ): string  =
  raise newException ( Exception ,
    "foo" )
  foo ( a , b , c )
  d [ a ]  =  3
  discard    "string to discard"

  break
  return   "string to return"

Output:

proc my_foo(a: string; b: string; c: int): string =
  raise newException(Exception, "foo")
  foo(a, b, c)
  d[a] = 3
  discard "string to discard"
  break
  return "string to return"

Usage

  nimfmt <filename.nim> [<filename.nim> ... ]
  [ -p <prefix> ]     output file prefix
  [ -s <suffix> ]     output file suffix
  [ -c <filename>, ]  configuration file location(s) (default: ./.nimfmt.cfg ~/.nimfmt.cfg)
  [ -i ]              update files in-place (dangerous!)
  [ -w ]              overwrite existing files (automatically enabled when using -i)
  [-v]                version
  [-h]                this help

  If any of -p ..., -s ... or -i are specified the output will be written to disk,
  otherwise to stdout

Installation

nimble install https://github.com/FedericoCeratto/nimfmt

About

Nim code formatter / linter / style checker

License:GNU General Public License v3.0


Languages

Language:Nim 100.0%