RubyMine with Rubocop - How to Reformat? - rubymine

I have RuboCop installed with Rubymine and the inspection errors for rubocop are showing up properly.
Running ⌘+Alt+L converts the code to rubymine style that conflicts with rubocop style.
For example:
some_array = 10.times.map {|index| index * 3} # rubymine
some_array = 10.times.map { |index| index * 3 } # rubocop
rubocop puts spaces inside of inline blocks. a small thing I know. but rubymine autoformats without spaces so I have a crapton of of inspection notices.

In Rubymine, go to Settings → Editor → Code Style → Ruby and ensure you have the Spaces around curly braces option checked.

Related

What does the rust-analyzer error "could not resolve macro `$crate::format_args`" mean and how do I fix it?

I'm using rust-analyzer version 0.2.408 on Visual Studio Code.
I'm writing a command line application that involves centering text in the terminal. This is the function I wrote to do this:
use console::{Alignment, pad_str};
fn get_padded_row(row: &str, width: u16, symbol: Option<char>) -> String {
let symbol = symbol.unwrap_or(' ');
return pad_str(row, width as usize, Alignment::Center, None)
.to_string()
.replace(' ', &symbol.to_string());
}
This function works perfectly fine, and there were no errors with it. Then I wrote a test:
#[cfg(test)]
mod tests {
use crate::get_padded_row;
#[test]
fn row_padding_dashes() {
let padded_row = get_padded_row("hello", 15, Some('-'));
assert_eq!(
padded_row, "-----hello-----".to_string(),
"`get_padded_row` was not correct, got `{}`", padded_row
);
}
}
The code still works perfectly fine. Both cargo run and cargo test work, the function passes the test, and cargo check returns no issues. But rust-analyzer gives an error, highlighting everything from the tr}; in the use statement to the p right after return: "could not resolve macro $crate::format_args rust-analyzer(macro-error)". Searching for this error returns nothing. VSCode links me to rust-analyzer user manual, which says only "This diagnostic is shown for macro expansion errors". Restarting VSCode and reinstalling rust-analyzer have done nothing. The error always comes back, and highlighting the same oddly specific region. The only way I've found to get rid of it while keeping rust-analyzer installed is to remove the test.
Judging from how the error is about macro expansion, and how removing the test fixes the issue, I'd imagine it's caused by the #[test] macro, but it's strange that rustc finds no issues at all with my code while rust-analyzer is freaking out about this error. So far, I've had better experiences with rust-analyzer than with the official Rust VSCode extension, but I'm on the verge of switching back to fix this issue.
This is a bug in rust-analyzer. For now, you can disable the warning in your settings.json:
"rust-analyzer.diagnostics.disabled": [
"macro-error"
]
The bug was fixed on nightly, so you could install the nightly binary of rust-analyzer from GitHub, or you could just wait a couple days for the fix to land on stable.
Alternatively, you could downgrade to rls version 0.2.400, because the bug was caused by a commit in version 0.2.408:
Extensions Icon -> rust-analyzer -> Manage (gear icon) -> Install Another Version
Three months later and there seems to be a bug with Nightly release? Unsure.
I added unresolved-macro-call to Diagnostics: Disabled settings for rust-analyzer.
I've tried many things, read the open issue on github, etc which is tagged as solved, but persists here.
For vscode users, open settings (json) and disable by adding:
"rust-analyzer.procMacro.enable": false

VS Code - space before function parentheses

