SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

Add syntax to swiftlint_version to allow for specifying minimum and maximum versions

Open alex-taffe opened this issue 1 year ago • 12 comments
trafficstars

Currently, the configuration supports a swiftlint_version option. This option does not work for our workflow because we have many branches that may not be up to date with main/master. However, there are breaking changes that occur in SwiftLint, such as redundant_optional_initialization changing between 0.53.0 and 0.55.1, causing our team to not have consistency in their linting.

This adds new syntax to swiftlint_version that will compare to the current version installed and throw a warning/error if the installed version does not match the pattern the user specified

warning: Currently running SwiftLint 0.55.1 but configuration specified minimum version 0.55.3.

The syntax is as follows:

swiftlint_version: 0.54.0
swiftlint_version: ">0.54.0"
swiftlint_version: ">=0.54.0"
swiftlint_version: "<0.54.0"
swiftlint_version: "<=0.54.0"

alex-taffe avatar Jul 24 '24 15:07 alex-taffe

1 Error
:no_entry_sign: Could not build branch
1 Warning
:warning: This PR may need tests.

Generated by :no_entry_sign: Danger

SwiftLintBot avatar Jul 24 '24 15:07 SwiftLintBot

@SimplyDanny @mildm8nnered if you could take a look at this when you get a chance, thanks!

alex-taffe avatar Jul 31 '24 01:07 alex-taffe

I see where you are coming from and why this would help, yet I was wondering whether a new separate key is really the way to go. The list is continuously growing and there is the problem of conflicting options. What about minimum_swiftlint_version: 0.54.0 and swiftlint_version: 0.53.0 for example? So there should probably be some consistency checks.

What I was thinking about is an extension of swiftlint_version in a way that it supports both fixed versions and a range of version given a minimum version. Something like the syntax swiftlint_version: >=0.54.0 could be conceivable. What's your opinion on that?

SimplyDanny avatar Jul 31 '24 20:07 SimplyDanny

Yeah I think I actually like that better, what're your thoughts on syntax? I kinda like Dart's. Traditional and caret. Then if we can't parse, just throw a fatal error.

image image

Plus '>=1.2.3 <2.0.0' for inclusive

alex-taffe avatar Jul 31 '24 20:07 alex-taffe

Also what's the minimum version of macOS that SwiftLint supports? Would love to use new SwiftRegex but it's macOS 13 or newer only

alex-taffe avatar Jul 31 '24 20:07 alex-taffe

Also what's the minimum version of macOS that SwiftLint supports? Would love to use new SwiftRegex but it's macOS 13 or newer only

SwiftLint still supports macOS 12. We'd need good reasons to change that. While I fancy as well with SwiftRegex, it's not enough reason to change the minimum deployment version. But that might change when macOS 15 is out.

About the syntax: I personally don't like the caret style so much. Only the three variants

  • 0.54.0
  • >0.54.0
  • >=0.54.0

seem to be enough. There is no good reason for <0.54.0 or <=0.54.0, is there?

SimplyDanny avatar Jul 31 '24 21:07 SimplyDanny

In practice I’m guessing the less than or inclusive versions wouldn’t actually be used much (I doubt we ever will), but doesn’t seem like that much more work so might as well just do it while I’m in there. I’m fine with omitting caret syntax

alex-taffe avatar Jul 31 '24 21:07 alex-taffe

In your implementation it could be helpful to know that Version objects are Comparable. 😉

SimplyDanny avatar Jul 31 '24 21:07 SimplyDanny

@SimplyDanny updated

alex-taffe avatar Aug 01 '24 15:08 alex-taffe

@SimplyDanny how do you suggest I approach tests on this? AFAIK, XCTest can't handle pulling out info from stdout nor can it intercept calls to abort(). I could refactor the method so it throws out an error enum with an intermediary that actually calls abort, but seems like a lot of boilerplate. Does bazel have some other better way to tackle this?

alex-taffe avatar Aug 05 '24 14:08 alex-taffe

@SimplyDanny just seeing if you had any thoughts on this. Apologies for the follow up, this is just rapidly causing chaos amongst our 9000 internal branches (which is a whole separate issue but)

alex-taffe avatar Aug 13 '24 02:08 alex-taffe

@SimplyDanny yeah sorry I pushed a bunch of stuff earlier then got distracted with some fires at work, I was working on refactoring into a struct anyways

alex-taffe avatar Aug 19 '24 21:08 alex-taffe