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

standard-1-37-0 #4

Merged
merged 8 commits into from
Dec 4, 2024
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ source "https://rubygems.org"

gem "activesupport", require: false
gem "mry", "~> 0.52.0", require: false
gem "parser", "~> 3.0.2"
gem "parser", "~> 3.3.0"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

required in order to satisfy gem dependencies

gem "pry", require: false
gem "safe_yaml"
gem "standard", "~> 1.4", require: false
gem "standard", "1.37.0", require: false
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hardlocked without twiddle wakka to emphasize this is the last version before ruby 3 is a minimum requirement for standard


group :test do
gem "rake"
Expand Down
60 changes: 38 additions & 22 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,25 @@ GEM
diff-lcs (1.4.4)
i18n (1.8.10)
concurrent-ruby (~> 1.0)
json (2.8.2)
language_server-protocol (3.17.0.3)
lint_roller (1.1.0)
method_source (1.0.0)
minitest (5.14.4)
mry (0.52.0.0)
rubocop (>= 0.41.0)
parallel (1.21.0)
parser (3.0.3.1)
parallel (1.26.3)
parser (3.3.6.0)
ast (~> 2.4.1)
racc
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
rainbow (3.0.0)
racc (1.8.1)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.1.1)
rexml (3.2.5)
regexp_parser (2.9.2)
rexml (3.3.9)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
Expand All @@ -40,28 +45,39 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
rubocop (1.22.3)
rubocop (1.64.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.0.0.0)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.12.0, < 2.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.13.0)
parser (>= 3.0.1.1)
rubocop-performance (1.11.5)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
ruby-progressbar (1.11.0)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.36.1)
parser (>= 3.3.1.0)
rubocop-performance (1.21.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (1.13.0)
safe_yaml (1.0.5)
standard (1.4.0)
rubocop (= 1.22.3)
rubocop-performance (= 1.11.5)
standard (1.37.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.64.0)
standard-custom (~> 1.0.0)
standard-performance (~> 1.4)
standard-custom (1.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.50)
standard-performance (1.4.0)
lint_roller (~> 1.1)
rubocop-performance (~> 1.21.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (2.1.0)
unicode-display_width (2.6.0)
zeitwerk (2.4.2)

PLATFORMS
Expand All @@ -70,12 +86,12 @@ PLATFORMS
DEPENDENCIES
activesupport
mry (~> 0.52.0)
parser (~> 3.0.2)
parser (~> 3.3.0)
pry
rake
rspec
safe_yaml
standard (~> 1.4)
standard (= 1.37.0)

BUNDLED WITH
2.1.4
1 change: 1 addition & 0 deletions spec/cc/engine/issue_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "spec_helper"
require "cc/engine/issue"
require "ostruct"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This spec and the one below was failing after the gem updates due to needing OpenStruct explicitly required now. OpenStruct is not used in the engine itself, only in specs. Therefore adding these requires here is an appropriate fix

uninitialized constant CC::Engine::OpenStruct


module CC::Engine
describe Issue do
Expand Down
1 change: 1 addition & 0 deletions spec/cc/engine/standard_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "spec_helper"
require "cc/engine/standard"
require "tmpdir"
require "ostruct"

module CC::Engine
describe Standard do
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/config_patch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module CC::Engine
expect { config.validate }.to output(<<~TXT).to_stderr
The `Style/TrailingComma` cop has been removed. Please use `Style/TrailingCommaInArguments`, `Style/TrailingCommaInArrayLiteral` and/or `Style/TrailingCommaInHashLiteral` instead.
(obsolete configuration found in .rubocop.yml, please update it)
unrecognized cop Style/TrailingComma found in .rubocop.yml
unrecognized cop or department Style/TrailingComma found in .rubocop.yml
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

On master without any changes at all, this is failing. Seems that Style/TrailingComma modified its output and rake docs:scrape has differences in it than what it once was

Did you mean `Style/TrailingCommaInArguments`?
TXT
end
Expand Down
1 change: 1 addition & 0 deletions spec/support/currently_undocumented_cops.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ RuboCop::Cop::Lint::Syntax
RuboCop::Cop::Migration::DepartmentName
RuboCop::Cop::Style::ConditionalAssignment
RuboCop::Cop::Style::DoubleCopDisableDirective
RuboCop::Cop::Style::BlockDelimiters
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Again, on master without any changes, this too is also failing a spec (even after running rake docs:scrape). Added here to fix

"#{cop.name} has no content ..."

17 changes: 16 additions & 1 deletion spec/support/standard_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
module StandardRunner
def self.included(example_group)
example_group.include FilesystemHelpers
example_group.before do
allow_any_instance_of(RuboCop::AST::ProcessedSource).to receive(:registry).and_return(registry)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

after the updates (due to rubocop version change), we see a STDERR after 3 specs run

An error occurred while Lint/MissingCopEnableDirective cop was inspecting /tmp/.../test.rb
An error occurred while Lint/UselessAssignment cop was inspecting /tmp/.../test.rb
An error occurred while Style/RedundantReturn cop was inspecting /tmp/.../test.rb

If you add a debug: true kwarg to lib/cc/engine/source_file#rubocop_team instance of RuboCop::Cop::Team.new instantiation, we get a detailed backrace (analogous to using rubocop -d cli + flag) which says

undefined method 'disabled' for nil:NilClass
  /home/milesstanfield/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.68.0/lib/rubocop/comment_config.rb:116:in `inject_disabled_cops_directives'

and points to this line of code in the rubocop gem. A github issue was opened about this and it appears to only be spec-related. There was a more involved solution proposed but generally the idea is we need to stub this registry method call value on the RuboCop::AST::ProcessedSource instance.

That is what i've done here by borrowing from the code suggested as a fix in that github issue using CopHelper#registry found here

end
example_group.around do |example|
Dir.mktmpdir do |code|
@code = code
Expand All @@ -21,10 +24,22 @@ def issues(output = @engine_output)
end

def run_engine(config = nil)
@config = config
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

set as an instance variable now so if config arg was passed into this (which it is in at least one spec in this repo) then we use that when generating the registry value instead of a blank config object (see below)

io = StringIO.new
standard = CC::Engine::Standard.new(@code, config, io)
standard = CC::Engine::Standard.new(@code, @config, io)
standard.run

@engine_output = io.string
end

def registry
# https://github.com/rubocop/rubocop/blob/master/lib/rubocop/rspec/cop_helper.rb
@registry ||= begin
keys = RuboCop::Config.new(@config || {}, "#{Dir.pwd}/.rubocop.yml").keys
cops = keys.map { |directive| RuboCop::Cop::Registry.global.find_cops_by_directive(directive) }.flatten
cops << cop_class if defined?(cop_class) && !cops.include?(cop_class)
cops.compact!
RuboCop::Cop::Registry.new(cops)
end
end
end