Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make custom cop inherit RuboCop::Cop::Base #9597

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions rubocop/jekyll/assert_equal_literal_actual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ module Jekyll
# @alpha.omega
# )
#
class AssertEqualLiteralActual < Cop
MSG = "Provide the 'expected value' as the first argument to `assert_equal`.".freeze
class AssertEqualLiteralActual < Base
extend AutoCorrector

MSG = "Provide the 'expected value' as the first argument to `assert_equal`."
RESTRICT_ON_SEND = %i[assert_equal].freeze

SIMPLE_LITERALS = %i(
true
Expand Down Expand Up @@ -61,12 +64,10 @@ class AssertEqualLiteralActual < Cop

def on_send(node)
return unless literal_actual?(node) || literal_actual_with_msg?(node)
add_offense(node, location: :expression)
end

def autocorrect(node)
lambda do |corrector|
corrector.replace(node.loc.expression, replacement(node))
range = node.loc.expression
add_offense(range) do |corrector|
corrector.replace(range, replacement(node))
end
end

Expand Down
11 changes: 5 additions & 6 deletions rubocop/jekyll/no_p_allowed.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
# frozen_string_literal: true

require "rubocop"

module RuboCop
module Cop
module Jekyll
class NoPAllowed < Cop
MSG = "Avoid using `p` to print things. Use `Jekyll.logger` instead.".freeze
class NoPAllowed < Base
MSG = "Avoid using `p` to print things. Use `Jekyll.logger` instead."
RESTRICT_ON_SEND = %i[p].freeze

def_node_search :p_called?, <<-PATTERN
(send _ :p _)
(send _ :p _)
PATTERN

def on_send(node)
if p_called?(node)
add_offense(node, :location => :selector)
add_offense(node.loc.selector)
end
end
end
Expand Down
11 changes: 5 additions & 6 deletions rubocop/jekyll/no_puts_allowed.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
# frozen_string_literal: true

require "rubocop"

module RuboCop
module Cop
module Jekyll
class NoPutsAllowed < Cop
MSG = "Avoid using `puts` to print things. Use `Jekyll.logger` instead.".freeze
class NoPutsAllowed < Base
MSG = "Avoid using `puts` to print things. Use `Jekyll.logger` instead."
RESTRICT_ON_SEND = %i[puts].freeze

def_node_search :puts_called?, <<-PATTERN
(send nil? :puts _)
(send nil? :puts _)
PATTERN

def on_send(node)
if puts_called?(node)
add_offense(node, :location => :selector)
add_offense(node.loc.selector)
end
end
end
Expand Down