Skip to content

Commit

Permalink
Update rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
bolshakov committed Nov 14, 2020
1 parent 53169a3 commit 0f9fd8f
Show file tree
Hide file tree
Showing 32 changed files with 90 additions and 37 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ inherit_gem:
ruby_coding_standard: .rubocop.yml

AllCops:
TargetRubyVersion: 2.4
TargetRubyVersion: 2.5
Exclude:
- vendor/**/*
10 changes: 5 additions & 5 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# frozen_string_literal: true

require 'simplecov-lcov'
require "simplecov-lcov"

SimpleCov::Formatter::LcovFormatter.config do |c|
c.report_with_single_file = true
c.single_report_path = 'coverage/lcov.info'
c.single_report_path = "coverage/lcov.info"
end
SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new(
[
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::LcovFormatter
]
SimpleCov::Formatter::LcovFormatter,
],
)
SimpleCov.start do
add_filter 'spec/'
add_filter "spec/"
end
30 changes: 18 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ GEM
remote: https://rubygems.org/
specs:
any (0.1.0)
ast (2.4.0)
ast (2.4.1)
benchmark-ips (2.8.3)
concurrent-ruby (1.1.7)
diff-lcs (1.4.4)
Expand Down Expand Up @@ -54,15 +54,16 @@ GEM
rspec (~> 3.0)
irb (1.1.0)
reline (>= 0.0.1)
jaro_winkler (1.5.3)
lru_redux (1.1.0)
parallel (1.17.0)
parser (2.6.3.0)
ast (~> 2.4.0)
parallel (1.20.0)
parser (2.7.2.0)
ast (~> 2.4.1)
polyglot (0.3.5)
rainbow (3.0.0)
rake (13.0.1)
regexp_parser (1.8.2)
reline (0.0.7)
rexml (3.2.4)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
Expand All @@ -76,26 +77,30 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.0)
rubocop (0.73.0)
jaro_winkler (~> 1.5.1)
rubocop (1.0.0)
parallel (~> 1.10)
parser (>= 2.6)
parser (>= 2.7.1.5)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8)
rexml
rubocop-ast (>= 0.6.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (1.1.1)
parser (>= 2.7.1.5)
rubocop-rspec (1.34.0)
rubocop (>= 0.60.0)
ruby-progressbar (1.10.1)
ruby_coding_standard (0.2.0)
rubocop
ruby_coding_standard (0.3.0)
rubocop (~> 1.0.0)
simplecov (0.19.1)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov-html (0.12.3)
simplecov-lcov (0.8.0)
treetop (1.6.11)
polyglot (~> 0.3)
unicode-display_width (1.6.0)
unicode-display_width (1.7.0)
yard (0.9.25)

PLATFORMS
Expand All @@ -114,6 +119,7 @@ DEPENDENCIES
qo!
rake (~> 13.0)
rspec (~> 3.1)
rubocop (= 1.0.0)
rubocop-rspec (= 1.34.0)
ruby_coding_standard
simplecov
Expand Down
3 changes: 3 additions & 0 deletions examples/pattern_matching_binary_tree_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
#
class BinaryTreeSet
Position = Module.new
private_constant(:Position)
Right = Module.new.include(Position)
private_constant(:Right)
Left = Module.new.include(Position)
private_constant(:Left)

def initialize(elem = 0, removed: true)
@elem = elem
Expand Down
2 changes: 2 additions & 0 deletions examples/pattern_matching_number_in_words.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ToWords
80 => "eighty",
90 => "ninety",
}.freeze
private_constant :NUMBERS

CONVERTER = Fear.matcher do |m|
NUMBERS.each_pair do |number, in_words|
Expand All @@ -46,6 +47,7 @@ class ToWords
m.case(->(n) { n < 1_000_000 }) { |n| "#{CONVERTER.(n / 1_000)} thousands #{CONVERTER.(n % 1_000)}" }
m.else { |n| raise "#{n} too big " }
end
private_constant :CONVERTER

def self.call(number)
Fear.case(Integer, &:itself).and_then(CONVERTER).(number)
Expand Down
5 changes: 3 additions & 2 deletions fear.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "rspec", "~> 3.1"
spec.add_development_dependency "rubocop-rspec", "1.34.0"
spec.add_development_dependency "rubocop", "1.0.0"
spec.add_development_dependency "ruby_coding_standard"
spec.add_development_dependency "yard"
spec.add_development_dependency "dry-types"
spec.add_development_dependency "fear-rspec"
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'simplecov-lcov'
spec.add_development_dependency "simplecov"
spec.add_development_dependency "simplecov-lcov"
end
9 changes: 9 additions & 0 deletions lib/fear.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@

module Fear
Error = Class.new(StandardError)
public_constant :Error

IllegalStateException = Class.new(Error)
public_constant :IllegalStateException

MatchError = Class.new(Error)
public_constant :MatchError

NoSuchElementError = Class.new(Error)
public_constant :NoSuchElementError

PatternSyntaxError = Class.new(Error)
public_constant :PatternSyntaxError

extend EitherApi
extend ExtractorApi
Expand Down
3 changes: 3 additions & 0 deletions lib/fear/either_pattern_match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ module Fear
# @api private
class EitherPatternMatch < Fear::PatternMatch
LEFT_EXTRACTOR = :left_value.to_proc
public_constant :LEFT_EXTRACTOR

RIGHT_EXTRACTOR = :right_value.to_proc
public_constant :RIGHT_EXTRACTOR

# Match against +Fear::Right+
#
Expand Down
2 changes: 2 additions & 0 deletions lib/fear/extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ module Extractor
autoload :ValueMatcher, "fear/extractor/value_matcher"

ExtractorNotFound = Class.new(Error)
public_constant :ExtractorNotFound

@mutex = Mutex.new
@registry = PartialFunction::EMPTY

EXTRACTOR_NOT_FOUND = proc do |klass|
raise ExtractorNotFound, "could not find extractor for " + klass.inspect
end
private_constant :EXTRACTOR_NOT_FOUND

class << self
# @param klass [Class, String]
Expand Down
2 changes: 1 addition & 1 deletion lib/fear/extractor/any_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def defined_at?(_other)
end

def bindings(_)
EMPTY_HASH
Utils::EMPTY_HASH
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fear/extractor/array_splat_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def defined_at?(_other)
end

def bindings(_)
EMPTY_HASH
Utils::EMPTY_HASH
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fear/extractor/empty_list_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def defined_at?(other)
end

def bindings(_)
EMPTY_HASH
Utils::EMPTY_HASH
end
end
end
Expand Down
3 changes: 0 additions & 3 deletions lib/fear/extractor/matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ module Extractor
class Matcher < OpenStruct
autoload :And, "fear/extractor/matcher/and"

EMPTY_HASH = {}.freeze
EMPTY_ARRAY = [].freeze

# @param node [Fear::Extractor::Grammar::Node]
def initialize(node:, **attributes)
@input = node.input
Expand Down
1 change: 1 addition & 0 deletions lib/fear/extractor/pattern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Extractor
# Parse pattern. Used within +Fear[]+
class Pattern
DEFAULT_PATTERN_CACHE_SIZE = 10_000
private_constant :DEFAULT_PATTERN_CACHE_SIZE
@pattern_cache = LruRedux::Cache.new(ENV.fetch("FEAR_PATTERNS_CACHE_SIZE", DEFAULT_PATTERN_CACHE_SIZE))

class << self
Expand Down
2 changes: 1 addition & 1 deletion lib/fear/extractor/value_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def defined_at?(arg)
end

def bindings(_)
EMPTY_HASH
Utils::EMPTY_HASH
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/fear/failure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ class Failure
include Try
include RightBiased::Left
include FailurePatternMatch.mixin

EXTRACTOR = proc do |try|
if Fear::Failure === try
Fear.some([try.exception])
else
Fear.none
end
end
public_constant :EXTRACTOR

