SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

`number_separator`: allow ignoring certain types of numbers

Open rgoldberg opened this issue 10 months ago • 5 comments
trafficstars

New Issue Checklist

Feature or Enhancement Proposal

number_separator should be able to be configured to ignore/exclude certain types / typealiases of numbers like:

number_separator:
  ignore: [pid_t]

So any literal used for a pid_t is ignored by this rule.

rgoldberg avatar Jan 02 '25 11:01 rgoldberg

In which regard would this be helpful? Why would numbers used for pid_ts not benefit from separators?

SimplyDanny avatar Jan 02 '25 16:01 SimplyDanny

There are some typealiases that I'd prefer to see without underscores. Mainly if they're IDs instead of counts. It's just a personal preference. Not the most necessary option, but figured I'd document it here in case others would like it, too.

rgoldberg avatar Jan 02 '25 17:01 rgoldberg

Note, that this only works well for declarations with initializations such as let id: ID = 1234 or let id = ID(123). Otherwise there's no way to know the type of a literal to be ignored.

SimplyDanny avatar Jan 02 '25 17:01 SimplyDanny

A cast or the type of a function parameter can also indicate the type of the literal.

rgoldberg avatar Jan 02 '25 18:01 rgoldberg

Cast yes, function parameters only for default values. At the call side, there is no way to know the type of the argument, at least not for fast lint rules like number_separator.

SimplyDanny avatar Jan 02 '25 18:01 SimplyDanny