Is there a way to disable removing space before parentheses when editing a function in VS Code?
Lets say I have a function
function render () {
// some code here
}
When I start editing it, VS Code removes the space before parentheses and transforms this code to:
function render() {
// some code here
}
Is there a way to disable this behavior?
In VS Code open File -> Preferences -> Settings
Add to your JSON config:
"javascript.format.insertSpaceBeforeFunctionParenthesis": true
function render () {
// some code here
}
"javascript.format.insertSpaceBeforeFunctionParenthesis": false
function render() {
// some code here
}
Now you can continue using your auto format option "editor.formatOnType": true
I had opposite problem with anonymous functions. We use prettier extension. Auto-correct inserts a space before parenthesis. And then prettier complains about it.
var anonfunc = function() {
// Expected syntax.
}
var autocorrected = function () {
// Auto-correct inserts a space
}
There is similar code option, which solves my problem:
"javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": false
By default it is true. Took me some time, until I was tired correcting auto-correct.
I had a similar issue with VSCode removing spaces after a constructor and ESLint complaining because there wasn't a space.
Go to File -> Preferences -> Settings
Search for constructor
Add a check next to JavaScript › Format: Insert Space After Constructor
I'm on the VSCode team. As of VSCode 1.8, this formatting option is not supported out of the box, but we are tracking the feature: https://github.com/Microsoft/vscode/issues/15386, https://github.com/Microsoft/TypeScript/issues/12234
As a workaround, try the following:
Install the eslint extension: ext install eslint
Add "eslint.autoFixOnSave": true to your workspace or user settings
In the root of your project, create an .eslintrc.json with:
{
...
"rules": {
...
"space-before-function-paren": "error"
}
}
The eslint extension can create a starter .eslintrc.json for you with the create .eslintrc.json command.
This will automatically format functions to have a space after them when you save the file.
In my case, I wanted the normal indenting/formatting behavior of VS Code, so I disabled the eslint warning:
In the .eslintrc.js file I typed inside the rules:
'rules': {
....
//disable rule of space before function parentheses
"space-before-function-paren": 0
}
I found out I had "editor.formatOnType": true setting enabled. This is what makes the editor auto-format the code when you type. Disabling it helped to resolve the issue.
Also adding to Yan's answer, you can just hit the Command + , on Mac or CTRL + , on your keyboard then, add the following lines in your settings.json
"javascript.format.insertSpaceBeforeFunctionParenthesis": false,
"javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": false
The second entry also disables the space for anonymous functions, on format e.g
var anon = function() {
// do something..
}
Go to Preferences, and search for insertSpaceBeforeFunctionParenthesis in the search bar at top.
Now, select the checkbox which says: JavaScript: Format: Insert Space Before Function Parenthesis
Problem:
My issue was in package.json
My project was using prettier#1.18.2 which did not have the space after the function keyword or arrowParens: 'always' as default configuration.
One of the maintainers upgraded prettier to version 2 prettier#2.3.2, which had these two as default config. These were among the breaking changes in prettier version 2.
https://prettier.io/blog/2020/03/21/2.0.0.html#always-add-a-space-after-the-function-keyword-3903
https://prettier.io/blog/2020/03/21/2.0.0.html#change-default-value-for-arrowparens-to-always-7430
Solution:
npm ci - just installed the npm packages again.
npm install will also work. npm ci will install exact versions from package-lock.json, while npm install would install latest versions with minor changes.
In my case I had to explicitly enable ESLint on my Vue.js project even though I had a .eslintrc.js file that should have been implementing:
extends: ['plugin:vue/exxential', '#vue/standard']
To do that I pressed CTRL+Shift+P and searched for "ESLint: Enable ESLint"

Eclipse + PyDev says json.load() and json.dump() do not exist

The following lines in Eclipse + PyDev with Python 3.4 work, but it is highlighted as Undefined variable from import: dump error:
import json
with open('C:\\test', 'w') as outfile:
json.dump([1, 2, 3], outfile)
Here is a snapshot of the Eclipse editor:
How do I get rid of that error?
EDIT
The output of:
import json
with open('C:\\test', 'w') as outfile:
json.dump([1, 2, 3], outfile)
print(json.__file__)
Is:
C:\Python34\lib\json\__init__.py
Here is the list of attributes that Eclipse shows:
problem in line 313 in file ../lib/json/__init__.py
...
if s.startswith(u'\ufeff'):
...
change this line to
if s.startswith('\ufeff'):
or wait for the new version
I was not able to get Eclipse to work, but I was able to get rid of the error (and of similar error/warnings): select the highlighted word, press ctrl+1 and select the line containing #UndefinedVariable to add a comment at the end of the row that will tell Eclipse to ignore that error on that line.
I use the same technique to ignore other errors with other modules, and it helps keeping the project clean.
See here for more details.
I had the same problem, but I had a file called json.py. Renaming my file to jsonTest.py from Eclipse left behind a json.pyc. Deleting that file did not help. Doing a Project->Clean did not help. Finally, I created a new workspace and things now work as expected. This was with Eclipse Kepler Release 2.
Adding json to the list of Forced Builtins of your Python Interpreter in PyDev Preferences also fix this issue.

Threads in Eclipse AND c++11

