Skip to content
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
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ permissions:
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10
name: Ruby ${{ matrix.ruby }}
strategy:
fail-fast: false
matrix:
ruby:
- 3.3
- 3.4
- ruby-head
steps:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@

# rspec failure tracking
.rspec_status

/Gemfile.lock
3 changes: 2 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
inherit_from: config/eightyfourcodes.yml

plugins:
- rubocop-rspec
- rubocop-rake

AllCops:
NewCops: enable
Expand Down
14 changes: 7 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"

# Specify your gem's dependencies in rubocop-eightyfourcodes.gemspec
gemspec

group :development, :test do
gem 'rake'
gem 'rspec'
gem 'rubocop'
gem 'rubocop-rake'
gem 'rubocop-rspec'
gem 'yard'
gem "rake"
gem "rspec"
gem "rubocop"
gem "rubocop-rake"
gem "rubocop-rspec"
gem "yard"
end
77 changes: 0 additions & 77 deletions Gemfile.lock

This file was deleted.

21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ require: rubocop-eightyfourcodes
Now you can run `rubocop` and it will automatically load the RuboCop eightyfourcodes
cops together with the standard cops.

To use the `eightyfourcodes` RuboCop config:

```yaml
inherit_gem:
rubocop-eightyfourcodes: config/eightyfourcodes.yml
```

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
Expand All @@ -36,6 +43,20 @@ Use `bundle exec rake 'new_cop[EightyFourCodes/CommandLiteralInjection]'` to gen

