RuboCop core team member ● Many patches (recently a few patches) ● The author of ○ rubocop-rake ○ rubocop-extention-generator ○ mry ○ gry ○ rubocop-rubycw ○ rubocop-typed ○ rubocop-regression-test ← Today’s topic
RuboCop breaks easily, with Ruby syntax ● Ruby has too complex syntax. ● Actually we do not understand Ruby syntax perfectly. ● A cop, implemented by us, will overlooks edge cases of Ruby syntax. ● Example: omitting parens
RuboCop breaks easily, with the configuration ● RuboCop has many options. You can configure RuboCop for your style. ● But it introduces complexity. ● Not default option is not maintained enough.
Conclusion of this section ● RuboCop breaks easily ○ with Ruby syntax ○ with configurations ● The regression test is necessary to find bugs before releasing RuboCop.
Example of default configuration Style/StringLiterals: EnforcedStyle: single_quotes SupportedStyles: - single_quotes - double_quotes Layout/DotPosition: EnforcedStyle: leading SupportedStyles: - leading - trailing
It tests RuboCop in real Ruby projects ● Unit test contains only a few code. ○ It may overlook. ● Real Ruby projects contain many codes. ○ We can test cop with many patterns.
It tests RuboCop in real Ruby projects ● Now it tests with: ○ tric/trick2013, 2015 and 2018 ○ rubocop-hq/rubocop ● In the future, I plan adding test with: ○ ruby/spec (pocke/rubocop-regressiontest#16) ○ ruby/ruby ○ rails/rails ○ gitlabhq/gitlabhq ○ discourse/discourse
Execute the following command $ git clone https://github.com/pocke/rubocop-regression-t est $ cd rubocop-regression-test # Clone repo from GitHub and run the test $ ruby main.rb check OWNER/REPO # You can specify local directory also $ ruby main.rb check path/to/your/project/dir
Contribute to RuboCop Regression Test ● You can add more repositories to the test. ○ Add them to CircleCI configuration. ○ If it is green on CI, I can merge it. ● Work for TODOs ○ See the next section, “Future work”.
Test infinite loop in auto correction ● Currently it ignores infinite loop in auto correction. ○ Because it is too noisy. ● But it also should detect and fix infinite loops.
More test for --auto-correct ● Auto correction should generate code that have same meaning if the cop is marked as “safe”. ● In short, test `rubocop -a && rspec`.
Test plugins ● RuboCop has many plugins under the rubocop-hq organization. It should test them also. ○ rubocop-rails ○ rubocop-performance ○ rubocop-rspec ○ rubocop-rake ○ and so on.