Would like to be able to exempt rules in cookbooks #10

Closed
jaymzh opened this Issue Feb 22, 2012 · 7 comments

Projects

None yet

2 participants

@jaymzh
Collaborator
jaymzh commented Feb 22, 2012

It would be great to be able to exempt specific rules. Perhaps an implicit tag of the rule number for each rule so I could do foodcritic -t ~fc002 or whatever. In general, for example, I want the style rules, but there may be one particular style rule I don't want to enforce or that we do differently at our site for whatever reason.

Alternatively - or additionally - the ability to exempt in-code would be great, along the lines that you can tell gcc to ignore certain warnings with #pragma statements.

@acrmp
Owner
acrmp commented Feb 22, 2012

Hi Phil,

Thanks for flagging this up. The functionality for this already exists but you need to use uppercase for the leading 'FC' for this to work. There's no good reason for the case sensitivity except that's how Cucumber tags work.

We don't appear to have documented this feature anywhere so I've updated the FAQ entry for excluding rules based on tag to reflect this:
http://acrmp.github.com/foodcritic/#faq-spurious-warnings

Exempting in code would be a useful feature. It might be nice to do this as a comment as below but I don't think this will be available in the AST. What syntax would you like to see?

#~FC006 - Depeche mode
directory "/tmp/something" do
  owner "root"
  group "root"
  mode 0755
  action :create
end

Thanks,

Andrew.

@jaymzh
Collaborator
jaymzh commented Feb 22, 2012

Yup, as a comment was what I had in mind. BTW, a similar feature request is coming from me in a moment. Forgot to do it earlier.

Anyway, I would imagine a syntax along the lines of:

# pragma-foodcritic: ~FC006 - bla bla

I like having something leading there since I could ideally do something like:

# pragma-foodcritic: ~style - This violates all sorts of style stuff, but sadly <something>

to turn off the style tag for a block. Since "~style" wouldn't mean anything to anyone... having something to denote what it's for is useful. I don't care too much of it's "pragma-foodcritic" or "pragma-fc" or "foodcritic". I don't care if it's long to type since ideally one shouldn't be using this feature anyway... painful to type is probably a good thing :)

As to the fact there are already implicit per-rule tags - AWESOME! Thanks. :)

@jaymzh
Collaborator
jaymzh commented Feb 22, 2012

Update here on the original request... ~ seems to work on -t but NOT on -f.

If I do

foodcritic -f style,~FC014 foo

and FC014 triggers, it still exits with status 3. But FC014 shouldn't trigger failure in this case...

@acrmp acrmp referenced this issue Feb 22, 2012
Closed

Epic fail fail? #13

@acrmp
Owner
acrmp commented Feb 22, 2012

(moving --epic-fail discussion to a separate issue #13)

Thanks for the extra detail Phil. I like the very verbose # pragma-foodcritic in your example as I agree this is a feature to be used sparingly.

Foodcritic uses the Ripper library that ships with Ruby 1.9, in particular it works on the S-exp tree. Unfortunately comments have been stripped by the time we see them at the moment. They are available through Ripper separately in a call to lex(), so we can access them but there will need to be a little bit of accounting to tie them against the rule matches. I don't think this will be too hard but we'll need test thoroughly for edge cases.

Cheers,

Andrew.

@jaymzh
Collaborator
jaymzh commented Feb 22, 2012

That makes sense. Thanks for being open to this. :)

@jaymzh
Collaborator
jaymzh commented Mar 9, 2012

I'm updating the subject, because I keep coming in here to close this out and realizing it's not the issue I think it is.

@acrmp
Owner
acrmp commented Mar 31, 2013

Closing this as similar functionality was released in foodcritic 2.0.0.

Cheers,

Andrew.

@acrmp acrmp closed this Mar 31, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment