I'd like to get the SubLime Linter plugin (https://github.com/Kronuz/SublimeLinter) to recognize Ruby 1.9 syntax. Has anybody been able to get this to work in SublimeText 2?
Here is my current default settings file:
/*
SublimeLinter default settings
*/
{
/*
Sets the mode in which SublimeLinter runs:
true - Linting occurs in the background as you type (the default).
false - Linting only occurs when you initiate it.
"load-save" - Linting occurs only when a file is loaded and saved.
*/
"sublimelinter": true,
/*
Maps linters to executables for non-built in linters. If the executable
is not in the default system path, or on posix systems in /usr/local/bin
or ~/bin, then you must specify the full path to the executable.
Linter names should be lowercase.
This is the effective default map; your mappings may override these.
"sublimelinter_executable_map":
{
"perl": "perl",
"php": "php",
"ruby": "ruby"
},
*/
"sublimelinter_executable_map":
{
},
/*
Maps syntax names to linters. This allows variations on a syntax
(for example "Python (Django)") to be linted. The key is
the base filename of the .tmLanguage syntax files, and the value
is the linter name (lowercase) the syntax maps to.
*/
"sublimelinter_syntax_map":
{
"Python Django": "python"
},
// An array of linter names to disable. Names should be lowercase.
"sublimelinter_disable":
[
],
/*
The minimum delay in seconds (fractional seconds are okay) before
a linter is run when the "sublimelinter" setting is true. This allows
you to have background linting active, but defer the actual linting
until you are idle. When this value is greater than the built in linting delay,
errors are erased when the file is modified, since the assumption is
you don't want to see errors while you type.
*/
"sublimelinter_delay": 0,
// If true, lines with errors or warnings will be filled in with the outline color.
"sublimelinter_fill_outlines": false,
// If true, lines with errors or warnings will have a gutter mark.
"sublimelinter_gutter_marks": false,
// If true, the find next/previous error commands will wrap.
"sublimelinter_wrap_find": true,
// If true, when the file is saved any errors will appear in a popup list
"sublimelinter_popup_errors_on_save": false,
// jshint: options for linting JavaScript. See http://jshint.com/#docs for more info.
// By deault, eval is allowed.
"jshint_options":
{
"evil": true,
"regexdash": true,
"browser": true,
"wsh": true,
"trailing": true,
"sub": true,
"strict": false
},
// A list of pep8 error numbers to ignore. By default "line too long" errors are ignored.
// The list of error codes is in this file: https://github.com/jcrocholl/pep8/blob/master/pep8.py.
// Search for "Ennn:", where nnn is a 3-digit number.
"pep8_ignore":
[
"E501"
],
/*
If you use SublimeLinter for pyflakes checks, you can ignore some of the "undefined name xxx"
errors (comes in handy if you work with post-processors, globals/builtins available only at runtime, etc.).
You can control what names will be ignored with the user setting "pyflakes_ignore".
Example:
"pyflakes_ignore":
[
"some_custom_builtin_o_mine",
"A_GLOBAL_CONSTANT"
],
*/
"pyflakes_ignore":
[
],
/*
Ordinarily pyflakes will issue a warning when 'from foo import *' is used,
but it is ignored since the warning is not that helpful. If you want to see this warning,
set this option to false.
*/
"pyflakes_ignore_import_*": true,
// Objective-J: if true, non-ascii characters are flagged as an error.
"sublimelinter_objj_check_ascii": false
}
I was able to get it to work using the absolute path to my ruby 1.9 executable. I’m using rbenv, so to get the path I ran rbenv which ruby, you might need to put in /usr/local/bin/ruby or /usr/local/bin/ruby19.
This is how my sublimelinter default setting looks like (you can put this into a project-specific file too if you prefer:)
Preferences -> Package Settings -> SublimeLinter -> Settings - User
"sublimelinter_executable_map":
{
"ruby": "~/.rbenv/versions/1.9.3-p0/bin/ruby"
},
when using rvm you should be able to use rvm-auto-ruby for it.
there was an issue with this, but i think it's solved right now: https://github.com/SublimeLinter/SublimeLinter/issues/30
All, just wanted to chime in because I was having this issue, too and the following works on ST2 v 2.0.1 on Ubuntu in the User/SublimeLinter.sublime-settings file which is found at
Preferences -> Package Settings -> SublimeLinter -> Settings - User
{
"sublimelinter_executable_map": {
"ruby": "~/.rvm/bin/rvm-auto-ruby"
}
}
After adding, restart ST2, go to the console and check that it has updated by running the following:
view.settings().get("sublimelinter_executable_map")
You should get the following output:
{'ruby': u'~/.rvm/bin/rvm-auto-ruby'}
I was also able to get this to work by adding the PATH and point ruby to the rbenv shim to the sublimelinter_executable_map (I think this is recommended way from the official documentation too.) This also enables you to switch ruby versions without having to update the config too.
{
"sublimelinter_executable_map": {
"path": "/usr/local/var/rbenv/shims:/Users/luke/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin",
"ruby": "/usr/local/var/rbenv/shims/ruby"
}
}
In SublimeLinter 3, rbenv (and hopefully rvm) is supported out of the box with no extra config (other than making sure they are initialized in the right place in your shell startup).
Related
I'm setting up linting with golangci-lint in my Go project. I have a file generated by go-bindata that VSCode is listing the following under the Problems tab:
assets/assets.go: redundant type from array, slice, or map composite literal (simplifycompositelit)
I can't seem to get rid of it. It's not a compiler error and I'll be re-running go-bindata from time to time so I don't want to make a habit of modifying generated code.
Right now, with the configuration below, I can't make VSCode stop reporting this error. If I run golangci-lint run ./... in the root of the workspace I get no output. I can provide my linting config if needed but VSCode seems to be running something else. How do I figure out what's reporting this error and how do I make it stop reporting anything for the file assets/assets.go in this one workspace?
Here's Go-related vscode settings:
{
"go.formatTool": "gofmt",
"go.lintTool": "golangci-lint",
"go.liveErrors": {
"enabled": true,
"delay": 500
},
"go.lintOnSave": "workspace",
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"go.useLanguageServer": true,
"go.languageServerExperimentalFeatures": {
"diagnostics": true,
"documentLink": true
},
}
Here's the line in question even with a nolint comment to show it's not behaving as expected. If it were golangci-lint outputting this, the nolint would prevent the warning from showing. I reloaded the window and closed/reopened vscode to be sure the change was noticed.
After reproducing locally, it seems this message comes from gopls, as disabling gopls silences the message. There are a couple of related complaints/issues on the Go issue tracker:
hide gofmt -s diagnostics (and others?) in generated files
should not issue lint-style warnings on generated code
Neither offers an actual solution.
However, this issue on the vscode-go repo, provides a work-around. In your VSCode config, add the gopls.analyses.simplifycompositelit key, with a value of false:
"gopls": {
"analyses": {
"simplifycompositelit": false
},
}
Of course, this disables it for all projects, not just generated files, but if you're also using golangci-lint, it can be configured to catch the same types of errors, and can be configured on a more granular basis, so that you won't miss the same class of errors in non-generated code.
Environments
vscode Version 1.19.1 (1.19.1)
rubocop (0.52.1)
Darwin mbp 16.7.0 Darwin Kernel Version 16.7.0: Wed Oct 4 00:17:00 PDT 2017; root:xnu-3789.71.6~1/RELEASE_X86_64 x86_64
ruby 2.3.5p376 (2017-09-14 revision 59905) [x86_64-darwin16]
followed https://github.com/rubyide/vscode-ruby#linters and installed all gems and edited the settings.json like this.
{
"ruby.rubocop.executePath": "/Users/ac/.rbenv/shims/",
"ruby.rubocop.onSave": true,
"ruby.lint": {
"ruby": {
"unicode": true //Runs ruby -wc -Ku
},
"reek": true,
"rubocop": {
"lint": true,
"rails": true
},
"fasterer": true,
"debride": {
"rails": true //Add some rails call conversions.
},
"ruby-lint": true
},
"ruby.locate": {
"include": "**/*.rb",
"exclude": "{**/#(test|spec|tmp|.*),**/#(test|spec|tmp|.*)/**,**/*_spec.rb}"
}
}
On vscode, code highlighting is working fine.
*just to note, you see the extensions installed, and warnings in the problem tab.
Question
I was under the inpression that vscode-ruby and rubocop would auto-correct indentations and cop rules on file save, but apparently it doesn't.
If I want it to format my code like prettier, how should I set this up?
Per this comment on the vscode-ruby-rubocop GitHub, you can use the following settings:
{
"editor.formatOnSave": true,
"editor.formatOnSaveTimeout": 5000,
"ruby.rubocop.executePath": "path/where/rubocop/is/located",
"ruby.format": "rubocop",
}
Just applied them to my user settings on my local box and it appears to work. VS Code was throwing an error for my ruby.rubocop.executePath setting saying it wasn't executable, and removing the line appears to not cause that error to show, and still formats my code accordingly. Setting a lower timeout (I tried 2500) also seems to break auto format on saving, so I'd suggest leaving it at 5000.
I've tried all the options other people shared and it fixed linking for me (so I would get warnings when my code wasn't formatted correctly) but it didn't fix indentation or other formatting on save.
What seemed to work for me is adding a default formatter option. If you look at the bottom right corner in vscode you should see a notification icon which might throw in a few warnings that can help with your config. For me it was adding:
"[ruby]": {
"editor.defaultFormatter": "misogi.ruby-rubocop"
}
Now, it's enough just adding these lines:
{
"ruby.rubocop.onSave": true,
"editor.formatOnSave": true,
}
I had this problem for a while and none of the other solutions worked for me.
According to a github comment, what solved was:
I Replace bin in the PATH with wrappers and solved the issue:
vscode setting:
ruby.rubocop.executePath": "/Users/USER_NAME/.rvm/gems/ruby-2.6.5/wrappers/
Note: Another useful thing you could check if none of the above worked for you is to check your home folder for a .rubocop.yml file (~/.rubocop.yml) and delete it so you only have your project's .rubocop.yml working on.
To make sure autocorrection works with ruby-rubocop add below settings
make sure "ruby.rubocop.executePath": "path/where/rubocop/is/located", is set to default
"ruby.rubocop.executePath": "",
Add the following to your json file in vscode
"editor.formatOnSave": true,
"editor.formatOnSaveTimeout": 5000,
"ruby.rubocop.executePath": "",
"ruby.format": "rubocop",
I struggled with the extension ruby-rubocop, last updated in Dec 2021. It seems it's still using the auto-correct command --autocorrect while Rubocop now uses --auto-correct. I switched to another extension, ruby-rubocop-revived, which fixed my auto-correct issue.
It also introduces the useServer option that speeds up the execution.
Here are the settings I used:
# .vscode/settings.json
"ruby.format": "rubocop",
"ruby.rubocop.onSave": true,
"ruby.rubocop.useServer": true,
"[ruby]": {
"editor.defaultFormatter": "rebornix.ruby"
},
This comment is now thankfully outdated
--
Unfortunately this cannot be done with the current rubocop extension. The primary use case is to lint your ruby and show visual cues in the IDE.
It is currently an open issue/feature request on github. View this issue to see progress until it is resolved.
https://github.com/misogi/vscode-ruby-rubocop/issues/49
I install Ruby and ruby-rubocop extension in my Visual Studio Code, but this warning is showing in my editor:
Value is not an accepted value. Valid values: ["rubocop"] (737, 20)
When I click in warning redirect to settings.json (/), specifically "ruby.format": "",.
// ruby language settings
// Defines where the Ruby extension will look to find Modules, Classes and methods.
"ruby.locate": {
"exclude": "{**/#(test|spec|tmp|.*),**/#(test|spec|tmp|.*)/**,**/*_spec.rb}",
"include": "**/*.rb"
},
// Path to the Ruby interpreter. Set this to an absolute path to select from multiple installed Ruby versions.
"ruby.interpreter.commandPath": "ruby",
// Path to the rct-complete command. Set this to an absolute path to select from multiple installed Ruby versions.
"ruby.rctComplete.commandPath": "rct-complete",
// Select the type of formatter to use. If 'rubocop' is selected, the ruby.lint.rubocop options will be passed to the formatter.
"ruby.format": "",
// Set individual ruby linters to use
"ruby.lint": {},
In my .vscode/settings.json I try "ruby.format": "rubocop", and "ruby.format": ["rubocop"], but warning keep showing.
Restart Visual Studio Code solve the problem with "ruby.format": "rubocop", configuration.
I'm using vscode with Go extensions to edit golang source code. Each time I want to format code, I have to press Ctrl-Shift-i on linux, Shift-Alt-F on Windows, or Ctrl-Shift-p and type format. Is it possible to set format on save, that is, when I press ctrl-s, it format the code automatically using go.fmt (or something alike)?
From my visual code version, i cannot use config go.formatOnSave": false.
Then I can turn them off in settings as below:
Build (Turn off using go.buildOnSave setting)
Lint (Turn off using go.lintOnSave setting)
Vet (Turn off using go.vetOnSave setting)
Format (Turn off by adding the below in your settings):
"[go]": {
"editor.formatOnSave": false
}
You should install this plugin: https://github.com/golang/vscode-go. One of the options is to set "auto format" on save: go.formatOnSave": false. It uses the Golang tooling for formatting.
For me, none of the answers worked. My Go version is 1.17.1, VSCode version is 1.60.1 and I'm using Linux Pop!_os.
After some digging online found this in the official VSCode documentation for Go. https://code.visualstudio.com/docs/languages/go#_formatting
My settings.json looks like this
"[go]": {
"editor.insertSpaces": true,
"editor.formatOnSave": true,
"editor.defaultFormatter": "golang.go"
},
Note: You need to install the required extensions for the go lang in VS code. Check the bottom left bar after opening a *.go file and you should see the go version. If you see an exclamation icon click on it and install the suggested extensions.
For me the followed settings worked. I disabled the annoying import refactoring.
"[go]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": false
},
}
I've been trying to configure SublimeLinter to use different JSHint settings, but my settings are being totally ignored. Mostly I just want to be able to use double quotes without getting a linting error. Here's what I have in my 'User' SublimeLinter.sublime-settings
{
"jshint_options":
{
"evil": true,
"regexdash": true,
"browser": true,
"wsh": true,
"sub": true,
"quotmark" : true
}
}
The file is definitely being parsed, as it throws an error whenever it's not properly formatted (amusingly this includes whenever the strings are wrapped in single quotes). It's also ignoring more than just the quote preference- I can set "evil" to false and it'll still give me eval warnings.
Any ideas? This is on OSX.
Thanks in advance.
FYI just in case: jshint_options is no longer available on SublimeLinter-jshint and settings are now set with .jshintrc files. See this and this.
I had the exact same problem. The default .jshintrc in "sublime/preferences/package settings/js hint/set linting preferences" did absolutely nothing for me either.
In order to fix it, I created a .jshintrc file in the root folder of the web project I was working on. I then opened the folder through sublime text and sublinter/jshint picked up my settings.
Maybe your Jshint options are overridden by a .jshinrc file. According to SublimeLinter README file :
SublimeLinter supports .jshintrc files. If using JSHint, SublimeLinter will recursively search the directory tree (from the file location to the file-system root directory). This functionality is specified in the JSHint README.
and
The jshint follows convention set by node-jshint (though node is not required) and will attempt to locate the configuration file for you starting in pwd. (or "present working directory") If this does not yield a .jshintrc file, it will move one level up (..) the directory tree all the way up to the filesystem root. If a file is found, it stops immediately and uses that set of configuration instead of "jshint_options".