-
Notifications
You must be signed in to change notification settings - Fork 5
153 add rubocop for linting uniformity #156
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
base: main
Are you sure you want to change the base?
Changes from all commits
eea8e55
1565fb2
734d24d
aa6de18
666218f
02eec5a
dba6812
d405d6d
49772c3
9414d7f
16ac1f8
7c69ef0
8b9fc81
5661f3f
e9062e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
AllCops: | ||
TargetRubyVersion: 3.3.0 | ||
NewCops: enable | ||
Exclude: | ||
- 'bin/**/*' | ||
- 'vendor/**/*' | ||
- 'tmp/**/*' | ||
- 'coverage/**/*' | ||
|
||
Gemspec/RequiredRubyVersion: | ||
Enabled: false | ||
|
||
Layout/LineLength: | ||
Max: 120 | ||
Exclude: | ||
- 'decanter.gemspec' | ||
|
||
Lint/UnderscorePrefixedVariableName: | ||
Exclude: | ||
- 'lib/decanter/core.rb' | ||
|
||
Metrics/AbcSize: | ||
Max: 20 | ||
Exclude: | ||
- 'lib/decanter/core.rb' | ||
|
||
Metrics/BlockLength: | ||
Exclude: | ||
- 'spec/**/*_spec.rb' | ||
- 'decanter.gemspec' | ||
|
||
Metrics/CyclomaticComplexity: | ||
Exclude: | ||
- 'lib/decanter/core.rb' | ||
Comment on lines
+22
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it might be better to disable the specific methods/blocks that are violating the rules. Then, if that code is modified before #158 is resolved, any new code will be subject to the linting rules. |
||
|
||
Metrics/MethodLength: | ||
Max: 25 | ||
|
||
Metrics/ModuleLength: | ||
Max: 205 | ||
|
||
Naming/PredicateName: | ||
Exclude: | ||
- 'lib/decanter/core.rb' | ||
|
||
Style/Documentation: | ||
Enabled: false | ||
|
||
Style/StringLiterals: | ||
EnforcedStyle: single_quotes |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in decanter.gemspec | ||
gemspec | ||
|
||
group :development, :test do | ||
gem 'bundler', '~> 2.4.22' | ||
gem 'dotenv' | ||
gem 'rake', '~> 12.0' | ||
gem 'rspec-rails', '~> 3.9' | ||
gem 'rubocop', '~> 1.59' | ||
gem 'simplecov', '~> 0.15.1' | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
require "bundler/gem_tasks" | ||
# frozen_string_literal: true | ||
|
||
require 'bundler/gem_tasks' | ||
require 'rspec/core/rake_task' | ||
require 'rubocop/rake_task' | ||
|
||
RSpec::Core::RakeTask.new(:spec) | ||
RuboCop::RakeTask.new | ||
|
||
task default: %i[spec rubocop] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
lib = File.expand_path('lib', __dir__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
require 'decanter/version' | ||
|
@@ -20,19 +22,17 @@ Gem::Specification.new do |spec| | |
|
||
spec.metadata['allowed_push_host'] = 'https://rubygems.org' | ||
|
||
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } | ||
spec.files = `git ls-files -z`.split("\x0").reject do |f| | ||
f.match(%r{^(test|spec|features)/}) | ||
end | ||
spec.bindir = 'exe' | ||
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } | ||
spec.require_paths = ['lib'] | ||
|
||
spec.add_dependency 'rails', '>= 7.1.3.2' | ||
spec.add_dependency 'actionpack', '>= 7.1.3.2' | ||
spec.add_dependency 'activesupport' | ||
spec.add_dependency 'rails', '>= 7.1.3.2' | ||
spec.add_dependency 'rails-html-sanitizer', '>= 1.0.4' | ||
|
||
spec.add_development_dependency 'bundler', '~> 2.4.22' | ||
spec.add_development_dependency 'dotenv' | ||
spec.add_development_dependency 'rake', '~> 12.0' | ||
spec.add_development_dependency 'rspec-rails', '~> 3.9' | ||
spec.add_development_dependency 'simplecov', '~> 0.15.1' | ||
spec.metadata['rubygems_mfa_required'] = 'true' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nicoledow not sure if MFA is already required for publishing this gem but rubocop is requiring it. Seems like a good idea. |
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'active_support/all' | ||
|
||
module Decanter | ||
|
||
class << self | ||
|
||
def decanter_for(klass_or_sym) | ||
decanter_name = | ||
case klass_or_sym | ||
when Class | ||
klass_or_sym.name | ||
"#{klass_or_sym.name}Decanter" | ||
when Symbol | ||
klass_or_sym.to_s.singularize.camelize | ||
"#{klass_or_sym.to_s.singularize.camelize}Decanter" | ||
Comment on lines
+11
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting - why did you have to add "Decanter" to the end of this string? |
||
else | ||
raise ArgumentError.new("cannot lookup decanter for #{klass_or_sym} with class #{klass_or_sym.class}") | ||
end + 'Decanter' | ||
raise ArgumentError, | ||
"cannot lookup decanter for #{klass_or_sym} with class #{klass_or_sym.class}" | ||
end | ||
begin | ||
decanter_name.constantize | ||
rescue | ||
raise NameError.new("uninitialized constant #{decanter_name}") | ||
rescue StandardError | ||
raise NameError, "uninitialized constant #{decanter_name}" | ||
end | ||
end | ||
|
||
|
@@ -29,22 +30,21 @@ def decanter_from(klass_or_string) | |
when String | ||
begin | ||
klass_or_string.constantize | ||
rescue | ||
raise NameError.new("uninitialized constant #{klass_or_string}") | ||
rescue StandardError | ||
raise NameError, "uninitialized constant #{klass_or_string}" | ||
end | ||
else | ||
raise ArgumentError.new("cannot find decanter from #{klass_or_string} with class #{klass_or_string.class}") | ||
raise ArgumentError, | ||
"cannot find decanter from #{klass_or_string} with class #{klass_or_string.class}" | ||
end | ||
|
||
unless constant.ancestors.include? Decanter::Base | ||
raise ArgumentError.new("#{constant.name} is not a decanter") | ||
end | ||
raise ArgumentError, "#{constant.name} is not a decanter" unless constant.ancestors.include? Decanter::Base | ||
|
||
constant | ||
end | ||
|
||
def configuration | ||
@config ||= Decanter::Configuration.new | ||
@configuration ||= Decanter::Configuration.new | ||
end | ||
|
||
def config | ||
|
@@ -61,4 +61,4 @@ def config | |
require 'decanter/extensions' | ||
require 'decanter/exceptions' | ||
require 'decanter/parser' | ||
require 'decanter/railtie' if defined?(::Rails) | ||
require 'decanter/railtie' if defined?(Rails) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'decanter/core' | ||
require 'decanter/collection_detection' | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not want to mess with functionality in this PR, so I opted to exclude certain rubocop configs on
core.rb
that would require more invasive changes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the general premise of not doing those refactorings within this PR, but I might prefer to actually address the
Lint/UnderscorePrefixedVariableName
errors within this PR, since it just involves renaming variables without changing any logic, rather than disabling the Rubocop rule. I'm good with handling the other violations separately in this new issue.