From 364994bf80ddccca25712f3d3b86c407a828eb8f Mon Sep 17 00:00:00 2001 From: Sam Bostock Date: Wed, 26 Feb 2025 16:21:11 +0000 Subject: [PATCH 1/2] Enable RuboCop in `vscode` & `jekyll` directories This identifies a number of offenses, which have been corrected. Notably, `rubocop-md` treats Markdown code blocks without a language specified as Ruby by default. We could change this behaviour, but it's clearer to explicitly mark the snippets as `txt` when there is no matching language. --- .rubocop.yml | 3 +-- jekyll/Gemfile | 1 - jekyll/add-ons.markdown | 12 ++++++------ jekyll/vscode-extension.markdown | 4 ++-- vscode/.rubocop.yml | 4 ++++ vscode/README.md | 4 ++-- vscode/activation.rb | 4 +++- 7 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 vscode/.rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml index 11d6299cb6..2e910eee03 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -16,11 +16,10 @@ AllCops: - "sorbet/rbi/shims/**/*.rbi" Exclude: - "vendor/**/*" - - "vscode/**/*" + - "vscode/node_modules/**/*" - "features/**/*" - "test/fixtures/**/*" - "test/expectations/**/*" - - "jekyll/**/*" Layout/LeadingCommentSpace: AllowRBSInlineAnnotation: true diff --git a/jekyll/Gemfile b/jekyll/Gemfile index c40e888406..eca4db0699 100644 --- a/jekyll/Gemfile +++ b/jekyll/Gemfile @@ -1,4 +1,3 @@ - # frozen_string_literal: true source "https://rubygems.org" diff --git a/jekyll/add-ons.markdown b/jekyll/add-ons.markdown index 7bb01c7c02..02d0e4035c 100644 --- a/jekyll/add-ons.markdown +++ b/jekyll/add-ons.markdown @@ -286,13 +286,13 @@ class MyIndexingEnhancement < RubyIndexer::Enhancement # Create the array of signatures that this method will accept. Every signatures is composed of a list of # parameters. The parameter classes represent each type of parameter signatures = [ - RubyIndexer::Entry::Signature.new([RubyIndexer::Entry::RequiredParameter.new(name: :a)]) + RubyIndexer::Entry::Signature.new([RubyIndexer::Entry::RequiredParameter.new(name: :a)]), ] @listener.add_method( "new_method", # Name of the method location, # Prism location for the node defining this method - signatures # Signatures available to invoke this method + signatures, # Signatures available to invoke this method ) end @@ -576,7 +576,7 @@ require "ruby_lsp/test_helper" class MyAddonTest < Minitest::Test def test_my_addon_works - source = <<~RUBY + source = <<~RUBY # Some test code that allows you to trigger your add-on's contribution class Foo def something @@ -595,9 +595,9 @@ class MyAddonTest < Minitest::Test }, position: { line: 3, - character: 5 - } - } + character: 5, + }, + }, ) # Pop the server's response to the definition request diff --git a/jekyll/vscode-extension.markdown b/jekyll/vscode-extension.markdown index 531adfc001..4da1319c10 100644 --- a/jekyll/vscode-extension.markdown +++ b/jekyll/vscode-extension.markdown @@ -317,7 +317,7 @@ repository is. Consider a project where the top level of the repository is a Rails application and a sub-directory called `frontend` contains a React application that implements the frontend layer. -``` +```txt my_project/ frontend/ Gemfile @@ -354,7 +354,7 @@ A possible configuration for the `super_awesome_project` would be this: Now consider a monorepo where both the client and the server are under sub-directories. -``` +```txt my_project/ client/ server/ diff --git a/vscode/.rubocop.yml b/vscode/.rubocop.yml new file mode 100644 index 0000000000..a1971be040 --- /dev/null +++ b/vscode/.rubocop.yml @@ -0,0 +1,4 @@ +inherit_from: ../.rubocop.yml + +Sorbet: + Enabled: false diff --git a/vscode/README.md b/vscode/README.md index 9ec7528581..b48a69856a 100644 --- a/vscode/README.md +++ b/vscode/README.md @@ -313,7 +313,7 @@ repository is. Consider a project where the top level of the repository is a Rails application and a sub-directory called `frontend` contains a React application that implements the frontend layer. -``` +```txt my_project/ frontend/ Gemfile @@ -350,7 +350,7 @@ A possible configuration for the `super_awesome_project` would be this: Now consider a monorepo where both the client and the server are under sub-directories. -``` +```txt my_project/ client/ server/ diff --git a/vscode/activation.rb b/vscode/activation.rb index 728508fb04..1a585b8c78 100644 --- a/vscode/activation.rb +++ b/vscode/activation.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + env = ENV.filter_map do |k, v| utf_8_value = v.dup.force_encoding(Encoding::UTF_8) "#{k}RUBY_LSP_VS#{utf_8_value}" if utf_8_value.valid_encoding? end env.unshift(RUBY_VERSION, Gem.path.join(","), !!defined?(RubyVM::YJIT)) -STDERR.print("RUBY_LSP_ACTIVATION_SEPARATOR#{env.join("RUBY_LSP_FS")}RUBY_LSP_ACTIVATION_SEPARATOR") +$stderr.print("RUBY_LSP_ACTIVATION_SEPARATOR#{env.join("RUBY_LSP_FS")}RUBY_LSP_ACTIVATION_SEPARATOR") From 12992c25a648e8af64bef6cd71af7562959d3087 Mon Sep 17 00:00:00 2001 From: Andy Waite <13400+andyw8@users.noreply.github.com> Date: Thu, 6 Mar 2025 11:40:04 -0500 Subject: [PATCH 2/2] Disable `UseRegisterWithHandlerMethod` cop for add-ons docs --- .rubocop.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 2e910eee03..7ce91d88ae 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -38,6 +38,10 @@ RubyLsp/UseLanguageServerAliases: Exclude: - "test/**/*.rb" +RubyLsp/UseRegisterWithHandlerMethod: + Exclude: + - "jekyll/add-ons.markdown" # this cop doesn't apply to enhancements + Sorbet/FalseSigil: Enabled: false