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

Is smol callable via CLI ? #27

Open
nvuillam opened this issue Sep 12, 2024 · 4 comments
Open

Is smol callable via CLI ? #27

nvuillam opened this issue Sep 12, 2024 · 4 comments

Comments

@nvuillam
Copy link

We are looking for a TOML linter to integrate within MegaLinter, and smol is a serious candidate :)

I don't see in the documentation a way to call it via CLI... is there one ?

If not, would it be considered adding one ?

Many thanks for your responses :)

@cyyynthia
Copy link
Member

Hi! smol-toml is only a library and does not provide a CLI currently. It is however trivial to use it via CLI using node -e "..." or by using a thin wrapper file.

For use as a linter, I see a few of blockers that may make this library limited, mostly:

  • There are currently no formatting options, and the output is "whatever was looking decent, able to serialize anything, and fast" (Is it possible to specify style? #13)
  • Inline tables are never produced (always produces a [table]or [[table]])
  • Comments are not preserved ([Feature Request] Get the comments of .toml #17)
  • Certain integer semantics are not preserved, as mentioned on the README: floats without a decimal part are serialized as integers (stringify(parse('a = 1.0')) === 'a = 1')

I do want to address these at some point, however there are a handful of unanswered questions about the internal design to preserve performance, simplicity of plain JS objects, and flexibility, so I don't really know when I'll get around addressing these (or how) 😅

@nvuillam
Copy link
Author

nvuillam commented Sep 13, 2024

@cyyynthia Thanks for your reply :)

We're looking for a TOML linter, not a formatter for now (it seems there is a prettier-toml anyway), so the linting capability would be enough :)

Would you eventually interested that someone makes a PR to CLI-ify your tool ? ( don't know who and where, just asking ^^ )

It shouldn't be that complicated using cosmiconfig :)

@cyyynthia
Copy link
Member

Well, this library is purely a parser/serializer and I can see the added value of a CLI tool, but I am quite happy about the library being zero-dependency which makes it very lightweight to install and use

Checking if a file has errors is really trivial (just a call to parse in a try/catch), so I'm not sure if it's worth having it here. Projects wanting to use it via CLI can most likely afford using a wrapper file, use Just shebang recipes, or node -e 🤔

@cyyynthia
Copy link
Member

FYI this is what I mean by using node -e:

$ node -e "try{require('smol-toml').parse('[a.x]\nz=')}catch(e){console.log(e.message);process.exit(0)}"
Invalid TOML document: incomplete key-value declaration: no value specified

1:  [a.x]
2:  z=
      ^

Which could be implemented as a very barebones "CLI" that uses a naive arg parser:

$ pnpx smol-toml [file.toml]
> Reads file.toml, and serializes it back to stdout (or errors if invalid)

$ pnpx smol-toml --to-json [file.toml]
> Reads file.toml, and serializes it as (pretty-printed) JSON to stdout (or errors if invalid)

$ pnpx smol-toml --to-toml [file.json]
> Reads file.json, and serializes it as TOML to stdout (or errors if invalid)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants