Skip to content

Commit

Permalink
Initial Rubocop setup (#2279)
Browse files Browse the repository at this point in the history
* add rubocop

* minimal working rubocop

* more rubocop disables

* auto correct padrino-core with base rubocop spec

* lock platform for rubocop

---------

Co-authored-by: Arthur Chiu <[email protected]>
  • Loading branch information
achiurizo and achiurizo authored Jan 18, 2024
1 parent 3dec238 commit a34dcbb
Show file tree
Hide file tree
Showing 36 changed files with 243 additions and 153 deletions.
92 changes: 92 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
require:
- rubocop-minitest

AllCops:
NewCops: disable

Metrics:
Enabled: false
Naming:
Enabled: false
Layout:
Enabled: false
Lint/AssignmentInCondition:
Enabled: false
Lint/UnusedMethodArgument:
Enabled: false
Style/AccessorGrouping:
Enabled: false
Style/Alias:
Enabled: false
Style/ArrayJoin:
Enabled: false
Style/BlockDelimiters:
Enabled: false
Style/CharacterLiteral:
Enabled: false
Style/ClassCheck:
Enabled: false
Style/ClassVars:
Enabled: false
Style/CommentedKeyword:
Enabled: false
Style/Documentation:
Enabled: false
Style/EmptyCaseCondition:
Enabled: false
Style/FormatString:
Enabled: false
Style/FormatStringToken:
Enabled: false
Style/FrozenStringLiteralComment:
Enabled: false
Style/GuardClause:
Enabled: false
Style/HashSyntax:
Enabled: false
Style/IfInsideElse:
Enabled: false
Style/IfUnlessModifier:
Enabled: false
Style/IfUnlessModifierOfIfUnless:
Enabled: false
Style/MultilineIfModifier:
Enabled: false
Style/MultilineTernaryOperator:
Enabled: false
Style/NestedTernaryOperator:
Enabled: false
Style/MutableConstant:
Enabled: false
Style/NumericPredicate:
Enabled: false
Style/ParallelAssignment:
Enabled: false
Style/PreferredHashMethods:
Enabled: false
Style/RedundantSelf:
Enabled: false
Style/RegexpLiteral:
Enabled: false
Style/Semicolon:
Enabled: false
Style/SignalException:
Enabled: false
Style/SingleLineMethods:
Enabled: false
Style/SoleNestedConditional:
Enabled: false
Style/StringConcatenation:
Enabled: false
Style/StringLiterals:
Enabled: false
Style/StringLiteralsInInterpolation:
Enabled: false
Style/SymbolArray:
Enabled: false
Style/TrailingCommaInHashLiteral:
Enabled: false
Style/WordArray:
Enabled: false
Style/ZeroLengthPredicate:
Enabled: false
24 changes: 13 additions & 11 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path("../padrino-core/lib/padrino-core/version.rb", __FILE__)
require File.expand_path('padrino-core/lib/padrino-core/version.rb', __dir__)

source 'https://rubygems.org'

Expand All @@ -7,9 +7,9 @@ if ENV["AS_VERSION"]
end

group :db do
gem "jdbc-sqlite3", "~> 3.7.2", :platform => :jruby
gem "sequel"
gem "sqlite3", :platforms => [:mri]
gem "jdbc-sqlite3", "~> 3.7.2", :platform => :jruby
end

group :development do
Expand All @@ -21,8 +21,8 @@ group :development do
gem "sinatra", :git => "git://github.com/sinatra/sinatra.git"
end

gem "slim", ">= 1.3.0"
gem "liquid", ">= 2.1.1"
gem "slim", ">= 1.3.0"

if ENV['HAML_ENGINE'] == 'hamlit'
puts "=> Using Hamlit Haml engine"
Expand All @@ -41,23 +41,25 @@ group :development do
gem "erubi", ">= 1.6.1"
end

gem "rack", ">= 1.3.0"
gem "rake", ">= 10.5.0"
gem "yard", ">= 0.7.2"
gem "rack-test", ">= 0.6.3"
gem "fakeweb", ">= 1.2.8"
gem "oga", ">= 2.5", "< 3"
gem "builder", ">= 2.1.2"
gem "mocha", ">= 2.0"
gem "fakeweb", ">= 1.2.8"
gem "minitest", ">= 4.0"
gem "mocha", ">= 2.0"
gem "oga", ">= 2.5", "< 3"
gem "rack", ">= 1.3.0"
gem "rack-test", ">= 0.6.3"
gem "rake", ">= 10.5.0"
gem 'rb-readline', '~> 0.4.2'
gem 'rubocop', '~> 1.6', :platforms => [:mri]
gem 'rubocop-minitest', '~>0.34.4', :platforms => [:mri]
gem "yard", ">= 0.7.2"

platforms :jruby do
gem "jruby-openssl"
end
end

load File.expand_path('../padrino/subgems.rb', __FILE__)
load File.expand_path('padrino/subgems.rb', __dir__)
PADRINO_GEMS.each_key do |name|
gem name, :path => File.expand_path('../' + name, __FILE__)
end
2 changes: 1 addition & 1 deletion padrino-core/bin/padrino
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'padrino-core/cli/binstub'
Padrino.replace_with_binstub('padrino')

padrino_core_path = File.expand_path('../../lib', __FILE__)
padrino_core_path = File.expand_path('../lib', __dir__)
$:.unshift(padrino_core_path) if File.directory?(padrino_core_path) && !$:.include?(padrino_core_path)

require 'padrino-core/cli/base'
Expand Down
2 changes: 1 addition & 1 deletion padrino-core/lib/padrino-core/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def dependencies
'controllers/**/*.rb',
'controllers.rb',
'helpers/**/*.rb',
'helpers.rb',
'helpers.rb'
].flat_map{ |file| Dir.glob(File.join(settings.root, file)) }
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def default_prerequisites
'/models.rb',
'/models/**/*.rb',
'/lib.rb',
'/lib/**/*.rb',
'/lib/**/*.rb'
].map{ |glob| File.join(settings.root, glob) }
end

Expand Down
11 changes: 5 additions & 6 deletions padrino-core/lib/padrino-core/application/routing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,9 @@ def value_to_param(object)
when Array
object.map { |item| value_to_param(item) }.compact
when Hash
object.inject({}) do |all, (key, value)|
object.each_with_object({}) do |(key, value), all|
next all if value.nil?
all[key] = value_to_param(value)
all
end
when nil
else
Expand All @@ -453,7 +452,7 @@ def value_to_param(object)

# Add prefix slash if its not present and remove trailing slashes.
def conform_uri(uri_string)
uri_string.gsub(/^(?!\/)(.*)/, '/\1').gsub(/[\/]+$/, '')
uri_string.gsub(/^(?!\/)(.*)/, '/\1').gsub(/\/+$/, '')
end

##
Expand Down Expand Up @@ -863,7 +862,7 @@ def static_file?(path_info)
path = File.expand_path(public_dir + unescape(path_info))
return unless path.start_with?(public_dir)
return unless File.file?(path)
return path
path
end

#
Expand Down Expand Up @@ -993,7 +992,7 @@ def invoke_route(route, params, first_time)
filter! :before if first_time

catch(:pass) do
begin

(route.before_filters - settings.filters[:before]).each{|block| instance_eval(&block) }
@layout = route.use_layout if route.use_layout
route.custom_conditions.each {|block| pass if block.bind(self).call == false }
Expand All @@ -1002,7 +1001,7 @@ def invoke_route(route, params, first_time)
halt(route_response)
ensure
(route.after_filters - settings.filters[:after]).each {|block| instance_eval(&block) }
end

end
end

Expand Down
7 changes: 3 additions & 4 deletions padrino-core/lib/padrino-core/caller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ module Padrino
%r{custom_require\.rb$},
%r{active_support},
%r{/thor},
%r{/lib/bundler},
%r{/lib/bundler}
] unless defined?(PADRINO_IGNORE_CALLERS)

##
# Add rubinius (and hopefully other VM implementations) ignore patterns ...
#
PADRINO_IGNORE_CALLERS.concat(RUBY_IGNORE_CALLERS) if defined?(RUBY_IGNORE_CALLERS)

private
##
# The filename for the file that is the direct caller (first caller).
#
Expand All @@ -48,7 +47,7 @@ def self.first_caller
def self.caller_files
caller(1).
map { |line| line.split(/:(?=\d|in )/)[0,2] }.
reject { |file,line| PADRINO_IGNORE_CALLERS.any? { |pattern| file =~ pattern } }.
map { |file,line| file }
reject { |file,_line| PADRINO_IGNORE_CALLERS.any? { |pattern| file =~ pattern } }.
map { |file,_line| file }
end
end
14 changes: 7 additions & 7 deletions padrino-core/lib/padrino-core/cli/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def rake(*args)
ARGV.clear
ARGV.concat(args)
puts "=> Executing Rake #{ARGV.join(' ')} ..."
load File.expand_path('../rake.rb', __FILE__)
load File.expand_path('rake.rb', __dir__)
Rake.application.init
Rake.application.instance_variable_set(:@rakefile, __FILE__)
load File.expand_path('Rakefile')
Expand All @@ -27,10 +27,10 @@ def rake(*args)
map "c" => :console
def console(*args)
prepare :console
require File.expand_path("../../version", __FILE__)
require File.expand_path('../version', __dir__)
require File.expand_path('config/boot.rb')
puts "=> Loading #{Padrino.env} console (Padrino v.#{Padrino.version})"
require File.expand_path('../console', __FILE__)
require File.expand_path('console', __dir__)
ARGV.clear
if defined? Pry
Pry.start
Expand All @@ -47,18 +47,18 @@ def console(*args)
desc "generate", "Executes the Padrino generator with given options (alternatively use 'gen' or 'g')."
map ["gen", "g"] => :generate
def generate(*args)
begin

# We try to load the vendored padrino-gen if exist
padrino_gen_path = File.expand_path('../../../../../padrino-gen/lib', __FILE__)
padrino_gen_path = File.expand_path('../../../../padrino-gen/lib', __dir__)
$:.unshift(padrino_gen_path) if File.directory?(padrino_gen_path) && !$:.include?(padrino_gen_path)
require 'padrino-core/command'
require 'padrino-gen/command'
ARGV.shift
ARGV << 'help' if ARGV.empty?
Padrino.bin_gen(*ARGV)
rescue
rescue StandardError
puts "<= You need padrino-gen! Run: gem install padrino-gen"
end

end

desc "version", "Show current Padrino version."
Expand Down
2 changes: 1 addition & 1 deletion padrino-core/lib/padrino-core/cli/binstub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def self.replace_with_binstub(executable)
project_root = project_root.rpartition('/').first
end

if %w(Gemfile .components).all? { |file| File.file?(File.join(project_root, file)) }
if %w[Gemfile .components].all? { |file| File.file?(File.join(project_root, file)) }
binstub = File.join(project_root, 'bin', executable)
if File.file?(binstub)
exec Gem.ruby, binstub, *ARGV
Expand Down
12 changes: 6 additions & 6 deletions padrino-core/lib/padrino-core/cli/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Launcher < Thor
method_option :server_options, :type => :boolean, :desc => "Tells the current server handler's options that can be used with --options"
def start(*args)
prepare :start
require File.expand_path("../adapter", __FILE__)
require File.expand_path('adapter', __dir__)
require File.expand_path('config/boot.rb')

if options[:server_options]
Expand All @@ -36,15 +36,15 @@ def start(*args)
method_option :pid, :type => :string, :aliases => "-p", :desc => "File to store pid", :default => 'tmp/pids/server.pid'
def stop
prepare :stop
require File.expand_path("../adapter", __FILE__)
require File.expand_path('adapter', __dir__)
Padrino::Cli::Adapter.stop(options)
end

private

# https://github.com/rack/rack/blob/master/lib/rack/server.rb\#L100
def server_options(options)
begin

info = []
server = Rack::Handler.get(options[:server]) || Rack::Handler.default(options)
if server && server.respond_to?(:valid_options)
Expand All @@ -57,12 +57,12 @@ def server_options(options)
info << " -O %-21s %s" % [name, description]
has_options = true
end
return "" if !has_options
return "" unless has_options
end
info.join("\n")
rescue NameError
return "Warning: Could not find handler specified (#{options[:server] || 'default'}) to determine handler-specific options"
end
"Warning: Could not find handler specified (#{options[:server] || 'default'}) to determine handler-specific options"

end

protected
Expand Down
10 changes: 7 additions & 3 deletions padrino-core/lib/padrino-core/cli/rake.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('../../tasks', __FILE__)
require File.expand_path('../tasks', __dir__)
require 'rake'
require 'rake/dsl_definition'
require 'thor'
Expand All @@ -10,8 +10,12 @@

module PadrinoTasks
def self.init(init=false)
Padrino::Tasks.files.flatten.uniq.each { |rakefile| Rake.application.add_import(rakefile) rescue puts "<= Failed load #{ext}" }
load(File.expand_path('../rake_tasks.rb', __FILE__))
Padrino::Tasks.files.flatten.uniq.each { |rakefile| begin
Rake.application.add_import(rakefile)
rescue StandardError
puts "<= Failed load #{ext}"
end }
load(File.expand_path('rake_tasks.rb', __dir__))
Rake.application.load_imports
end

Expand Down
Loading

0 comments on commit a34dcbb

Please sign in to comment.