Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rubocop #97

Merged
merged 4 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
inherit_from: .rubocop_todo.yml

# The behavior of RuboCop can be controlled via the .rubocop.yml
# configuration file. It makes it possible to enable/disable
# certain cops (checks) and to alter their behavior if they accept
# any parameters. The file can be placed either in your home
# directory or in some project directory.
#
# RuboCop will start looking for the configuration file in the directory
# where the inspected file is and continue its way up to the root directory.
#
# See https://docs.rubocop.org/rubocop/configuration
AllCops:
NewCops: enable
Exclude:
- vendor/bundle/**/**
TargetRubyVersion: 2.6

Metrics/ParameterLists:
Enabled: false

# This cop is annoying with typed configuration
Style/TrivialAccessors:
Enabled: false

# This rubocop is annoying when we use interfaces a lot
Lint/UnusedMethodArgument:
Enabled: false

Gemspec/RequireMFA:
Enabled: false

Lint/DuplicateBranch:
Enabled: false

# If is sometimes easier to think about than unless sometimes
Style/NegatedIf:
Enabled: false

# Disabling for now until it's clearer why we want this
Style/FrozenStringLiteralComment:
Enabled: false

# It's nice to be able to read the condition first before reading the code within the condition
Style/GuardClause:
Enabled: false

#
# Leaving length metrics to human judgment for now
#
Metrics/ModuleLength:
Enabled: false

Layout/LineLength:
Enabled: false

Metrics/BlockLength:
Enabled: false

Metrics/MethodLength:
Enabled: false

Metrics/AbcSize:
Enabled: false

Metrics/ClassLength:
Enabled: false

# This doesn't feel useful
Metrics/CyclomaticComplexity:
Enabled: false

# This doesn't feel useful
Metrics/PerceivedComplexity:
Enabled: false

# It's nice to be able to read the condition first before reading the code within the condition
Style/IfUnlessModifier:
Enabled: false

# This leads to code that is not very readable at times (very long lines)
Style/ConditionalAssignment:
Enabled: false

# For now, we prefer to lean on clean method signatures as documentation. We may change this later.
Style/Documentation:
Enabled: false

# Sometimes we leave comments in empty else statements intentionally
Style/EmptyElse:
Enabled: false

# Sometimes we want to more explicitly list out a condition
Style/RedundantCondition:
Enabled: false

# This leads to code that is not very readable at times (very long lines)
Layout/MultilineMethodCallIndentation:
Enabled: false

# Blocks across lines are okay sometimes
Style/BlockDelimiters:
Enabled: false

# Sometimes we like methods like `get_packages`
Naming/AccessorMethodName:
Enabled: false

# This leads to code that is not very readable at times (very long lines)
Layout/FirstArgumentIndentation:
Enabled: false

# This leads to code that is not very readable at times (very long lines)
Layout/ArgumentAlignment:
Enabled: false

Style/AccessorGrouping:
Enabled: false

Style/HashSyntax:
Enabled: false

Gemspec/DevelopmentDependencies:
Enabled: true
EnforcedStyle: gemspec
76 changes: 76 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-11-15 19:57:24 UTC using RuboCop version 1.65.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: 1
# Configuration parameters: EnforcedStyle, AllowedGems, Include.
# SupportedStyles: Gemfile, gems.rb, gemspec
# Include: **/*.gemspec, **/Gemfile, **/gems.rb
Gemspec/DevelopmentDependencies:
Exclude:
- 'spec/fixtures/rails-7.0/Gemfile'

# Offense count: 2
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/RequiredRubyVersion:
Exclude:
- 'packs-rails.gemspec'
- 'spec/fixtures/rails-7.0/components/jackets/jackets.gemspec'

# Offense count: 16
# Configuration parameters: AllowComments.
Lint/EmptyClass:
Enabled: false

# Offense count: 3
# Configuration parameters: AllowComments.
Lint/EmptyFile:
Exclude:
- 'spec/fixtures/rails-6.1/packs/shirts/app/models/shirts/pocket.rb'
- 'spec/fixtures/rails-7.0/components/jackets/jackets.gemspec'
- 'spec/fixtures/rails-7.0/packs/shirts/app/models/shirts/pocket.rb'

# Offense count: 2
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
# CheckDefinitionPathHierarchyRoots: lib, spec, test, src
# 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:
- 'Rakefile.rb'
- 'lib/packs-rails.rb'
- 'spec/packs-rails_spec.rb'

# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
Naming/MemoizedInstanceVariableName:
Exclude:
- 'lib/packs/rails/integrations/rails.rb'

# Offense count: 1
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
# SupportedStyles: snake_case, normalcase, non_integer
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
Naming/VariableNumber:
Exclude:
- 'lib/packs/rails/integrations/rails.rb'

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/GlobalStdStream:
Exclude:
- 'spec/fixtures/rails-6.1/config/environments/production.rb'
- 'spec/fixtures/rails-7.0/config/environments/production.rb'

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: RequireEnglish.
# SupportedStyles: use_perl_names, use_english_names, use_builtin_english_names
Style/SpecialGlobalVars:
EnforcedStyle: use_perl_names
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source "https://rubygems.org"
source 'https://rubygems.org'

# Specify your gem's dependencies in packs-rails.gemspec
gemspec
6 changes: 3 additions & 3 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "packs-rails"
require 'bundler/setup'
require 'packs-rails'

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

require "irb"
require 'irb'
IRB.start(__FILE__)
12 changes: 6 additions & 6 deletions bin/tapioca
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
Pathname.new(__FILE__).realpath)

bundle_binstub = File.expand_path("../bundle", __FILE__)
bundle_binstub = File.expand_path('bundle', __dir__)

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

require "rubygems"
require "bundler/setup"
require 'rubygems'
require 'bundler/setup'

load Gem.bin_path("tapioca", "tapioca")
load Gem.bin_path('tapioca', 'tapioca')
10 changes: 5 additions & 5 deletions lib/packs-rails.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'packs'
require "active_support"
require "rails/application"
require 'active_support'
require 'rails/application'
require 'sorbet-runtime'

module Packs
Expand All @@ -22,7 +22,7 @@ def root
end

@config = ActiveSupport::OrderedOptions.new
@config.paths = %w(
@config.paths = %w[
app
app/controllers
app/channels
Expand All @@ -36,8 +36,8 @@ def root
config/locales
config/initializers
config/routes
)
]
end

require "packs/rails/railtie"
require 'packs/rails/railtie'
end
8 changes: 4 additions & 4 deletions lib/packs/rails/integrations.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require "active_support"
require 'active_support'

module Packs
module Rails
module Integrations
autoload :FactoryBot, "packs/rails/integrations/factory_bot"
autoload :Rails, "packs/rails/integrations/rails"
autoload :RSpec, "packs/rails/integrations/rspec"
autoload :FactoryBot, 'packs/rails/integrations/factory_bot'
autoload :Rails, 'packs/rails/integrations/rails'
autoload :RSpec, 'packs/rails/integrations/rspec'
end
end
end
4 changes: 2 additions & 2 deletions lib/packs/rails/integrations/factory_bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def initialize(app)
return unless app.config.respond_to?(:factory_bot)

Packs.all.reject(&:is_gem?).each do |pack|
app.config.factory_bot.definition_file_paths << pack.relative_path.join("spec/factories").to_s
app.config.factory_bot.definition_file_paths << pack.relative_path.join("test/factories").to_s
app.config.factory_bot.definition_file_paths << pack.relative_path.join('spec/factories').to_s
app.config.factory_bot.definition_file_paths << pack.relative_path.join('test/factories').to_s
end
end
end
Expand Down
13 changes: 7 additions & 6 deletions lib/packs/rails/integrations/rails.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# frozen_string_literal: true
# typed: true

require "active_support/inflections"
require 'active_support/inflections'

module Packs
module Rails
module Integrations
class Rails
CONFIG_ROUTES_PATH = "config/routes".freeze
CONFIG_ROUTES_PATH = 'config/routes'

def initialize(app)
@app = app
Expand Down Expand Up @@ -42,12 +42,13 @@ def inject_paths

def pre_rails_6_1?
return @_pre_rails_6_1 if defined?(@_pre_rails_6_1)
@_pre_rails_6_1 = ::Rails.gem_version < Gem::Version.new("6.1")

@_pre_rails_6_1 = ::Rails.gem_version < Gem::Version.new('6.1')
end

def create_namespace(name)
namespace = ActiveSupport::Inflector.camelize(name)
namespace.split("::").reduce(Object) do |base, mod|
namespace.split('::').reduce(Object) do |base, mod|
if base.const_defined?(mod, false)
base.const_get(mod, false)
else
Expand All @@ -57,10 +58,10 @@ def create_namespace(name)
end

def create_engine(pack)
name = pack.metadata.fetch("engine_name", pack.last_name)
name = pack.metadata.fetch('engine_name', pack.last_name)
namespace = create_namespace(name)
stim = Stim.new(pack, namespace)
namespace.const_set("Engine", Class.new(::Rails::Engine)).include(stim)
namespace.const_set('Engine', Class.new(::Rails::Engine)).include(stim)
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions lib/packs/rails/integrations/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def initialize

pack_paths = Packs.all.map do |pack|
next if pack.is_gem?

spec_path = pack.relative_path.join(default_path)
spec_path.to_s if spec_path.exist?
end
Expand All @@ -28,11 +29,11 @@ def initialize
# end of it.
#
# packs/my_pack => packs/my_pack/spec
#
#
# If it doesn't match a pack path, we leave it alone.

to_run.map! do |path|
if pack = Packs.find(path)
if (pack = Packs.find(path))
[
pack,
*nested_packs_for(pack)
Expand Down
3 changes: 1 addition & 2 deletions lib/packs/rails/railtie.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "rails/railtie"
require 'rails/railtie'

module Packs
module Rails
Expand All @@ -11,7 +11,6 @@ class Railtie < ::Rails::Railtie
# hook into packs-rails via ActiveSupport hooks.
ActiveSupport.run_load_hooks(:packs_rails, Packs)
end

end
end
end
2 changes: 1 addition & 1 deletion lib/packs/rails/rspec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require "packs-rails"
require 'packs-rails'

Packs::Rails::Integrations::RSpec.new
Loading