From bb0e750779eeb0eb14187d97aa3c13da9a4d1c50 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Tue, 9 May 2023 17:33:15 +0400 Subject: [PATCH] Add RuboCop --- .rubocop.yml | 61 +++++++++++++++++++++++++++++++++++++ Rakefile | 16 +++++++++- diversipub.gemspec | 11 +++++-- lib/diversipub/puma_task.rb | 30 +++++++++--------- 4 files changed, 100 insertions(+), 18 deletions(-) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..520e174 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,61 @@ +require: + - rubocop-performance + - rubocop-rake + +AllCops: + TargetRubyVersion: 3.0 + DisplayCopNames: true + NewCops: enable + +Layout/AccessModifierIndentation: + EnforcedStyle: outdent + +Layout/LineLength: + Max: 80 + +Lint/AmbiguousOperatorPrecedence: + Enabled: false + +Lint/ReturnInVoidContext: + Enabled: false + +Metrics/BlockLength: + Exclude: + - '*.gemspec' + - 'Rakefile' + - 'spec/**/*_spec.rb' + +Metrics/MethodLength: + CountAsOne: ['array', 'hash', 'heredoc'] + +Metrics/ParameterLists: + Exclude: + - 'lib/diversipub/main.rb' + +Style/AndOr: + EnforcedStyle: conditionals + +Style/Documentation: + Exclude: + - 'Rakefile' + +Style/DoubleNegation: + Enabled: false + +Style/HashAsLastArrayItem: + Enabled: false + +Style/PerlBackrefs: + Enabled: false + +Style/TrailingCommaInArguments: + EnforcedStyleForMultiline: comma + +Style/TrailingCommaInArrayLiteral: + EnforcedStyleForMultiline: comma + +Style/TrailingCommaInHashLiteral: + EnforcedStyleForMultiline: comma + +Style/VariableInterpolation: + Enabled: false diff --git a/Rakefile b/Rakefile index 2bbbd21..1061dcb 100644 --- a/Rakefile +++ b/Rakefile @@ -2,7 +2,21 @@ require 'bundler/gem_tasks' -task default: [] +desc 'Run default checks' +task default: %i[lint] + +desc 'Run code analysis tools' +task lint: %i[rubocop] + +desc 'Fix code style (rubocop --auto-correct)' +task fix: 'rubocop:auto_correct' + +begin + require 'rubocop/rake_task' + RuboCop::RakeTask.new +rescue LoadError + nil +end desc 'Open development console' task :console do diff --git a/diversipub.gemspec b/diversipub.gemspec index 98ecf75..e1c0e38 100644 --- a/diversipub.gemspec +++ b/diversipub.gemspec @@ -19,9 +19,11 @@ Gem::Specification.new do |spec| spec.authors = ['Alex Kotov'] spec.email = ['kotovalexarian@gmail.com'] - spec.summary = '' + spec.summary = + 'A publishing platform for HTTP, Gemini, ActivityPub, RSS, Atom, and others' spec.description = <<~DESCRIPTION.split("\n").map(&:strip).join ' ' + A publishing platform for HTTP, Gemini, ActivityPub, RSS, Atom, and others. DESCRIPTION spec.metadata['rubygems_mfa_required'] = 'true' @@ -45,6 +47,9 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency 'rack', '~> 2.2', '>= 2.2.7' spec.add_runtime_dependency 'sinatra', '~> 3.0', '>= 3.0.6' - spec.add_development_dependency 'pry', '~> 0.14' - spec.add_development_dependency 'rake', '~> 13.0' + spec.add_development_dependency 'bundler', '~> 2.4' + spec.add_development_dependency 'pry', '~> 0.14' + spec.add_development_dependency 'rake', '~> 13.0' + spec.add_development_dependency 'rubocop-performance', '~> 1.13' + spec.add_development_dependency 'rubocop-rake', '~> 0.6' end diff --git a/lib/diversipub/puma_task.rb b/lib/diversipub/puma_task.rb index abee979..e1c68f1 100644 --- a/lib/diversipub/puma_task.rb +++ b/lib/diversipub/puma_task.rb @@ -35,20 +35,22 @@ module Diversipub end def puma_config - @puma_config ||= Puma::Configuration.new( - { - app: rack_app, - binds: ['tcp://127.0.0.1:9292'].freeze, - environment: 'production', - log_requests: true, - logger: puma_logger, - rackup: nil, - tag: 'diversipub', - tcp_host: '127.0.0.1', - tcp_port: 9292, - workers: 0, - }, - ) + @puma_config ||= Puma::Configuration.new puma_options.dup + end + + def puma_options + @puma_options ||= { + app: rack_app, + binds: ['tcp://127.0.0.1:9292'].freeze, + environment: 'production', + log_requests: true, + logger: puma_logger, + rackup: nil, + tag: 'diversipub', + tcp_host: '127.0.0.1', + tcp_port: 9292, + workers: 0, + }.freeze end def puma_log_writer