My goal has been to create multi-threading programs, and I can not even get a simple thread
to execute ON ECLIPSE CDT. my Tools:
ECLIPSE 3.8.1 CDT
Ubuntu 13.10
I have noticed very similar issues regarding mine. I have tried those other solutions but I could not get them to work for me.
When I type the code in Eclipse CDT, Eclipse does not 'resolve' the symbols 'thread', however, It can find the header file 'thread'. 'Mutex' also does not resolve. Furthermore, after building, I run the program, eclipse returns :
"terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted"
Some additional notes:
I can compile and execute the code in the terminal using:
'clang++ c.cpp -pthread -std=c++11'
but...
'g++ c.cpp -pthread -std=c++11' compiles and
produces the same error as quoted above. So it looks like it's a compiler issue. I did
start to write the code in a new project within Eclipse CDT with the clang++ compiler and now that gives the same non-resolved 'thread' and produces the error as quoted above. So now I think I have some wrong settings, paths or flags set in Eclipse.
include <iostream>
include <thread>
using namespace std;
void p1(){
cout<<"process 1 is processing"<<endl;
}
int main() {
thread t1(&p1);
cout<<"Hello from main()"<<endl;
t1.join();
return 0;
}
I have been struggling with the very same issue and I finally resolved it. Here is what I did:
1) Add -std=c++11 for c++ build. To do that right-click your project, select properties and then: C/C++ Build -> Settings -> GCC C++ Compiler -> Miscellaneous(last option)
In other flags append -std=c++11. My Other flags now looks like: -c -fmessage-length=0 -std=c++11 but yours may be a bit different.
2) Add some linker options. In the same view(C/C++ Build -> Settings) as above select the GCC C++ Linker option and from there go to Miscellaneous(second to last option). Add the following Linker flags(the field was empty for me): -Wl,--no-as-needed -pthread. Hit apply.
3) Add a macro. Again from the project properties menu(project->right click->properties). Navigate to C/C++ General -> Paths and symbols -> Symbols. Select GNU C++. Add a symbol with the name __GXX_EXPERIMENTAL_CXX0X__ and no value. Again hit apply.
4) Navigate to C/C++ General -> Preprocessor Include paths.. Select the providers tab. In this tab leave only the following two options checked: CDT GCC Built-in Compiler Settings and CDT Managed Build Setting Entries. Select CDT GCC Built-in Compiler Settings uncheck the checkbox Share setting entries between projects(global provider) and now the text box labeled Command to get compiler specs should be enabled. In this text box append the good old -std=c++11. The text now looks like this for me ${COMMAND} -E -P -v -dD ${INPUTS} -std=c++11. Hit apply one last time.
5) Rebuild the index for the project. To do that right click the project->Index->Rebuild
Following these steps I was able to compile a c++11 multithreaded program, execute it and also Eclipse CDT did not report any errors and was helpful with the autocompletion. Unfortunately this setting has to be done separately for Release and Debug(or at least I have not found a way to share it). Hope this helps.

How can I setup compass on netbeans 7.4

There is a feature in netbeans 7.4 that allows scss and less to auto compile on save.
I have managed to set up scss to compile but I am having problems compiling scss files using compass.
Here is an example error:
Syntax error: File to import not found or unreadable: compass/css3.
Load path: /www/site
on line 2 of /www/site/app/View/Themed/Admin/webroot/scss/core.scss
Currently the compass is imported like so:
#import "compass/css3";
Thanks
In NetBeans, click the File > Project Properties menu item.
In the dialog that opens, select the CSS Preprocessors category.
At the bottom of the Sass properties is Compiler options. Enter --compass
That fixed the problem you are asking about for me. However, I then encountered further problems with Compass because it was ignorant of the paths to files. To overcome this I created a config.rb file in the root of my project. This had to define a full project path and directory names. Moreover, working on a Windows machine, it was fussy about the direction of slashes and types of quotes.
project_path = 'c:\path\to\project'
css_dir = "css"
sass_dir = "sass"
images_dir = "images"
javascripts_dir = "js"
Another way that you can add Compass to all SASS projects without adding the argument to each project is by going to Tools > Options > Miscellaneous > CSS Preprocessors and adding " --compass" to the end of the Sass Path.
For example, mine reads "C:\Ruby200-x64\bin\sass.bat --compass".