28
\$\begingroup\$

Lints and Hints: What tools are available for checking and correcting the conventions, style and common errors in my language (lint tools), and are there tools that can automatically fix them (hint tools)?

This is a follow-up to a comment posted on Is there a place for automated code reviews?

Would a list of static analysis tools help jumpstart this? – h.j.k. 34 mins ago

Let's list a few tools that people can use to address easy and common issues in their code before they ask their questions, and that can help reviewers gather "easy" points to mention in their CR answers...:


To keep this organized, please post one tool/language per answer; if it's a paid/commercial tool, please mention it. Also please include a link to the website.

\$\endgroup\$

26 Answers 26

10
\$\begingroup\$

C / C++

Website: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html


Simply compiling code with -Wall -Wextra -pedantic options catches quite a number of potential or actual problems.

\$\endgroup\$
10
\$\begingroup\$

Python

Python uses Python Enhancement Proposals (PEPs) to improve Python, ranging from style guides to feature requests. There are linter's for a few of these:

There is also "PEP 7 -- Style Guide for C Code". But this does not seem to have a linter.


There are also some other analysis tools:

  • pylinth
  • Pyflakesh
  • PyCheckerh

    Warning: This imports the code to analyse it.

  • Flake8h

    Combines Pyflakes and pycodestyle into one tool.

  • Prospectorh

    Combines all of: pylint, Pyflakes, pycodestyle, pydocstyle and more tools.


There are also ways to incorporating some of the above tools into different editors. For a small list of incorporations:

These are good to make sure your answers are PEP 8 compliant, and so there are no contradictions when saying to follow PEP 8. However using the tools from the above sections will give a report that you can comment from.

\$\endgroup\$
  • 2
    \$\begingroup\$ The python IDE pycharm automatically checks for pep-8 compliance and also can suggest a number of conformity changes \$\endgroup\$ – Vogel612 May 2 '15 at 12:13
  • \$\begingroup\$ black is the new kid on the block of Python code formatting \$\endgroup\$ – bhathiya-perera Jul 10 at 15:01
9
\$\begingroup\$

C#

  • StyleCop (free)

    It can be run from inside of Visual Studio or integrated into an MSBuild project.

  • ReSharper (commercial)

    A paid Visual Studio extension (possibility for open-source "community" license though) with a free 30-day trial.

  • FxCop (free)

    Can be run standalone, but later versions are bundled into Visual Studio as the "Code Analysis" feature.

\$\endgroup\$
9
\$\begingroup\$

VB6 / VBA6 / VBA7 (x86/x64)

  • Rubberduck is a free (beer & speech), open-source add in for the VBE IDE maintained by several members of the and community here on Code Review. For more info see the tag.

Features include static code analysis, code metrics, refactoring tools, Smart Indenter, a unit testing framework, and more.

Direct Link to Code Inspection Documentation

\$\endgroup\$
7
\$\begingroup\$

JavaScript

For JavaScript, there are a few options:

  • JSLint (the original, created by Douglas Crockford)
  • JSHint (a community-driven fork of JSLint)
  • ESLint (an ES6-compatible fork of JSHint. Necessary if you want to lint ES6 code).

In all cases, if you're using a transpiler like Babel or Traceur, you should run the linter before the transpile step. Don't lint compiled code.

Note that all major browsers and other interpreters support the "use strict"; directive in code, and will ensure that many common mistakes in code are identified before running the code. See: What does “use strict” do in JavaScript, and what is the reasoning behind it?

\$\endgroup\$
5
\$\begingroup\$

VB.NET

  • ReSharper (commercial)

    A paid Visual Studio extension (possibility for open-source "community" license though) with a free 30-day trial.

\$\endgroup\$
  • \$\begingroup\$ As of the Visual Studio 2015 RC, some of this functionality is built in. visualstudio.com/news/vs2015-vs#ManLang \$\endgroup\$ – RubberDuck May 1 '15 at 15:55
  • 1
    \$\begingroup\$ @RubberDuck Yeah, VS ended up implementing an actual "rename" refactoring, too. But VS just isn't the same without R# ;) \$\endgroup\$ – Mathieu Guindon May 1 '15 at 15:56
5
\$\begingroup\$

HTML5, XHTML, CSS

Tool: Markup validation checker

Also, there are beautifiers to help improve formatting, CodeBeautify.org has a good one.

\$\endgroup\$
5
\$\begingroup\$

Delphi

Tool: FixInsight (commercial)

Website: https://www.tmssoftware.com/site/fixinsight.asp

