Automated Code Reviews

Ship better code, faster.

What is static code analysis?

Static analysis is a process to inspect a program based on its source code. There is no need to compile or execute the program: only the source code is necessary. As only the source code is needed, static analysis tools are language-specific. Such tools parse, interpret the program to analyze it, and find potential issues.

The static analysis tool processes the source code and finds potential issues. Static analysis tools can encounter various problems, such as security (e.g., a buffer overflow in C), lack of documentation, potential design issues (e.g., too many dependencies across multiple files).

A static analysis tool reports problems that can be severe and require immediate attention, while others are minor and focus on the code style.

There are many great static analyzers on the market—for example, PMD for Java or pylint for Python (to name a few).

Static Code Analysis vs. Dynamic Code Analysis

Many people may ask the difference between static analysis and dynamic analysis. Dynamic analysis is done by executing the program and inspecting its behavior.

Dynamic analysis requires being able to:

  1. Compile the program: you have all the dependencies (compiler or runtime + linked libraries)
  2. Run the program: you have access to a machine that can execute the program and observe its behavior.

If you wonder what type of analysis is better, the answer is quite simple: it depends on the language you are using and what you are trying to do. Some issues are easy to detect with static analysis (such as design issues, lack of documentation). In contrast, some problems can only be caught using dynamic analysis (especially when it comes to pointer arithmetic).

One good example of a dynamic analysis tool is valgrind, a dynamic analysis to diagnose memory issues.

Pros and Cons of Static Code Analysis

The main benefit of static code analysis is the absence of compiling and running the program. You only need the source code to start finding issues. It's fast and very efficient.

The main drawback of static code analysis is the false-positive report. As the program doing the analysis does not have all the execution context, it reports errors that are not relevant and not applicable. Such errors are called false-positive. When a static code analyzer reports too many false-positive errors, finding real issues among the list of errors is like finding a needle in a haystack.

Static Code Analysis with Code Inspector

Code Inspector relies on multiple static code analyzers to inspect code and find potential issues. It aggregates dozens of static analyzers working on 10+ languages to find bugs in your program.

Most importantly, Code Inspector calibrates all the static code analyzers it uses, which means that each analyzer is maintained and configured with the most optimal options for you. Code Inspector also filters false positives to only surface real issues to the user.

Code Inspector analyzes your code in real-time and reports all code issues at each change. It also analyzes each pull request or merge request and reports all issues by doing automated code reviews.

In summary, Code Inspector makes the use of static code analyzer simple and easy. There is no need to install, configure, or maintain a static code analyzer on your machine. Code Inspector makes this process seamless and easy so that you can focus on writing great code.

Want to start using static code analysis?

Code Inspector is a code analysis platform for GitHub, GitLab, and Bitbucket. It is free to use for public projects. Try it now!

Try Code Inspector today!