nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.67k stars 623 forks source link

genericExtensions has no effect for me #1593

Closed stherold closed 7 months ago

stherold commented 7 months ago

My config file looks like below (don't wonder I'm in setup mode right now and enable rule by rule). What exactly has to be written in the option generictypes?

#
# Format command: `swiftformat --swiftversion 5 --config "./.config/swiftformat" .`
#

#
# Disable all • Delete when all rules have been applied
#

--disable all

#
# Rules enabled by default (enable statements can be deleted as soon as "--disable all" is removed)
#

--enable anyObjectProtocol
--enable applicationMain
--enable assertionFailures # https://www.hackingwithswift.com/plus/intermediate-swift/understanding-assertions#assert
--enable blankLineAfterImports
--enable blankLinesAroundMark
  --lineaftermarks true
--enable blankLinesAtEndOfScope # removes
# Too much changes - wait for the right moment to enable
# --enable blankLinesAtStartOfScope # removes
# --typeblanklines preserve
--enable blankLinesBetweenChainedFunctions
--enable blankLinesBetweenImports
--enable blankLinesBetweenScopes
--enable blockComments
--enable braces
  --allman false
--enable conditionalAssignment
--enable consecutiveBlankLines
# Conflict with https://github.com/dbdrive/beiwagen/pull/4613 - wait for the right moment to enable
# --enable consecutiveSpaces
# Needs some manual edition since the changed locations should not all be doc comments
# --enable docComments
--enable duplicateImports
--enable elseOnSameLine
  --elseposition same-line
  --guardelse auto
--enable emptyBraces
  --emptybraces no-space
--enable enumNamespaces
  --enumnamespaces always
--enable extensionAccessControl
  --extensionacl on-extension
--enable fileHeader
  --header strip
--enable genericExtensions
  --generictypes 

#
# Rule config
#

# --assetliterals visual-width
# --asynccapturing 
# --beforemarks 
# --binarygrouping none
# --categorymark "MARK: %c"
# --classthreshold 0
# --closingparen same-line
# --closurevoid remove
# --commas inline
# --conflictmarkers reject
# --decimalgrouping none
# --enumthreshold 0
# --exponentcase lowercase
# --exponentgrouping disabled
# --extensionlength 0
# --extensionmark "MARK: - %t + %c"
# --fractiongrouping disabled
# --fragment false
# --funcattributes preserve
# --groupedextension "MARK: %c"
# --header ignore
# --hexgrouping none
# --hexliteralcase lowercase
# --ifdef no-indent
# --importgrouping alpha
# --indent 4
# --indentcase false
# --indentstrings false
# --lifecycle 
# --linebreaks lf
# --markcategories true
# --markextensions always
# --marktypes always
# --maxwidth none
# --modifierorder 
# --nevertrailing 
# --nospaceoperators ...,..<
# --nowrapoperators 
# --octalgrouping none
# --operatorfunc spaced
# --organizetypes actor,class,enum,struct
# --patternlet hoist
# --ranges spaced
# --redundanttype infer-locals-only
# --self init-only
# --selfrequired 
# --semicolons inline
# --shortoptionals always
# --smarttabs enabled
# --someany true
# --stripunusedargs closure-only
# --structthreshold 0
# --tabwidth unspecified
# --throwcapturing 
# --trailingclosures 
# --trimwhitespace always
# --typeattributes preserve
# --typemark "MARK: - %t"
# --varattributes preserve
# --voidtype void
# --wraparguments preserve
# --wrapcollections preserve
# --wrapconditions preserve
# --wrapeffects preserve
# --wrapenumcases always
# --wrapparameters default
# --wrapreturntype preserve
# --wrapternary default
# --wraptypealiases preserve
# --xcodeindentation disabled
# --yodaswap always

#
# Excludes
#

--exclude ../Tuist, \
  ../Pods, \
  ../changelog, \
  ../doc, \
  ../fastlane, \
  ../scripts, \
  ../.gem, \
  ../.mint, \
  ../.tuist-bin \

#
# Disabled rules
#

# We should use camelCase by default
--disable acronyms
# && and || are easier to read
--disable andOperator
# https://github.com/Blackjacx/Development/blob/main/ios-coding-guidelines.md#never-omit-specifying-the-value-of-string-typed-enum-cases
--disable redundantRawValues 
nicklockwood commented 7 months ago

--generictypes is a list of types that support being extended using a syntax like:

extension Array<Int> { ... }

Instead of

extension Array where Element == Int { ... }
stherold commented 7 months ago

Thx for the hint 👍

But still it SwiftFormat does not correct extension Array where Element == Int { ... } for me.

nicklockwood commented 7 months ago

@stherold it looks like you are setting the --swiftversion option to 5, but this syntax is only available since 5.7, so the rule will be disabled.

stherold commented 7 months ago

Ooops, this would have been a long journey without your hint! thank you very much 🎉

stherold commented 7 months ago

Works, thanks 🎉