Skip to content

Commit

Permalink
Fix Cops, Fix problems with v2 (#49)
Browse files Browse the repository at this point in the history
* require suggested sigil to be strict

Co-Authored-By: Matjaž Kavčič <[email protected]>

* ensure the sigil is strict

Co-Authored-By: Matjaž Kavčič <[email protected]>

* ensure private is inlined (same as private_class_method)

* add a cop for line length

* fix version 2

* CI

* Update CHANGELOG.md

* fix merge conflict

* safe doesn't exist for layout cop

* rubocop fixes for the gem's code

---------

Co-authored-by: Matjaž Kavčič <[email protected]>
  • Loading branch information
swiknaba and MatjazKavcic authored Mar 19, 2024
1 parent 6a33360 commit 00b08f9
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 113 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ on: [push]
jobs:
test:
name: ${{ matrix.ruby }} / ${{ matrix.gemfile }}
runs-on: ubuntu-latest
env:
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"

strategy:
fail-fast: false
Expand All @@ -22,7 +21,6 @@ jobs:
- gemfiles/rails_6.1.gemfile
- gemfiles/rails_7.0.gemfile
exclude:
# fatal error with: 1.8.0 (using Parser 3.1.0.0, rubocop-ast 1.15.1, running on ruby 3.1.0 x86_64-linux)
- ruby: 3.1
gemfile: gemfiles/rubocop_1.8.gemfile
- ruby: 3.2
Expand Down
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
inherit_from: ./config/dbl.yml

Sorbet/StrictSigil:
Enabled: false
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.1.0] - 2024-03-19
### Changed
- Removed Rails cops, but auto-add Rails config when generating the config file if Rails is defined

## [2.0.0] - 2023-12-30
### Changed
- Rails Cops are only enabled, if `Rails` is a defined constant
Expand Down
7 changes: 7 additions & 0 deletions config/cops/layout.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ Layout/ParameterAlignment:
SupportedStyles:
- with_first_parameter
- with_fixed_indentation

Layout/LineLength:
Max: 120
IgnoreCopDirectives: true
AllowedPatterns: ['\s#\s'] # allows comments to overflow the line length. E.g. for URLs
Exclude:
- 'spec/**/*'
83 changes: 0 additions & 83 deletions config/cops/rails.yml

This file was deleted.

4 changes: 4 additions & 0 deletions config/cops/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,7 @@ Style/RedundantArgument:

Style/SwapValues:
Enabled: true

# "private_class_method" must always be inlined, no need for a cop
Style/AccessModifierDeclarations:
EnforcedStyle: inline
12 changes: 9 additions & 3 deletions config/cops/types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@
#

Sorbet/HasSigil:
MinimumStrictness: true
MinimumStrictness: strict
SuggestedStrictness: strict
Exclude:
- spec/**/*
- test/**/*
- "spec/**/*"
- "test/**/*"

Sorbet/StrictSigil:
Enabled: true
Exclude:
- "spec/**/*"
- "lib/tasks/**/*"
3 changes: 1 addition & 2 deletions config/dbl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ inherit_from:
# see: https://docs.rubocop.org/rubocop/usage/caching.html
AllCops:
UseCache: true
TargetRubyVersion: 3.1.4
TargetRubyVersion: 3.0.0
NewCops: enable
Exclude:
- '**/tmp/**/*'
Expand All @@ -30,7 +30,6 @@ AllCops:
- 'actionmailbox/test/dummy/**/*'
- 'actiontext/test/dummy/**/*'
- '**/node_modules/**/*'
# Additional exclude files by rubocop-rails
- 'bin/**/*'
- 'config/**/*'
- 'db/**/*'
145 changes: 125 additions & 20 deletions lib/generators/rubocop_dbl/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,143 @@ class InstallGenerator < Rails::Generators::Base

def create_config_file
file_method = config_file_exists? ? :prepend : :create
send :"#{file_method}_file", config_file_path, config_file_content
end
content = defined?(Rails) ? config_file_content_rails : config_file_content

private
send(
:"#{file_method}_file",
config_file_path,
content,
)
end

def config_file_exists?
private def config_file_exists?
File.exist?(config_file_path)
end

def config_file_path
private def config_file_path
'.rubocop.yml'
end

def config_file_content
if defined?(Rails)
<<~HEREDOC
require:
- rubocop-rails
private def config_file_content
<<~HEREDOC
inherit_gem:
rubocop-dbl:
- config/dbl.yml
- config/cops/rails.yml
HEREDOC
else
<<~HEREDOC
- config/dbl.yml
inherit_gem:
rubocop-dbl:
# we do not want to overwrite the base-array (from rubocop-dbl), but extend it
inherit_mode:
merge:
- Exclude
AllCops:
TargetRubyVersion: 3.3.0
Exclude:
- 'sorbet/rbi/shims/**/*'
HEREDOC
end

private def config_file_content_rails
<<~HEREDOC
require:
- rubocop-rails
inherit_gem:
rubocop-dbl:
- config/dbl.yml
HEREDOC
end
inherit_mode:
merge:
- Exclude
AllCops:
TargetRubyVersion: 3.3.0
Exclude:
- 'sorbet/rbi/shims/**/*'
# Defaults for this cop are found here:
# https://github.com/rubocop/rubocop-rails/blob/master/config/default.yml
#
# Add customizations below.
#
# Ensure to document why we change a default by linking the corresponding PR.
# For example:
#
# Rails/ActionFilter:
# Enabled: false
#
# @NOTE: added: "staging"
Rails/UnknownEnv:
Environments:
- production
- development
- test
- staging
# @NOTE: disabled
Rails/HttpStatus:
Enabled: false
# @NOTE: disabled
Rails/ApplicationController:
Enabled: false
#
# @NOTE: all the cops ahead are "pending" in the current default config
#
Rails/ActiveRecordCallbacksOrder:
Enabled: true
Rails/AfterCommitOverride:
Enabled: true
Rails/AttributeDefaultBlockValue:
Enabled: true
Rails/FindById:
Enabled: true
Rails/Inquiry:
Enabled: true
Rails/MailerName:
Enabled: true
Rails/MatchRoute:
Enabled: true
Rails/NegateInclude:
Enabled: true
Rails/Pluck:
Enabled: true
Rails/PluckInWhere:
Enabled: true
Rails/RenderInline:
Enabled: true
Rails/RenderPlainText:
Enabled: true
Rails/ShortI18n:
Enabled: true
EnforcedStyle: aggressive
Rails/SquishedSQLHeredocs:
Enabled: true
Rails/WhereEquals:
Enabled: true
Rails/WhereExists:
Enabled: true
Rails/WhereNot:
Enabled: true
HEREDOC
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop_dbl/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# typed: false

module RubocopDbl
VERSION = '2.0.0'.freeze
VERSION = '2.1.0'.freeze
end
2 changes: 1 addition & 1 deletion rubocop-dbl.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
]
spec.homepage = 'https://github.com/dbl-works/rubocop-dbl'
spec.license = 'MIT'
spec.required_ruby_version = '>= 3.1'
spec.required_ruby_version = '>= 3.0'

spec.add_dependency 'rubocop', '~> 1'
spec.add_dependency 'rubocop-ast', '~> 1'
Expand Down

0 comments on commit 00b08f9

Please sign in to comment.