# @param [StandardError]
def initialize(exception)
Expand Down
8 changes: 3 additions & 5 deletions lib/fear/future.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,9 @@ def flat_map
on_complete_match do |m|
m.case(Fear::Failure) { |failure| promise.complete!(failure) }
m.success do |value|
begin
yield(value).on_complete { |callback_result| promise.complete!(callback_result) }
rescue StandardError => error
promise.failure!(error)
end
yield(value).on_complete { |callback_result| promise.complete!(callback_result) }
rescue StandardError => error
promise.failure!(error)
end
end
promise.to_future
Expand Down
4 changes: 2 additions & 2 deletions lib/fear/future_api.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Fear
# rubocop: disable Metrics/LineLength
# rubocop: disable Layout/LineLength
module FutureApi
# Asynchronously evaluates the block
# @param options [Hash] options will be passed directly to underlying +Concurrent::Promise+
Expand All @@ -17,5 +17,5 @@ def future(options = {}, &block)
Future.new(options, &block)
end
end
# rubocop: enable Metrics/LineLength
# rubocop: enable Layout/LineLength
end
1 change: 1 addition & 0 deletions lib/fear/left.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Left
Fear.none
end
end
public_constant :EXTRACTOR

# @api private
def left_value
Expand Down
3 changes: 3 additions & 0 deletions lib/fear/none.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class NoneClass
Fear.none
end
end
public_constant :EXTRACTOR

# @raise [NoSuchElementError]
def get
Expand Down Expand Up @@ -79,7 +80,9 @@ def filter_map
private_constant(:NoneClass)

# The only instance of NoneClass
# @api private
None = NoneClass.new.freeze
public_constant :None

class << NoneClass
def new
Expand Down
1 change: 1 addition & 0 deletions lib/fear/option_pattern_match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module Fear
# @api private
class OptionPatternMatch < Fear::PatternMatch
GET_METHOD = :get.to_proc
private_constant :GET_METHOD

# Match against Some
#
Expand Down
2 changes: 2 additions & 0 deletions lib/fear/partial_function/empty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ module Fear
module PartialFunction
EMPTY = EmptyPartialFunction.new
EMPTY.freeze

public_constant :EMPTY
end
end
2 changes: 2 additions & 0 deletions lib/fear/right.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Right
end
end

public_constant :EXTRACTOR

# @api private
def right_value
value
Expand Down
2 changes: 2 additions & 0 deletions lib/fear/some.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Some
end
end

public_constant :EXTRACTOR

attr_reader :value
protected :value

Expand Down
3 changes: 3 additions & 0 deletions lib/fear/struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def ==(other)
end

INSPECT_TEMPLATE = "<#Fear::Struct %{class_name} %{attributes}>"
private_constant :INSPECT_TEMPLATE

# @return [String]
#
Expand All @@ -208,6 +209,7 @@ def inspect
alias to_s inspect

MISSING_KEYWORDS_ERROR = "missing keywords: %{keywords}"
private_constant :MISSING_KEYWORDS_ERROR

private def _check_missing_attributes!(provided_attributes)
missing_attributes = members - provided_attributes.keys
Expand All @@ -218,6 +220,7 @@ def inspect
end

UNKNOWN_KEYWORDS_ERROR = "unknown keywords: %{keywords}"
private_constant :UNKNOWN_KEYWORDS_ERROR

private def _check_unknown_attributes!(provided_attributes)
unknown_attributes = provided_attributes.keys - members
Expand Down
1 change: 1 addition & 0 deletions lib/fear/success.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Success
Fear.none
end
end
public_constant :EXTRACTOR

attr_reader :value
protected :value
Expand Down
3 changes: 3 additions & 0 deletions lib/fear/try_pattern_match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ module Fear
# @api private
class TryPatternMatch < Fear::PatternMatch
SUCCESS_EXTRACTOR = :get.to_proc
private_constant :SUCCESS_EXTRACTOR

FAILURE_EXTRACTOR = :exception.to_proc
private_constant :FAILURE_EXTRACTOR

# Match against +Fear::Success+
#
Expand Down

0 comments on commit 0f9fd8f

Please sign in to comment.