Skip to content

Commit

Permalink
Introduce Rubocop/Standard as linter
Browse files Browse the repository at this point in the history
Problem: No coding style is enforced in this project.

Solution: Use standard to get the de facto modern standard of code
style.
  • Loading branch information
stac47 committed Jan 4, 2024
1 parent 37b3717 commit 1ce2bef
Show file tree
Hide file tree
Showing 24 changed files with 464 additions and 209 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,33 @@ on:
push:
branches:
- master

pull_request:

jobs:
lint:
runs-on: ubuntu-latest
name: Lint
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.2.2"
bundler-cache: true
- name: Linter
run: bundle exec rake standard
test:
runs-on: ubuntu-latest
name: Ruby ${{ matrix.ruby }}
strategy:
fail-fast: false
matrix:
ruby: [ '2.7' ]
ruby: [ '2.7', '3.0', '3.1', '3.2', '3.3' ]
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run the default task
- name: Run specs
run: bundle exec rake
100 changes: 100 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
inherit_from: .rubocop_todo.yml

require:
- standard
- rubocop-rspec
- rubocop-rake

inherit_gem:
standard: config/base.yml

Capybara/ClickLinkOrButtonStyle: # new in 2.19
Enabled: false
Capybara/MatchStyle: # new in 2.17
Enabled: false
Capybara/NegationMatcher: # new in 2.14
Enabled: false
Capybara/RedundantWithinFind: # new in 2.20
Enabled: false
Capybara/SpecificActions: # new in 2.14
Enabled: false
Capybara/SpecificFinders: # new in 2.13
Enabled: false
Capybara/SpecificMatcher: # new in 2.12
Enabled: false
Capybara/RSpec/HaveSelector: # new in 2.19
Enabled: false
Capybara/RSpec/PredicateMatcher: # new in 2.19
Enabled: false
FactoryBot/AssociationStyle: # new in 2.23
Enabled: false
FactoryBot/ConsistentParenthesesStyle: # new in 2.14
Enabled: false
FactoryBot/FactoryAssociationWithStrategy: # new in 2.23
Enabled: false
FactoryBot/FactoryNameStyle: # new in 2.16
Enabled: false
FactoryBot/IdSequence: # new in <<next>>
Enabled: false
FactoryBot/RedundantFactoryOption: # new in 2.23
Enabled: false
FactoryBot/SyntaxMethods: # new in 2.7
Enabled: false
RSpec/BeEmpty: # new in 2.20
Enabled: true
RSpec/BeEq: # new in 2.9.0
Enabled: true
RSpec/BeNil: # new in 2.9.0
Enabled: true
RSpec/ChangeByZero: # new in 2.11
Enabled: true
RSpec/ContainExactly: # new in 2.19
Enabled: true
RSpec/DuplicatedMetadata: # new in 2.16
Enabled: true
RSpec/EmptyMetadata: # new in 2.24
Enabled: true
RSpec/Eq: # new in 2.24
Enabled: true
RSpec/ExcessiveDocstringSpacing: # new in 2.5
Enabled: true
RSpec/IdenticalEqualityAssertion: # new in 2.4
Enabled: true
RSpec/IndexedLet: # new in 2.20
Enabled: true
RSpec/MatchArray: # new in 2.19
Enabled: true
RSpec/MetadataStyle: # new in 2.24
Enabled: true
RSpec/NoExpectationExample: # new in 2.13
Enabled: true
RSpec/PendingWithoutReason: # new in 2.16
Enabled: true
RSpec/ReceiveMessages: # new in 2.23
Enabled: true
RSpec/RedundantAround: # new in 2.19
Enabled: true
RSpec/SkipBlockInsideExample: # new in 2.19
Enabled: true
RSpec/SortMetadata: # new in 2.14
Enabled: true
RSpec/SpecFilePathFormat: # new in 2.24
Enabled: true
RSpec/SpecFilePathSuffix: # new in 2.24
Enabled: true
RSpec/SubjectDeclaration: # new in 2.5
Enabled: true
RSpec/VerifiedDoubleReference: # new in 2.10.0
Enabled: true
RSpec/Rails/AvoidSetupHook: # new in 2.4
Enabled: true
RSpec/Rails/HaveHttpStatus: # new in 2.12
Enabled: true
RSpec/Rails/InferredSpecType: # new in 2.14
Enabled: true
RSpec/Rails/MinitestAssertions: # new in 2.17
Enabled: true
RSpec/Rails/NegationBeValid: # new in 2.23
Enabled: true
RSpec/Rails/TravelAround: # new in 2.19
Enabled: true
89 changes: 89 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-01-04 11:01:13 UTC using RuboCop version 1.59.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.

# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
RSpec/BeEq:
Exclude:
- 'spec/outcome_spec.rb'

# Offense count: 8
# Configuration parameters: Prefixes, AllowedPatterns.
# Prefixes: when, with, without
RSpec/ContextWording:
Exclude:
- 'spec/outcome_spec.rb'
- 'spec/validation_spec.rb'

# Offense count: 7
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: SkipBlocks, EnforcedStyle.
# SupportedStyles: described_class, explicit
RSpec/DescribedClass:
Exclude:
- 'spec/outcome_spec.rb'
- 'spec/step_spec.rb'

# Offense count: 5
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 8

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
RSpec/ExpectActual:
Exclude:
- '**/spec/routing/**/*'
- 'spec/validation_spec.rb'

# Offense count: 5
# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
# Include: **/*_spec*rb*, **/spec/**/*
RSpec/FilePath:
Exclude:
- 'spec/hooks_spec.rb'
- 'spec/outcome_spec.rb'
- 'spec/sequence_spec.rb'
- 'spec/step_spec.rb'
- 'spec/validation_spec.rb'

# Offense count: 9
RSpec/MultipleExpectations:
Max: 6

# Offense count: 10
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
# SupportedStyles: always, named_only
RSpec/NamedSubject:
Exclude:
- 'spec/outcome_spec.rb'
- 'spec/validation_spec.rb'

# Offense count: 4
# Configuration parameters: AllowedGroups.
RSpec/NestedGroups:
Max: 4

# Offense count: 5
# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
# Include: **/*_spec.rb
RSpec/SpecFilePathFormat:
Exclude:
- '**/spec/routing/**/*'
- 'spec/hooks_spec.rb'
- 'spec/outcome_spec.rb'
- 'spec/sequence_spec.rb'
- 'spec/step_spec.rb'
- 'spec/validation_spec.rb'

# Offense count: 4
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Exclude:
- 'spec/tzu_spec.rb'
- 'spec/validation_spec.rb'
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ gem "debug"
gem "irb"
gem "rake"
gem "rspec"
gem "rubocop-rspec"
gem "rubocop-rake"
gem "standard"
gem "virtus"
55 changes: 55 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
ast (2.4.2)
axiom-types (0.1.1)
descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0)
Expand All @@ -36,14 +37,25 @@ GEM
irb (1.11.0)
rdoc
reline (>= 0.3.8)
json (2.7.1)
language_server-protocol (3.17.0.3)
lint_roller (1.1.0)
minitest (5.20.0)
parallel (1.24.0)
parser (3.2.2.4)
ast (~> 2.4.1)
racc
psych (5.1.2)
stringio
racc (1.7.3)
rainbow (3.1.1)
rake (13.1.0)
rdoc (6.6.2)
psych (>= 4.0.0)
regexp_parser (2.8.3)
reline (0.4.1)
io-console (~> 0.5)
rexml (3.2.6)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
Expand All @@ -57,10 +69,50 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.1)
rubocop (1.59.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.4)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.30.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-capybara (2.20.0)
rubocop (~> 1.41)
rubocop-factory_bot (2.24.0)
rubocop (~> 1.33)
rubocop-performance (1.20.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (2.25.0)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
ruby-progressbar (1.13.0)
standard (1.33.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.59.0)
standard-custom (~> 1.0.0)
standard-performance (~> 1.3)
standard-custom (1.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.50)
standard-performance (1.3.0)
lint_roller (~> 1.1)
rubocop-performance (~> 1.20.1)
stringio (3.1.0)
thread_safe (0.3.6)
tzinfo (1.2.11)
thread_safe (~> 0.1)
unicode-display_width (2.5.0)
virtus (2.0.0)
axiom-types (~> 0.1)
coercible (~> 1.0)
Expand All @@ -75,6 +127,9 @@ DEPENDENCIES
irb
rake
rspec
rubocop-rake
rubocop-rspec
standard
tzu!
virtus

Expand Down
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "standard/rake"

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
task default: :spec
24 changes: 12 additions & 12 deletions lib/tzu.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
require 'tzu/errors'
require 'tzu/run_methods'
require 'tzu/failure'
require 'tzu/hooks'
require 'tzu/invalid'
require 'tzu/match'
require 'tzu/sequence'
require 'tzu/step'
require 'tzu/outcome'
require 'tzu/validation'
require 'tzu/validation_result'
require "tzu/errors"
require "tzu/run_methods"
require "tzu/failure"
require "tzu/hooks"
require "tzu/invalid"
require "tzu/match"
require "tzu/sequence"
require "tzu/step"
require "tzu/outcome"
require "tzu/validation"
require "tzu/validation_result"

module Tzu
def self.included(base)
Expand All @@ -31,7 +31,7 @@ def run!(params)
outcome.is_a?(Tzu::Outcome) ? outcome : Outcome.new(true, outcome)
end
rescue
rollback! if self.respond_to?(:rollback!)
rollback! if respond_to?(:rollback!)
raise
end

Expand Down
2 changes: 1 addition & 1 deletion lib/tzu/failure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(type = nil, errors = nil)
end

def errors
string_error? ? { errors: @raw_errors } : @raw_errors
string_error? ? {errors: @raw_errors} : @raw_errors
end

def message
Expand Down
1 change: 0 additions & 1 deletion lib/tzu/hooks.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module Tzu

# Provides hooks for arbitrary pre- and post- processing within a command
module Hooks
def self.included(base)
Expand Down
Loading

0 comments on commit 1ce2bef

Please sign in to comment.