snippets/old_snippets/vs-code-tasks.en.md

57 lines
1.5 KiB
Markdown

---
title: "vs code tasks"
seo_description: "How to configure VS Code with custom tasks"
date: 2021-11-12T14:44:37+01:00
draft: false
snippet_types:
- vscode
---
For the past years whenever I needed to lint or test a single file I would:
- right click it in the navigation tree
- copy relative path
- open the built in terminal with Command-J
- Control-R to search recent commands for 'npm run test' or 'npm run lint'
- Select old path in the command and paste with path I want to test
- hit Enter
- wait
Over time doing this adds up. Recently I stumbled upon VS Code Tasks and found
a way to speed things up. By configuring the following tasks.json:
```json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "test single xxxxx file",
"command": "npm run test -- ${file} --coverage=false",
"problemMatcher": []
},
{
"type": "shell",
"label": "lint and fix single file xxxxx file",
"command": "./node_modules/.bin/eslint ${file} --fix",
"problemMatcher": []
},
]
}
```
Now to test the file that I'm currently working on I:
- Command-Shift-P to bring up commands input
- Usually 'Tasks: Run Task' is the last run command so just press Enter, In the
case it is not typing 'Task' is enough to bring it up
- Then the lint and test tasks appier in the drop down and all I have to do is hit
Enter again
- wait
- profit
Don't know why I held out on customizing VS Code so long! Wonder what other time saving
features there are?
source: [vs code docs](https://code.visualstudio.com/Docs/editor/tasks#_custom-tasks)