No description
Find a file
Federico Ceratto 8fe9829e66 Version 0.2.0
Add compiler dep back
2021-12-29 13:07:58 +00:00
test Add test 2021-12-29 13:03:50 +00:00
.gitignore update to current nim version 2020-11-07 20:10:33 +08:00
LICENSE Rebase onto nimpretty, update for Nim 1.0.0 2019-10-08 23:15:49 +01:00
nim.cfg Remove flag 2021-12-29 13:03:37 +00:00
nimfmt.nim update to current nim version 2020-11-07 20:10:33 +08:00
nimfmt.nimble Version 0.2.0 2021-12-29 13:07:58 +00:00
README.adoc Update deps and install instructions 2021-12-29 12:55:06 +00:00

=== Nim code formatter / style checker

.Features
* [x] Detect inconsistent variable and proc naming
* [x] Fix inconsistent variable and proc naming
* [x] 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:
[source,nim]
----
# 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:
[source,nim]
----
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:
[source,nim]
----
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

[source,bash]
----
  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

[source,bash]
----
nimble install https://github.com/FedericoCeratto/nimfmt
----