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

Alternative config format #336

Open
mgrebenets opened this issue Dec 30, 2018 · 10 comments
Open

Alternative config format #336

mgrebenets opened this issue Dec 30, 2018 · 10 comments

Comments

@mgrebenets
Copy link

mgrebenets commented Dec 30, 2018

Hi

This is a feature request for supporting alternative config format.
While plain text works, it lacks a few features, such as:

  • Detect syntax errors, e.g. if I type incorrect flag or add a space where there shouldn't be a space, etc.
  • Syntax highlight when editing
  • No out of the box support to parse config

As an example, using YAML would offer all of the above and more.

One other example where a yaml config would be better (in my opinion), is having a long list of exclude paths.

A mangled example:

--exclude archive,buck-out,build,Carthage,Doc,Docs,Documentation,path/xxxx/xxxX/Abcd/Xyz/Generated,path/xxxx/xxxX/Abcd/Storyboards,path/xxxx/xxxX/Abcd/Zyz/XYZ/Generated,path/xxxx/Pods,path/yyy/App/abcd/Generated,path/yyy/App/abcd/Templates,path/yyy/App/abcd/View/Ignore,path/yyy/abcd/Sources/Ignore,path/yyy/abcd/Sources/Generated/UIStoryboard+SwiftGen.swift,path/yyy/Pods,path,path,Pods,sonar-reports,test

It's not easy to review in pull requests or edit without wrapping it first (both may be subjective criteria).

the same example in yaml:

exclude:
  - archive
  - buck-out
  - build
  - Carthage
  - Doc
  - Docs
  - Documentation
  - path/xxxx/xxxX/Abcd/Xyz/Generated
  - path/xxxx/xxxX/Abcd/Storyboards
  - path/xxxx/xxxX/Abcd/Zyz/XYZ/Generated
  - path/xxxx/Pods
  - path/yyy/App/abcd/Generated
  - path/yyy/App/abcd/Templates
  - path/yyy/App/abcd/View/Ignore
  - path/yyy/abcd/Sources/Ignore
  - path/yyy/abcd/Sources/Generated/UIStoryboard+SwiftGen.swift
  - path/yyy/Pods
  - path
  - path
  - Pods
  - sonar-reports
  - test

Another benefit would being able to share same exclude lists between tools like SwiftFormat and SwiftLint.

@specialfor
Copy link
Contributor

@mgrebenets I think the same would be great for long list of --enable or --disable rules.
I have explictly added all enabled and disabled rules in .swiftformat file, because, as for me, it looks more obvious what rules are used and what are not.

@nicklockwood
Copy link
Owner

I agree that yml seems to be the standard. I think it would be confusing to have two formats, but I'll consider migrating to yml in future.

@dogo
Copy link

dogo commented Nov 13, 2020

@nicklockwood Any plans for this?

@nicklockwood
Copy link
Owner

@dogo I assume this relates to your other query? I don't think the problem is due to not using yaml, as spaces in paths are supported with the existing format.

@nicklockwood
Copy link
Owner

nicklockwood commented Nov 13, 2020

@mgrebenets, @specialfor FYI it's now possible to split your rules onto separate lines, as follows:

#excludes 
--exclude some/path
--exclude some/other/path

#rules 
--enable foo
--enable bar
--disable baz

@dogo
Copy link

dogo commented Nov 13, 2020

@dogo I assume this relates to your other query? I don't think the problem is due to not using YAML, as spaces in paths are supported with the existing format.

@nicklockwood It's not related, I found this issue when I was searching for any issue with whitespace, but this issue/enhancement its a great feature for improving the readability and detect syntax errors.

@sindresorhus
Copy link

I think the current way the config is structured is a bit confusing. I have a lot of experience with linter config from the JavaScript ecosystem. For example, it's not immediately clear what rules are enabled/disabled by default.

Here's how I would do it:

  1. All rules are disabled by default.

  2. Only one way to enable/disable individual rules:

rules:
  attributes: true
  todo: false

This format makes it possible to support config inheritance in the future, as individual entries in the rules dictionary can override the parent config.

  1. Recommended preset, which would be what the current defaults are.
presets:
  builtin: true

I understand that 1 is quite a breaking change, so a less breaking change would be to do only 2 and 3, and then I could just disable the builtin preset myself.

@nicklockwood
Copy link
Owner

@sindresorhus probably a good idea to open this as its own issue, since it doesn't really relate to the question of yaml vs other formats.

FWIW, I think you can get the behaviour you want by using the --rules option to just specify the rules you would like to opt-in to.

@sindresorhus
Copy link

probably a good idea to open this as its own issue, since it doesn't really relate to the question of yaml vs other formats.

Which part? Assume you mean 1, because the other things are related to the YAML config format.

@nicklockwood
Copy link
Owner

Which part? Assume you mean 1, because the other things are related to the YAML config format.

Having a single way to disable/enable rules, and having presets are both suggestions that can be implemented independently of the config file format.

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

No branches or pull requests

5 participants