Are there any good tools for static code analysis in typescript? [closed]
Asked Answered
T

3

22

We have been searching for good tools for measuring the quality of our TypeScript code. Mainly, we are interested in measuring Cyclomatic Complexity, LCOM, Instability and similar metrics. A tool for visualizing dependencies between modules would also be nice.

A sort of "NDepend for typescript" would be great - but we haven't been able to find anything like it...

Can anyone point us in the direction of any tools that provide some such functionality?

Tamah answered 24/11, 2014 at 13:13 Comment(0)
H
5

We have been searching for good tools for measuring the quality of our TypeScript code

Similar to JSHint (mentioned by Steve) for TypeScript there is TSLint https://github.com/palantir/tslint (with a grunt plugin https://github.com/palantir/grunt-tslint)

The rules aren't that complex to create yourself based on TypeScript language service ASTWalker mechanism e.g. Indent rule : https://github.com/palantir/tslint/blob/master/src/rules/indentRule.ts

Herdic answered 24/11, 2014 at 22:55 Comment(0)
L
4

For visualizing TypeScript module dependencies you can use JavaScript module dependency visualizers:

  • Kenneth Auchenberg's dependo. Creates single-file SPA with with interactive graph
  • Patrik Henningsson's MaDGe. Creates report and static image using Graphviz
  • ...
Longtin answered 29/11, 2014 at 7:20 Comment(0)
I
1

If you were to use an existing JavaScript analyser, such as JSHint (or any similar alternative if it doesn't have all the metrics you want), the results would not be far wrong for your TypeScript code. TypeScript makes very few code transformations, so you would find minor differences in the following areas:

  • If you use inheritance, there will be one additional method in your program.
  • If you use rest parameters, the mapping to an array is added to each method with rest parameters.
  • Enums generate into more complex JavaScript code.

But none of these would throw off the analysis by a great margin.

Sample metrics from the JSHint site:

Metrics

There is only one function in this file.

It takes no arguments.

This function contains only one statement.

Cyclomatic complexity number for this function is 1.

Ingeminate answered 24/11, 2014 at 17:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.