-
-
Notifications
You must be signed in to change notification settings - Fork 277
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 RSpec/UndescriptiveLiteralsDescription
cop
#1796
Conversation
f0b91b2
to
0736d4a
Compare
Is it ok to have a cop that singles out the |
RSpec/ExecuteStringOnlyDescription
copRSpec/DescriptiveDescription
cop
For example, description specifies the class to be tested, so I don't think it is just string and dstr. Regex and Integer have added support and renamed Cop. |
RSpec/DescriptiveDescription
copRSpec/UnclearDescription
cop
RSpec/UnclearDescription
copRSpec/UndescriptiveLiteralsDescription
cop
I changed this cop name from UnclearDescription to UndescriptiveLiteralsDescription. |
spec/rubocop/cop/rspec/undescriptive_literals_description_spec.rb
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good. Thank you!
i’d love to run this on real-world-rspec but lack capacity to do this myself
d5836ea
to
feb60e6
Compare
private | ||
|
||
def offense?(node) | ||
if node.send_type? && node.method?(:+) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You’ve added a test for foo + time, but only when all? is false.
If your experience suggests that we need to dive as deep as handling +, I think that if any of parts is an xstr, the whole thing is non-deterministic.
Is sometimh like “‘time’ + ‘whoami’” real? Or just as mistyped quotes like “‘when it is’ + time”?
Again, no objections on merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I re-think it might be better to always allow for concatenation by +
. Because it seems difficult to understand the offense in case of offenses, and it seems to be outside the scope of this cop.
it 'registers an offense when using `describe` with `time`+"foo"' do
expect_offense(<<~RUBY)
describe `time` + 'foo' do
^^^^^^^^^^^^^^ Description should be descriptive.
end
RUBY
end
it 'registers an offense when using `describe` with "foo"+`time`' do
expect_offense(<<~RUBY)
describe 'foo' + `time` do
^^^^^^^^^^^^^^ Description should be descriptive.
end
RUBY
end
it 'registers an offense when using `describe` with "foo+(`time`+"bar")' do
expect_offense(<<~RUBY)
describe 'foo' + (`time` + 'bar') do
^^^^^^^^^^^^^^^^^^^^^^^^ Description should be descriptive.
end
RUBY
end
7bf03f9
to
b60ff5f
Compare
Looks fine:
|
@pirj Do you have any concerns? |
@ydah The code looks good. |
@pirj I'm sorry. It seems that I didn't explain it enough, but the following comment shows that after doing it with real-wolrld-rspec, I was able to see the offense I expected to detect without generating any false positives or errors 🙇🏻 |
@ydah my apologies, this slipped my attention. |
Fix: #1754
Before submitting the PR make sure the following are checked:
master
(if not - rebase it).CHANGELOG.md
if the new code introduces user-observable changes.bundle exec rake
) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).If you have created a new cop:
config/default.yml
.Enabled: pending
inconfig/default.yml
.Enabled: true
in.rubocop.yml
.VersionAdded: "<<next>>"
indefault/config.yml
.