Giter Club home page Giter Club logo

nimfmt's Introduction

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

nimfmt's People

Contributors

bung87 avatar federicoceratto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nimfmt's Issues

Unable to install nimfmt

I'm running nim version 1.4.0, as installed by choosenim on linux.

Running this command:

nimble install compiler@#head

Doesn't seem to install nimfmt

Trying to install nimfmt from github with this command:

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

Has this error:

   Building nimfmt/nimfmt using c backend
/tmp/nimble_33447/githubcom_FedericoCerattonimfmt/nimfmt.nim(30, 31) Error: undeclared identifier: 'setupParsers'
       Tip: 351 messages have been suppressed, use --verbose to show them.
     Error: Build failed for package: nimfmt
        ... Execution failed with exit code 1
        ... Command: /home/david/.nimble/bin/nim c --colors:on --noNimblePath -d:release -d:NimblePkgVersion=0.1.0 --path:'/home/david/.nimble/pkgs/compiler-#head' --hints:off -o:/tmp/nimble_33447/githubcom_FedericoCerattonimfmt/nimfmt /tmp/nimble_33447/githubcom_FedericoCerattonimfmt/nimfmt.nim

I get a similar error with this command, but with fewer suppressed messages:

nimble install https://github.com/FedericoCeratto/nimfmt@#head
   Building nimfmt/nimfmt using c backend
/tmp/nimble_33775/githubcom_FedericoCerattonimfmt_#head/nimfmt.nim(30, 31) Error: undeclared identifier: 'setupParsers'
       Tip: 5 messages have been suppressed, use --verbose to show them.
     Error: Build failed for package: nimfmt
        ... Execution failed with exit code 1
        ... Command: /home/david/.nimble/bin/nim c --colors:on --noNimblePath -d:release -d:NimblePkgVersion=0.1.0 --path:'/home/david/.nimble/pkgs/compiler-#head' --hints:off -o:'/tmp/nimble_33775/githubcom_FedericoCerattonimfmt_#head/nimfmt' '/tmp/nimble_33775/githubcom_FedericoCerattonimfmt_#head/nimfmt.nim'

Make hint message optional trough a flag or write it to stderr

Hi, just before anything thanks for your work, I'm trying to use nimfmt but despite the hint provided due to the lack of a config file, that is easy to adress creating it, I think it would be better for the tool to display said message to stderr or maybe disable it with a flag, best regards.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.