Skip to content

Commit

Permalink
fix: build with hound/rubocop
Browse files Browse the repository at this point in the history
! build with hound/rubocop
  • Loading branch information
majioa committed Jun 9, 2022
1 parent 2508aaf commit 0053403
Show file tree
Hide file tree
Showing 15 changed files with 298 additions and 2,893 deletions.
20 changes: 20 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
engines:
rubocop:
enabled: true
checks:
Layout/IndentationWidth:
Width: 3
Layout/LineLength:
Max: 130
Lint/AmbiguousOperatorPrecedence: # new in 1.21
Enabled: false
Metrics/MethodLength:
Max: 15
Metrics/AbcSize:
Max: 30
Style/MethodDefParentheses:
EnforcedStyle: require_no_parentheses
Style/NegatedIf:
Enabled: false
Style/TrailingCommaInHashLiteral:
Enabled: false
140 changes: 140 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
---
AllCops:
NewCops: enable
Gemspec/DateAssignment: # new in 1.10
Enabled: true
Gemspec/DeprecatedAttributeAssignment: # new in 1.30
Enabled: true
Gemspec/RequireMFA: # new in 1.23
Enabled: true
Layout/IndentationWidth:
Width: 3
Layout/LineEndStringConcatenationIndentation: # new in 1.18
Enabled: true
Layout/LineLength:
Max: 130
Layout/SpaceBeforeBrackets: # new in 1.7
Enabled: true
Lint/AmbiguousAssignment: # new in 1.7
Enabled: true
Lint/AmbiguousOperatorPrecedence: # new in 1.21
Enabled: false
Lint/AmbiguousRange: # new in 1.19
Enabled: true
Lint/DeprecatedConstants: # new in 1.8
Enabled: true
Lint/DuplicateBranch: # new in 1.3
Enabled: true
Lint/DuplicateRegexpCharacterClassElement: # new in 1.1
Enabled: true
Lint/EmptyBlock: # new in 1.1
Enabled: true
Lint/EmptyClass: # new in 1.3
Enabled: true
Lint/EmptyInPattern: # new in 1.16
Enabled: true
Lint/IncompatibleIoSelectWithFiberScheduler: # new in 1.21
Enabled: true
Lint/LambdaWithoutLiteralBlock: # new in 1.8
Enabled: true
Lint/NoReturnInBeginEndBlocks: # new in 1.2
Enabled: true
Lint/NumberedParameterAssignment: # new in 1.9
Enabled: true
Lint/OrAssignmentToConstant: # new in 1.9
Enabled: true
Lint/RedundantDirGlobSort: # new in 1.8
Enabled: true
Lint/RefinementImportMethods: # new in 1.27
Enabled: true
Lint/RequireRelativeSelfPath: # new in 1.22
Enabled: true
Lint/SymbolConversion: # new in 1.9
Enabled: true
Lint/ToEnumArguments: # new in 1.1
Enabled: true
Lint/TripleQuotes: # new in 1.9
Enabled: true
Lint/UnexpectedBlockArity: # new in 1.5
Enabled: true
Lint/UnmodifiedReduceAccumulator: # new in 1.1
Enabled: true
Lint/UselessRuby2Keywords: # new in 1.23
Enabled: true
Metrics/MethodLength:
Max: 15
Metrics/AbcSize:
Max: 30
Naming/BlockForwarding: # new in 1.24
Enabled: true
Security/CompoundHash: # new in 1.28
Enabled: true
Security/IoMethods: # new in 1.22
Enabled: true
Style/ArgumentsForwarding: # new in 1.1
Enabled: true
Style/CollectionCompact: # new in 1.2
Enabled: true
Style/DocumentDynamicEvalDefinition: # new in 1.1
Enabled: true
Style/EndlessMethod: # new in 1.8
Enabled: true
Style/EnvHome: # new in 1.29
Enabled: true
Style/FetchEnvVar: # new in 1.28
Enabled: true
Style/FileRead: # new in 1.24
Enabled: true
Style/FileWrite: # new in 1.24
Enabled: true
Style/HashConversion: # new in 1.10
Enabled: true
Style/HashExcept: # new in 1.7
Enabled: true
Style/IfWithBooleanLiteralBranches: # new in 1.9
Enabled: true
Style/InPatternThen: # new in 1.16
Enabled: true
Style/MapCompactWithConditionalBlock: # new in 1.30
Enabled: true
Style/MapToHash: # new in 1.24
Enabled: true
Style/MethodDefParentheses:
EnforcedStyle: require_no_parentheses
Style/MultilineInPatternThen: # new in 1.16
Enabled: true
Style/NegatedIfElseCondition: # new in 1.2
Enabled: true
Style/NegatedIf:
Enabled: false
Style/NestedFileDirname: # new in 1.26
Enabled: true
Style/NilLambda: # new in 1.3
Enabled: true
Style/NumberedParameters: # new in 1.22
Enabled: true
Style/NumberedParametersLimit: # new in 1.22
Enabled: true
Style/ObjectThen: # new in 1.28
Enabled: true
Style/OpenStructUse: # new in 1.23
Enabled: true
Style/QuotedSymbols: # new in 1.16
Enabled: true
Style/RedundantArgument: # new in 1.4
Enabled: true
Style/RedundantInitialize: # new in 1.27
Enabled: true
Style/RedundantSelfAssignmentBranch: # new in 1.19
Enabled: true
Style/SelectByRegexp: # new in 1.22
Enabled: true
Style/StringChars: # new in 1.12
Enabled: true
Style/StringLiterals:
Enabled: true
# EnforcedStyle: double_quotes
Style/SwapValues: # new in 1.1
Enabled: true
Style/TrailingCommaInHashLiteral:
Enabled: false
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ group :development do
gem 'ed25519', '~> 1.2'
gem 'bcrypt_pbkdf', '~> 1.0'
gem 'bullet'
gem 'rubocop'
gem 'rubocop-rails'
end

group :development, :test do
Expand Down Expand Up @@ -141,7 +143,7 @@ end

group :production do
gem 'puma', '~> 4.3', '>= 4.3.12'
gem 'sentry-ruby', '~> 5.3', '>= 5.3.1'
gem 'sentry-rails'
gem 'sentry-ruby', '~> 5.3', '>= 5.3.1'
gem 'sentry-sidekiq'
end
24 changes: 24 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ GEM
airbrussh (1.4.0)
sshkit (>= 1.6.1, != 1.7.0)
arel (9.0.0)
ast (2.4.2)
attribute-defaults (0.9.1)
activerecord (>= 5.0.0, < 7.0.0)
bcrypt_pbkdf (1.1.0)
Expand Down Expand Up @@ -293,6 +294,9 @@ GEM
railties (>= 4.0.0, < 6.0.0)
sprockets (~> 3.5)
oj (3.13.10)
parallel (1.22.1)
parser (3.1.2.0)
ast (~> 2.4.1)
pattern_generator (0.1.0)
rails (>= 4.0.0)
pdf-core (0.9.0)
Expand Down Expand Up @@ -351,6 +355,7 @@ GEM
method_source
rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0)
rainbow (3.1.1)
rake (13.0.6)
rb-fsevent (0.11.0)
rb-inotify (0.10.1)
Expand Down Expand Up @@ -385,7 +390,23 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.3)
rubocop (1.30.1)
parallel (~> 1.10)
parser (>= 3.1.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.18.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.18.0)
parser (>= 3.1.1.0)
rubocop-rails (2.14.2)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.7.0, < 2.0)
ruby-prof (1.4.3)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
ruby_dep (1.5.0)
sdoc (1.0.0)
Expand Down Expand Up @@ -457,6 +478,7 @@ GEM
thread_safe (~> 0.1)
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
unicode-display_width (2.1.0)
uniform_notifier (1.14.2)
uri_template (0.7.0)
validate_url (1.0.13)
Expand Down Expand Up @@ -536,6 +558,8 @@ DEPENDENCIES
redis-rack-cache
redis-rails (~> 5.0)
rspec-expectations
rubocop
rubocop-rails
ruby-prof
sdoc (~> 1.0.0)
sentry-rails
Expand Down
46 changes: 23 additions & 23 deletions app/models/memo.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'when_easter'

# class Memo содержит сведения о помине какой-либо памяти в календаре,
Expand Down Expand Up @@ -127,15 +129,10 @@ class Memo < ActiveRecord::Base
left_outer_joins(:slug).select(selector.uniq).group('_slug').order('_slug')
end

scope :by_date, -> (dates_in, julian = false) do
scope :by_date, ->(dates_in, julian = false) do
return self if dates_in.blank?

relays =
CONDITIONALS.map do |(cond, range)|
range.map {|x| (date - x.days).strftime("%2d.%m") + "#{cond}#{wday}" }
end.flatten

result = relays.dup << new_date << Memo.dates_to_days(dates_in, julian)
result = Memo.dates_to_days(dates_in, julian)

if !date.leap?
result |= result.grep(/28\.02[%<>~]?/).map do |date|
Expand Down Expand Up @@ -531,35 +528,38 @@ class Memo < ActiveRecord::Base

class << self
def dates_to_days dates_in, julian
days = [dates_in].flatten.map do |date_in|
[dates_in].flatten.map do |date_in|
date = date_in.is_a?(Date) && date_in || Date.parse(date_in)
new_date = date.strftime("%2d.%m")
gap = (julian && 13.days || 0)
new_date = date.strftime('%2d.%m')
gap = julian && 13.days || 0
wday = (date + gap).wday
easter = WhenEaster::EasterCalendar.find_greek_easter_date(date.year) - gap

sprintf("%+i", date.to_time.yday - easter.yday)
relays =
CONDITIONALS.map do |(cond, range)|
range.map { |x| (date - x.days).strftime('%2d.%m') + "#{cond}#{wday}" }
end.flatten

[relays, new_date, format('%+i', date.to_time.yday - easter.yday)]
end.flatten.uniq
end
end

def year_date_for year
case self.year_date
when /([+-])(.*)/
# gap = (julian && 13.days || 0)
# wday = (date + gap).wday
mul = $1 == '-' && -1 || 1
WhenEaster::EasterCalendar.find_greek_easter_date(year.to_i) + (mul * $2.to_i).days
when /(.*)%(.*)/
date = Date.parse([$1, year].join('.'))
gap_in = $2.to_i - date.wday
gap = gap_in < 0 && gap_in + 7 || gap_in
case year_date
when /(?<sign>[+-])(?<indent>.*)/
mul = sign == '-' && -1 || 1
WhenEaster::EasterCalendar.find_greek_easter_date(year.to_i) + (mul * indent.to_i).days
when /(?<year_m>.*)%(?<date_m>.*)/
date = Date.parse([year_m, year].join('.'))
gap_in = date_m.to_i - date.wday
gap = gap_in.negative? && gap_in + 7 || gap_in

date + gap.days
else
Date.parse([self.year_date, year].join('.'))
Date.parse([year_date, year].join('.'))
end
rescue
rescue StandardError
Time.at(0)
end

Expand Down
4 changes: 2 additions & 2 deletions app/services/memo_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class MemoService
titles: {
ру_РУ: "\{day}-й день Страстного поста"
}
},
},
}
}
}

def initialize calendary, add_date = Time.now.strptime("%d.%m.%Y %H:%M")
Expand Down
Loading

0 comments on commit 0053403

Please sign in to comment.