Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dividing and Managing: The Cops Squad of RuboCo...

ydah
May 11, 2023

Dividing and Managing: The Cops Squad of RuboCop RSpec Dept

RubyKaigi 2023 Lightning Talks 「Dividing and Managing: The Cops Squad of RuboCop RSpec Dept」の発表スライド
https://rubykaigi.org/2023/ #rubykaigi

ydah

May 11, 2023
Tweet

More Decks by ydah

Other Decks in Technology

Transcript

  1. Dividing and Managing: The Cops Squad of RuboCop RSpec Dept.

    Yudai Takada RubyKaigi 2023 2023.05.11 (Thu)
  2. ɾ Name: Yudai Takada ɾ GitHub: @ydah ɾ Twitter: @ydah_

    ɾ Member of RuboCop RSpec core team ɾ Software Engineer at ANDPAD, Inc. self.inspect
  3. What is RuboCop RSpec? RSpec-speci fi c analysis for your

    projects, as an extension to RuboCop. Project Goals • Enforce the guidelines and best practices outlined in the community RSpec style guide • Simplify the process of adopting new RSpec functionality
  4. Motivation for splitting gems Capybara and factory_bot cops are not

    limited to RSpec and can also be used with other test frameworks. For example: • Test::Unit • Cucumber • Minitest • Minitest::Spec
  5. If you are not using RSpec but you are using

    FactoryBot. # .rubocop.yml RSpec: Enabled: false RSpec/FactoryBot: Enabled: true 🤔 Should rubocop-rspec really be included in the Gem fi le for a project that is not using RSpec?
  6. Points to note when proceeding RuboCop RSpec follows semantic versioning,

    just like RuboCop, so breaking changes cannot be introduced until the next major version update. Performing the extraction all at once in the next major version update carries high risk ⚠ 👉 So we decided to proceed steadily, step by step, while maintaining backward compatibility.
  7. The steps to extract rubocop-rspec rubocop- capybara rubocop- factory_bot 1.

    Extract cops from each department for rubocop-capybara and rubocop- factory_bot RSpec/ Capybara RSpec/ FactoryBot
  8. The steps to extract 2. Add dependency on the extracted

    gem to rubocop-rspec # rubocop - rspec/lib/rubocop - rspec.rb : 6 require 'rubocop' 7 require 'rubocop - capybara' 8 require 'rubocop - factory_bot'
  9. The steps to extract module RuboCop module Cop module RSpec

    module FactoryBot # @!parse # # Use string value when setting the class attribute explicitly. # # # # @example # # # bad # # factory :foo, class: Foo do # # end # # # # # good # # factory :foo, class: 'Foo' do # # end # # # class FactoryClassName < :: RuboCop :: Cop :: Base; end FactoryClassName = :: RuboCop :: Cop :: FactoryBot : : FactoryClassName end : 3. Create local copies of these cops
  10. The steps to extract 4. Keep the default con fi

    guration settings for the old cop name of rubocop- rspec # conf i g/default.yml RSpec/FactoryBot/AttributeDef i nedStatically: Description: Always declare attribute values as blocks. Enabled: true Include: - spec/factories.rb - spec/factories/**/*.rb - features/support/factories/**/*.rb VersionAdded: '1.28' VersionChanged: '2.0'
  11. The steps to extract 5. Add a deprecation setting to

    warn users about the new cop's name ❯ bundle exec rubocop -A .rubocop.yml: RSpec/Capybara/MatchStyle has the wrong namespace - should be Capybara .rubocop.yml: RSpec/FactoryBot/ConsistentParenthesesStyle has the wrong namespace - should be FactoryBot Inspecting 274 f i les ........................................................................ ........................................................................ ........................................................................ .......................................................... 274 f i les inspected, no offenses detected
  12. Release plan v3.x rubocop-rspec rubocop- capybara rubocop- factory_bot Remove these

    dependencies and notify to install and con fi gure them separately.
  13. Regarding the outstanding issues Since we only extracted the department

    from RuboCop RSpec, there may be cops that do not work properly with test frameworks other than RSpec ⚠ We have not yet been able to address. So, we welcome any contributions :-)
  14. end