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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for rubocop deprecations #85

Merged
merged 2 commits into from
Oct 30, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/smart_todo_cop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ module SmartTodo
# This Cop does not run by default. It should be added to the RuboCop host's configuration file.
#
# @see https://rubocop.readthedocs.io/en/latest/extensions/#loading-extensions
class SmartTodoCop < Cop
class SmartTodoCop < Base
HELP = "For more info please look at https://github.com/Shopify/smart_todo/wiki/Syntax"
MSG = "Don't write regular TODO comments. Write SmartTodo compatible syntax comments. #{HELP}"

# @param processed_source [RuboCop::ProcessedSource]
# @return [void]
def investigate(processed_source)
def on_new_investigation
processed_source.comments.each do |comment|
next unless /^#\sTODO/.match?(comment.text)

Expand Down
12 changes: 6 additions & 6 deletions test/smart_todo/smart_todo_cop_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,19 @@ def expected_message

def expect_offense(source)
annotated_source = RuboCop::RSpec::ExpectOffense::AnnotatedSource.parse(source)
investigate(annotated_source.plain_source)
report = investigate(annotated_source.plain_source)

actual_annotations = annotated_source.with_offense_annotations(cop.offenses)
assert_equal(actual_annotations.to_s, annotated_source.to_s)
actual_annotations = annotated_source.with_offense_annotations(report.offenses)
assert_equal(annotated_source.to_s, actual_annotations.to_s)
end
alias_method :expect_no_offense, :expect_offense

def investigate(source, ruby_version = 2.5, file = "(file)")
processed_source = RuboCop::ProcessedSource.new(source, ruby_version, file)

RuboCop::Cop::Commissioner.new([cop], [], raise_error: true).tap do |commissioner|
commissioner.investigate(processed_source)
end
assert(processed_source.valid_syntax?)
comm = RuboCop::Cop::Commissioner.new([cop], [], raise_error: true)
comm.investigate(processed_source)
end

def cop
Expand Down
Loading