RuboCop
rubyide/vscode-rubyが非推奨になり、代わりに Shopify/vscode-ruby-lsp を使うように公式から勧告が出ました。 この記事ではShopify/vscode-ruby-lspを導入する手順を紹介します。 formatterにはrubocopを使用します。 1. 開発環境 VSCode:1.84.0 Ruby:3.…
バージョン情報 rubocop 1.34.1 Ruby 3.1.2 エラー内容 Use a guard clause instead of wrapping the code inside a conditional expression. →例外処理の条件分岐のネストが深くなるのを防ぐためにGuard Clause(ガード節)を使いましょう。 エラー対処 # こ…
バージョン情報 Ruby:3.1.0 robocop:1.32.0 経緯 以下のような、JSONファイルを読み込むコードを書いていた。 require 'json' file_path = "test.json" p File.open(file_path) { |f| JSON.load(f) } #=> ファイルの内容 これをrubocopでチェックすると以…
環境 rubocop 1.30.0 Ruby 3.1.0 エラー内容 Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||. if文の中身が1行の場合は、後置ifを使用するか、&&または||を使用してください。 エラ…
rubocopでUse the return of the conditional for variable assignment and comparison.のエラーが出た時の対処法。 環境 rubocop 1.30.0 Ruby 3.1.0 エラー内容 Use the return of the conditional for variable assignment and comparison. 変数の代入と比…