Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/FedericoCeratto/nimfmt
Nim code formatter / linter / style checker
https://github.com/FedericoCeratto/nimfmt
linter nim nim-lang nimfmt
Last synced: 3 months ago
JSON representation
Nim code formatter / linter / style checker
- Host: GitHub
- URL: https://github.com/FedericoCeratto/nimfmt
- Owner: FedericoCeratto
- License: gpl-3.0
- Created: 2016-12-19T23:58:03.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2021-12-29T13:09:08.000Z (almost 3 years ago)
- Last Synced: 2024-01-23T02:48:39.538Z (10 months ago)
- Topics: linter, nim, nim-lang, nimfmt
- Language: Nim
- Homepage:
- Size: 29.3 KB
- Stars: 79
- Watchers: 5
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.adoc
- License: LICENSE
Awesome Lists containing this project
- static-analysis - nimfmt
README
=== 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 blocksOne 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.cfgConfiguration 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 [ ... ]
[ -p ] output file prefix
[ -s ] output file suffix
[ -c , ] 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 helpIf 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
----