Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Formatter #241

Merged
merged 10 commits into from
Mar 31, 2020
Merged

feat: Formatter #241

merged 10 commits into from
Mar 31, 2020

Conversation

sh0rez
Copy link
Member

@sh0rez sh0rez commented Mar 18, 2020

Adds a tk fmt command that basically exposes what's know as
jsonnetfmt: A formatter for Jsonnet.

Did some work around actually finding files to format, think it looks good.

Semantics:

  • only works on .jsonnet and .libsonnet, unless specified explicitely
  • ignores hidden files, and vendor
  • tk fmt <directory>: reformat every jsonnet file recursively
  • tk fmt <file>: reformat that file
  • tk fmt --stdout: print to stdout instead of writing to disk
  • tk fmt --test: exit with non-zero in case of differences. Does not
    touch files

@sh0rez sh0rez added the kind/feature Something new should be added label Mar 18, 2020
@sh0rez sh0rez requested a review from rfratto March 18, 2020 18:55
Adds a `tk fmt` command that basically exposes what's know as
`jsonnetfmt`: A formatter for Jsonnet.

Did some work around actually finding files to format, think it looks good.

Semantics:

- only works on `.jsonnet` and `.libsonnet`, unless specified explicitely
- ignores hidden files, and `vendor`
- `tk fmt <directory>`: reformat every jsonnet file recursively
- `tk fmt <file>`: reformat that file
- `tk fmt --inplace=false`: print to stdout instead of writing
- `tk fmt --test`: exit with non-zero in case of differences. Does not
  touch files
@malcolmholmes
Copy link
Contributor

I tried this on an un-linted Jsonnet codebase. Running tk fmt did nothing. tk fmt lib did nothing. tk fmt --help gave me help output, suggesting I'm using the right version. Is this my mistake, or a fault with the code?

@sh0rez
Copy link
Member Author

sh0rez commented Mar 19, 2020

I tried this on an un-linted Jsonnet codebase. Running tk fmt did nothing. tk fmt lib did nothing. tk fmt --help gave me help output, suggesting I'm using the right version. Is this my mistake, or a fault with the code?

Added some more bad usage handling and a verbose mode:

  • it now fails when not specifying anything
  • --verbose / -v prints all files and whether they are reformatted
  • prints a message if all files are already okay

Makes init properly format the k.libsonnet it creates
Improves the experience of using `tk fmt` by providing better output:

- notice how many files were formatted
- notice if nothing has been done
@sh0rez
Copy link
Member Author

sh0rez commented Mar 26, 2020

ping @malcolmholmes @rfratto, had success using this the last week, sb wanna approve?

@malcolmholmes
Copy link
Contributor

Completion: tk fmt e<tab> gives tk fmt env not environments. Why?

@malcolmholmes
Copy link
Contributor

This shouldn't block, but the thing that is missing for me is a "lint diff". i.e. show me what you would change. --stdout (which should have a short switch) doesn't tell me what changed (other than the number of files). Otherwise, this seems to be behaving as described.

upgrades go-clix to v0.1.1
@sh0rez
Copy link
Member Author

sh0rez commented Mar 31, 2020

Completion: tk fmt e<tab> gives tk fmt env not environments. Why?

because go-clix@v0.1.0 had an issue, fixed it in go-clix@v0.1.1

Changes from sh0rez/go-jsonnet are merged in upstream now
@sh0rez sh0rez merged commit 17d91dc into master Mar 31, 2020
@sh0rez sh0rez deleted the fmt branch March 31, 2020 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Something new should be added
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants