Skip to content

Commit 2c3d9af

Browse files
tstannardashleywillardivy
authored
Add rubocop (#97)
Co-authored-by: Ashley Willard <[email protected]> Co-authored-by: Ivy Evans <[email protected]>
1 parent d9363b9 commit 2c3d9af

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+473
-253
lines changed

.rubocop.yml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
inherit_from: .rubocop_todo.yml
2+
3+
# The behavior of RuboCop can be controlled via the .rubocop.yml
4+
# configuration file. It makes it possible to enable/disable
5+
# certain cops (checks) and to alter their behavior if they accept
6+
# any parameters. The file can be placed either in your home
7+
# directory or in some project directory.
8+
#
9+
# RuboCop will start looking for the configuration file in the directory
10+
# where the inspected file is and continue its way up to the root directory.
11+
#
12+
# See https://docs.rubocop.org/rubocop/configuration
13+
AllCops:
14+
NewCops: enable
15+
Exclude:
16+
- vendor/bundle/**/**
17+
TargetRubyVersion: 2.6
18+
19+
Metrics/ParameterLists:
20+
Enabled: false
21+
22+
# This cop is annoying with typed configuration
23+
Style/TrivialAccessors:
24+
Enabled: false
25+
26+
# This rubocop is annoying when we use interfaces a lot
27+
Lint/UnusedMethodArgument:
28+
Enabled: false
29+
30+
Gemspec/RequireMFA:
31+
Enabled: false
32+
33+
Lint/DuplicateBranch:
34+
Enabled: false
35+
36+
# If is sometimes easier to think about than unless sometimes
37+
Style/NegatedIf:
38+
Enabled: false
39+
40+
# Disabling for now until it's clearer why we want this
41+
Style/FrozenStringLiteralComment:
42+
Enabled: false
43+
44+
# It's nice to be able to read the condition first before reading the code within the condition
45+
Style/GuardClause:
46+
Enabled: false
47+
48+
#
49+
# Leaving length metrics to human judgment for now
50+
#
51+
Metrics/ModuleLength:
52+
Enabled: false
53+
54+
Layout/LineLength:
55+
Enabled: false
56+
57+
Metrics/BlockLength:
58+
Enabled: false
59+
60+
Metrics/MethodLength:
61+
Enabled: false
62+
63+
Metrics/AbcSize:
64+
Enabled: false
65+
66+
Metrics/ClassLength:
67+
Enabled: false
68+
69+
# This doesn't feel useful
70+
Metrics/CyclomaticComplexity:
71+
Enabled: false
72+
73+
# This doesn't feel useful
74+
Metrics/PerceivedComplexity:
75+
Enabled: false
76+
77+
# It's nice to be able to read the condition first before reading the code within the condition
78+
Style/IfUnlessModifier:
79+
Enabled: false
80+
81+
# This leads to code that is not very readable at times (very long lines)
82+
Style/ConditionalAssignment:
83+
Enabled: false
84+
85+
# For now, we prefer to lean on clean method signatures as documentation. We may change this later.
86+
Style/Documentation:
87+
Enabled: false
88+
89+
# Sometimes we leave comments in empty else statements intentionally
90+
Style/EmptyElse:
91+
Enabled: false
92+
93+
# Sometimes we want to more explicitly list out a condition
94+
Style/RedundantCondition:
95+
Enabled: false
96+
97+
# This leads to code that is not very readable at times (very long lines)
98+
Layout/MultilineMethodCallIndentation:
99+
Enabled: false
100+
101+
# Blocks across lines are okay sometimes
102+
Style/BlockDelimiters:
103+
Enabled: false
104+
105+
# Sometimes we like methods like `get_packages`
106+
Naming/AccessorMethodName:
107+
Enabled: false
108+
109+
# This leads to code that is not very readable at times (very long lines)
110+
Layout/FirstArgumentIndentation:
111+
Enabled: false
112+
113+
# This leads to code that is not very readable at times (very long lines)
114+
Layout/ArgumentAlignment:
115+
Enabled: false
116+
117+
Style/AccessorGrouping:
118+
Enabled: false
119+
120+
Style/HashSyntax:
121+
Enabled: false
122+
123+
Gemspec/DevelopmentDependencies:
124+
Enabled: true
125+
EnforcedStyle: gemspec

.rubocop_todo.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# This configuration was generated by
2+
# `rubocop --auto-gen-config`
3+
# on 2024-11-15 19:57:24 UTC using RuboCop version 1.65.0.
4+
# The point is for the user to remove these configuration records
5+
# one by one as the offenses are removed from the code base.
6+
# Note that changes in the inspected code, or installation of new
7+
# versions of RuboCop, may require this file to be generated again.
8+
9+
# Offense count: 1
10+
# Configuration parameters: EnforcedStyle, AllowedGems, Include.
11+
# SupportedStyles: Gemfile, gems.rb, gemspec
12+
# Include: **/*.gemspec, **/Gemfile, **/gems.rb
13+
Gemspec/DevelopmentDependencies:
14+
Exclude:
15+
- 'spec/fixtures/rails-7.0/Gemfile'
16+
17+
# Offense count: 2
18+
# Configuration parameters: Severity, Include.
19+
# Include: **/*.gemspec
20+
Gemspec/RequiredRubyVersion:
21+
Exclude:
22+
- 'packs-rails.gemspec'
23+
- 'spec/fixtures/rails-7.0/components/jackets/jackets.gemspec'
24+
25+
# Offense count: 16
26+
# Configuration parameters: AllowComments.
27+
Lint/EmptyClass:
28+
Enabled: false
29+
30+
# Offense count: 3
31+
# Configuration parameters: AllowComments.
32+
Lint/EmptyFile:
33+
Exclude:
34+
- 'spec/fixtures/rails-6.1/packs/shirts/app/models/shirts/pocket.rb'
35+
- 'spec/fixtures/rails-7.0/components/jackets/jackets.gemspec'
36+
- 'spec/fixtures/rails-7.0/packs/shirts/app/models/shirts/pocket.rb'
37+
38+
# Offense count: 2
39+
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
40+
# CheckDefinitionPathHierarchyRoots: lib, spec, test, src
41+
# 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
42+
Naming/FileName:
43+
Exclude:
44+
- 'Rakefile.rb'
45+
- 'lib/packs-rails.rb'
46+
- 'spec/packs-rails_spec.rb'
47+
48+
# Offense count: 3
49+
# This cop supports unsafe autocorrection (--autocorrect-all).
50+
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
51+
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
52+
Naming/MemoizedInstanceVariableName:
53+
Exclude:
54+
- 'lib/packs/rails/integrations/rails.rb'
55+
56+
# Offense count: 1
57+
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
58+
# SupportedStyles: snake_case, normalcase, non_integer
59+
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
60+
Naming/VariableNumber:
61+
Exclude:
62+
- 'lib/packs/rails/integrations/rails.rb'
63+
64+
# Offense count: 2
65+
# This cop supports unsafe autocorrection (--autocorrect-all).
66+
Style/GlobalStdStream:
67+
Exclude:
68+
- 'spec/fixtures/rails-6.1/config/environments/production.rb'
69+
- 'spec/fixtures/rails-7.0/config/environments/production.rb'
70+
71+
# Offense count: 2
72+
# This cop supports unsafe autocorrection (--autocorrect-all).
73+
# Configuration parameters: RequireEnglish.
74+
# SupportedStyles: use_perl_names, use_english_names, use_builtin_english_names
75+
Style/SpecialGlobalVars:
76+
EnforcedStyle: use_perl_names

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
source "https://rubygems.org"
1+
source 'https://rubygems.org'
22

33
# Specify your gem's dependencies in packs-rails.gemspec
44
gemspec

bin/console

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env ruby
22

3-
require "bundler/setup"
4-
require "packs-rails"
3+
require 'bundler/setup'
4+
require 'packs-rails'
55

66
# You can add fixtures and/or initialization code here to make experimenting
77
# with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "packs-rails"
1010
# require "pry"
1111
# Pry.start
1212

13-
require "irb"
13+
require 'irb'
1414
IRB.start(__FILE__)

bin/tapioca

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
# this file is here to facilitate running it.
99
#
1010

11-
require "pathname"
12-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11+
require 'pathname'
12+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
1313
Pathname.new(__FILE__).realpath)
1414

