31
\$\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\$
3

26 Answers 26

15
\$\begingroup\$

Python

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

There is also "PEP 7 -- Style Guide for C Code [in the C implementation of Python]". But this does not seem to have a linter.


When starting a new project you might choose to do this:

  • "$ ruff check" -- fast and "not too picky" linter, you should probably do what it suggests, or let --fix do that for you.
  • "$ isort ." -- "I sort imports so you don't have to", per PEP8, so just do it.
  • "$ black ." -- will reformat source code, in an opinionated way.

The first two are no-brainers, they won't hurt anything. Adopting black can be a bit more of a hurdle, but once you bite the bullet there's all manner of trivial pull-request code review remarks that simply never arise any more. Blacked code will typically lint clean.

Start with "$ black -S ." followed by "git diff". The -S says don't turn single- into double- quote strings, basically noise when you're viewing the initial diffs. Go through some commits, plus one or two PRs, and watch the S/N ratio improve.


There are also some other analysis 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\$
0
    10
    \$\begingroup\$

    C / C++

    • Clang's Static Analyzer, a free static analyzer based on Clang.

    • Coverity, a commercial static analyzer, free for open source developers.

    • Cppcheck, an open-source static analyzer.

    • CppDepend, a commercial static analyzer based on Clang.

    • GCC, free compiler that closely follows C and C++ standards.

    • Valgrind, run-time analyser that is particularly good for the kind of memory errors common in these languages.


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

    \$\endgroup\$
      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\$
        0
          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\$
          0
            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\$
            2
            • \$\begingroup\$As of the Visual Studio 2015 RC, some of this functionality is built in. visualstudio.com/news/vs2015-vs#ManLang\$\endgroup\$CommentedMay 1, 2015 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\$CommentedMay 1, 2015 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
                • 2
                  \$\begingroup\$There is also a bunch of maven plugins that can be used\$\endgroup\$CommentedMay 2, 2015 at 11:14
                • \$\begingroup\$Funny enough running PMD on PMD reveals the exact thing it's trying to correct ;)\$\endgroup\$
                  – Bono
                  CommentedMay 6, 2015 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\$
                0
                  4
                  \$\begingroup\$

                  Perl

                  Plugins:

                  Or natively using B::Lint module.

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

                    PHP

                    Online:

                    Plugins:

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

                    \$\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
                            • 4
                              \$\begingroup\$Can I be on this list?\$\endgroup\$
                              – nhgrif
                              CommentedMay 1, 2015 at 18:49
                            • 1
                              \$\begingroup\$The real question is: Do you really want to? ;-)\$\endgroup\$
                              – Phrancis
                              CommentedMay 1, 2015 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\$
                              – MastMod
                              CommentedMay 1, 2015 at 21:44
                            • \$\begingroup\$Good catch, I corrected it!\$\endgroup\$
                              – Phrancis
                              CommentedMay 1, 2015 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\$
                                            0
                                              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.

                                                Start asking to get answers

                                                Find the answer to your question by asking.

                                                Ask question

                                                Explore related questions

                                                See similar questions with these tags.