VSCode Style/PercentLiteralDelimiters rule not being respected in ruby files - ruby

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
}
}

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.

Does Rubocop not highlight undefined variables?

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!

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.

Debugger fails to compile in Ruby

Ruby 2.2.2 on Ubuntu
I have been following the saasbook tutorial on Rails and am getting to grips with the workflow.
I am confused about debugger which some sources says us now 'included' post Ruby version 2. It fails to compile on the example projects and many people have the same issue.
I have found that any bundle install that I try to do with the examples. (see here) (possibly after a bundle update) will fail on trying to 'gem install debugger -v '1.6.x''.
I have found that by commenting out the debugger line in the Gemfile will get me around this hurdle and upon firing up the Rails server, everything seems to work. I also have to change the Ruby version to my current one (2.2.2).
I am assuming that I am working with pre version 2 Ruby examples and this is good to do post version 2.
Am I correct? What has happened to the debugger post version 2?
The debugger gem is not supported on Ruby 1.9. See the debugger readme on GitHub here. If you need a command line debugger for newer versions of Ruby you can use byebug.
You can use the basic built in debugger if you prefer. Simply put require 'debug' anywhere in your source code and the Ruby interpretor will stop at that point and allow you to inspect variables etc. You do not need to install or add any additional gems to your Gemfile to use this as it is built in. See the built in debugger documentation here

Use default ruby version in Sublime Text 2

My default and current version of ruby is 1.9.3. It's actually the only version that appears when I run rvm list so I don't see how I can be messing that part up. I did follow this
tutorial that I found here, but it just seemed to break everything. I keep getting "No such file or directory" for all the variations of the fix I see, even the in the comments. I am on a Mac, please let me know what other information I need to post here to help you figure out how I'm breaking things.
You can always edit which ruby is used by editing your Build command preferences:
subl ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/Ruby/Ruby.sublime-build
Change the default "ruby" to whatever path you require. The version you're using at any given time can be discovered with:
which ruby
Alternatively you can just link to the default which is often located at /opt/local/rvm/bin/ruby.

Resources