\$\endgroup\$
4
\$\begingroup\$

Java

Java lint tools are usually dependent of the IDE you develop in. All the major IDE's (Eclipse, IntelliJ, Netbeans, etc. - alphabetical order) have mechanisms in place for not only checking for lint-like problems, but also for fixing them too.

Features to expect from your IDE - identification of, and correction of:

  1. automatic code formatting (indentation, brace positions, line-wrapping, etc.)
  2. redundant code, or impossible code
  3. incomplete documentation
  4. variable and function name "shadowing"
  5. and much, much more.

Standalone tools:

  1. PMD
  2. FindBugs
\$\endgroup\$
  • 2
    \$\begingroup\$ There is also a bunch of maven plugins that can be used \$\endgroup\$ – Simon Forsberg May 2 '15 at 11:14
  • \$\begingroup\$ Funny enough running PMD on PMD reveals the exact thing it's trying to correct ;) \$\endgroup\$ – Bono May 6 '15 at 14:35
4
\$\begingroup\$

Regex:

JS-Flavored

Offline-Tools:

  • RegexBuddy - commercial regex-development helper tool, supporting a multitude of regex-flavors and programming languages
\$\endgroup\$
3
\$\begingroup\$

PHP

Online:

Plugins:

You can also use the native php_check_syntax from an IDE or command line.

\$\endgroup\$
3
\$\begingroup\$

Perl

Plugins:

Or natively using B::Lint module.

\$\endgroup\$
3
\$\begingroup\$

C

Although not currently actively developed, this free, open-source software provides error checking that can be enhanced with in-code commenting.

\$\endgroup\$
3
\$\begingroup\$

Bash, Shell

Online:

Plugins:

\$\endgroup\$
3
\$\begingroup\$

SQL

General:

SQL Server / Transact-SQL

Online: SQL-Format.org

Natively: SET SHOWPLAN_XML

MySQL

Online: MySQL Syntax Check

Natively: EXPLAIN

PostgreSQL & PL/pgSQL

Plugin: pg-validator

Natively: EXPLAIN

SQLite

Plugin: sqllogictest

Natively: EXPLAIN

Oracle:

Natively: EXPLAIN

\$\endgroup\$
3
\$\begingroup\$

Objective-C

Plugins:

These should also work for C/C++

\$\endgroup\$
  • 4
    \$\begingroup\$ Can I be on this list? \$\endgroup\$ – nhgrif May 1 '15 at 18:49
  • 1
    \$\begingroup\$ The real question is: Do you really want to? ;-) \$\endgroup\$ – Phrancis May 1 '15 at 19:01
  • \$\begingroup\$ Note Atom.io is a text-editor. linter is a plug-in for Atom providing the necessary checks for many, many languages. \$\endgroup\$ – Mast May 1 '15 at 21:44
  • \$\begingroup\$ Good catch, I corrected it! \$\endgroup\$ – Phrancis May 1 '15 at 21:48
2
\$\begingroup\$

XML

Online validators:

Plugins:

\$\endgroup\$
2
\$\begingroup\$

jQuery

Plugins:

You can also use JavaScriptLint.com.

\$\endgroup\$
2
\$\begingroup\$

Lisp

Plugins:

\$\endgroup\$
2
\$\begingroup\$

MongoDB

Plugins:

Or natively use validate

\$\endgroup\$
2
\$\begingroup\$

Lua

Plugins:

\$\endgroup\$
2
\$\begingroup\$

Ruby

Gems:

  • rubocop is probably the most popular

But there are many more each with emphasis on different things (style, code complexity, etc.).

Online:

  • Don't know if this counts as it's more like CI, but there's always CodeClimate (also works for JavaScript, PHP, and Python)
\$\endgroup\$
2
\$\begingroup\$

Swift

\$\endgroup\$
2
\$\begingroup\$

Go

  • golint Style and convention problems with documentation, naming, dead-code analysis, and more.
  • go fmt adjusts your go code to conform to standard Go style (indentation, spacing, import orders, etc.)
  • go vet does deeper static analysis on your code and determines if there are more serious problems in the code, including poorly structured printf statements, etc.

In addition, there are profiling tools, race-condition-analysis tools, and so on that work at program runtime.

\$\endgroup\$
2
\$\begingroup\$

Scala

Style checker plug-in: ScalaStyle.org

\$\endgroup\$
2
\$\begingroup\$

JSON

Online validator: JSONLint.com

They also have a free Pro Version

For those at the linux command line, use jq for all sorts of cool features.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .