Skip to content

Commit

Permalink
Ruby: Introduce rubocop (#49)
Browse files Browse the repository at this point in the history
* Add initial legacy versions of rubocop gems

* Initial files

* Downgrade rubocop gems to support v2.3

* Further downgrade of rubocop gems

* Re-generate files

* Update rubocop to later versions

* Upgrade rubocop slightly and scan on 2.5

* Re-generate config

* Add marker for rubocop autogen

* AF: FrozenStringLiteral

* AF: DescribedClass

* AF: TrailingLines

* AF: StringLiterals

* AF: SpecialGlobalVars

* Re-generated todo file

* Add changelog entry

* Fix ruby changelog message
  • Loading branch information
luke-hill authored Oct 5, 2023
1 parent 39d0039 commit f065f70
Show file tree
Hide file tree
Showing 28 changed files with 428 additions and 25 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- [Ruby] Initial rubocop gems and basic compliance added (More work to come) ([#49](https://github.com/cucumber/compatibility-kit/pull/49))

### Changed
- [Ruby] Minimum ruby version is now bumped from 2.3 to 2.5 ([#47](https://github.com/cucumber/compatibility-kit/pull/47))

Expand All @@ -25,7 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [11.2.0] - 2022-12-23
### Changed
- Update cucumber-messages requirement from ~> 19.1, >= 19.1.2 to >= 19.1.2, < 22.0 in /ruby ([#28](https://github.com/cucumber/compatibility-kit/pull/28))
- [Ruby] Update cucumber-messages requirement from `~> 19.1, >= 19.1.2` to `>= 19.1.2, < 22.0` ([#28](https://github.com/cucumber/compatibility-kit/pull/28))

## [11.1.0] - 2022-12-17

Expand Down
32 changes: 32 additions & 0 deletions ruby/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require:
- rubocop-performance
- rubocop-rake
- rubocop-rspec

inherit_from: .rubocop_todo.yml

inherit_mode:
merge:
- Exclude

AllCops:
TargetRubyVersion: 2.5
NewCops: enable

# Disabled on our repo's to enable polyglot-release
# TODO: Re-enable once rubocop > 1.40
#Gemspec/RequireMFA:
# Enabled: false

Layout/LineLength:
Max: 200

Style/Documentation:
Enabled: false

Style/RegexpLiteral:
EnforcedStyle: slashes
AllowInnerSlashes: true

RSpec/MessageSpies:
EnforcedStyle: receive
317 changes: 317 additions & 0 deletions ruby/.rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,317 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-10-05 09:37:18 UTC using RuboCop version 1.17.0.
# 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 -> 25 files inspected, 145 offenses detected, 96 offenses auto-correctable

# Offense count: 1
# Cop supports --auto-correct.
Layout/EmptyLineAfterGuardClause:
Exclude:
- 'lib/messages_comparator.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: aligned, indented, indented_relative_to_receiver
Layout/MultilineMethodCallIndentation:
Exclude:
- 'lib/cucumber-compatibility-kit.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator.
# SupportedStylesForExponentOperator: space, no_space
Layout/SpaceAroundOperators:
Exclude:
- 'features/attachments/attachments.feature.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: require_no_space, require_space
Layout/SpaceInLambdaLiteral:
Exclude:
- 'features/parameter-types/parameter-types.feature.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
# SupportedStyles: space, no_space
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceInsideBlockBraces:
Exclude:
- 'features/attachments/attachments.feature.rb'

# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: space, no_space
Layout/SpaceInsideStringInterpolation:
Exclude:
- 'spec/capture_warnings.rb'

# Offense count: 1
# Configuration parameters: AllowComments, AllowEmptyLambdas.
Lint/EmptyBlock:
Exclude:
- 'features/minimal/minimal.feature.rb'

# Offense count: 1
# Cop supports --auto-correct.
Lint/EnsureReturn:
Exclude:
- 'spec/capture_warnings.rb'

# Offense count: 1
# Cop supports --auto-correct.
Lint/NonDeterministicRequireOrder:
Exclude:
- 'Rakefile'

# Offense count: 1
# Configuration parameters: AllowComments, AllowNil.
Lint/SuppressedException:
Exclude:
- 'spec/capture_warnings.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
Lint/UnusedBlockArgument:
Exclude:
- 'features/unknown-parameter-type/unknown-parameter-type.feature.rb'

# Offense count: 3
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 27

# Offense count: 3
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
# IgnoredMethods: refine
Metrics/BlockLength:
Max: 83

# Offense count: 3
# Configuration parameters: IgnoredMethods.
Metrics/CyclomaticComplexity:
Max: 11

# Offense count: 3
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
Metrics/MethodLength:
Max: 20

# Offense count: 3
# Configuration parameters: IgnoredMethods.
Metrics/PerceivedComplexity:
Max: 11

# Offense count: 7
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, Regex, IgnoreExecutableScripts, AllowedAcronyms.
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
Naming/FileName:
Exclude:
- 'features/data-tables/data-tables.feature.rb'
- 'features/examples-tables/examples-tables.feature.rb'
- 'features/parameter-types/parameter-types.feature.rb'
- 'features/stack-traces/stack-traces.feature.rb'
- 'features/unknown-parameter-type/unknown-parameter-type.feature.rb'
- 'lib/cucumber-compatibility-kit.rb'
- 'spec/cucumber-compatibility-kit_spec.rb'

# Offense count: 2
# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
# NamePrefix: is_, has_, have_
# ForbiddenPrefixes: is_, has_, have_
# AllowedMethods: is_a?
# MethodDefinitionMacros: define_method, define_singleton_method
Naming/PredicateName:
Exclude:
- 'lib/cucumber-compatibility-kit.rb'

# Offense count: 2
# Cop supports --auto-correct.
Performance/Count:
Exclude:
- 'lib/cucumber-compatibility-kit.rb'

# Offense count: 1
# Cop supports --auto-correct.
Performance/RedundantBlockCall:
Exclude:
- 'spec/capture_warnings.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect.
Performance/StringInclude:
Exclude:
- 'spec/capture_warnings.rb'

# Offense count: 1
Performance/UnfreezeString:
Exclude:
- 'spec/capture_warnings.rb'

# Offense count: 2
# Configuration parameters: Max.
RSpec/ExampleLength:
Exclude:
- 'spec/messages_comparator_spec.rb'

# Offense count: 3
# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
# Include: **/*_spec*rb*, **/spec/**/*
RSpec/FilePath:
Exclude:
- 'spec/cucumber-compatibility-kit_spec.rb'
- 'spec/keys_checker_spec.rb'
- 'spec/messages_comparator_spec.rb'

# Offense count: 1
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 7

# Offense count: 10
# Configuration parameters: IgnoreSharedExamples.
RSpec/NamedSubject:
Exclude:
- 'spec/keys_checker_spec.rb'
- 'spec/messages_comparator_spec.rb'

# Offense count: 1
Rake/Desc:
Exclude:
- 'Rakefile'

# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods.
# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
# FunctionalMethods: let, let!, subject, watch
# IgnoredMethods: lambda, proc, it
Style/BlockDelimiters:
Exclude:
- 'spec/cucumber-compatibility-kit_spec.rb'
- 'spec/keys_checker_spec.rb'
- 'templates/specs.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: nested, compact
Style/ClassAndModuleChildren:
Exclude:
- 'lib/cucumber-compatibility-kit.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: Keywords.
# Keywords: TODO, FIXME, OPTIMIZE, HACK, REVIEW, NOTE
Style/CommentAnnotation:
Exclude:
- 'lib/shared_examples.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/Encoding:
Exclude:
- 'Rakefile'

# Offense count: 1
# Cop supports --auto-correct.
Style/ExpandPathArguments:
Exclude:
- 'Rakefile'

# Offense count: 3
# Cop supports --auto-correct.
Style/GlobalStdStream:
Exclude:
- 'spec/capture_warnings.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: AllowedReceivers.
Style/HashEachMethods:
Exclude:
- 'lib/messages_comparator.rb'

# Offense count: 5
# Cop supports --auto-correct.
Style/IfUnlessModifier:
Exclude:
- 'features/retry/retry.feature.rb'
- 'lib/shared_examples.rb'
- 'spec/capture_warnings.rb'

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: IgnoredMethods.
Style/MethodCallWithoutArgsParentheses:
Exclude:
- 'spec/messages_comparator_spec.rb'

# Offense count: 1
Style/MixinUsage:
Exclude:
- 'Rakefile'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, IgnoredMethods.
# SupportedStyles: predicate, comparison
Style/NumericPredicate:
Exclude:
- 'lib/cucumber-compatibility-kit.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, AllowedCompactTypes.
# SupportedStyles: compact, exploded
Style/RaiseArgs:
Exclude:
- 'lib/cucumber-compatibility-kit.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: Methods.
Style/RedundantArgument:
Exclude:
- 'features/attachments/attachments.feature.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/RedundantBegin:
Exclude:
- 'spec/capture_warnings.rb'

# Offense count: 2
# Cop supports --auto-correct.
Style/RedundantSelf:
Exclude:
- 'features/attachments/attachments.feature.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: only_raise, only_fail, semantic
Style/SignalException:
Exclude:
- 'lib/shared_examples.rb'
- 'spec/capture_warnings.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: MinSize, WordRegex.
# SupportedStyles: percent, brackets
Style/WordArray:
EnforcedStyle: brackets
2 changes: 2 additions & 0 deletions ruby/Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec
6 changes: 4 additions & 2 deletions ruby/Rakefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# encoding: utf-8
# frozen_string_literal: true

require 'rubygems'
require 'bundler'
Bundler::GemHelper.install_tasks

$:.unshift File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)

Dir['./rake/*.rb'].each do |f|
require f
end

require "rspec/core/rake_task"
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)

require_relative 'spec/capture_warnings'
Expand Down
Loading

0 comments on commit f065f70

Please sign in to comment.