-
-
Notifications
You must be signed in to change notification settings - Fork 276
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
Remove relevance detection code #1063
Conversation
@fatkodima Please take a look, what do you think about memory consumption? Is this faster, or worse than previously? |
I think that's because I'm not a member of a rubocop organization. Just measured - memory is good, good job! 👏 👏 |
.rubocop_todo.yml
Outdated
|
||
RSpec/ExampleLength: | ||
Exclude: | ||
- spec/rubocop/cop/rspec/factory_bot/attribute_defined_statically_spec.rb |
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.
It was a single it_behaves_like
with good_code
and bad_code
defined on example group level. Now, when it's an example, it has overflown the allowed margin.
@@ -1,14 +1,9 @@ | |||
--- | |||
AllCops: |
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 reason I've dropped AllCops
is that it's never mentioned in the docs it's a preferred way to configure cops in departments. It works quite fine on the root level. https://docs.rubocop.org/rubocop/1.0/configuration.html
Also, I think there was some complication where for_badge
didn't work properly with configuration options defined inside AllCops
.
@@ -241,6 +236,9 @@ RSpec/ExpectOutput: | |||
RSpec/FilePath: | |||
Description: Checks that spec file paths are consistent and well-formed. | |||
Enabled: true | |||
Include: | |||
- "**/*_spec*rb*" |
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.
This is due to file name detection, e.g. some_spec.rb.rb
and some_specorb
.
- features/support/factories/**/*.rb | ||
|
||
RSpec: | ||
Include: |
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.
This behavior of Include (overriding default.yml) was introduced in 0.56.0 via rubocop/rubocop#5882. This change allows people to include/exclude precisely what they need to, without the defaults getting in the way.
Include: | ||
- spec/factories.rb | ||
- spec/factories/**/*.rb | ||
- features/support/factories/**/*.rb |
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.
This cop should only inspect factory definitions.
@@ -1,22 +1,57 @@ | |||
# frozen_string_literal: true | |||
|
|||
RSpec.describe RuboCop::Cop::RSpec::FactoryBot::AttributeDefinedStatically do | |||
def inspected_source_filename |
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.
Our overloaded expect_offense
/expect_no_offenses
use this to pass the file name to super
.
This tells the cop that it inspects a relevant source.
end | ||
RUBY | ||
|
||
include_examples 'autocorrect', bad, corrected |
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.
autocorrect
shared example does not pass the correct file path to expect_offense
, and thus the cop considers the file irrelevant and skips it, failing the example.
@@ -1,6 +1,6 @@ | |||
# frozen_string_literal: true | |||
|
|||
RSpec.describe RuboCop::Cop::RSpec::InstanceVariable do | |||
RSpec.describe RuboCop::Cop::RSpec::InstanceVariable, :config do |
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.
Because it needs the default config, specifically Include
, otherwise
expect_no_offenses(<<-RUBY, 'lib/source_code.rb')
fails.
department_name = cop_class.badge.department.to_s | ||
# By default, `RSpec/Include: ['**/*_spec.rb', '**/spec/**/*']` | ||
department_configuration = RuboCop::ConfigLoader | ||
.default_configuration | ||
.for_department(department_name) |
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 hope to submit this upstream.
@fatkodima Thanks! 🙌
Just not yet. Keep up the good work! |
561d04e
to
676b2f4
Compare
Rebased. It's down from |
super | ||
end | ||
|
||
def expect_no_offenses(source, filename = DEFAULT_FILENAME) # rubocop:disable Lint/UselessMethodDefinition |
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.
@tejasbubane Removed it 🤷
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.
This is looking real good. rubocop/rubocop#5882 is an amazing find, and I hope it works as well as it seems 👍
c2105b0
to
bcb058c
Compare
We have had problems with it: - it was slow - it is a non-standard extension of RuboCop's config - Include option exists - department-specific (e.g. FactoryBot) config was ignored
7fb58c3
to
4920879
Compare
@bquorning @Darhazer Please merge at will. Addressed your concerns. |
We have had problems with it:
Patterns
), while a comparableInclude
option existsClose #967
Close #1062
Fixes #1044
It's all interconnected in this PR, here's the path I had to go through:
TODOs
Patterns
->Include
migration (added a TODO there)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 modified an existing cop's configuration options:
VersionChanged
inconfig/default.yml
to the next major version.