low_type 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ef30b8ad7d079a95270a664aacb4b28255cad9dcd743451e1f78b1391549222
4
- data.tar.gz: 4e4329460d20826d604b99d1d7e57cee581cb7c3d8e6ffe2621e7ed383967b57
3
+ metadata.gz: 6e3e1dca0d960082a4de505f3422e00c648f660306c22d24db65590db0543f5e
4
+ data.tar.gz: a87156e750aee311a9afb2a95166a9d00f99a744c05fc1dac0d9ab7120882760
5
5
  SHA512:
6
- metadata.gz: c08f01a89a82f293c0320034eceff0831b87a63ec52c45f0bd01ebd23ef067af2099bd8f554c45579ef285284c9afa34713556962a8a2b167d99bf5bc65ce73b
7
- data.tar.gz: d90226573c175294ecc61258b1ed013f9b2351b4fdea32672bed0cf0786dbbea64341021710d21c0826feb152257fbaf4fc11d24cf180b9b3ac739523afef74a
6
+ metadata.gz: f8e3054ab427c0635aa27f78ae966e3a90c9f78ec660651d6025956ddc83582a1b46f66268e7a335d8ff72ed87bf92a09672a38509067d42d3b79253a97e8d49
7
+ data.tar.gz: 4698ae94c57a2de408ba085029f18b1bc100375972f3f253294dfcef71741d959da1db6773544f4bf55133d5a95d3e2eee44f274f167c503e7f462489e247153
@@ -4,6 +4,23 @@ module LowType
4
4
  class ErrorInterface
5
5
  attr_reader :file
6
6
 
7
+ def initialize
8
+ @file = nil
9
+ @output_mode = LowType.config.output_mode
10
+ @output_size = LowType.config.output_size
11
+ end
12
+
13
+ def output(value:)
14
+ case @output_mode
15
+ when :type
16
+ value.class
17
+ when :value
18
+ value.inspect[0...@output_size]
19
+ else
20
+ 'REDACTED'
21
+ end
22
+ end
23
+
7
24
  def error_type
8
25
  raise NotImplementedError
9
26
  end
data/lib/low_type.rb CHANGED
@@ -37,8 +37,8 @@ module LowType
37
37
 
38
38
  class << self
39
39
  def config
40
- config = Struct.new(:deep_type_check, :severity_level, :union_type_expressions)
41
- @config ||= config.new(false, :error, true)
40
+ config = Struct.new(:error_mode, :output_mode, :output_size, :deep_type_check, :union_type_expressions)
41
+ @config ||= config.new(:error, :type, 100, false, true)
42
42
  end
43
43
 
44
44
  def configure
@@ -8,6 +8,8 @@ module LowType
8
8
  attr_reader :type_expression, :name
9
9
 
10
10
  def initialize(type_expression:, name:, file:)
11
+ super()
12
+
11
13
  @type_expression = type_expression
12
14
  @name = name
13
15
  @file = file
@@ -18,7 +20,7 @@ module LowType
18
20
  end
19
21
 
20
22
  def error_message(value:)
21
- "Invalid variable type #{value.class} in '#{@name.class}' on line #{@file.line}. Valid types: '#{@type_expression.valid_types}'"
23
+ "Invalid variable type #{output(value:)} in '#{@name.class}' on line #{@file.line}. Valid types: '#{@type_expression.valid_types}'"
22
24
  end
23
25
  end
24
26
  end
@@ -8,6 +8,8 @@ module LowType
8
8
  attr_reader :type_expression, :name, :type, :position
9
9
 
10
10
  def initialize(type_expression:, name:, type:, file:, position: nil)
11
+ super()
12
+
11
13
  @type_expression = type_expression
12
14
  @name = name
13
15
  @type = type
@@ -20,7 +22,7 @@ module LowType
20
22
  end
21
23
 
22
24
  def error_message(value:)
23
- "Invalid argument type '#{value.class}' for parameter '#{@name}'. Valid types: '#{@type_expression.valid_types}'"
25
+ "Invalid argument type '#{output(value:)}' for parameter '#{@name}'. Valid types: '#{@type_expression.valid_types}'"
24
26
  end
25
27
  end
26
28
  end
@@ -8,6 +8,8 @@ module LowType
8
8
  attr_reader :type_expression, :name
9
9
 
