-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Rule request: Comment lines in function bodies #2077
Comments
I'm strictly against this (even when done as an opt-in rule). While I agree that inline method comments often can be a doc-comment on top of the method declaration, I don't believe disallowing comments entirely within method is somehow encouragable. While comments are often used to document code that is poorly written and that would be self-explanatory if implemented properly (one common example being the (mis)use of a
Given those two scenarios, I don't think such a rule should be added, not even opt-in which nonetheless implied it's something to be encouraged. |
The methods (and classes) are supposed to be small and fulfill only one goal. If your method has "parts", then it probably does several things and should be split. If you cannot split a single method into separate ones, then you have to rework your design.
If your API forces you to use a hack, you need to properly document in the class documentation header. You need to inform the users what the bug is about, how you fixed it and why. You should also leave a link to the bug report website. All of this belongs to the documentation section, not the code itself. |
|
Das hat mich gerade zum Lachen gebracht. 😄 Es bedeutet sowas wie „Es soll verwirrend und einfach nicht richtig formuliert sein.“ – ganz das Gegenteil von dem, was Sie meinen: “It would be confusing and simply not in its proper place.”/„Es wäre verwirrend und einfach nicht an der richtigen Stelle.“ Aber ich habe erst am letzten Satz gecheckt, dass es von einem Fremdsprachiger geschrieben wurde, also haben Sie es recht gut hingekriegt. (Vergeben Sie mir in dem Fall, dass Sie nur vertippt haben, Englischsprachiger sind, und dazu nur zufällig in Karlsruhe wohnen. Man weiß ja nie ...) Ach und übrigens bin ich ganz Ihrer Meinung. |
@SDGGiesbrecht Danke für den Hinweis, ist korrigiert ;) |
@fredpi While I understand that you don't consider this idea a "best practice" (I also don't), I can still imagine a programming style where a function is the smallest possible unit and should always have a clear goal – and if anything as part of that function needs explanation or needs to be grouped, that should be put into a separate function. Of course, this programming style has it's own drawbacks, but before we get into further discussions here I'd like it to be clear what SwiftLint is about so we can maybe just close this or merge it although we don't think it's a best practice widely used in the community: @marcelofabri @jpsim Like I already asked here the big question is if SwiftLint should also include opt-in rules that enable enforcing programming styles that are not considered best practice by a wide part of the Swift community but still is a coding style a minority might decide to use. What are your opinions on this? Because I feel like this is the case here and we should be very clear about it so we can either close this or merge it although we might not agree it to be a best practice. |
Looking at SwiftLint's own description, which is "A tool to enforce Swift style and conventions" to me it sounds like we should include any rule that might be a reasonable Swift syle or convention as long as there's no "definitely better way" – and I don't think @driver733's idea suggested here can be clearly stated as a "bad style" since his rationale does make sense. Some exceptions of course should be made, for example for rarely used conventions that might make this project too much harder to maintain. But that's a different discussion. |
I think it's fine to have it as opt-in as realistically, plugins are not coming so soon. |
@Dschee That rationale seems reasonable, yet I still believe that the decision to include rules that aren't considered best practice by most, should only applied to rules that cannot be defined via a custom regex rule... If you can define a rule via a regex (which I believe is the case here) and it's only needed by few projects, I don't see a need to include it as a part of SwiftLint... |
New Issue Checklist
Rule Request
Description
The code, in my opinion, should not have in-line comments. If any kind of explanations is needed, it has to be put in the method or class documentation. Furthermore, if your code requires comments, then it might be necessary to refactor it, so that it would be self-explainatory.
What would trigger?
What would not trigger?
Configurable?
The rule should not be configurable.
Opt-in or enabled?
This rule could be a personal preference or coding style from various individuals, so it could be kept as opt-in.
The text was updated successfully, but these errors were encountered: