rucoa 0.6.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +4 -1
- data/data/definitions_ruby_3_1 +0 -0
- data/lib/rucoa/configuration.rb +10 -0
- data/lib/rucoa/definition_store.rb +113 -6
- data/lib/rucoa/definitions/class_definition.rb +16 -0
- data/lib/rucoa/definitions/method_definition.rb +14 -2
- data/lib/rucoa/definitions/module_definition.rb +8 -0
- data/lib/rucoa/definitions.rb +2 -0
- data/lib/rucoa/handler_concerns/diagnostics_publishable.rb +14 -2
- data/lib/rucoa/handlers/initialize_handler.rb +1 -0
- data/lib/rucoa/handlers/initialized_handler.rb +1 -1
- data/lib/rucoa/handlers/text_document_completion_handler.rb +9 -2
- data/lib/rucoa/handlers/text_document_definition_handler.rb +155 -0
- data/lib/rucoa/handlers/text_document_did_close_handler.rb +20 -0
- data/lib/rucoa/handlers/text_document_formatting_handler.rb +2 -2
- data/lib/rucoa/handlers/text_document_hover_handler.rb +3 -4
- data/lib/rucoa/handlers/text_document_range_formatting_handler.rb +2 -2
- data/lib/rucoa/handlers.rb +2 -0
- data/lib/rucoa/node_inspector.rb +48 -15
- data/lib/rucoa/nodes/base.rb +2 -2
- data/lib/rucoa/nodes/const_node.rb +31 -0
- data/lib/rucoa/position.rb +1 -1
- data/lib/rucoa/rbs/class_definition_mapper.rb +46 -0
- data/lib/rucoa/{definition_builders/rbs_constant_definition_builder.rb → rbs/constant_definition_mapper.rb} +4 -8
- data/lib/rucoa/{definition_builders/rbs_method_definition_builder.rb → rbs/method_definition_mapper.rb} +4 -7
- data/lib/rucoa/rbs/module_definition_mapper.rb +40 -0
- data/lib/rucoa/rbs/ruby_definitions_loader.rb +82 -0
- data/lib/rucoa/rbs.rb +11 -0
- data/lib/rucoa/rubocop/autocorrector.rb +51 -0
- data/lib/rucoa/rubocop/configuration_checker.rb +44 -0
- data/lib/rucoa/rubocop/investigator.rb +59 -0
- data/lib/rucoa/rubocop.rb +9 -0
- data/lib/rucoa/server.rb +2 -0
- data/lib/rucoa/source.rb +11 -3
- data/lib/rucoa/version.rb +1 -1
- data/lib/rucoa/yard/definitions_loader.rb +85 -0
- data/lib/rucoa/{definition_builders/yard_method_definition_builder.rb → yard/method_definition_mapper.rb} +22 -25
- data/lib/rucoa/yard.rb +8 -0
- data/lib/rucoa.rb +3 -7
- metadata +19 -12
- data/lib/rucoa/definition_builders.rb +0 -9
- data/lib/rucoa/rbs_document_loader.rb +0 -43
- data/lib/rucoa/rubocop_autocorrector.rb +0 -38
- data/lib/rucoa/rubocop_configuration_checker.rb +0 -42
- data/lib/rucoa/rubocop_investigator.rb +0 -48
- data/lib/rucoa/yard_glob_document_loader.rb +0 -47
- data/lib/rucoa/yard_string_document_loader.rb +0 -70
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
require 'yard'
|
5
|
+
|
6
|
+
module Rucoa
|
7
|
+
module Yard
|
8
|
+
class DefinitionsLoader
|
9
|
+
class << self
|
10
|
+
# @param content [String]
|
11
|
+
# @return [Array<Rucoa::Definitions::Base>]
|
12
|
+
# @example returns method definitions from Ruby source code
|
13
|
+
# content = <<~RUBY
|
14
|
+
# class Foo
|
15
|
+
# # Return given argument as an Integer.
|
16
|
+
# # @param bar [String]
|
17
|
+
# # @return [Integer]
|
18
|
+
# def foo(bar)
|
19
|
+
# bar.to_i
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
# RUBY
|
23
|
+
# definitions = Rucoa::Yard::DefinitionsLoader.load_string(
|
24
|
+
# content: content,
|
25
|
+
# path: '/path/to/foo.rb'
|
26
|
+
# )
|
27
|
+
# expect(definitions.size).to eq(2)
|
28
|
+
# expect(definitions[1].full_qualified_name).to eq('Foo#foo')
|
29
|
+
# expect(definitions[1].source_path).to eq('/path/to/foo.rb')
|
30
|
+
# expect(definitions[1].description).to eq('Return given argument as an Integer.')
|
31
|
+
# expect(definitions[1].return_types).to eq(%w[Integer])
|
32
|
+
def load_string(content:, path:)
|
33
|
+
load(path: path) do
|
34
|
+
::YARD.parse_string(content)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# @param globs [String]
|
39
|
+
# @return [Array<Rucoa::Definitions::Base>]
|
40
|
+
def load_globs(globs:)
|
41
|
+
load do
|
42
|
+
::YARD.parse(globs)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# @param code_object [YARD::CodeObjects::Base]
|
49
|
+
# @param path [String, nil]
|
50
|
+
# @return [Rucoa::Definitions::Base, nil]
|
51
|
+
def map(code_object, path:)
|
52
|
+
case code_object
|
53
|
+
when ::YARD::CodeObjects::ClassObject
|
54
|
+
Definitions::ClassDefinition.new(
|
55
|
+
full_qualified_name: code_object.path,
|
56
|
+
source_path: path || code_object.file,
|
57
|
+
super_class_name: code_object.superclass.to_s # TODO: superclass may not include full namespace on `YARD.parse_string`.
|
58
|
+
)
|
59
|
+
when ::YARD::CodeObjects::ModuleObject
|
60
|
+
Definitions::ModuleDefinition.new(
|
61
|
+
full_qualified_name: code_object.path,
|
62
|
+
source_path: path || code_object.file
|
63
|
+
)
|
64
|
+
when ::YARD::CodeObjects::MethodObject
|
65
|
+
MethodDefinitionMapper.call(code_object, path: path)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# @param path [String, nil]
|
70
|
+
# @return [Array<Rucoa::Definitions::Base>]
|
71
|
+
def load(path: nil, &block)
|
72
|
+
::YARD::Registry.clear
|
73
|
+
quietly(&block)
|
74
|
+
::YARD::Registry.all.filter_map do |code_object|
|
75
|
+
map(code_object, path: path)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def quietly(&block)
|
80
|
+
::YARD::Logger.instance.enter_level(::Logger::FATAL, &block)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -3,30 +3,27 @@
|
|
3
3
|
require 'yard'
|
4
4
|
|
5
5
|
module Rucoa
|
6
|
-
module
|
7
|
-
class
|
6
|
+
module Yard
|
7
|
+
class MethodDefinitionMapper
|
8
8
|
class << self
|
9
9
|
# @param code_object [YARD::CodeObjects::MethodObject]
|
10
|
-
# @param path [String]
|
11
|
-
# @return [Rucoa::Definitions::Base]
|
12
|
-
def call(code_object
|
13
|
-
new(
|
14
|
-
code_object: code_object,
|
15
|
-
path: path
|
16
|
-
).call
|
10
|
+
# @param path [String] This must be passed if the path is not available from code object.
|
11
|
+
# @return [Rucoa::Definitions::Base, nil]
|
12
|
+
def call(code_object, path: code_object.file)
|
13
|
+
new(code_object, path: path).call
|
17
14
|
end
|
18
15
|
end
|
19
16
|
|
20
|
-
# @param code_object [YARD::CodeObjects::
|
17
|
+
# @param code_object [YARD::CodeObjects::MethodObject]
|
21
18
|
# @param path [String]
|
22
|
-
def initialize(code_object
|
19
|
+
def initialize(code_object, path:)
|
23
20
|
@code_object = code_object
|
24
21
|
@path = path
|
25
22
|
end
|
26
23
|
|
27
|
-
# @return [Rucoa::Definitions::
|
24
|
+
# @return [Rucoa::Definitions::MethodDefinition]
|
28
25
|
def call
|
29
|
-
|
26
|
+
Definitions::MethodDefinition.new(
|
30
27
|
description: description,
|
31
28
|
kind: kind,
|
32
29
|
method_name: method_name,
|
@@ -52,9 +49,9 @@ module Rucoa
|
|
52
49
|
end
|
53
50
|
end
|
54
51
|
|
55
|
-
# @return [String
|
52
|
+
# @return [String]
|
56
53
|
def method_name
|
57
|
-
@code_object.name
|
54
|
+
@code_object.name.to_s
|
58
55
|
end
|
59
56
|
|
60
57
|
# @return [String]
|
@@ -74,7 +71,7 @@ module Rucoa
|
|
74
71
|
|
75
72
|
# @return [String]
|
76
73
|
# @example
|
77
|
-
# definitions = Rucoa::
|
74
|
+
# definitions = Rucoa::Yard::DefinitionsLoader.load_string(
|
78
75
|
# content: <<~RUBY,
|
79
76
|
# class Foo
|
80
77
|
# def bar(
|
@@ -91,7 +88,7 @@ module Rucoa
|
|
91
88
|
# RUBY
|
92
89
|
# path: '/path/to/foo.rb'
|
93
90
|
# )
|
94
|
-
# expect(definitions.
|
91
|
+
# expect(definitions[1].signatures).to eq(
|
95
92
|
# [
|
96
93
|
# 'Foo#bar(argument1, argument2 = nil, *arguments, keyword1:, keyword2: nil, **keywords, &block) -> Object'
|
97
94
|
# ]
|
@@ -116,7 +113,7 @@ module Rucoa
|
|
116
113
|
# @return [Array<Rucoa::Definitions::MethodParameterDefinition>]
|
117
114
|
def parameters
|
118
115
|
parameter_tags.map do |parameter_tag|
|
119
|
-
|
116
|
+
Definitions::MethodParameterDefinition.new(
|
120
117
|
name: parameter_tag.name,
|
121
118
|
types: parameter_tag.types
|
122
119
|
)
|
@@ -133,7 +130,7 @@ module Rucoa
|
|
133
130
|
# @return [Array<String>]
|
134
131
|
# @return [String]
|
135
132
|
# @example returns return type annotated by YARD @return tags
|
136
|
-
# definitions = Rucoa::
|
133
|
+
# definitions = Rucoa::Yard::DefinitionsLoader.load_string(
|
137
134
|
# content: <<~RUBY,
|
138
135
|
# # @return [String]
|
139
136
|
# def foo
|
@@ -148,7 +145,7 @@ module Rucoa
|
|
148
145
|
# ]
|
149
146
|
# )
|
150
147
|
# @example ignores empty @return tags
|
151
|
-
# definitions = Rucoa::
|
148
|
+
# definitions = Rucoa::Yard::DefinitionsLoader.load_string(
|
152
149
|
# content: <<~RUBY,
|
153
150
|
# # @return []
|
154
151
|
# def foo
|
@@ -181,27 +178,27 @@ module Rucoa
|
|
181
178
|
|
182
179
|
# @return [String]
|
183
180
|
# @example scrubs "Array<String>" to "Array"
|
184
|
-
# yard_type = Rucoa::
|
181
|
+
# yard_type = Rucoa::Yard::MethodDefinitionMapper::YardType.new(
|
185
182
|
# 'Array<String>'
|
186
183
|
# )
|
187
184
|
# expect(yard_type.to_rucoa_type).to eq('Array')
|
188
185
|
# @example scrubs "Array(String, Integer)" to "Array"
|
189
|
-
# yard_type = Rucoa::
|
186
|
+
# yard_type = Rucoa::Yard::MethodDefinitionMapper::YardType.new(
|
190
187
|
# 'Array(String, Integer)'
|
191
188
|
# )
|
192
189
|
# expect(yard_type.to_rucoa_type).to eq('Array')
|
193
190
|
# @example scrubs "::Array" to "Array"
|
194
|
-
# yard_type = Rucoa::
|
191
|
+
# yard_type = Rucoa::Yard::MethodDefinitionMapper::YardType.new(
|
195
192
|
# '::Array'
|
196
193
|
# )
|
197
194
|
# expect(yard_type.to_rucoa_type).to eq('Array')
|
198
195
|
# @example scrubs "Hash{Symbol => Object}" to "Hash"
|
199
|
-
# yard_type = Rucoa::
|
196
|
+
# yard_type = Rucoa::Yard::MethodDefinitionMapper::YardType.new(
|
200
197
|
# 'Hash{Symbol => Object}'
|
201
198
|
# )
|
202
199
|
# expect(yard_type.to_rucoa_type).to eq('Hash')
|
203
200
|
# @example scrubs "Array<Array<Integer>>" to "Array"
|
204
|
-
# yard_type = Rucoa::
|
201
|
+
# yard_type = Rucoa::Yard::MethodDefinitionMapper::YardType.new(
|
205
202
|
# 'Array<Array<Integer>>'
|
206
203
|
# )
|
207
204
|
# expect(yard_type.to_rucoa_type).to eq('Array')
|
data/lib/rucoa/yard.rb
ADDED
data/lib/rucoa.rb
CHANGED
@@ -6,7 +6,6 @@ module Rucoa
|
|
6
6
|
autoload :Cli, 'rucoa/cli'
|
7
7
|
autoload :Configuration, 'rucoa/configuration'
|
8
8
|
autoload :DefinitionArchiver, 'rucoa/definition_archiver'
|
9
|
-
autoload :DefinitionBuilders, 'rucoa/definition_builders'
|
10
9
|
autoload :Definitions, 'rucoa/definitions'
|
11
10
|
autoload :DefinitionStore, 'rucoa/definition_store'
|
12
11
|
autoload :Errors, 'rucoa/errors'
|
@@ -21,14 +20,11 @@ module Rucoa
|
|
21
20
|
autoload :ParserBuilder, 'rucoa/parser_builder'
|
22
21
|
autoload :Position, 'rucoa/position'
|
23
22
|
autoload :Range, 'rucoa/range'
|
24
|
-
autoload :
|
25
|
-
autoload :
|
26
|
-
autoload :RubocopConfigurationChecker, 'rucoa/rubocop_configuration_checker'
|
27
|
-
autoload :RubocopInvestigator, 'rucoa/rubocop_investigator'
|
23
|
+
autoload :Rbs, 'rucoa/rbs'
|
24
|
+
autoload :Rubocop, 'rucoa/rubocop'
|
28
25
|
autoload :Server, 'rucoa/server'
|
29
26
|
autoload :Source, 'rucoa/source'
|
30
27
|
autoload :SourceStore, 'rucoa/source_store'
|
31
28
|
autoload :Types, 'rucoa/types'
|
32
|
-
autoload :
|
33
|
-
autoload :YardStringDocumentLoader, 'rucoa/yard_string_document_loader'
|
29
|
+
autoload :Yard, 'rucoa/yard'
|
34
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rucoa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -92,16 +92,14 @@ files:
|
|
92
92
|
- lib/rucoa/cli.rb
|
93
93
|
- lib/rucoa/configuration.rb
|
94
94
|
- lib/rucoa/definition_archiver.rb
|
95
|
-
- lib/rucoa/definition_builders.rb
|
96
|
-
- lib/rucoa/definition_builders/rbs_constant_definition_builder.rb
|
97
|
-
- lib/rucoa/definition_builders/rbs_method_definition_builder.rb
|
98
|
-
- lib/rucoa/definition_builders/yard_method_definition_builder.rb
|
99
95
|
- lib/rucoa/definition_store.rb
|
100
96
|
- lib/rucoa/definitions.rb
|
101
97
|
- lib/rucoa/definitions/base.rb
|
98
|
+
- lib/rucoa/definitions/class_definition.rb
|
102
99
|
- lib/rucoa/definitions/constant_definition.rb
|
103
100
|
- lib/rucoa/definitions/method_definition.rb
|
104
101
|
- lib/rucoa/definitions/method_parameter_definition.rb
|
102
|
+
- lib/rucoa/definitions/module_definition.rb
|
105
103
|
- lib/rucoa/errors.rb
|
106
104
|
- lib/rucoa/handler_concerns.rb
|
107
105
|
- lib/rucoa/handler_concerns/configuration_requestable.rb
|
@@ -114,7 +112,9 @@ files:
|
|
114
112
|
- lib/rucoa/handlers/shutdown_handler.rb
|
115
113
|
- lib/rucoa/handlers/text_document_code_action_handler.rb
|
116
114
|
- lib/rucoa/handlers/text_document_completion_handler.rb
|
115
|
+
- lib/rucoa/handlers/text_document_definition_handler.rb
|
117
116
|
- lib/rucoa/handlers/text_document_did_change_handler.rb
|
117
|
+
- lib/rucoa/handlers/text_document_did_close_handler.rb
|
118
118
|
- lib/rucoa/handlers/text_document_did_open_handler.rb
|
119
119
|
- lib/rucoa/handlers/text_document_document_symbol_handler.rb
|
120
120
|
- lib/rucoa/handlers/text_document_formatting_handler.rb
|
@@ -145,18 +145,25 @@ files:
|
|
145
145
|
- lib/rucoa/parser_builder.rb
|
146
146
|
- lib/rucoa/position.rb
|
147
147
|
- lib/rucoa/range.rb
|
148
|
-
- lib/rucoa/
|
149
|
-
- lib/rucoa/
|
150
|
-
- lib/rucoa/
|
151
|
-
- lib/rucoa/
|
148
|
+
- lib/rucoa/rbs.rb
|
149
|
+
- lib/rucoa/rbs/class_definition_mapper.rb
|
150
|
+
- lib/rucoa/rbs/constant_definition_mapper.rb
|
151
|
+
- lib/rucoa/rbs/method_definition_mapper.rb
|
152
|
+
- lib/rucoa/rbs/module_definition_mapper.rb
|
153
|
+
- lib/rucoa/rbs/ruby_definitions_loader.rb
|
154
|
+
- lib/rucoa/rubocop.rb
|
155
|
+
- lib/rucoa/rubocop/autocorrector.rb
|
156
|
+
- lib/rucoa/rubocop/configuration_checker.rb
|
157
|
+
- lib/rucoa/rubocop/investigator.rb
|
152
158
|
- lib/rucoa/server.rb
|
153
159
|
- lib/rucoa/source.rb
|
154
160
|
- lib/rucoa/source_store.rb
|
155
161
|
- lib/rucoa/types.rb
|
156
162
|
- lib/rucoa/types/method_type.rb
|
157
163
|
- lib/rucoa/version.rb
|
158
|
-
- lib/rucoa/
|
159
|
-
- lib/rucoa/
|
164
|
+
- lib/rucoa/yard.rb
|
165
|
+
- lib/rucoa/yard/definitions_loader.rb
|
166
|
+
- lib/rucoa/yard/method_definition_mapper.rb
|
160
167
|
- rucoa.gemspec
|
161
168
|
homepage: https://github.com/r7kamura/rucoa
|
162
169
|
licenses:
|
@@ -1,9 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Rucoa
|
4
|
-
module DefinitionBuilders
|
5
|
-
autoload :RbsConstantDefinitionBuilder, 'rucoa/definition_builders/rbs_constant_definition_builder'
|
6
|
-
autoload :RbsMethodDefinitionBuilder, 'rucoa/definition_builders/rbs_method_definition_builder'
|
7
|
-
autoload :YardMethodDefinitionBuilder, 'rucoa/definition_builders/yard_method_definition_builder'
|
8
|
-
end
|
9
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rbs'
|
4
|
-
|
5
|
-
module Rucoa
|
6
|
-
class RbsDocumentLoader
|
7
|
-
class << self
|
8
|
-
def call
|
9
|
-
new.call
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
# @return [Array<Rucoa::Definitions::Base>]
|
14
|
-
def call
|
15
|
-
declarations.flat_map do |declaration|
|
16
|
-
case declaration
|
17
|
-
when ::RBS::AST::Declarations::Constant
|
18
|
-
[
|
19
|
-
DefinitionBuilders::RbsConstantDefinitionBuilder.call(declaration: declaration)
|
20
|
-
]
|
21
|
-
when ::RBS::AST::Declarations::Class, ::RBS::AST::Declarations::Module
|
22
|
-
declaration.members.grep(::RBS::AST::Members::MethodDefinition).map do |method_definition|
|
23
|
-
DefinitionBuilders::RbsMethodDefinitionBuilder.call(
|
24
|
-
declaration: declaration,
|
25
|
-
method_definition: method_definition
|
26
|
-
)
|
27
|
-
end
|
28
|
-
else
|
29
|
-
[]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
# @return [Array<RBS::AST::Declarations::Base>]
|
37
|
-
def declarations
|
38
|
-
::RBS::Environment.from_loader(
|
39
|
-
::RBS::EnvironmentLoader.new
|
40
|
-
).resolve_type_names.declarations
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rubocop'
|
4
|
-
|
5
|
-
module Rucoa
|
6
|
-
class RubocopAutocorrector < ::RuboCop::Runner
|
7
|
-
class << self
|
8
|
-
# @param source [Rucoa::Source]
|
9
|
-
# @return [String]
|
10
|
-
def call(source:)
|
11
|
-
new(source: source).call
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
# @param source [Rucoa::Source]
|
16
|
-
def initialize(source:)
|
17
|
-
@source = source
|
18
|
-
super(
|
19
|
-
::RuboCop::Options.new.parse(
|
20
|
-
%w[
|
21
|
-
--stderr
|
22
|
-
--force-exclusion
|
23
|
-
--format RuboCop::Formatter::BaseFormatter
|
24
|
-
-A
|
25
|
-
]
|
26
|
-
).first,
|
27
|
-
::RuboCop::ConfigStore.new
|
28
|
-
)
|
29
|
-
end
|
30
|
-
|
31
|
-
# @return [String]
|
32
|
-
def call
|
33
|
-
@options[:stdin] = @source.content
|
34
|
-
run([@source.path || 'untitled'])
|
35
|
-
@options[:stdin]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'pathname'
|
4
|
-
|
5
|
-
module Rucoa
|
6
|
-
class RubocopConfigurationChecker
|
7
|
-
class << self
|
8
|
-
# @return [Boolean]
|
9
|
-
def call
|
10
|
-
new.call
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
# @return [Boolean]
|
15
|
-
def call
|
16
|
-
rubocop_configured_for_current_directory?
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
# @return [Boolean]
|
22
|
-
def rubocop_configured_for_current_directory?
|
23
|
-
each_current_and_ancestor_pathname.any? do |pathname|
|
24
|
-
pathname.join('.rubocop.yml').exist?
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# @return [Enumerable<Pathname>]
|
29
|
-
def each_current_and_ancestor_pathname
|
30
|
-
return to_enum(__method__) unless block_given?
|
31
|
-
|
32
|
-
pathname = ::Pathname.pwd
|
33
|
-
loop do
|
34
|
-
yield pathname
|
35
|
-
break if pathname.root?
|
36
|
-
|
37
|
-
pathname = pathname.parent
|
38
|
-
end
|
39
|
-
self
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rubocop'
|
4
|
-
|
5
|
-
module Rucoa
|
6
|
-
class RubocopInvestigator < ::RuboCop::Runner
|
7
|
-
class << self
|
8
|
-
# @param source [Rucoa::Source]
|
9
|
-
# @return [Array<RuboCop::Cop::Offense>]
|
10
|
-
def call(source:)
|
11
|
-
new(source: source).call
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
# @param source [Rucoa::Source]
|
16
|
-
def initialize(source:)
|
17
|
-
@source = source
|
18
|
-
@offenses = []
|
19
|
-
super(
|
20
|
-
::RuboCop::Options.new.parse(
|
21
|
-
%w[
|
22
|
-
--stderr
|
23
|
-
--force-exclusion
|
24
|
-
--format RuboCop::Formatter::BaseFormatter
|
25
|
-
]
|
26
|
-
).first,
|
27
|
-
::RuboCop::ConfigStore.new
|
28
|
-
)
|
29
|
-
end
|
30
|
-
|
31
|
-
# @return [Array<RuboCop::Cop::Offense>]
|
32
|
-
def call
|
33
|
-
@options[:stdin] = @source.content
|
34
|
-
run([@source.path || 'untitled'])
|
35
|
-
@offenses
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
# @param file [String]
|
41
|
-
# @param offenses [Array<RuboCop::Cop::Offense>]
|
42
|
-
# @return [void]
|
43
|
-
def file_finished(file, offenses)
|
44
|
-
@offenses = offenses
|
45
|
-
super
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'logger'
|
4
|
-
require 'yard'
|
5
|
-
|
6
|
-
module Rucoa
|
7
|
-
class YardGlobDocumentLoader
|
8
|
-
class << self
|
9
|
-
# @param globs [Array<String>]
|
10
|
-
# @return [Array<Rucoa::Definitions::Base>]
|
11
|
-
def call(globs:)
|
12
|
-
new(
|
13
|
-
globs: globs
|
14
|
-
).call
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
# @param globs [String]
|
19
|
-
def initialize(globs:)
|
20
|
-
@globs = globs
|
21
|
-
end
|
22
|
-
|
23
|
-
# @return [Array<Rucoa::Definitions::Base>]
|
24
|
-
def call
|
25
|
-
code_objects.filter_map do |code_object|
|
26
|
-
case code_object
|
27
|
-
when ::YARD::CodeObjects::MethodObject
|
28
|
-
DefinitionBuilders::YardMethodDefinitionBuilder.call(
|
29
|
-
code_object: code_object,
|
30
|
-
path: code_object.file
|
31
|
-
)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
# @return [Array<YARD::CodeObjects::Base>]
|
39
|
-
def code_objects
|
40
|
-
::YARD::Logger.instance.enter_level(::Logger::FATAL) do
|
41
|
-
::YARD::Registry.clear
|
42
|
-
::YARD.parse(@globs)
|
43
|
-
::YARD::Registry.all
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'logger'
|
4
|
-
require 'yard'
|
5
|
-
|
6
|
-
module Rucoa
|
7
|
-
class YardStringDocumentLoader
|
8
|
-
class << self
|
9
|
-
# @param content [String]
|
10
|
-
# @return [Array<Rucoa::Definitions::Base>]
|
11
|
-
# @example returns method definitions from Ruby source code
|
12
|
-
# content = <<~RUBY
|
13
|
-
# class Foo
|
14
|
-
# # Return given argument as an Integer.
|
15
|
-
# # @param bar [String]
|
16
|
-
# # @return [Integer]
|
17
|
-
# def foo(bar)
|
18
|
-
# bar.to_i
|
19
|
-
# end
|
20
|
-
# end
|
21
|
-
# RUBY
|
22
|
-
# definitions = Rucoa::YardStringDocumentLoader.call(
|
23
|
-
# content: content,
|
24
|
-
# path: '/path/to/foo.rb'
|
25
|
-
# )
|
26
|
-
# expect(definitions.size).to eq(1)
|
27
|
-
# expect(definitions.first.full_qualified_name).to eq('Foo#foo')
|
28
|
-
# expect(definitions.first.source_path).to eq('/path/to/foo.rb')
|
29
|
-
# expect(definitions.first.description).to eq('Return given argument as an Integer.')
|
30
|
-
# expect(definitions.first.return_types).to eq(%w[Integer])
|
31
|
-
def call(content:, path:)
|
32
|
-
new(
|
33
|
-
content: content,
|
34
|
-
path: path
|
35
|
-
).call
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
# @param content [String]
|
40
|
-
# @param path [String]
|
41
|
-
def initialize(content:, path:)
|
42
|
-
@content = content
|
43
|
-
@path = path
|
44
|
-
end
|
45
|
-
|
46
|
-
# @return [Array<Rucoa::Definitions::Base>]
|
47
|
-
def call
|
48
|
-
code_objects.filter_map do |code_object|
|
49
|
-
case code_object
|
50
|
-
when ::YARD::CodeObjects::MethodObject
|
51
|
-
DefinitionBuilders::YardMethodDefinitionBuilder.call(
|
52
|
-
code_object: code_object,
|
53
|
-
path: @path
|
54
|
-
)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
|
61
|
-
# @return [Array<YARD::CodeObjects::Base>]
|
62
|
-
def code_objects
|
63
|
-
::YARD::Logger.instance.enter_level(::Logger::FATAL) do
|
64
|
-
::YARD::Registry.clear
|
65
|
-
::YARD.parse_string(@content)
|
66
|
-
::YARD::Registry.all
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|