10
10
  def initialize(type_expression:, name:, file:)
11
+ super()
12
+
11
13
  @type_expression = type_expression
12
14
  @name = name
13
15
  @file = file
@@ -18,7 +20,7 @@ module LowType
18
20
  end
19
21
 
20
22
  def error_message(value:)
21
- "Invalid return type '#{value.class}' for method '#{@name}'. Valid types: '#{@type_expression.valid_types}'"
23
+ "Invalid return type '#{output(value:)}' for method '#{@name}'. Valid types: '#{@type_expression.valid_types}'"
22
24
  end
23
25
  end
24
26
  end
@@ -62,7 +62,7 @@ module LowType
62
62
 
63
63
  @instance_methods = []
64
64
  @class_methods = []
65
- @line_numbers = { class_start: 0, class_end: root_node.respond_to?(:end_line) ? root_node.end_line : nil}
65
+ @line_numbers = { class_start: 0, class_end: root_node.respond_to?(:end_line) ? root_node.end_line : nil }
66
66
  end
67
67
 
68
68
  def visit_def_node(node)
@@ -1,19 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LowType
2
4
  class FileQuery
3
5
  class << self
4
6
  def file_path(klass:)
5
- includer_line = line_with_class(klass:) || line_with_include || ''
7
+ includer_line = line_from_class(klass:) || line_from_include || ''
6
8
  includer_line.split(':').first || ''
7
9
  end
8
10
 
9
11
  private
10
12
 
11
- def line_with_class(klass:)
13
+ def line_from_class(klass:)
12
14
  class_name = klass.to_s.split(':').last # Also remove the module namespaces from the class.
13
15
  caller.find { |callee| callee.end_with?("<class:#{class_name}>'") }
14
16
  end
15
17
 
16
- def line_with_include
18
+ def line_from_include
17
19
  caller.find { |callee| callee.end_with?("include'") }
18
20
  end
19
21
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LowType
2
4
  # TODO: Unit test.
3
5
  class TypeQuery
@@ -7,7 +9,7 @@ module LowType
7
9
  end
8
10
 
9
11
  def basic_type?(type:)
10
- type.class == Class
12
+ type.instance_of?(Class)
11
13
  end
12
14
 
13
15
  def complex_type?(type:)
data/lib/redefiner.rb CHANGED
@@ -5,8 +5,8 @@ require_relative 'factories/proxy_factory'
5
5
  require_relative 'proxies/file_proxy'
6
6
  require_relative 'proxies/method_proxy'
7
7
  require_relative 'proxies/param_proxy'
8
- require_relative 'syntax/syntax'
9
8
  require_relative 'queries/type_query'
9
+ require_relative 'syntax/syntax'
10
10
  require_relative 'type_expression'
11
11
  require_relative 'value_expression'
12
12
 
@@ -45,9 +45,7 @@ module LowType
45
45
  method_start = method_node.respond_to?(:start_line) ? method_node.start_line : nil
46
46
  method_end = method_node.respond_to?(:end_line) ? method_node.end_line : nil
47
47
 
48
- if method_start && method_end && class_end
49
- next unless method_start > class_start && method_end <= class_end
50
- end
48
+ next if method_start && method_end && class_end && !(method_start > class_start && method_end <= class_end)
51
49
 
52
50
  name = method_node.name
53
51
 
data/lib/syntax/syntax.rb CHANGED
@@ -6,14 +6,16 @@ module LowType
6
6
  module Syntax
7
7
  refine Array.singleton_class do
8
8
  def [](*types)
9
- return LowType::TypeExpression.new(type: [*types]) if types.all? { |type| LowType::TypeQuery.type?(type) }
9
+ return TypeExpression.new(type: [*types]) if types.all? { |type| TypeQuery.type?(type) }
10
+
10
11
  super
11
12
  end
12
13
  end
13
14
 
14
15
  refine Hash.singleton_class do
15
16
  def [](type)
16
- return LowType::TypeExpression.new(type:) if LowType::TypeQuery.type?(type)
17
+ return TypeExpression.new(type:) if TypeQuery.type?(type)
18
+
17
19
  super
18
20
  end
19
21
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ###
2
4
  # Type expressions from union types.
3
5
  #
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LowType
4
- VERSION = '1.0.7'
4
+ VERSION = '1.0.8'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: low_type
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - maedi