Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable RuboCop in vscode & jekyll directories #3246

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sambostock
Copy link
Contributor

Motivation

The vscode and jekyll directories are not being checked by RuboCop.

  • vscode/activation.rb should be checked, as it is Ruby
  • Both directories contain Ruby within Markdown code snippets. If we care about linting those in the main directory, then we should also lint them here.

Implementation

The Include config is updated so the additional directories are linted.

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.

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.
@sambostock sambostock requested a review from a team as a code owner February 26, 2025 16:26
Copy link

graphite-app bot commented Feb 26, 2025

How to use the Graphite Merge Queue

Add the label graphite-merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

Copy link
Contributor

@andyw8 andyw8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@andyw8 andyw8 added the chore Chore task label Feb 26, 2025
Copy link
Contributor Author

@sambostock sambostock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what to do about

jekyll/add-ons.markdown:274:3: C: RubyLsp/UseRegisterWithHandlerMethod: Created a handler without registering the associated on_call_node_enter event.
  def on_call_node_enter(node) ...
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
jekyll/add-ons.markdown:301:3: C: RubyLsp/UseRegisterWithHandlerMethod: Created a handler without registering the associated on_call_node_leave event.
  def on_call_node_leave(node); end
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

but it's the repo's own cops failing, so I'm guessing we should be addressing them?

Comment on lines +3 to +4
Sorbet:
Enabled: false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RuboCop was complaining that vscode/activation.rb should be

# typed: strict

which enforces sigs on all methods. The file currently has no method definitions, but if it ever gained any, we couldn't attach any sigs without sorbet-runtime, so strict is clearly too high.

We could use

# typed: true

to simply benefit from type checking, but then Sorbet complains about

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))
#    Expected `String` but found `T::Boolean` ^^^^^^^^^^^^^^^^^^^^^^^^^ 
$stderr.print("RUBY_LSP_ACTIVATION_SEPARATOR#{env.join("RUBY_LSP_FS")}RUBY_LSP_ACTIVATION_SEPARATOR")

because it thinks env must be a T::Array[String]. We could do

env.unshift(RUBY_VERSION, Gem.path.join(","), defined?(RubyVM::YJIT) ? "true" : "false")

but technically, we don't need to (interpolating a boolean works fine), so it seemed simplest to just disable the Sorbet cops.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, all we have under vscode for Ruby are the activation scripts. There's no point in adopting Sorbet, let's please keep it disabled.

@vinistock
Copy link
Member

The linting error doesn't make much sense because it's not really intended to run on Markdown. Let's just add a comment as the body of those methods saying what people are supposed to do in them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Chore task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants