Intellisense doesn't work in .spec files (works when I remove .spec) - visual-studio-code

I am writing test in Jest and files have .spec.ts extension.
I noticed that when I reference my classes, vscode doesn't automatically resolve their name and I have to provide path manually.
When I remove .spec from file it magically starts working and gives me hints to automatically import classes.
When I add .spec it stops working again.

Seems you can just rename spec.ts to test.ts and then it somehow works

Related

How do I prevent the .dccache file from being created?

vscode keeps adding a file named .dccache. How can I prevent this?
It messes up the github diffs and I keep on having to add .dccache to the .gitignore for several different projects.
I can't find anything about why .dccache is being created in the first place
It can also be created by the Snyk extension.
I have the same file, I believe this is being created from DeepCode: https://www.deepcode.ai/
This is a code analysis tool to try to find issues. Check if you installed the DeepCode extension in VSCode if you want to get rid of this file, otherwise ignoring it should be fine.
The DeepCode plugins or the CLI is using this file to create a cache for the source code bundles send to the analysis engine. Without this cache, the collection and upload would be very time-consuming.
As it only serves as a caching mechanism, you can exclude it from git uploads and ignore it otherwise.
Snyk extention has a Help&Feedback tab, on the FAQ there is a 'Add custom .dcignore file to your workspace'.
Sometimes git ignore doesn't work for me
I used this file: https://github.com/DeepCodeAI/dcignore/blob/master/full.dcignore.js
just create .dcignore and copy all contents to that. I manually add .dccache and .dcignore just in case.
I had the same issue and when I disabled Snyk extension on VS code editor is disappeared, if you don't have Snyk installed and still have .dccache appearing every now and them, just keep an eye on the other extensions, disable each one at a time and see which one is creating the .dccache file

VSCode: how to structure a simple python package with few modules and tests, debugging and linting?

I'm having more trouble than I'd like to admit to structure a simple project in Python to develop using Visual Studio Code.
How should I structure in my file system a project that is a simple Python package with a few modules? Just a bunch of *.py files together. My requisites are:
I must be able to step debug it in vscode.
It has a bunch of unit tests using pytest.
I can select to debug a specific test from vscode tab and it must stop in breakpoints.
pylint must not show any false positives.
The test files must be in a different directory of the main module files.
I must be able to run all the tests from the console.
The module is executed inside a virtual environment using python standard lib module venv
The code will use type hints
I may use another linter, even another test framework.
Nothing fancy, but I'm really having trouble to get it right. I want to know:
How should I organize my subdirectory: a folder with the main files and a sibling folder with the tests? Or a subfolder with the code and a subsubfolder with the tests?
Which dirs must have a init.py file?
How the tests should import the files from the module? Should I use relative imports?
Should I create a pytest.ini file?
Should I create a .env file?
What's the content of my launch.json the debugger file config in vscode?
Common dir structure:
app
__init__.py
yourappcode.py
tests (pytest looks for this)
__init__.py
test_yourunittests.py
server.py if you have one
.env
.coveragerc
README.md
Pipfile
.gitignore
pyproject.toml if you want
.vscode (helpful)
launch.json
settings.json
Or you could do one better. Ignore my structure and look at the some of famous python projects github page. Like fastAPI, Flask, asgi, aiohttp are some that I can think of right now
Also:
I think absolute imports are easier to work with compared to relative imports, I could be wrong though
vscode is able to use pytest. Make sure you have a testing extension. Vscode has a built in one im pretty sure. You can configure it to pytest and specify your test dir. You can also run your test from command line. If youre at the root, just running ‘pytest’ will recognise your tests dir if it’s named that by default. Also your actual test files need to start with prefix test_ i think.
The launch.json doesn’t need to be anything special. When you click on the settings button next to play button in the debug panel. Vscode will ask what kind of app is it. I.e If its a flask app, select python then select flask and it will auto generate a settings file which you can tweak however you want in order to get your app to run. I.e maybe you want to expose a different port or the commands to run your app are different
It sounds to me like you just need to spend a bit of time configuring vscode to your specific python needs. For example, you can use a virtualenv and linting in whichever way you want. You just need to have a settings.json file in the .vscode folder in your repo where you specify your settings. Configurations to specify python virtualenv and linting methods can be found online

VS Code style-lint ignore directories

Is it possible to ignore my CSS path, beacuse I only use stylelint for SCSS validation?
e.g. - I have the following structure:
assets/
css/
scss/
How can I disable the css/ folder from being indexed, trough the settings.json file of VSCode?
I found this in the docs, but I don't know how to implement it in VSCode.
If you're using the VS Code stylelint extension, you can specify ignore paths via the stylelint.configOverrides setting.
Add the following to your VS Code settings.json file:
"stylelint.configOverrides": {
"ignoreFiles": "assets/css/**"
}
Alternatively you can add a .stylelintignore file to the root folder of your project and add the ignore paths there:
assets/css/**
I'm using stylelint#9.2.0 with vscode-stylelint#0.20.4, and for me the .stylelintignore file is not being respected. If i use the CLI it is respected but the vscode plugin does not seem to do this correctly.
Similar to Jack Russell, I found that the VS Code stylelint plugin currently seems to ignore the .stylelintignore file.
To get around this limitation, I removed the .stylelintignore entirely and moved its settings into .stylelintrc instead. I.e. from something like this in .stylelintignore:
ignorethisfolder/**/*
path/to/ignorethisfile.css
To something like this in .stylelintrc:
"ignoreFiles": [
"ignorethisfolder/**/*",
"path/to/ignorethisfile.css",
]

Resolving NED Path issue Veins/Omnet++

I am working with veins. I needed to change the default behavior of BaseWaveApplLayer. Rather doing in file changes, I created a second application file with the name MyApp. I added MyApp.cc, MyApp.h, MyApp.ned files. Then I duplicated TraCIDemoRSU11p, and added files for TraCIDemoRSU11pEnhanced. Now in .ini file when I changed *.rsu[*].applType to point to "TraCIDemoRSU11pEnhanced". It compiles fine, but when I try to run it, generates the following error:
Submodule appl: no module type named `TraCIDemo11pEnhanced' found that implements module interface org.car2x.veins.base.modules.IBaseApplLayer (not in the loaded NED files?).
In MyApp.ned file it is declared to be of type IBaseApplLayer. I tried setting ned-path parameter in ini file, didn't resolve the problem. In veins project properties, NED source folder is checked. Do I have to add the ned path for the newly created application file, somewhere?
Try using the cookiecutter package (https://veins.car2x.org/tutorial/#newprojects) to create new applications that use veins instead of copying and pasting files:
Use pip to install the package (https://github.com/cookiecutter/cookiecutter)
Then follow the steps in (https://github.com/veins/cookiecutter-veins-project/blob/master/README.md) to create the new project; following the prompts that appear.
This will create a new project that uses Veins and has the application layer-related files for you to update according to your application with no errors.

importing go files in same folder

I am having difficulty in importing a local go file into another go file.
My project structure is like something below
-samplego
--pkg
--src
---github.com
----xxxx
-----a.go
-----b.go
--bin
I am trying to import a.go inside b.go. I tried the following,
import "a"
import "github.com/xxxx/a"
None of these worked..I understand I have to meddle up with GOPATH but I couldn't get it right. Presently my GOPATH is pointing to samplego(/workspace/samplego).I get the below error
cannot find package "a" in any of:
/usr/local/go/src/pkg/a (from $GOROOT)
/workspace/samplego/src/a (from $GOPATH)
Also, how does GOPATH work when these source files are imported into another project/module? Would the local imports be an issue then? What is the best practice in this case - is it to have just one go file in module(with associated tests)?
Any number of files in a directory are a single package; symbols declared in one file are available to the others without any imports or qualifiers. All of the files do need the same package foo declaration at the top (or you'll get an error from go build).
You do need GOPATH set to the directory where your pkg, src, and bin directories reside. This is just a matter of preference, but it's common to have a single workspace for all your apps (sometimes $HOME), not one per app.
Normally a Github path would be github.com/username/reponame (not just github.com/xxxx). So if you want to have main and another package, you may end up doing something under workspace/src like
github.com/
username/
reponame/
main.go // package main, importing "github.com/username/reponame/b"
b/
b.go // package b
Note you always import with the full github.com/... path: relative imports aren't allowed in a workspace. If you get tired of typing paths, use goimports. If you were getting by with go run, it's time to switch to go build: run deals poorly with multiple-file mains and I didn't bother to test but heard (from Dave Cheney here) go run doesn't rebuild dirty dependencies.
Sounds like you've at least tried to set GOPATH to the right thing, so if you're still stuck, maybe include exactly how you set the environment variable (the command, etc.) and what command you ran and what error happened. Here are instructions on how to set it (and make the setting persistent) under Linux/UNIX and here is the Go team's advice on workspace setup. Maybe neither helps, but take a look and at least point to which part confuses you if you're confused.
No import is necessary as long as you declare both a.go and b.go to be in the same package. Then, you can use go run to recognize multiple files with:
$ go run a.go b.go
./main.go (in package main)
./a/a.go (in package a)
./a/b.go (in package a)
in this case:
main.go import "./a"
It can call the function in the a.go and b.go,that with first letter caps on.
If none of the above answers works,
Just try,
go run .
for production,
go build
This will take care of all the .go files in the folder.
I just wanted something really basic to move some files out of the main folder, like user2889485's reply, but his specific answer didnt work for me. I didnt care if they were in the same package or not.
My GOPATH workspace is c:\work\go and under that I have
/src/pg/main.go (package main)
/src/pg/dbtypes.go (pakage dbtypes)
in main.go I import "/pg/dbtypes"
As people mentioned previously, there is no need to use any imports.
A lot of people mention that using go run is possibe when you mention most files, however when having multiple .go-files in the same dir it can be cumbersome.
Therefore using go run *.go is what I usually do.
As I understand for packages in your project subfolders it's possible now to do, just need to add "." in front of module, like
. "github.com/ilyasf/deadlock-train/common"
where github.com/ilyasf/deadlock-train my main module name and common is just package from /common subfolder inside project.
go1.19.1 version here. I've just had the same issue, discovered that you must simply do: import (a "github.com/xxxx")
You can go to the correct folder and execute: $ go run *.go
As long as the code only 1 main function in all files it works perfect!