Crystal: format tool does not ignore ./libs

Created on 6 Sep 2016  路  8Comments  路  Source: crystal-lang/crystal

When using a project with dependencies, crystal deps will end up installing files in ./libs.
This prevents using $ crystal tool format --check to check the whole source code as part of the ci in projects with dependencies.

proposals:

  • a) ./libsshould be excluded. (fixed)
  • b) add --exclude PATTERN with default to exclude ./libs
  • c) add --exclude PATTERN with no default

I reach this while trying to add the format --check to crystal-mysql

feature topicformatter

Most helpful comment

I also vote for skippling libs

All 8 comments

may be create config file .crystal in project home when crystal generate it. and add option by default

formatter:
  exclude:
    - ./libs

this allow, to add more options later

Right, some of the options should be considered.

As a workaround you can try to see if crystal tool format src --check works in this case.

Yes, I can split the check per directory.

crystal tool format src --check
crystal tool format spec --check

(or force formatting in dependable project, as long as it can be applied)
But it's just a use case that is not polished: formatter + deps.

You can also pass multiple directories :-)

crystal tool format src spec --check

But I agree that maybe the default should skip libs.

I also vote for skippling libs

We can already specify a list of folders and files; the include argument feels redundant. Overall this looks complex for no real benefit

Why not just specify the folders to format? instead of specifying additional? What about defaulting to the standard locations (i.e. "src spec") instead of "." when no folders are specified?

I had this idea in #4635 (comment) as well (last item). For most basic projects this should be totally fine and would be easy to implement.

But with more complicated project setups this might not be sufficient. I'm thinking about formatting sample code in samples/ but ignoring samples/*/lib. I don't know if this is such a big use-case (at least I have it this way in crinja) and it might not be necessary to provide this feature directly but I feel like this should be possible somehow. An external solution would be to allow crystal tool format to receive a list of files from stdin. Then you could use find or other tools (like git ls-files) to provide a selection of files to format.

This has been fixed by #4635

Was this page helpful?
0 / 5 - 0 ratings