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

Enabling rubo configs/12 20 23 #241

Open
wants to merge 45 commits into
base: main
Choose a base branch
from

Conversation

calderete
Copy link

🤔 What's changed?

Regenerated rubcop todo and fixed warnings.
Added to rubocop config:

Metrics/AbcSize:
Max: 30

Metrics/MethodLength:
Max: 23

RSpec/ExampleLength:
Max: 6

⚡️ What's your motivation?

Helping out

🏷️ What kind of change is this?

  • 🏦 Refactoring/debt/DX (improvement to code design, tooling, documentation etc. without changing behaviour)

♻️ Anything particular you want feedback on?

I added some configs to rubocop.yml for code length. Should those be refactored to fit those cops instead?

📋 Checklist:


This text was originally generated from a template, then edited by hand. You can modify the template here.

@mpkorstanje
Copy link
Contributor

Hey! Thanks for wanting to help out!

I'll have to let Luke do the actual review. But for your pull request title and description please follow the guidance from https://cbea.ms/git-commit

It helps everyone to quickly see what your pull request is about.

@olleolleolle
Copy link
Contributor

(And yeah, awesome that you made a PR!)

Copy link
Contributor

@luke-hill luke-hill left a comment

Choose a reason for hiding this comment

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

Few things to unpick or tweak if you can. Will chat on slack too.

ruby/.rubocop.yml Outdated Show resolved Hide resolved
ruby/Gemfile Outdated Show resolved Hide resolved
ruby/lib/cucumber/ci_environment.rb Outdated Show resolved Hide resolved
ruby/lib/cucumber/ci_environment/variable_expression.rb Outdated Show resolved Hide resolved
ruby/lib/cucumber/ci_environment/variable_expression.rb Outdated Show resolved Hide resolved
ruby/lib/cucumber/ci_environment/variable_expression.rb Outdated Show resolved Hide resolved
result = evaluate(expression, { 'GO_SCM_MY_MATERIAL_PR_BRANCH' => 'ashwankthkumar:feature-1' })
expect(result).to eq('feature-1')
end

it 'evaluates a complex expression' do
expression = "hello-${VAR1}-${VAR2/(.*) (.*)/\\2-\\1}-world"
expression = 'hello-${VAR1}-${VAR2/(.*) (.*)/\\2-\\1}-world'
result = evaluate(expression, {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you're comfortable using multi-line here this can be fixed. Or I can tackle it at a later date

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, I'm not sure what is meant by "multi-line" here

Copy link
Contributor

Choose a reason for hiding this comment

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

This stylistically is quite wild now, so ideally it should be on multiple lines. i.e.

(
  {
  }
)

If you're not comfortable tidying it up, don't feel the need to fix it all. We can revisit these at a later date.

Copy link
Author

Choose a reason for hiding this comment

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

I guess I'm not understanding how the highlighted line could be refactored into multi line. The rest of that block is multi line. Do you mean the other blocks in this file?

Copy link
Contributor

Choose a reason for hiding this comment

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

As written above, the rubocop parser is detecting you want to have this right-aligned, which shifts all the code along. If you make it left aligned in the braces then it fixes this issue

Copy link
Contributor

@luke-hill luke-hill left a comment

Choose a reason for hiding this comment

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

Popped an update on to help you along if you have time.

ruby/Rakefile Outdated Show resolved Hide resolved
variable = $1
pattern = $2
replacement = $3
variable = ::Regexp.last_match(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure these need to be top-level namespaced

Copy link
Author

Choose a reason for hiding this comment

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

Tests pass when refactoring ::Regexp to just Regexp do you want me to change these to Regexp?

@@ -3,15 +3,15 @@
require 'cucumber/ci_environment'
require 'json'

describe 'detect_ci_environment' do
describe Cucumber::CiEnvironment, '.detect_ci_environment' do
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be in 2 blocks. So the top level should say

describe Cucumber::CiEnvironment

and then underneath it it should have the 2nd block

Copy link
Author

@calderete calderete Jan 11, 2024

Choose a reason for hiding this comment

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

Do you mean refactor it to be ?

describe Cucumber::CiEnvironment do
  it 'detects CI environment' do
    <test code>
  end
end

Copy link
Contributor

Choose a reason for hiding this comment

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

2nd line should be describe '.detect_ci_environment'

require 'cucumber/ci_environment'

describe 'remove_user_info_from_url' do
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as the above one.

require 'cucumber/ci_environment'

describe 'Cucumber::CiEnvironment::VariableExpression.evaluate' do
Copy link
Contributor

Choose a reason for hiding this comment

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

This also needs to be in double blocks

require 'cucumber/ci_environment'

describe 'Cucumber::CiEnvironment::VariableExpression.evaluate' do
include Cucumber::CiEnvironment::VariableExpression
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to amend this as this isn't the way to write these kinds of specs, we should be using isolated lets. But given this is already here we can ignore this and fix it later.

Copy link
Author

Choose a reason for hiding this comment

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

I am curious as to how the let refactor would work and what is the difference? From looking at this spec file I can see what it is testing, the inputs and expected outputs are readily seen. What is bad about this rspec file?

Copy link
Contributor

Choose a reason for hiding this comment

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

When you include something inside a describe block it pollutes the whole namespace. Dependent on how you ran / checked rubocop it will flag this to you. A better way it to use an isolated anonymous class inside a let so something like

let(:foo) do
  Class.new(inheritance) do
    include RequiredModule1
    include RequiredModule2
  end
end

Now the inclusion is completely isolated inside the memoized let.

# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# TODO: Oct '23 -> 10 files inspected, 63 offenses detected, 53 offenses autocorrectable
Copy link
Contributor

Choose a reason for hiding this comment

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

if you leave these stylistic markers in it'll show we're slowly getting more conformant. It'll also warn us if we're getting less conformant

result = evaluate(expression, { 'GO_SCM_MY_MATERIAL_PR_BRANCH' => 'ashwankthkumar:feature-1' })
expect(result).to eq('feature-1')
end

it 'evaluates a complex expression' do
expression = "hello-${VAR1}-${VAR2/(.*) (.*)/\\2-\\1}-world"
expression = 'hello-${VAR1}-${VAR2/(.*) (.*)/\\2-\\1}-world'
result = evaluate(expression, {
Copy link
Contributor

Choose a reason for hiding this comment

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

This stylistically is quite wild now, so ideally it should be on multiple lines. i.e.

(
  {
  }
)

If you're not comfortable tidying it up, don't feel the need to fix it all. We can revisit these at a later date.

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.

None yet

4 participants