-
Notifications
You must be signed in to change notification settings - Fork 1
SwiftLint 0.45.1 adaptation #292
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
base: master
Are you sure you want to change the base?
Conversation
- ok | ||
- URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SwiftLint и так не агрится на такое название, можно удалить
@@ -107,12 +107,15 @@ enum_case_associated_values_count: | |||
identifier_name: | |||
excluded: | |||
- id | |||
- to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не соглашусь, с этим исключением. from и to как названия переменных не отражают типа своего содержимого.
В случае с примером
func foo(from: Date, to: Date) {
// code
}
на мой взгляд лучше сделать так:
func foo(from fromDate: Date, to toDate: Date) {
// code
}
Получается понятно что за переменные и что в себе содержат.
opening_brace: | ||
allow_multiline_func: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ну, единственное что я могу заметить, у нас единственная ссылка на свифт код стайл гайд лежащая вот тут https://github.com/TouchInstinct/Styleguide/blob/90dfb56c398440926c60b619f83be06d5ed2337c/IOS/OnboardingGuide.md#ios-developer-onboarding-letter ведет на гайд от raywenderlich в котором сказано:
- Method braces and other braces (if/else/switch/while etc.) always open on the same line as the statement but close on a new line.
Поэтому лично мне в целом не критично конечно, но получается некоторое противоречие между линтером и предложеным кодстайлом) Так что этот момент можно было бы обсудить)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
При этом замечал, что люди часто нарушают пункт оттуда же:
- There should be no blank lines after an opening brace or before a closing brace.
Пишут так, чтобы разграничить визуально тело функции от заголовка:
func foo(bar: ParameterClosure<WibbleWobbleWubble>,
baz: @escaping VoidClosure,
qux: @escaping ParameterClosure<WibbleWobbleWubble>) {
let keke = 123
let lele = 123
}
Хотя это куда нагляднее выглядит:
func foo(bar: ParameterClosure<WibbleWobbleWubble>,
baz: @escaping VoidClosure,
qux: @escaping ParameterClosure<WibbleWobbleWubble>)
{
let keke = 123
let lele = 123
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ещё отмечу, что правило срабатывает только в случае многострочных параметров, в остальных случаях линтер перенос убирает, т.е. такого не будет:
func foo(bar: ParameterClosure<WibbleWobbleWubble>)
{
// code
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ну, вообще есть 2 путя в таком случае:
- реквестировать правки код стайла у рея (возможно не дождемся, поскольку некоторые Issues там с 19 года висят)
- Сделать свой код стайл с переносами скобок (у нас где-то в стайлгайд репо лежит кстати ссылка на свой код стайл которого нет)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Но опять же, отмечу, стоит это обсудить, прежде чем рубить с плеча)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
При этом замечал, что люди часто нарушают пункт оттуда же:
- There should be no blank lines after an opening brace or before a closing brace.
Пишут так, чтобы разграничить визуально тело функции от заголовка:
func foo(bar: ParameterClosure<WibbleWobbleWubble>, baz: @escaping VoidClosure, qux: @escaping ParameterClosure<WibbleWobbleWubble>) { let keke = 123 let lele = 123 }Хотя это куда нагляднее выглядит:
func foo(bar: ParameterClosure<WibbleWobbleWubble>, baz: @escaping VoidClosure, qux: @escaping ParameterClosure<WibbleWobbleWubble>) { let keke = 123 let lele = 123 }
Ну кстати, если уж си шарп стайл не зайдет, может быть есть правило, которое запретит пустую строку после открывающей скобки?
Прошёлся по релизам SwiftLint 0.39.1 - 0.45.1, новых полезных opt-in правил не заметил.
У
opening_brace
появился параметрallow_multiline_func
, кажется нужным, разрешает перенести скобку на новую строку в функциях с многострочными параметрами:В 0.43.0 заменили
swiftlint autocorrect
наswiftlint --fix
.Добавил название
to
в список исключений правилаidentifier_name
, довольно распространённое название переменной, на мой взгляд: