How To Analyze TypeScript Using TSLint

Image for post

There are quite a few people in the team who dislike using JavaScript as it is. Common reasons include difficulties in defining types, there being too many parentheses, and codes often becoming too difficult to understand. That is why Microsoft has been mainly developing TypeScript, a substitute language for JavaScript. TypeScript can be converted to JavaScript.

Even with TypeScript, however, it is necessary to conduct a proper code review in team development. Here, we introduce TSLint, which is a static code analysis tool that can make it even easier in the stages before the review, and in the development stage.

Installing TSLint

Install TSLint with npm command.

Once installed, you can use tslint command.

How to use TSLint

TSLint specifies the .ts of the target file for analysis and executes it. Multiple files can also be selected by specifying a pattern. When executed, points that have been modified for the better will be output.

All that is left is to make corrections according to the specified items.

Automatic correction

If there are common problems (e.g., spaces at the end of the line), you can use the --fix option to automatically fix it.

This option does not modify the maximum number of characters in a line, the description in JSDoc, how variable names are assigned (the interface should start with an uppercase I), and so on. It is necessary to manually respond to these indications.

Change settings

Like other analyzers, TSLint can be changed in the settings file. First, use the --init option to generate a base configuration file tslint.json. The contents are as follows.

By editing this configuration file you can limit the items being highlighted.

Change the output format

By default, it will simply issue an error message to standard output, but by specifying the --format option, it will be able to output in a different format. For example, if you specify `json’, the result will be JSON.

In addition to JSON, the supported formats are: stylish / verbose / pmd / msbuild / checkstyle / vso / fileslist / codeFrame.

Although TypeScript is widely being used at major companies, there are also cases where SMEs and start-ups are adopting it because of its compatibility with casual programming editors such as Visual Studio Code. If you are using TypeScript at your company, it’s a good idea to use TSLint.

Sider is compatible with TSLint. For individual development, it can be installed locally; for team development, a mechanism that automatically performs code review on the cloud will be more efficient.

Sider offers a free trial. Please try it out.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.