Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Dragolea
Participant

 

2024-04-25_10-03-19.png

 

Hi all,

Introduction

Many of us are working with SAP CAP (Node.js with TypeScript) for our projects. (We) Developers prefer always to have the best setup for our development and VSCode community provided us with all the tools that we need.

Prerequisites

Before we dive in, you should have a basic understanding of SAP CAP NodeJS, TypeScript and VSCode.

VSCode extensions

Below there's a list of the best VSCode Extensions for TypeScript development for UI5 and NodeJS to ease your developer life. 

1. Prettier

Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.

Dragolea_0-1714041625547.png

Installation

1. To have same uniform programming style on the project for all developers we need also to add it to npm package.json :

 

npm install --save-dev --save-exact prettier

 

2. We need to create 2 prettier config files the .prettierrc and .prettierignore

 

node --eval "fs.writeFileSync('.prettierrc','{}\n')" 
node --eval "fs.writeFileSync('.prettierignore','{}\n')"

 

3. We add some prettier configs like : 

 

{
  "semi": true,
  "trailingComma": "all",
  "singleQuote": true,
  "printWidth": 120,
  "tabWidth": 2
}

 

4. We add a new script in the package.json

 

"prettier": "npx prettier . --write"

 

5. Run the prettier :

 

npm run prettier

 

SAVE ON FORMAT OPTION

1. We need firstly to install the VSCodePrettier 

2. We need to check VSCode - Settings like below, this setting will call Prettier everytime when we save our files.

Dragolea_1-1714116712083.png

2. ESLint

ESlint is installed by default when the command cds init is performed. Now we will set it up for TypeScript development.

Dragolea_1-1714051579147.png

Installation

 

npm init @eslint/config

 

Above command will prompt a list of messages, and we choose option 3

Dragolea_5-1714057722130.png

2. Which type of modules does your project use  : None of these

3. Which framework does your project use?  : None of these

4. Does your project use TypeScript? : Yes

5. Where does your code runs? : Node

6. Which style guide do you want to follow? : Standard

7. Would you like to install them now? : Yes

Do the following steps : 

1. Remove the .eslintrc.json

2. Add the following to .eslintrc

 

{
    "env": {
        "browser": true,
        "es2022": true,
        "node": true,
        "jest": true,
        "mocha": true
    },
    "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "standard-with-typescript", "prettier"],
    "parserOptions": {
        "ecmaVersion": "latest"
    },
    "globals": {
        "SELECT": true,
        "INSERT": true,
        "UPSERT": true,
        "UPDATE": true,
        "DELETE": true,
        "CREATE": true,
        "DROP": true,
        "CDL": true,
        "CQL": true,
        "CXL": true,
        "cds": true
    },
    "rules": {
    }
}

 

3. Add the following script to package.json

 

"eslint": "npx eslint ."

 

4. Run the eslint 

 

npm run eslint

 

3. Better Comments

The Better Comments extension will help you create more human-friendly comments in your code

Dragolea_2-1714051607172.png

Example

Dragolea_3-1714051663870.png

Installation

VSCode extension: Better Comments 

4. Bookmarks

Dragolea_8-1714051788571.png

It helps you to navigate in your code, moving between important positions easily and quickly. No more need to search for code. It also supports a set of selection commands, which allows you to select bookmarked lines and regions between bookmarked lines. It's really useful for log file analysis.

Installation

VSCode extension: Bookmarks 

5 Code Spell Checker

Dragolea_9-1714051848447.png

A basic spell checker that works well with code and documents.

The goal of this spell checker is to help catch common spelling errors.

Installation

VSCode extension: Code Spell Checker 

6. DotENV

Installation

VSCode extension: DotENV 

7. Edit CSV

This extensions allows you to edit csv files with an excel like table ui,

Dragolea_11-1714052124604.png

VSCode extension: Edit CSV 

 8.Error Lens

ErrorLens turbo-charges language diagnostic features by making diagnostics stand out more prominently, highlighting the entire line wherever a diagnostic is generated by the language and also prints the message inline.

Dragolea_12-1714056246920.png

VSCode extension: Error Lens 

11. Path Intellisense

Visual Studio Code plugin that autocompletes filenames.

VSCode extension: Path Intellisense 

12. Pretty TypeScript Errors

TypeScript errors become messier as the complexity of types increases. At some point, TypeScript will throw on you a **bleep** heap of parentheses and "...".
This extension will help you understand what's going on. For example, in this relatively simple error:

Dragolea_13-1714056476147.png

VSCode extension: Pretty TypeScript Errors 

13. Project Manager

It helps you to easily access your projects, no matter where they are located. Don't miss those important projects anymore.

VSCode extension: Project manager 

14. Rainbow CSV

Dragolea_0-1714056686291.png

VSCode extension: Rainbow CSV 

15. TODO Highlight

Highlight TODO, FIXME and other annotations within your code.

Sometimes you forget to review the TODOs you've added while coding before you publish the code to production. So I've been wanting an extension for a long time that highlights them and reminds me that there are notes or things not done yet.

 
Dragolea_0-1714058871807.pngDragolea_1-1714058884591.png

16. npm Outdated

Displays a diagnostic message in package.json files for packages which have newer versions available as well as a code action to quickly update packages to their latest version.

Dragolea_3-1714057210310.png

17 .npm Intellisense

Visual Studio Code plugin that autocompletes npm modules in import statements.

 

Conclusion

In conclusion, all above VSCode extensions will make you feel much more confortable writing code, by automatize code formatting, check spelling mistakes and also common style of writing code.

 

Additional Resources

You can have a look at this following .devcontainer Github repository  which uses VSCode and Docker and has all above VSCode extensions installed by default in the container.

 

Sharing experience from developers to developers bABS & DxFrontier team

 

Labels in this area