15-
bundle_binstub = File.expand_path("../bundle", __FILE__)
15+
bundle_binstub = File.expand_path('bundle', __dir__)
1616

1717
if File.file?(bundle_binstub)
1818
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
@@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
2323
end
2424
end
2525

26-
require "rubygems"
27-
require "bundler/setup"
26+
require 'rubygems'
27+
require 'bundler/setup'
2828

29-
load Gem.bin_path("tapioca", "tapioca")
29+
load Gem.bin_path('tapioca', 'tapioca')

lib/packs-rails.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'packs'
2-
require "active_support"
3-
require "rails/application"
2+
require 'active_support'
3+
require 'rails/application'
44
require 'sorbet-runtime'
55

66
module Packs
@@ -22,7 +22,7 @@ def root
2222
end
2323

2424
@config = ActiveSupport::OrderedOptions.new
25-
@config.paths = %w(
25+
@config.paths = %w[
2626
app
2727
app/controllers
2828
app/channels
@@ -36,8 +36,8 @@ def root
3636
config/locales
3737
config/initializers
3838
config/routes
39-
)
39+
]
4040
end
4141

42-
require "packs/rails/railtie"
42+
require 'packs/rails/railtie'
4343
end

lib/packs/rails/integrations.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
require "active_support"
1+
require 'active_support'
22

33
module Packs
44
module Rails
55
module Integrations
6-
autoload :FactoryBot, "packs/rails/integrations/factory_bot"
7-
autoload :Rails, "packs/rails/integrations/rails"
8-
autoload :RSpec, "packs/rails/integrations/rspec"
6+
autoload :FactoryBot, 'packs/rails/integrations/factory_bot'
7+
autoload :Rails, 'packs/rails/integrations/rails'
8+
autoload :RSpec, 'packs/rails/integrations/rspec'
99
end
1010
end
1111
end

lib/packs/rails/integrations/factory_bot.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ def initialize(app)
88
return unless app.config.respond_to?(:factory_bot)
99

1010
Packs.all.reject(&:is_gem?).each do |pack|
11-
app.config.factory_bot.definition_file_paths << pack.relative_path.join("spec/factories").to_s
12-
app.config.factory_bot.definition_file_paths << pack.relative_path.join("test/factories").to_s
11+
app.config.factory_bot.definition_file_paths << pack.relative_path.join('spec/factories').to_s
12+
app.config.factory_bot.definition_file_paths << pack.relative_path.join('test/factories').to_s
1313
end
1414
end
1515
end

lib/packs/rails/integrations/rails.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# frozen_string_literal: true
22
# typed: true
33

4-
require "active_support/inflections"
4+
require 'active_support/inflections'
55

66
module Packs
77
module Rails
88
module Integrations
99
class Rails
10-
CONFIG_ROUTES_PATH = "config/routes".freeze
10+
CONFIG_ROUTES_PATH = 'config/routes'
1111

1212
def initialize(app)
1313
@app = app
@@ -42,12 +42,13 @@ def inject_paths
4242

4343
def pre_rails_6_1?
4444
return @_pre_rails_6_1 if defined?(@_pre_rails_6_1)
45-
@_pre_rails_6_1 = ::Rails.gem_version < Gem::Version.new("6.1")
45+
46+
@_pre_rails_6_1 = ::Rails.gem_version < Gem::Version.new('6.1')
4647
end
4748

4849
def create_namespace(name)
4950
namespace = ActiveSupport::Inflector.camelize(name)
50-
namespace.split("::").reduce(Object) do |base, mod|
51+
namespace.split('::').reduce(Object) do |base, mod|
5152
if base.const_defined?(mod, false)
5253
base.const_get(mod, false)
5354
else
@@ -57,10 +58,10 @@ def create_namespace(name)
5758
end
5859

5960
def create_engine(pack)
60-
name = pack.metadata.fetch("engine_name", pack.last_name)
61+
name = pack.metadata.fetch('engine_name', pack.last_name)
6162
namespace = create_namespace(name)
6263
stim = Stim.new(pack, namespace)
63-
namespace.const_set("Engine", Class.new(::Rails::Engine)).include(stim)
64+
namespace.const_set('Engine', Class.new(::Rails::Engine)).include(stim)
6465
end
6566
end
6667
end

lib/packs/rails/integrations/rspec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def initialize
1717

1818
pack_paths = Packs.all.map do |pack|
1919
next if pack.is_gem?
20+
2021
spec_path = pack.relative_path.join(default_path)
2122
spec_path.to_s if spec_path.exist?
2223
end
@@ -28,11 +29,11 @@ def initialize
2829
# end of it.
2930
#
3031
# packs/my_pack => packs/my_pack/spec
31-
#
32+
#
3233
# If it doesn't match a pack path, we leave it alone.
3334

3435
to_run.map! do |path|
35-
if pack = Packs.find(path)
36+
if (pack = Packs.find(path))
3637
[
3738
pack,
3839
*nested_packs_for(pack)

lib/packs/rails/railtie.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require "rails/railtie"
1+
require 'rails/railtie'
22

33
module Packs
44
module Rails
@@ -11,7 +11,6 @@ class Railtie < ::Rails::Railtie
1111
# hook into packs-rails via ActiveSupport hooks.
1212
ActiveSupport.run_load_hooks(:packs_rails, Packs)
1313
end
14-
1514
end
1615
end
1716
end

lib/packs/rails/rspec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
require "packs-rails"
1+
require 'packs-rails'
22

33
Packs::Rails::Integrations::RSpec.new

0 commit comments

Comments
 (0)