gob-lang 1.0.0 → 1.1.0

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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +201 -0
  3. data/README.md +73 -0
  4. data/gob-lang.gemspec +2 -1
  5. data/lib/gob/cli/base.rb +2 -2
  6. data/lib/gob/cli/commands/fmt.rb +2 -2
  7. data/lib/gob/cli/completion.rb +104 -0
  8. data/lib/gob/cli/errors.rb +0 -2
  9. data/lib/gob/cli.rb +21 -3
  10. data/lib/gob/go/printer.rb +215 -72
  11. data/lib/gob/transpilation/context.rb +102 -0
  12. data/lib/gob/transpilation/runner.rb +1500 -0
  13. data/lib/gob/validation/rules/array_length.rb +45 -0
  14. data/lib/gob/validation/rules/attribute_type.rb +30 -0
  15. data/lib/gob/validation/rules/block_delimiters.rb +43 -0
  16. data/lib/gob/validation/rules/collection_literal.rb +107 -0
  17. data/lib/gob/validation/rules/config.yml +58 -4
  18. data/lib/gob/validation/rules/cop.rb +72 -0
  19. data/lib/gob/validation/rules/defer_statement.rb +33 -0
  20. data/lib/gob/validation/rules/error_check.rb +33 -0
  21. data/lib/gob/validation/rules/go_block.rb +58 -0
  22. data/lib/gob/validation/rules/indentation.rb +118 -0
  23. data/lib/gob/validation/rules/invoked_lambda.rb +48 -0
  24. data/lib/gob/validation/rules/lambda_signature.rb +58 -0
  25. data/lib/gob/validation/rules/multiline.rb +99 -0
  26. data/lib/gob/validation/rules/operator_assignment.rb +44 -0
  27. data/lib/gob/validation/rules/pointer_type.rb +36 -0
  28. data/lib/gob/validation/rules/quote_marks.rb +33 -0
  29. data/lib/gob/validation/rules/redundant_lambda_parentheses.rb +47 -0
  30. data/lib/gob/validation/rules/select_block.rb +85 -0
  31. data/lib/gob/validation/rules/signature_comment.rb +43 -0
  32. data/lib/gob/validation/rules/this_receiver.rb +38 -0
  33. data/lib/gob/validation/rules/trailing_whitespace.rb +38 -0
  34. data/lib/gob/validation/rules/variable_declaration.rb +32 -0
  35. data/lib/gob/validation/rules/word_array.rb +33 -0
  36. data/lib/gob/validation/rules/zero_based_range_loop.rb +63 -0
  37. data/lib/gob/validation/rules.rb +85 -11
  38. data/lib/gob/version.rb +1 -1
  39. data/lib/gob.rb +10 -12
  40. metadata +41 -9
  41. data/lib/gob/go/dsl.rb +0 -196
  42. data/lib/gob/matcher.rb +0 -34
  43. data/lib/gob/transpilation/rules/core.rb +0 -1184
  44. data/lib/gob/transpiler.rb +0 -815
  45. data/lib/gob/validation/rules/class_rules.rb +0 -78
  46. data/lib/gob/validation/rules/function_rules.rb +0 -33
  47. data/lib/gob/validation/rules/module_rules.rb +0 -78
  48. data/lib/gob/validation/rules/program_rules.rb +0 -72
@@ -1,78 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gob
4
- module Validation
5
- module Rules
6
- class ClassRules < Cop
7
- MSG = "Disallowed class-level statement: `%<name>s`"
8
-
9
- ALLOWED_SENDS = %w[
10
- define_const
11
- const
12
- define_var
13
- var
14
- attr_accessor
15
- private
16
- public
17
- protected
18
- include
19
- extend
20
- prepend
21
- ].freeze
22
- def on_class(node)
23
- check_body(node.body)
24
- end
25
-
26
- private
27
-
28
- def check_body(body)
29
- return if body.nil?
30
-
31
- if body.begin_type?
32
- children = body.children
33
- else
34
- children = [body]
35
- end
36
-
37
- children.each { |child| check_node(child) }
38
- end
39
-
40
- def check_node(node)
41
- return if node.nil?
42
-
43
- case node.type
44
- when :def, :class, :module, :casgn
45
- true
46
- when :defs
47
- add_offense(node.loc.keyword || node.loc.name || node.loc.expression, message: "Disallowed `def self.*` in class; Go has no static methods")
48
- when :lvasgn, :ivasgn, :cvasgn, :gvasgn
49
- true
50
- when :send
51
- name = node.method_name.to_s
52
- return if ALLOWED_SENDS.include?(name)
53
- add_offense(node.loc.selector || node.loc.expression, message: format(MSG, name: name))
54
- when :block
55
- send_node = node.send_node
56
-
57
- if (
58
- send_node &&
59
- ALLOWED_SENDS.include?(send_node.method_name.to_s)
60
- )
61
- true
62
- else
63
- if send_node
64
- name = send_node.method_name.to_s
65
- else
66
- name = "block"
67
- end
68
-
69
- add_offense(node.loc.expression, message: format(MSG, name: name))
70
- end
71
- else
72
- add_offense(node.loc.expression, message: format(MSG, name: node.type))
73
- end
74
- end
75
- end
76
- end
77
- end
78
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gob
4
- module Validation
5
- module Rules
6
- class FunctionRules < Cop
7
- MSG = "Disallowed construct in function: `%<name>s`"
8
-
9
- DISALLOWED_TYPES = %i[
10
- rescue
11
- resbody
12
- ensure
13
- retry
14
- redo
15
- ].freeze
16
- def on_def(node)
17
- check_body(node)
18
- end
19
-
20
- alias on_defs on_def
21
-
22
- private
23
-
24
- def check_body(node)
25
- node.each_descendant do |child|
26
- next unless DISALLOWED_TYPES.include?(child.type)
27
- add_offense(child.loc.keyword || child.loc.expression, message: format(MSG, name: child.type))
28
- end
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,78 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gob
4
- module Validation
5
- module Rules
6
- class ModuleRules < Cop
7
- MSG = "Disallowed module-level statement: `%<name>s`"
8
-
9
- ALLOWED_SENDS = %w[
10
- require
11
- define_const
12
- const
13
- define_var
14
- var
15
- attr_accessor
16
- private
17
- public
18
- protected
19
- module_function
20
- include
21
- extend
22
- prepend
23
- ].freeze
24
- def on_module(node)
25
- check_body(node.body)
26
- end
27
-
28
- private
29
-
30
- def check_body(body)
31
- return if body.nil?
32
-
33
- if body.begin_type?
34
- children = body.children
35
- else
36
- children = [body]
37
- end
38
-
39
- children.each { |child| check_node(child) }
40
- end
41
-
42
- def check_node(node)
43
- return if node.nil?
44
-
45
- case node.type
46
- when :def, :defs, :class, :module, :casgn
47
- true
48
- when :lvasgn, :ivasgn, :cvasgn, :gvasgn
49
- true
50
- when :send
51
- name = node.method_name.to_s
52
- return if ALLOWED_SENDS.include?(name)
53
- add_offense(node.loc.selector || node.loc.expression, message: format(MSG, name: name))
54
- when :block
55
- send_node = node.send_node
56
-
57
- if (
58
- send_node &&
59
- ALLOWED_SENDS.include?(send_node.method_name.to_s)
60
- )
61
- true
62
- else
63
- if send_node
64
- name = send_node.method_name.to_s
65
- else
66
- name = "block"
67
- end
68
-
69
- add_offense(node.loc.expression, message: format(MSG, name: name))
70
- end
71
- else
72
- add_offense(node.loc.expression, message: format(MSG, name: node.type))
73
- end
74
- end
75
- end
76
- end
77
- end
78
- end
@@ -1,72 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gob
4
- module Validation
5
- module Rules
6
- class ProgramRules < Cop
7
- MSG = "Disallowed top-level statement: `%<name>s`"
8
-
9
- ALLOWED_SENDS = %w[
10
- require
11
- private
12
- public
13
- protected
14
- define_const
15
- const
16
- define_var
17
- var
18
- ].freeze
19
- def on_new_investigation
20
- return unless processed_source.ast
21
-
22
- body = processed_source.ast
23
-
24
- if body.begin_type?
25
- children = body.children
26
- else
27
- children = [body]
28
- end
29
-
30
- children.each { |child| check_node(child) }
31
- end
32
-
33
- private
34
-
35
- def check_node(node)
36
- return if node.nil?
37
-
38
- case node.type
39
- when :def, :defs, :class, :module, :casgn
40
- true
41
- when :lvasgn, :ivasgn, :cvasgn, :gvasgn
42
- true
43
- when :send
44
- name = node.method_name.to_s
45
- return if ALLOWED_SENDS.include?(name)
46
-
47
- add_offense(node.loc.selector || node.loc.expression, message: format(MSG, name: name))
48
- when :block
49
- send_node = node.send_node
50
-
51
- if (
52
- send_node &&
53
- ALLOWED_SENDS.include?(send_node.method_name.to_s)
54
- )
55
- true
56
- else
57
- if send_node
58
- name = send_node.method_name.to_s
59
- else
60
- name = "block"
61
- end
62
-
63
- add_offense(node.loc.expression, message: format(MSG, name: name))
64
- end
65
- else
66
- add_offense(node.loc.expression, message: format(MSG, name: node.type))
67
- end
68
- end
69
- end
70
- end
71
- end
72
- end