Nim: nimpretty feature requests

Created on 27 Jul 2018  路  10Comments  路  Source: nim-lang/Nim

  • [x] nimpretty --margin=0 # means infinity (ie no line wrap); can pass any integer, eg 80, 120...
    EDIT this now exists: nimpretty --maxLineLen:N
  • [ ] nimpretty --fixcase=true # when true, changes case of identifiers to same case as symbol declaration, eg: splitlines will become splitLines because symbol declared as splitLines
  • [ ] nimpretty --safe # this one runs a subset of all transformations run by nimpretty that is known to work (eg, not break code)
  • [ ] use a git hook to give a warning when PR would generate a style violation; so PR author can fix it before it gets in hands of reviewer, see [1]; this requires git nimpretty to only consider style violations local to PR diff. Note that it should be a warning, not an error (eg when a PR has to move a block of code and it may be undesirable to nimpretty it for whatever reason, or if running nimpretty would somehow result in broken code due to a bug in nimpretty)
  • [x] nimpretty --tabwidth=2 # when set, changes tab width to requested value (useful when some source code uses tab width inconsistent with other code in a project)
    EDIT this now exists: nimpretty --indent:N

links

Feature nimpretty

Most helpful comment

Would it be possible to add support for stdin to stdout to nimpretty?

nimpretty - should read from stdin and write to stdout.

All 10 comments

Instead of --tabwidth you can fix the source file so that the first indentation uses the desired number of spaces. --margin is a bit against nimpretty's "zero configuration" philophy too. --fixcase will be though to support. ;-)

fixcase should instead support user-configurable styles (snake_case, camelCase, ...) at file and whole-project granularity

(moved from top-post for easy individual reference wo creating a new issue)

  • [ ] nimpretty --difflines:commit which is the exact analog of git clang-format which only applies formatting on lines that appear in the diff wrt commit This is very useful to apply formatting changes without creating un-necessary large diffs
    (especially when nimpretty changes its output over time; and it will)

Would it be possible to add support for stdin to stdout to nimpretty?

nimpretty - should read from stdin and write to stdout.

Also, nimpretty makes a mess of json %* macro code.

Also, nimpretty makes a mess of json %* macro code.

Can you please post an example (as a separate issue, ideally), because I was not able to reproduce the mess you mention?

@narimiran , see #11937.

Would it be possible to add support for stdin to stdout to nimpretty?

nimpretty - should read from stdin and write to stdout.

To compound this problem shell process substitution is broken because nimpretty renames input filepaths not ending in ".nim": nimpretty --out:/dev/stdout <(cat)

And complains cannot open /dev/fd/45.nim

Or /dev/stdin -> /dev/stdin.nim, for that matter.

nimfmt now implements a feature to fix casing with user-configurable parameters

nimpretty's --maxLineLen option addresses the first point of this Issue (I updated the issue accordingly)

Was this page helpful?
0 / 5 - 0 ratings