ruby-lsp-reek 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 59ca43ac3be906fb556abf46c2ce068efc8947751f28ad4ae8a9261756c9fba3
4
+ data.tar.gz: e94560794e1ffb3c8939956773591940e251e8eee6cb0cb6217028e145f1faaf
5
+ SHA512:
6
+ metadata.gz: e815486f76603036c9584ccaf3cfd23a4fd9a3c7ee7e33838af1c552b1ae7f64ca99c8c0309929fd5d889c3f10fca408e3dd60bc8cde61d64ec49080d0073ac8
7
+ data.tar.gz: d0bc712dd52531123eb3377c9bbbba1334b9d0a2e302eb955549157aa71a1dd5a48d7c9733f9fe449c2cfc369117e3cb96a21bf4794094a649744d0f10c30cb2
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at igray78756@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 iGray Consulting, LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # Ruby Lsp Reek
2
+
3
+ Adds [Reek](https://github.com/troessner/reek/tree/master) as a linter for [Ruby LSP](https://github.com/Shopify/ruby-lsp)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ruby-lsp-reek'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ruby-lsp-reek
20
+
21
+ ## Usage
22
+
23
+ Add `reek` to the list of linters in your Ruby LSP configuration.
24
+
25
+ ### Example: VS Code
26
+
27
+ In `settings.json`:
28
+
29
+ ```json
30
+ "rubyLsp.linters": [ "rubocop", "reek" ]
31
+ ```
32
+
33
+ After that, open the VS code command palette and select the option `Developer: Reload Window`.
34
+
35
+ ### Example: [LazyVim](https://www.lazyvim.org/):
36
+
37
+ Update your nvim-lspconfig as follows:
38
+
39
+ ```lua
40
+ {
41
+ "neovim/nvim-lspconfig",
42
+ opts = {
43
+ servers = {
44
+ ruby_lsp = {
45
+ init_options = {
46
+ linters = { "rubocop", "reek" },
47
+ },
48
+ },
49
+ },
50
+ },
51
+ },
52
+ ```
53
+
54
+ See the [Ruby LSP Editor docs](https://github.com/Shopify/ruby-lsp/blob/main/EDITORS.md)
55
+ for more information on how to configure other editors.
56
+
57
+ ## Development
58
+
59
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
60
+ `rake spec` to run the tests. You can also run `bin/console` for an interactive
61
+ prompt that will allow you to experiment.
62
+
63
+ To install this gem onto your local machine, run `bundle exec rake install`. To
64
+ release a new version, update the version number in `version.rb`, and then run
65
+ `bundle exec rake release`, which will create a git tag for the version, push
66
+ git commits and the created tag, and push the `.gem` file to
67
+ [rubygems.org](https://rubygems.org).
68
+
69
+ ## Contributing
70
+
71
+ Bug reports and pull requests are welcome on GitHub at
72
+ https://github.com/igray/ruby-lsp-reek. This project is intended to be a safe,
73
+ welcoming space for collaboration, and contributors are expected to adhere to
74
+ the [code of
75
+ conduct](https://github.com/igray/ruby-lsp-reek/blob/main/CODE_OF_CONDUCT.md).
76
+
77
+ ## License
78
+
79
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
80
+
81
+ ## Code of Conduct
82
+
83
+ Everyone interacting in the Ruby::Lsp::Reek project's codebases, issue
84
+ trackers, chat rooms and mailing lists is expected to follow the [code of
85
+ conduct](https://github.com/igray/ruby-lsp-reek/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task :code_analysis do
13
+ sh "bundle exec standardrb lib test"
14
+ sh "bundle exec reek lib"
15
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/setup"
4
+ require "sorbet-runtime"
5
+ require "ruby_lsp/addon"
6
+ require "ruby_lsp/base_server"
7
+ require "ruby_lsp/server"
8
+ require "uri"
9
+ require_relative "runner"
10
+ require_relative "version"
11
+
12
+ module RubyLsp
13
+ module Reek
14
+ # Implements the RubyLsp::Addon interface to provide Reek linter support to Ruby LSP.
15
+ class Addon < ::RubyLsp::Addon
16
+ def initializer
17
+ @runner = nil
18
+ end
19
+
20
+ # @return [String] The name of the addon.
21
+ def name
22
+ "Reek: Code smell detector for Ruby"
23
+ end
24
+
25
+ # @param global_state [GlobalState] The global state of the Ruby LSP server.
26
+ # @param outgoing_queue [Thread::Queue] The outgoing message queue of the Ruby LSP server.
27
+ def activate(global_state, message_queue)
28
+ warn "Activating Reek Ruby LSP addon v#{::RubyLsp::Reek::VERSION}"
29
+ @runner = Runner.new
30
+ global_state.register_formatter("reek", runner)
31
+ self.class.register_additional_file_watchers(global_state, message_queue)
32
+ warn "Initialized Reek Ruby LSP addon v#{::RubyLsp::Reek::VERSION}"
33
+ end
34
+
35
+ # @return [nil]
36
+ def deactivate
37
+ @runner = nil
38
+ end
39
+
40
+ # @param global_state [GlobalState] The global state of the Ruby LSP server.
41
+ # @param outgoing_queue [Thread::Queue] The outgoing message queue of the Ruby LSP server.
42
+ def self.register_additional_file_watchers(global_state, message_queue)
43
+ return unless global_state.supports_watching_files
44
+
45
+ message_queue << Request.new(
46
+ id: "reek-file-watcher",
47
+ method: "client/registerCapability",
48
+ params: Interface::RegistrationParams.new(
49
+ registrations: [
50
+ Interface::Registration.new(
51
+ id: "workspace/didChangeWatchedFilesReek",
52
+ method: "workspace/didChangeWatchedFiles",
53
+ register_options: Interface::DidChangeWatchedFilesRegistrationOptions.new(
54
+ watchers: [
55
+ Interface::FileSystemWatcher.new(
56
+ glob_pattern: "**/.reek.yml",
57
+ kind: Constant::WatchKind::CREATE | Constant::WatchKind::CHANGE | Constant::WatchKind::DELETE
58
+ )
59
+ ]
60
+ )
61
+ )
62
+ ]
63
+ )
64
+ )
65
+ end
66
+
67
+ # @param changes [Array<Hash>] The changes to the watched files.
68
+ def workspace_did_change_watched_files(changes)
69
+ return unless changes.any? { |change| change[:uri].end_with?(".reek.yml") }
70
+
71
+ runner.init!
72
+ warn "Re-initialized Reek Ruby LSP addon v#{::RubyLsp::Reek::VERSION} due to .reek.yml file change"
73
+ end
74
+
75
+ private
76
+
77
+ attr_reader :runner
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "reek"
4
+
5
+ module RubyLsp
6
+ module Reek
7
+ # Implements Ruby LSP Formatter interface: specifically run_diagnostic
8
+ class Runner
9
+ include RubyLsp::Requests::Support::Formatter
10
+
11
+ def initialize
12
+ @config = ::Reek::Configuration::AppConfiguration.from_default_path
13
+ end
14
+
15
+ # We are not implementing this method, but it is required by the interface
16
+ #
17
+ # @param uri [String] The URI of the document to format.
18
+ # @param document [RubyLsp::Interface::TextDocumentItem] The document to format.
19
+ # @return [String] The formatted document.
20
+ def run_formatting(_uri, document)
21
+ document.source
22
+ end
23
+
24
+ # @param uri [String] The URI of the document to run diagnostics on.
25
+ # @param document [RubyLsp::Interface::TextDocumentItem] The document to run diagnostics on.
26
+ def run_diagnostic(uri, document)
27
+ return [] if config.path_excluded?(Pathname.new(uri.path))
28
+
29
+ examiner = ::Reek::Examiner.new(document.source, configuration: config)
30
+ examiner.smells.map { |smell| warning_to_diagnostic(smell) }
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :config
36
+
37
+ # @param warning [Reek::SmellWarning] The warning to convert to a diagnostic.
38
+ # @return [RubyLsp::Interface::Diagnostic] The diagnostic.
39
+ def warning_to_diagnostic(warning)
40
+ lines = warning.lines
41
+ ::RubyLsp::Interface::Diagnostic.new(
42
+ range: ::RubyLsp::Interface::Range.new(
43
+ start: ::RubyLsp::Interface::Position.new(
44
+ line: lines.first - 1,
45
+ character: 0
46
+ ),
47
+ end: ::RubyLsp::Interface::Position.new(
48
+ line: lines.last - 1,
49
+ character: 0
50
+ )
51
+ ),
52
+ severity: Constant::DiagnosticSeverity::WARNING,
53
+ code: warning.smell_type,
54
+ code_description: ::RubyLsp::Interface::CodeDescription.new(href: warning.explanatory_link),
55
+ source: "Reek",
56
+ message: warning.message
57
+ )
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLsp
4
+ module Reek
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,198 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-lsp-reek
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Iain Gray
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 1980-01-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: reek
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '6.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: ruby-lsp
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.17'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 0.12.0
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '0.17'
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
73
+ - !ruby/object:Gem::Dependency
74
+ name: minitest
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '5.20'
80
+ type: :development
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - "~>"
85
+ - !ruby/object:Gem::Version
86
+ version: '5.20'
87
+ - !ruby/object:Gem::Dependency
88
+ name: pry
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '0.14'
94
+ type: :development
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: '0.14'
101
+ - !ruby/object:Gem::Dependency
102
+ name: rake
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: '13.1'
108
+ type: :development
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - "~>"
113
+ - !ruby/object:Gem::Version
114
+ version: '13.1'
115
+ - !ruby/object:Gem::Dependency
116
+ name: rubocop-minitest
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: '0.35'
122
+ type: :development
123
+ prerelease: false
124
+ version_requirements: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - "~>"
127
+ - !ruby/object:Gem::Version
128
+ version: '0.35'
129
+ - !ruby/object:Gem::Dependency
130
+ name: rubocop-rake
131
+ requirement: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - "~>"
134
+ - !ruby/object:Gem::Version
135
+ version: '0.6'
136
+ type: :development
137
+ prerelease: false
138
+ version_requirements: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - "~>"
141
+ - !ruby/object:Gem::Version
142
+ version: '0.6'
143
+ - !ruby/object:Gem::Dependency
144
+ name: standard
145
+ requirement: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '1.31'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - "~>"
155
+ - !ruby/object:Gem::Version
156
+ version: '1.31'
157
+ description: An addon for Ruby LSP that enables linting with reek
158
+ email:
159
+ - igray@igraycon.com
160
+ executables: []
161
+ extensions: []
162
+ extra_rdoc_files: []
163
+ files:
164
+ - CODE_OF_CONDUCT.md
165
+ - LICENSE
166
+ - README.md
167
+ - Rakefile
168
+ - lib/ruby_lsp/reek/addon.rb
169
+ - lib/ruby_lsp/reek/runner.rb
170
+ - lib/ruby_lsp/reek/version.rb
171
+ homepage: https://github.com/igray/ruby-lsp-reek
172
+ licenses:
173
+ - MIT
174
+ metadata:
175
+ allowed_push_host: https://rubygems.org
176
+ homepage_uri: https://github.com/igray/ruby-lsp-reek
177
+ source_code_uri: https://github.com/igray/ruby-lsp-reek
178
+ changelog_uri: https://github.com/igray/ruby-lsp-reek
179
+ post_install_message:
180
+ rdoc_options: []
181
+ require_paths:
182
+ - lib
183
+ required_ruby_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: 2.5.0
188
+ required_rubygems_version: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
193
+ requirements: []
194
+ rubygems_version: 3.5.11
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: Ruby LSP Reek
198
+ test_files: []