The [NodePattern Debugger](https://nodepattern.herokuapp.com/) is a very helpful resource when creating new AST matchers.


If you need to try out this gem in a project using it, before releasing a new version, you can do the following in the project:

```ruby
gem "rubocop-eightyfourcodes", **(ENV["LOCAL_RUBOCOP84"] ? { path: ENV["LOCAL_RUBOCOP84"] } : {})
```

Then try it like this:

```shell
LOCAL_RUBOCOP84=~/repos/rubocop-eightyfourcodes bundle install
LOCAL_RUBOCOP84=~/repos/rubocop-eightyfourcodes bundle exec rubocop
```

## Releasing

To install this gem onto your local machine, run `bundle exec rake install`.
Expand Down
18 changes: 9 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "rubocop/rake_task"

RuboCop::RakeTask.new

task default: %i[spec rubocop]

RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
spec.pattern = FileList["spec/**/*_spec.rb"]
end

desc 'Generate a new cop with a template'
desc "Generate a new cop with a template"
task :new_cop, [:cop] do |_task, args|
require 'rubocop'
require "rubocop"

cop_name = args.fetch(:cop) do
warn 'usage: bundle exec rake new_cop[Department/Name]'
warn "usage: bundle exec rake new_cop[Department/Name]"
exit!
end

generator = RuboCop::Cop::Generator.new(cop_name)

generator.write_source
generator.write_spec
generator.inject_require(root_file_path: 'lib/rubocop/cop/eightyfourcodes_cops.rb')
generator.inject_config(config_file_path: 'config/default.yml')
generator.inject_require(root_file_path: "lib/rubocop/cop/eightyfourcodes_cops.rb")
generator.inject_config(config_file_path: "config/default.yml")

puts generator.todo
end
6 changes: 3 additions & 3 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'rubocop/eightyfourcodes'
require "bundler/setup"
require "rubocop/eightyfourcodes"

# 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 @@ -11,5 +11,5 @@ require 'rubocop/eightyfourcodes'
# require "pry"
# Pry.start

require 'irb'
require "irb"
IRB.start(__FILE__)
143 changes: 143 additions & 0 deletions config/eightyfourcodes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
plugins:
- rubocop-minitest
- rubocop-performance
- rubocop-rake
- rubocop-sequel

require:
- rubocop-eightyfourcodes

AllCops:
TargetRubyVersion: 3.4
NewCops: enable

### Metrics

Metrics/ClassLength:
Max: 300
CountAsOne: ["array", "hash", "heredoc", "method_call"]

Metrics/ModuleLength:
Max: 300
CountAsOne: ["array", "hash", "heredoc", "method_call"]

Metrics/MethodLength:
Max: 50
CountAsOne: ["array", "hash", "heredoc", "method_call"]

Metrics/AbcSize:
Max: 40

Metrics/CyclomaticComplexity:
Max: 12

Metrics/BlockLength:
Max: 200
AllowedMethods:
- refine
- describe

Metrics/ParameterLists:
CountKeywordArgs: false

### Lint

Lint/DuplicateBranch:
IgnoreDuplicateElseBranch: true
IgnoreLiteralBranches: true
IgnoreConstantBranches: true

Lint/UselessConstantScoping:
# Increases indirection and reduces readability. We often don't care about constant scoping.
Enabled: false

### Style

Style/Documentation:
Enabled: false

Style/GuardClause:
AllowConsecutiveConditionals: true

Style/StringLiterals:
EnforcedStyle: double_quotes

Style/MethodCallWithArgsParentheses:
AllowParenthesesInMultilineCall: true
AllowParenthesesInChaining: true
AllowParenthesesInCamelCaseMethod: true
AllowParenthesesInStringInterpolation: true
AllowedMethods: ["puts", "print"]
AllowedPatterns: ["^assert"]

Style/ClassVars:
# We use them quite a lot, and the "good" alternative is not so nice.
# Need a targeted effort to refactor our codebase to get rid of them.
Enabled: false

Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: comma

Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: comma

Style/HashSyntax:
EnforcedShorthandSyntax: always

### Layout

Layout/FirstHashElementIndentation:
EnforcedStyle: consistent

Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented

Layout/LineLength:
URISchemes: ["http", "https", "amqp", "amqps"]
AllowedPatterns:
- '^\s*puts(\s|\()'
- '^\s*print(\s|\()'
- '^\s*@?log(ger)?[\s\(\.]'
- '^\s*LOG(GER)?[\s\(\.]'
- '^\s*debug[\s\(]'
- '^\s*\#'

### Performance

Performance/RedundantMerge:
MaxKeyValuePairs: 1

Performance/BigDecimalWithNumericArgument:
Enabled: false

Performance/ChainArrayAllocation:
Enabled: false

### Naming

Naming/MethodParameterName:
MinNameLength: 1

Naming/PredicateMethod:
AllowBangMethods: true

### Security

GitlabSecurity/JsonSerialization:
Enabled: false

### Minitest

Minitest/GlobalExpectations:
EnforcedStyle: _

Minitest/MultipleAssertions:
Enabled: true

# Sequel

Sequel/SaveChanges:
Enabled: false

Sequel/IrreversibleMigration:
Enabled: false
10 changes: 5 additions & 5 deletions lib/rubocop-eightyfourcodes.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

require 'rubocop'
require "rubocop"

require_relative 'rubocop/eightyfourcodes'
require_relative 'rubocop/eightyfourcodes/version'
require_relative 'rubocop/eightyfourcodes/inject'
require_relative "rubocop/eightyfourcodes"
require_relative "rubocop/eightyfourcodes/version"
require_relative "rubocop/eightyfourcodes/inject"

RuboCop::EightyFourCodes::Inject.defaults!

require_relative 'rubocop/cop/eightyfourcodes_cops'
require_relative "rubocop/cop/eightyfourcodes_cops"
2 changes: 1 addition & 1 deletion lib/rubocop/cop/eighty_four_codes/ensure_redirect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module EightyFourCodes
# cleanup
# end
class EnsureRedirect < Base
MSG = 'Do not redirect from an `ensure` block.'
MSG = "Do not redirect from an `ensure` block."

def on_ensure(node)
# `:send` nodes represent method calls, so we look for send nodes and then check if they are `redirect`
Expand Down
Loading