Skip to main content

4 posts tagged with "VS Code"

View All Tags

Preventing Ridiculous ESLint auto-fixes in VS code

I recently adopted ESLint into my workflow and enabled fix-on-save in VS Code. I've noticed since then that sometimes massive chunks of code get deleted on save by the fixes. My current suspicion is that this is entirely to blame on the rule @typescript-eslint/no-unused-expressions. I've noticed other auto-fix issues as well, however, and will track down the culprit rules as they occur.

It is possible to leave fix-on-save enabled yet disable only the bad rules! Below is the JSON config that you will need to insert in your VS Code settings to do that. As I discover more problematic rules in the future, I'll append them below.

"eslint.codeActionsOnSave.rules": [
"!@typescript-eslint/no-unused-expressions",
"*"
],

Open Multiple Files in VS Code from a Grep

A simple script:

grep -rl '<search-string>' <search/dir> | xargs code -r

Between two different directories:

cd <first-path> && grep -rl '<search-string>' <search/dir> | (cd <second-path>; xargs code -r)

ESLint Violations as Warnings in VS Code

If you're using TypeScript and ESLint in VS Code, wip files or legacy files can quickly explode into a sea of red squiggles, making it hard to know where to start or track what's going on.

I like to hone in on type errors first, since they're typically more critical (as in, type errors will often completely crash your code). I keep those as scary red squiggles and tone ESLint down a bit by changing all its squiggles to just (orange) warnings.

This is easy to do with a quick edit to your user settings JSON file (accessed via the >Preferences: Open User Settings (JSON) command in VS Code):

"eslint.rules.customizations": [
{ "rule": "*", "severity": "warn" },
]

Use @link JSDoc comments

Use {@link VarName} in JSDoc comments when referencing variables or types to get:

  • "Rename Symbol" support in VS Code
  • "Go to Definition" support in VS Code
  • "Find All References" support in VS Code
  • generated doc links to the original reference (in packages like typedoc)

I assume that all the features in VS Code are driven by the TypeScript Language Server and thus are applicable to any editor that utilizes that same language server.