-
Notifications
You must be signed in to change notification settings - Fork 153
Incorrect FC019 alarms #22
Comments
Hi Phil, I can't reproduce the warning from the example given (using the current version of the gem). Are you able to share a more complete example? I need to push another release soon as there are some other fixes on master it would be good to make more widely available. If we can get this one in there as well that would be great. Thanks, Andrew. |
Where in_tier? is a library function. |
Ah. Foodcritic knows that Why is the library function call prefixed with node? I would think that the method missing on node is really designed for attribute access so it's interesting that this works. |
On 04/15/2012 11:51 PM, Andrew Crump wrote:
Interestingly, Adam wrote that for me once. It just opens the Node class and Phil Dibowitz [email protected] "Be who you are and say what you feel, because those who mind don't matter
|
If you are re-opening the node class and defining a new method then foodcritic could look for that and treat it as a built-in method (ignore it). This is probably a good idea. The The libraries page on the Chef wiki has examples of how you would normally call into code you define in a library: |
gotcha. Currently this one is biting us - how hard is this feature/fix to implement? |
Something similar is done at present to detect the use of edelights chef-solo-search library: Were you thinking of tackling it yourself? Otherwise I might be able to take a look this weekend assuming you can share the library or enough detail to figure out how to match against it. Solving this for the general case is a bit harder because there are multiple ways to reopen a class in Ruby. |
Hi Phil. Any update on this? |
Sorry. No, I have no plans to fix this myself, I'm swamped. I was just expressing important to us. In the mean time, we're disabling the check. :( |
Sorry if I was unclear above. I didn't mean you had to implement it (although that would of course be great). As I said last week, if you can share the library or sufficient detail to get going I should be able to take a look at it. |
Oh, I missed that part. I don't have the code on me nwo, but it's basically:
It's just a short cut for writing stuff like:
|
Thanks. I'll try and take a look this week. |
awesome. lemme know if i can provide anything else. |
Hi Phil, I've committed a change that should resolve this for you. Can you test against current master on GitHub and let me know if this is still an issue? Thanks, Andrew. |
(ignore the last comment, my branch wasn't uptodate, hence I deleted the comment) |
Confirmed, this looks good. |
How soon can you roll a release? |
Ping? |
Pong. Sorry about the delay. I'll avoid cutting a release while I've got this head cold so will get onto it this weekend. Cheers, Andrew. |
Hi Phil, This has now been released in 1.3.0. |
Hey. So this does work... but a few suggestions/thoughts: Currently if you're checking a cookbook that uses a library call defined in a different cookbook it triggers. This isn't necessarily bad, but the error message of accessing attributes inconsistently isn't correct... and is very misleading. If what I did was a method call [node.foo()] then you should instead say something like "unrecognized method"... so people know what's going on. In fact, my preference here is that F019 would ignore method calls and a new rule would be written that would look for method calls that were invalid... |
Hi Phil, At present it shouldn't trigger provided the cookbook that contains the library and the cookbook using the library method are under the same cookbook path. Is this not the behaviour you are seeing? Can you provide an example? Cheers, Andrew. |
If I call fc on a given cookbook, then no. I need to give it a path with all the right dependencies. Which is fine, but the error message is misleading, so I don't know what I've done wrong. The error is "you didn't give me the cookbook that defines method foo()" but what you say is "inconsistent attribute access." |
Ok. Under the covers these are all method calls: # i'm accessing an attribute
node.foo
# or I could be calling a method added to Chef::Node
node.foo
# you probably mean this as a method call
# but it could also be used to retrieve an attribute value
node.foo() If you are explicit when you invoke your method and use parentheses then we could choose to interpret it as a call to a method and treat it differently. |
Yes, that's exactly what I'm suggesting. Currently chef will interpret node.foo as a an attribute access if it doesn't find a method. This is unfortunate and a "feature" even Adam wishes he didn't add. But what I'd like to do is say that assuming I'm explicit and say node.foo(), it should be exempt from FC019, and then potentially add another rule to validate that method. |
Hi Phil, The change to ignore explicit method calls with parentheses was shipped in 1.4.0. Can you test and confirm this one is good to close. Cheers, Andrew. |
Closing this one as resolved. |
doing:
will get you an FC019 alarm which I don't think is valid. :(
The text was updated successfully, but these errors were encountered: