Does Rubocop not highlight undefined variables? - ruby

I've installed Solargraph (which uses Rubocop) for my IDE (Neovim - using the CoC extension). Rubocop warnings are showing, but NameErrors are not detected until I run my ruby files. Is this the default behaviour, or do I need to do something more for configuration?
I'm using Ruby 2.7.2 (with rbenv).
Thanks in advance if you know the answer - I can provide more details if needed.

Simple answer: No. Because rubocop does not run your ruby code, it just parses the files.
So, its your duty to make your code work first, then fix styles with Rubocop :)
Small hint: you can create a github action to run both rubocop and your code on push/deploy
Cheers!

Related

Cannot install RuboCop on RubyMine

I'm opening ruby file via RubyMine. IDE suggests installing RuboCop. I accept it, but after a few seconds it shows:
Following gems were not installed: rubocop (1.0.0): Cancelled
Documentation says its problem with interpreter path. Problem is its already set. Even when i try to add it like documentation says, it won't let me, because its already set.
Any ideas what i can do? I have been using VisualStudio Code without issues before it, but Ruby support is pretty poor, i had to use terminal, while for example python has full support and you can just run program with one button.

Ruby formatter for VS Code

I am new to Ruby. I am using Visual Studio Code and was wondering if there is a formatter (like the extension Prettier) for Ruby. I would like to use it to indent properly, etc.
Thank you!
Prettier does support Ruby with the plugin-ruby [1] installed but the installation is a little bit tricky. You have to install the Prettier-Ruby-Plugin inside the vscode prettier extensions directory:
cd ~/.vscode/extensions/esbenp.prettier-vscode-1.8.1/
npm install #prettier/plugin-ruby
[1] https://github.com/prettier/plugin-ruby
I think rubocop is good option for it, I use this and is good https://github.com/rubocop-hq/rubocop
With Visual Code, you can use most feature exension of this. Some extensions i think with rails developer must to install are: Ruby, Ruby onrails, Simple Ruby Erb, ruby-linter.. And i think you need install Gitlens to control your project git version.
And i have some config to indent, theme, fonts.... in my github. Hope it can helpful to you.
https://github.com/Hungnv950/dotfiles/blob/master/visualcode/Setting

VSCode Style/PercentLiteralDelimiters rule not being respected in ruby files

Please help me I am being tortured by the linting squiggly and I cannot get rid of it. Here is the context
working in vscode 1.37.0
on a chef project (mostly ruby syntax)
I have the chef extension installed and chefdk installed an available in my path
And for the life of me I cannot get the linting warning for Style/PercentLiteralDelimiters to go away. I will get this warning when I am using []
Then if I make the suggested change to () it wants me to flip it the other way.
I get the same results if I specify this rule in my rubocop.yml
Style/PercentLiteralDelimiters:
Enabled: true
PreferredDelimiters:
default: '[]'
I know this is an obscure issue and if there is any further information that would help I will be happy to supply it but for my sanity I would really like to figure this out.
Update
Running rubocop from the command line does not report any issue. I believe that vscode is using chefdk's foodcritic. As according to the extension If you have the ChefDK installed, Foodcritic should "just work" on Windows. My understanding is foodcritic is just rubocop with a special config for chef style conventions. But even running foodcritic from the command line does not seem to report these as an issue.
I have even tried to be explicit in the vscode workspace settings, by setting the configFile path for both rubocop and foodcritic but this has not changed anything. Seems more and more like an issue the extension. Found this issue that sounds related. Might just have to watch this issue https://github.com/pendrica/vscode-chef/issues/29
So thanks to the comment from Draco Alter I was able to figure out the issue I had.
First I had a miss understanding about Foodcritic and was conflating it with cookstyle. After understanding that and the comment that Draco made saying
Some of the rules in Cookstyle and Rubocop are conflicting - and %w
is one of them.
I figured I would favor cookstyle as I am using ruby exclusively for chef. So I ensured rubocop was gone gem uninstall rubocop and then I just needed to update my vscode workspace settings to have from
{
"ruby.lint": {
-- "rubocop": true
++ "cookstyle": true
}
}

RSpec basics: bin/rspec --format doc

I've installed RSpec on a win7 lappy and am following along the http://rspec.info/ homepage tutorial to make sure everything works. If I am reading their demo correctly bin/rspec --format doc should run the specification test file.
Instead, I get a system prompt for a text editor... ? I am confused.
Any explanation of what is going on or guidance about how to get my RSPEC configuration working in accordance to the makers homepage would be great.
FWIW Ruby 2.2.5p319, Bundler version 1.13.1 and gem -v tells me 2.6.7 (originally I had 2.4 but that is broken on windows, so I upgraded according to http://guides.rubygems.org/ssl-certificate-update/) Also, I have basic RSpec functionality and have completed the tutorial here: https://www.tutorialspoint.com/rspec/rspec_writing_specs.htm
Ah, I figured out what I need to do... I just need to explicitly call ruby:
ruby bin/rspec --format doc
...and the test gets run - YaY!
Per #JörgWMittag, I confirmed my Environment Variable Path to make sure ruby.exe was in there (C:\Ruby22\bin;).
Then looking at my Program Defaults, I thought that maybe I could tell win7 to associate any file named "rspec" with ruby.exe per https://support.microsoft.com/en-us/help/18539/windows-7-change-default-programs ...but I couldn't actually add file type "extensions" or "protocols" - I could only change the association of existing ones, but .rb and .rbw were in there... Maybe there is a way to do this manually, but I am not a windows expert.
Thinking on all this it occurred to me that I just needed to explicitly tell ruby to ingest the command... Heh.
I apologize if this is off-topic.

Validating ruby installation after install?

I've installed Ruby 2.1.1 via source.
I've seen suggestions to type ruby -v, which I assume would show that the binary isn't corrupted, but are there more comprehensive ways to ensure that it's working as expect? Unit-tests, benchmarks, etc to validate it's functional?
Run make test after compiling in the directory you’ve compiled in. (This might actually happen by default, I can’t remember. There’s also make test-all, among others.)
ruby -v will show you the current version of ruby installed on your machine.
If you want, just create a hello.rb with puts "hello" and run it using ruby hello.rb to check if it is interpreting the ruby code correctly. So you know that its functional.

Resources