Make custom cop inherit `RuboCop::Cop::Base` (#9597)
Merge pull request 9597
This commit is contained in:
parent
c52149824d
commit
28e10da266
|
@ -26,8 +26,11 @@ module RuboCop
|
||||||
# @alpha.omega
|
# @alpha.omega
|
||||||
# )
|
# )
|
||||||
#
|
#
|
||||||
class AssertEqualLiteralActual < Cop
|
class AssertEqualLiteralActual < Base
|
||||||
MSG = "Provide the 'expected value' as the first argument to `assert_equal`.".freeze
|
extend AutoCorrector
|
||||||
|
|
||||||
|
MSG = "Provide the 'expected value' as the first argument to `assert_equal`."
|
||||||
|
RESTRICT_ON_SEND = %i[assert_equal].freeze
|
||||||
|
|
||||||
SIMPLE_LITERALS = %i(
|
SIMPLE_LITERALS = %i(
|
||||||
true
|
true
|
||||||
|
@ -61,12 +64,10 @@ module RuboCop
|
||||||
|
|
||||||
def on_send(node)
|
def on_send(node)
|
||||||
return unless literal_actual?(node) || literal_actual_with_msg?(node)
|
return unless literal_actual?(node) || literal_actual_with_msg?(node)
|
||||||
add_offense(node, location: :expression)
|
|
||||||
end
|
|
||||||
|
|
||||||
def autocorrect(node)
|
range = node.loc.expression
|
||||||
lambda do |corrector|
|
add_offense(range) do |corrector|
|
||||||
corrector.replace(node.loc.expression, replacement(node))
|
corrector.replace(range, replacement(node))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,19 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "rubocop"
|
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module Jekyll
|
module Jekyll
|
||||||
class NoPAllowed < Cop
|
class NoPAllowed < Base
|
||||||
MSG = "Avoid using `p` to print things. Use `Jekyll.logger` instead.".freeze
|
MSG = "Avoid using `p` to print things. Use `Jekyll.logger` instead."
|
||||||
|
RESTRICT_ON_SEND = %i[p].freeze
|
||||||
|
|
||||||
def_node_search :p_called?, <<-PATTERN
|
def_node_search :p_called?, <<-PATTERN
|
||||||
(send _ :p _)
|
(send _ :p _)
|
||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
def on_send(node)
|
def on_send(node)
|
||||||
if p_called?(node)
|
if p_called?(node)
|
||||||
add_offense(node, :location => :selector)
|
add_offense(node.loc.selector)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,20 +1,19 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "rubocop"
|
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module Jekyll
|
module Jekyll
|
||||||
class NoPutsAllowed < Cop
|
class NoPutsAllowed < Base
|
||||||
MSG = "Avoid using `puts` to print things. Use `Jekyll.logger` instead.".freeze
|
MSG = "Avoid using `puts` to print things. Use `Jekyll.logger` instead."
|
||||||
|
RESTRICT_ON_SEND = %i[puts].freeze
|
||||||
|
|
||||||
def_node_search :puts_called?, <<-PATTERN
|
def_node_search :puts_called?, <<-PATTERN
|
||||||
(send nil? :puts _)
|
(send nil? :puts _)
|
||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
def on_send(node)
|
def on_send(node)
|
||||||
if puts_called?(node)
|
if puts_called?(node)
|
||||||
add_offense(node, :location => :selector)
|
add_offense(node.loc.selector)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue