Having problems with the ESLint plugin for VSCode. It's marking a lot of inputs that are valid as unresolvable. Dunno how to fix it :/ Local server still runs fine despite the linter marking problems but it's really annoying seeing errors everywhere that aren't errors. My coworker thinks it has something to do with BABEL_ENV variable?
In my case I had specified the paths property on the tsconfig.json file but I was still facing the error on vscode but whenever I was running eslint via CLI the issue wasn't reported.
If you read the description of the eslint plugin on vscode there's asection that talks about eslint.workingDirectories which fixed it for me when I set that option to {"mode": "auto"} on the vscode settings
I guess your import statement like import Foo from "#/components/Foo".
If you import like this, you should setup compiler settings in tsconfig.json or jsconfig.json, like below
{
"compilerOptions": {
...
"paths": {
"#/*": ["src/*"]
}
...
},
...
}
Related
I have been working on a project for months and I have the following jsconfig.json file to make loading paths easier. I don't believe there's anything wrong with this config because it has been working for the entire length of the project, but here it is for reference:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"#/*": ["./src/*"],
"#/public/*": ["./public/*"],
"#/styles/*": ["./src/styles/*"],
"#/utils/*": ["./src/utils/*"],
"#/components/*": ["./src/components/*"]
}
}
}
And today, seemingly for no reason, I'm getting random modules that cannot be found. The example at the time of making this post, in the following screenshot, you can see that the #/utils/craft/client path worked absolutely fine, but the following module on line 4 throws an error.
As you can see in the following screenshot, the naming and file path matches exactly.
The fact it worked for ages and has thrown this error now out of the blue, suggests to me this a VSCode/jsconfig bug and not actually with the markup itself?
Any help would be appreciated.
Found the issue.
I accidentally labelled a file .tsx and when I ran npm run build, a tsconfig file was automatically added. This meant that the jsconfig file was no longer being used!
I have read and searched quite lot. All the discussions I have read about setting vscode to autocomplete on external (non-pip installed) modules say adding the directory of the modules in question to the user or workspace settings.json should make autocomplete available.
AFAIKT there is more to it, since nothing I've tried so far seems to work.
I have this in the workspace file:
"python.autoComplete.extraPaths": [
"/home/mac/freecad-build",
"/home/mac/freecad-build/Mod/Part"]
And in the user I have this:
"python.analysis.extraPaths": [
"/home/mac/freecad-build/Mod/Draft",
"/home/mac/freecad-build/lib",
"/home/mac/freecad-build/Mod/Part",
"/home/mac/freecad-build/Mod/Sketcher",
"/home/mac/freecad-build/Mod/Mesh",
"/home/mac/freecad-build/Mod/Drawing",
"/home/mac/freecad-build/Mod/MeshPart"
]
Module import seems to be ok.
So this is ok:
import Part
But, when I type:
Part.
It throws this error:
Expected member name after "."
What am I missing?
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
Why is VSCode showing this error?
It's just a jsconfig.json file.
NOTE: I'm not using TypeScript.
Try adding "exclude": ["node_modules"] as described in the VSCode docs.
I added this and restarted VSCode and the error message went away.
Disabling typescript in the workspace options seems to be the one thing that stopped this warning for me:
"typescript.validate.enable": false,
I was facing the issue in Vuejs/Nuxtjs project:
Check the jsconfig.json file in root and include the following things if not available already:
"exclude": ["node_modules"]
{
"compilerOptions": {
"target": "es6",
"baseUrl": "."
},
"exclude": ["node_modules"]
}
Important
If you are getting the error even after having these values then you SHOULD RESTART vs code application
Add "exclude": [ "node_modules/**/*", ], in the tsconfig.json file and if it still doesn't work, try reloading the VSCode by pressing Crtl + Shift + P and Reload Window and it should work.
I also had some issues like this while using node modules. I just recreated the project copied and pasted all the code that i needed and installed every node modules after that i was able to fix the issue. However i dont recommend for large projects.
I have vscode 1.9 and I want to have intellisense for jest tests. The problem is that describe, it, expect etc are globally available in jest and you don't need to import them in your test files. So vscode will not show intellisense for them.
Is there any configuration for globals for automatic type acquisition?
You have a few options in this case:
Add jest to your package.json:
"dependencies": {
"jest": "^18.1.0"
}
This only works if you are working JavaScript and do not have a tsconfig.json.
Install #types/jest
$ npm install -D #types/jest
This should work for both JavaScript and TypeScript projects. However #types but may be disabled by a jsconfig.json/tsconfig.json: http://www.typescriptlang.org/docs/handbook/tsconfig-json.html
Create a jsconfig.json file in the root of your workspace to specifically include jest:
{
"typeAcquisition": {
"include": [
"jest"
]
}
}
This will only work for JavaScript projects when automatic typings acquisition is enabled.
All of these should allow VSCode to pick up jest's typings without an import or require
I tried installing the #types/jest, and it did work, but the problem is that it resulted in the jest suggestions appearing in my .js files as well. I couldn't figure out how to get global suggestions for test, expect, etc. in only .test.js files but not .js files.
So I decided to just manually import each jest global I was going to use in each .test.js file, which allowed the suggestions to appear with types but avoided having the suggestions appear in the .js files:
import { test, expect } from '#jest/globals'
npm install -D #types/jest
edit jest.config.js
typeAcquisition: {
include: ['jest'],
},