ruby-lsp-reek 0.3.1 → 0.4.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.
- checksums.yaml +4 -4
- data/lib/ruby_lsp/reek/addon.rb +5 -1
- data/lib/ruby_lsp/reek/diagnostic.rb +32 -0
- data/lib/ruby_lsp/reek/runner.rb +20 -47
- data/lib/ruby_lsp/reek/version.rb +1 -1
- metadata +5 -36
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6ca16a81679c7c225ef738124db24b59751b5b76e356e233dda6b408fdc8dd04
|
|
4
|
+
data.tar.gz: 9c0eb73687b558b3289a90a520496309f2c7b63bcc8a03a9b29048e0e4e6bbed
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b16a943228c71549373623164061fc43cdf69348cef47e3b31d32ca565125f4964d9f78c4a02bb798a4149348d76818629928d080d982608183a54a19f4709d7
|
|
7
|
+
data.tar.gz: 993900224be3508be1a13ec40687573010b6571d31777fecee630eaa0ea5cbb9282514968e9948a25cf47fe9b9a89e756868409d4ce72ca87365ca41e9c87e01
|
data/lib/ruby_lsp/reek/addon.rb
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "bundler/setup"
|
|
4
|
-
require "sorbet-runtime"
|
|
5
4
|
require "ruby_lsp/addon"
|
|
6
5
|
require "ruby_lsp/base_server"
|
|
7
6
|
require "ruby_lsp/server"
|
|
@@ -22,6 +21,11 @@ module RubyLsp
|
|
|
22
21
|
"Reek: Code smell detector for Ruby"
|
|
23
22
|
end
|
|
24
23
|
|
|
24
|
+
# @return [String] The version of the addon.
|
|
25
|
+
def version
|
|
26
|
+
::RubyLsp::Reek::VERSION
|
|
27
|
+
end
|
|
28
|
+
|
|
25
29
|
# @param global_state [GlobalState] The global state of the Ruby LSP server.
|
|
26
30
|
# @param outgoing_queue [Thread::Queue] The outgoing message queue of the Ruby LSP server.
|
|
27
31
|
def activate(global_state, message_queue)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RubyLsp
|
|
4
|
+
module Reek
|
|
5
|
+
# Translates a Reek smell warning into the LSP diagnostic that Ruby LSP
|
|
6
|
+
# reports back to the editor.
|
|
7
|
+
module Diagnostic
|
|
8
|
+
# @param warning [Reek::SmellWarning] The warning to convert to a diagnostic.
|
|
9
|
+
# @return [RubyLsp::Interface::Diagnostic] The diagnostic.
|
|
10
|
+
def self.from_warning(warning)
|
|
11
|
+
lines = warning.lines
|
|
12
|
+
::RubyLsp::Interface::Diagnostic.new(
|
|
13
|
+
range: ::RubyLsp::Interface::Range.new(
|
|
14
|
+
start: ::RubyLsp::Interface::Position.new(
|
|
15
|
+
line: lines.first - 1,
|
|
16
|
+
character: 0
|
|
17
|
+
),
|
|
18
|
+
end: ::RubyLsp::Interface::Position.new(
|
|
19
|
+
line: lines.last - 1,
|
|
20
|
+
character: 0
|
|
21
|
+
)
|
|
22
|
+
),
|
|
23
|
+
severity: Constant::DiagnosticSeverity::WARNING,
|
|
24
|
+
code: warning.smell_type,
|
|
25
|
+
code_description: ::RubyLsp::Interface::CodeDescription.new(href: warning.explanatory_link),
|
|
26
|
+
source: "Reek",
|
|
27
|
+
message: warning.message
|
|
28
|
+
)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
data/lib/ruby_lsp/reek/runner.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "reek"
|
|
4
|
+
require_relative "diagnostic"
|
|
4
5
|
|
|
5
6
|
module RubyLsp
|
|
6
7
|
module Reek
|
|
@@ -12,69 +13,41 @@ module RubyLsp
|
|
|
12
13
|
@config = ::Reek::Configuration::AppConfiguration.from_default_path
|
|
13
14
|
end
|
|
14
15
|
|
|
15
|
-
# We are not implementing this method, but it is required by the
|
|
16
|
+
# We are not implementing this method, but it is required by the
|
|
17
|
+
# interface. Reek is a linter, so there is nothing to format and the
|
|
18
|
+
# source is handed back untouched.
|
|
16
19
|
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
20
|
+
# :reek:UtilityFunction { enabled: false } - the interface requires an
|
|
21
|
+
# instance method, so it cannot depend on instance state.
|
|
22
|
+
#
|
|
23
|
+
# @param uri [URI::Generic] The URI of the document to format.
|
|
24
|
+
# @param document [RubyLsp::RubyDocument] The document to format.
|
|
19
25
|
# @return [String] The formatted document.
|
|
20
26
|
def run_formatting(_uri, document)
|
|
21
27
|
document.source
|
|
22
28
|
end
|
|
23
29
|
|
|
24
|
-
# @param uri [
|
|
25
|
-
# @param document [RubyLsp::
|
|
30
|
+
# @param uri [URI::Generic] The URI of the document to run diagnostics on.
|
|
31
|
+
# @param document [RubyLsp::RubyDocument] The document to run diagnostics on.
|
|
26
32
|
def run_diagnostic(uri, document)
|
|
27
33
|
path = Pathname.new(uri.path)
|
|
28
34
|
return [] if path_excluded?(path)
|
|
29
35
|
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
# We lint the source as it currently stands in the editor, but Reek
|
|
37
|
+
# resolves directory directives from the origin, so the origin has to
|
|
38
|
+
# be set explicitly to the file on disk rather than defaulting to
|
|
39
|
+
# "string".
|
|
40
|
+
examiner = ::Reek::Examiner.new(
|
|
41
|
+
::Reek::Source::SourceCode.from(document.source, origin: path.to_s),
|
|
42
|
+
configuration: config
|
|
43
|
+
)
|
|
44
|
+
examiner.smells.map { |smell| Diagnostic.from_warning(smell) }
|
|
32
45
|
end
|
|
33
46
|
|
|
34
47
|
private
|
|
35
48
|
|
|
36
49
|
attr_reader :config
|
|
37
50
|
|
|
38
|
-
# Examiner does not allow separate source and origin, but we need to
|
|
39
|
-
# lint the string from the editor AND know what the filename of the
|
|
40
|
-
# edited file is. This patches the examiner to allow this.
|
|
41
|
-
def build_examiner(path, document)
|
|
42
|
-
examiner = ::Reek::Examiner.new(document.source, configuration: config)
|
|
43
|
-
origin = ::Reek::Source::SourceCode.from(path).origin
|
|
44
|
-
examiner.instance_variable_set(:@origin, origin)
|
|
45
|
-
examiner.instance_variable_set(
|
|
46
|
-
:@detector_repository,
|
|
47
|
-
::Reek::DetectorRepository.new(
|
|
48
|
-
smell_types: examiner.instance_variable_get(:@smell_types),
|
|
49
|
-
configuration: config.directive_for(origin)
|
|
50
|
-
)
|
|
51
|
-
)
|
|
52
|
-
examiner
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
# @param warning [Reek::SmellWarning] The warning to convert to a diagnostic.
|
|
56
|
-
# @return [RubyLsp::Interface::Diagnostic] The diagnostic.
|
|
57
|
-
def warning_to_diagnostic(warning)
|
|
58
|
-
lines = warning.lines
|
|
59
|
-
::RubyLsp::Interface::Diagnostic.new(
|
|
60
|
-
range: ::RubyLsp::Interface::Range.new(
|
|
61
|
-
start: ::RubyLsp::Interface::Position.new(
|
|
62
|
-
line: lines.first - 1,
|
|
63
|
-
character: 0
|
|
64
|
-
),
|
|
65
|
-
end: ::RubyLsp::Interface::Position.new(
|
|
66
|
-
line: lines.last - 1,
|
|
67
|
-
character: 0
|
|
68
|
-
)
|
|
69
|
-
),
|
|
70
|
-
severity: Constant::DiagnosticSeverity::WARNING,
|
|
71
|
-
code: warning.smell_type,
|
|
72
|
-
code_description: ::RubyLsp::Interface::CodeDescription.new(href: warning.explanatory_link),
|
|
73
|
-
source: "Reek",
|
|
74
|
-
message: warning.message
|
|
75
|
-
)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
51
|
def path_excluded?(path)
|
|
79
52
|
path.ascend do |ascendant|
|
|
80
53
|
break true if config.path_excluded?(ascendant)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby-lsp-reek
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Iain Gray
|
|
@@ -17,9 +17,6 @@ dependencies:
|
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
19
|
version: '6.0'
|
|
20
|
-
- - ">="
|
|
21
|
-
- !ruby/object:Gem::Version
|
|
22
|
-
version: '5.0'
|
|
23
20
|
type: :runtime
|
|
24
21
|
prerelease: false
|
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -27,49 +24,20 @@ dependencies:
|
|
|
27
24
|
- - "~>"
|
|
28
25
|
- !ruby/object:Gem::Version
|
|
29
26
|
version: '6.0'
|
|
30
|
-
- - ">="
|
|
31
|
-
- !ruby/object:Gem::Version
|
|
32
|
-
version: '5.0'
|
|
33
27
|
- !ruby/object:Gem::Dependency
|
|
34
28
|
name: ruby-lsp
|
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
|
36
30
|
requirements:
|
|
37
31
|
- - "~>"
|
|
38
32
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: '0.
|
|
40
|
-
- - ">="
|
|
41
|
-
- !ruby/object:Gem::Version
|
|
42
|
-
version: 0.12.0
|
|
33
|
+
version: '0.26'
|
|
43
34
|
type: :runtime
|
|
44
35
|
prerelease: false
|
|
45
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
46
37
|
requirements:
|
|
47
38
|
- - "~>"
|
|
48
39
|
- !ruby/object:Gem::Version
|
|
49
|
-
version: '0.
|
|
50
|
-
- - ">="
|
|
51
|
-
- !ruby/object:Gem::Version
|
|
52
|
-
version: 0.12.0
|
|
53
|
-
- !ruby/object:Gem::Dependency
|
|
54
|
-
name: sorbet-runtime
|
|
55
|
-
requirement: !ruby/object:Gem::Requirement
|
|
56
|
-
requirements:
|
|
57
|
-
- - "~>"
|
|
58
|
-
- !ruby/object:Gem::Version
|
|
59
|
-
version: '0.5'
|
|
60
|
-
- - ">="
|
|
61
|
-
- !ruby/object:Gem::Version
|
|
62
|
-
version: 0.5.5685
|
|
63
|
-
type: :runtime
|
|
64
|
-
prerelease: false
|
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
66
|
-
requirements:
|
|
67
|
-
- - "~>"
|
|
68
|
-
- !ruby/object:Gem::Version
|
|
69
|
-
version: '0.5'
|
|
70
|
-
- - ">="
|
|
71
|
-
- !ruby/object:Gem::Version
|
|
72
|
-
version: 0.5.5685
|
|
40
|
+
version: '0.26'
|
|
73
41
|
- !ruby/object:Gem::Dependency
|
|
74
42
|
name: minitest
|
|
75
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -166,6 +134,7 @@ files:
|
|
|
166
134
|
- README.md
|
|
167
135
|
- Rakefile
|
|
168
136
|
- lib/ruby_lsp/reek/addon.rb
|
|
137
|
+
- lib/ruby_lsp/reek/diagnostic.rb
|
|
169
138
|
- lib/ruby_lsp/reek/runner.rb
|
|
170
139
|
- lib/ruby_lsp/reek/version.rb
|
|
171
140
|
homepage: https://github.com/igray/ruby-lsp-reek
|
|
@@ -184,7 +153,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
184
153
|
requirements:
|
|
185
154
|
- - ">="
|
|
186
155
|
- !ruby/object:Gem::Version
|
|
187
|
-
version:
|
|
156
|
+
version: 3.0.0
|
|
188
157
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
189
158
|
requirements:
|
|
190
159
|
- - ">="
|