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.

share
1  
This should also help: en.wikipedia.org/wiki/List_of_tools_for_static_code_analysis – JaDogg May 2 '15 at 4:34
    

24 Answers 24

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.

share

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.

share

VBA

share

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?

share
    
Don't forget jshint either – Flambino May 1 '15 at 23:08
    
@Flambino - thanks, I added it, but I am also sure there's more. Feel free to edit to improve in whatever way you see fit. – rolfl May 2 '15 at 2:27

Python

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

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


There are also some other analysis tools:

  • pylint
  • pyflakes
  • pychecker

    Warning: This imports the code to analyse it.

  • flake8

    Combines pyflakes and pep8 into one tool.

  • Prospector

    Combines all of: pylint, pyflakes, pep8, pep257 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 PEP8 complient, and so there are no contradictions when saying to follow PEP8. However using the tools from the above sections will give a report that you can comment from.

share
2  
The python IDE pycharm automatically checks for pep-8 compliance and also can suggest a number of conformity changes – Vogel612 May 2 '15 at 12:13

HTML5, XHTML, CSS

Tool: Markup validation checker

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

share

VB.NET

  • ReSharper (commercial)

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

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

Delphi

Tool: FixInsight (commercial)

Website: http://sourceoddity.com/fixinsight/

share

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
share
2  
There is also a bunch of maven plugins that can be used – Simon Forsberg May 2 '15 at 11:14
    
Funny enough running PMD on PMD reveals the exact thing it's trying to correct ;) – Bono May 6 '15 at 14:35

PHP

Online:

Plugins:

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

share

C

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

share

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

share

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)
share

Regex:

JS-Flavored

Offline-Tools:

  • RegexBuddy - commercial regex-development helper tool, supporting a multitude of regex-flavors and programming languages
share

Objective-C

Plugins:

These should also work for C/C++

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

Perl

Plugins:

Or natively using B::Lint module.

share

Lua

Plugins:

share

JSON

Online validator: JSONLint.com

They also have a free Pro Version

share

Scala

Style checker plug-in: ScalaStyle.org

Online evaluator: SimplyScala.com

share

Bash, Shell

Online:

Plugins:

share

MongoDB

Plugins:

Or natively use validate

share

You must log in to answer this question.

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