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 +4 -4
- data/lib/interfaces/error_interface.rb +17 -0
- data/lib/low_type.rb +2 -2
- data/lib/proxies/local_proxy.rb +3 -1
- data/lib/proxies/param_proxy.rb +3 -1
- data/lib/proxies/return_proxy.rb +3 -1
- data/lib/queries/file_parser.rb +1 -1
- data/lib/queries/file_query.rb +5 -3
- data/lib/queries/type_query.rb +3 -1
- data/lib/redefiner.rb +2 -4
- data/lib/syntax/syntax.rb +4 -2
- data/lib/syntax/union_types.rb +2 -0
- data/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6e3e1dca0d960082a4de505f3422e00c648f660306c22d24db65590db0543f5e
|
|
4
|
+
data.tar.gz: a87156e750aee311a9afb2a95166a9d00f99a744c05fc1dac0d9ab7120882760
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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(:
|
|
41
|
-
@config ||= config.new(
|
|
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
|
data/lib/proxies/local_proxy.rb
CHANGED
|
@@ -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
|
|
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
|
data/lib/proxies/param_proxy.rb
CHANGED
|
@@ -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
|
|
25
|
+
"Invalid argument type '#{output(value:)}' for parameter '#{@name}'. Valid types: '#{@type_expression.valid_types}'"
|
|
24
26
|
end
|
|
25
27
|
end
|
|
26
28
|
end
|
data/lib/proxies/return_proxy.rb
CHANGED
|
@@ -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
|
|
23
|
+
"Invalid return type '#{output(value:)}' for method '#{@name}'. Valid types: '#{@type_expression.valid_types}'"
|
|
22
24
|
end
|
|
23
25
|
end
|
|
24
26
|
end
|
data/lib/queries/file_parser.rb
CHANGED
|
@@ -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)
|
data/lib/queries/file_query.rb
CHANGED
|
@@ -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 =
|
|
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
|
|
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
|
|
18
|
+
def line_from_include
|
|
17
19
|
caller.find { |callee| callee.end_with?("include'") }
|
|
18
20
|
end
|
|
19
21
|
end
|
data/lib/queries/type_query.rb
CHANGED
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
|
|
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
|
|
17
|
+
return TypeExpression.new(type:) if TypeQuery.type?(type)
|
|
18
|
+
|
|
17
19
|
super
|
|
18
20
|
end
|
|
19
21
|
end
|
data/lib/syntax/union_types.rb
CHANGED
data/lib/version.rb
CHANGED