-
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
Limit parameters count #447
Conversation
return false | ||
} | ||
|
||
return key == "source.lang.swift.decl.var.parameter" |
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.
You could avoid the hardcoded string literal by doing return SwiftDeclarationKind(rawValue: key) == . VarParameter
instead.
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.
nice, had no idea there were constants for that :)
I'm excited to see you getting started on this! Let me know if you have any questions moving forward. |
@jpsim assuming my code example here jpsim/SourceKitten#151 do you think there are "good" ™️ way to extract function parameters from AST? I'm inclining to simply get function declaration string and parse it manually. Moreover I have to do it anyway because of default parameters (they are not represented in SourceKit AFAIK) |
Yeah, it's spot on. You're using an |
@jpsim but apparently it triggers false positive for this simple snippet:
produces 1 level-nested structure which will count
|
In your example, In your example, you'd only end up with |
@jpsim thanks for this 👍 I had a feeling I'm missing something |
range: Range<Int>) -> Int { | ||
|
||
var count = 0 | ||
for e in structure { |
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.
usage of for
loop is intentional (not very functional 😃) : it allows to return early in case method reached end of current function declaration
@jpsim ready to be reviewed! |
let offset = Int(dictionary["key.offset"] as? Int64 ?? 0) | ||
return [StyleViolation(ruleDescription: self.dynamicType.description, | ||
severity: parameter.severity, | ||
location: Location(file: file, characterOffset: offset), |
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.
Could you please use Location(file: file, byteOffset: offset)
instead of Location(file: file, characterOffset: offset)
?
Because dictionary["key.offset"]
is byte offset.
return [StyleViolation(ruleDescription: self.dynamicType.description, | ||
severity: parameter.severity, | ||
location: Location(file: file, byteOffset: offset), | ||
reason: "{Parameters list should have \(config.warning) or less parameters: " + |
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.
Typo: {Parameters
The implementation here looks great! I'd like us to really nail down the rule name though. "Parameters List Length" and "Parameter List Length" seem to be used interchangeably. We're not really measuring the string length here, but rather the number of parameters. I think "Function Parameter Count" might be a more appropriate name. Otherwise like I said, the implementation looks spot on (as far as I can tell reveling this from my phone 😉). |
@jpsim agreed with naming, changed |
Thanks @garnett! I just had a few minor changes to add, so I'll merge in #459. Really nice work on this! Not too many people have ventured into writing |
👏 |
Very early version of #415.
Implementation depends on answer here: jpsim/SourceKitten#151.