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

Add new Minitest/SkipWithoutReason cop #199

Merged
merged 1 commit into from
Nov 25, 2022

Conversation

fatkodima
Copy link
Contributor

Closes #198.

I am thinking: do we need a config option to be able to always enforce skip with comments (no matter if in conditional or not)?

@koic
Copy link
Member

koic commented Nov 23, 2022

I think this cop can be published without a config option first. How about a rule like the one below for conditions?

# bad
if condition
  do_something
  skip
end

# good
skip if condition

if condition
  skip
end

It is clear when the if body has a single sentence, but may be ambiguous when there are multiple sentences.

while is also ambiguous than if, so it may be bad.

# bad
do_something while condition

And It's a corner case, I think the following is also bad.

# bad
if condition
  skip
else
  skip
end

Can you add test cases and adjust the implementation?

# # good
# skip if condition?
#
class SkipWithoutComment < Base
Copy link
Member

@koic koic Nov 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a name like SkipWithoutArgument, SkipWithoutMessageArgument, or SkipWithoutReason? Because "comment" might imagine source code comment.

@fatkodima fatkodima force-pushed the skip_without_comment-cop branch from f3bfda5 to 41713bc Compare November 23, 2022 22:50
@fatkodima
Copy link
Contributor Author

@koic Changed the name and adjusted the logic accordingly to the comments.

@koic
Copy link
Member

koic commented Nov 24, 2022

I tried running it with the rails/rails repo.

In the following, all when not use skip, only else uses skip. In other words, the reason for skip in else is derivable, so I think it can be allowed. e.g.:

          case connection.class::ADAPTER_NAME
          when "PostgreSQL"
            unless connection.instance_variable_get(:@raw_connection).transaction_status == ::PG::PQTRANS_INTRANS
              connection.instance_variable_get(:@raw_connection).async_exec("begin")
            end
            connection.instance_variable_get(:@raw_connection).async_exec("set idle_in_transaction_session_timeout = '10ms'")
            sleep 0.05
          when "Mysql2"
            connection.send(:internal_execute, "set @@wait_timeout=1")
            sleep 1.2
          else
            skip
          end

It also seems obvious to skip in case of an exception, so it seems that it can be also allowed. e.g.:

     begin
       @cache.delete_matched("*")
     rescue NotImplementedError
       skip
     end

@fatkodima Can you take a look at this?

@fatkodima fatkodima force-pushed the skip_without_comment-cop branch from 41713bc to ef1eeb4 Compare November 24, 2022 10:42
@fatkodima
Copy link
Contributor Author

@koic Updated with the suggested cases.

@fatkodima fatkodima force-pushed the skip_without_comment-cop branch from ef1eeb4 to f2d0dda Compare November 24, 2022 19:00
@fatkodima
Copy link
Contributor Author

Thanks for another review! Added more suggested changes.

@koic
Copy link
Member

koic commented Nov 25, 2022

Let's start with this behavior and adjust it according to feedback use cases. Thank you!

@koic koic merged commit aa58a56 into rubocop:master Nov 25, 2022
@fatkodima fatkodima deleted the skip_without_comment-cop branch November 25, 2022 15:37
@fatkodima fatkodima changed the title Add new Minitest/SkipWithoutComment cop Add new Minitest/SkipWithoutReason cop Dec 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New cop to ensure 'skip' has a message
2 participants