-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Investigate how the rubocop warning are working #49
Comments
From the rubocop docs Severity Each cop has a default severity level based on which department it belongs to. The level is normally warning for Lint and convention for all the others, but this can be changed in user configuration. Cops can customize their severity level. Allowed values are info, refactor, convention, warning, error and fatal. Cops with severity info will be reported but will not cause rubocop to return a non-zero value. There is one exception from the general rule above and that is Lint/Syntax, a special cop that checks for syntax errors before the other cops are invoked. It cannot be disabled and its severity (fatal) cannot be changed in configuration. Lint: Metrics/CyclomaticComplexity: |
@DanielePalombo @MassimilianoLattanzio @abhishekgupta5
Hey guys, Modifications required in a Cop Lets take this cop for example. class ClassEvalDecorator < Base
MSG = 'Do not use `class_eval` flag. Use a decorator module instead. Check this link for an example https://guides.solidus.io/cookbook/redefining-checkout-steps'
RESTRICT_ON_SEND = %i[class_eval].freeze
def_node_matcher :on_class_eval?, <<~PATTERN
(send ($...) :class_eval)
PATTERN
def on_send(node)
return unless on_class_eval?(node)
add_offense(node)
end
end Now if we want to modify this offense from a add_offense(node, severity: :warning) The above line modifies the severity of the Returned Object (For Default Offense) [#<RuboCop::Cop::Offense:0x000000011e1de830
@cop_name="Solidus/ClassEvalDecorator",
@corrector=nil,
@location=#<Parser::Source::Range (string) 0...18>,
@message="Do not use `class_eval` flag. Use a decorator module instead. Check this link for an example https://guides.solidus.io/cookbook/redefining-checkout-steps",
@severity=#<RuboCop::Cop::Severity:0x000000011e1de808 @name=:convention>] Returned Object (For Warning Level Offense) [#<RuboCop::Cop::Offense:0x000000011cda1250
@cop_name="Solidus/ClassEvalDecorator",
@corrector=nil,
@location=#<Parser::Source::Range (string) 0...18>,
@message="Do not use `class_eval` flag. Use a decorator module instead. Check this link for an example https://guides.solidus.io/cookbook/redefining-checkout-steps",
@severity=#<RuboCop::Cop::Severity:0x000000011cda1228 @name=:warning>] Now, onto RSpec Older Tests expect_offense(<<~RUBY)
Product.class_eval do
^^^^^^^^^^^^^^^^^^ Do not use `class_eval` flag. Use a decorator module instead. Check this link for an example https://guides.solidus.io/cookbook/redefining-checkout-steps\n
end
RUBY New Tests with severity warning expect_offense(<<~RUBY, severity: :warning)
Product.class_eval do
^^^^^^^^^^^^^^^^^^ Do not use `class_eval` flag. Use a decorator module instead. Check this link for an example https://guides.solidus.io/cookbook/redefining-checkout-steps\n
end
RUBY When the severity level does not match in a test then we get the following error. Failure/Error:
expected: [:warning]
got: [#<RuboCop::Cop::Severity:0x000000011e1de808 @name=:convention>] One thing to keep in mind is the heirarchy of severity in rubocop
I have noticed that the
|
Thanks for the investigation @piyushswain! Do we need to modify some severities in our current cops? |
Good find @piyushswain. I think we can use this |
@MassimilianoLattanzio I'm not sure, we should probably discuss which cops we would like to set a severity for in a donut probably or if you have some cops in mind we can start changing them. |
If possible support it and update the readme and documentation as well
The text was updated successfully, but these errors were encountered: