ESLint equivalents in Elm

Seedling 🌱
Planted Jul 2, 2022 - Last tended Jun 16, 2023
Contributor picture
Author: @jfmengels
Contributor picture
Editor: @supermario
If you're coming to Elm from the JavaScript world, you may be familiar with
ESLint
which is a community standard for modern JS projects, and be looking for the equivalent in Elm.
When it comes to enforcing code style and formatting, the Elm community uses
elm-format
, the de-facto Elm code formatter. It is similar to
Prettier
for JavaScript in that it rewrites your code in a very opinionated and predictable way, but in Elm it is more widely adopted and is not configurable at all.
elm-format
covers close to all stylistic rules that one would use ESLint for, therefore you don't need a linter to enforce code style.
When it comes to detecting bugs and problematic patterns, it may seem obvious a linter is needed for modern JavaScript. However in Elm, simply compiling your Elm code will give you a very large portion of what ESLint does! It is therefore not necessary to use a linter in your project, as we'll show in the next section.
It is however still a good idea to use a linter to raise the quality of your code and make it more maintainable. For that, we recommend using
elm-review
.

Comparing with ESLint

We claimed that you didn't need most of what ESLint provides. To explain why, we've categorized how all of the
core ESLint rules
translate to Elm.

228/263 (87%) of the core ESLint rules aren't necessary in Elm:

SHOW ONLY RECOMMENDED ESLINT RULES
FOCUS
84 (32%) are rules are already enforced by either Elm's design, or the compiler.
FOCUS
51 (19%) are related to code style issues handled by elm-format.
FOCUS
93 (35%) relate to features or problems that are not part of the Elm language.
That leaves 35 (13%) static analysis rules applicable in Elm, of which:
FOCUS
16 (6%) exist in elm-review already.
FOCUS
1 (0%) are ideas for elm-format.
FOCUS
18 (7%) could be expressed, but are probably bad ideas in Elm.
Possible problems - 56 (21%)
These rules relate to possible logic errors in code:
ESLint rule
Description
Elm advice
enforce `return` statements in callbacks of array methods

Elm functions always return values, there is no optional return statement.

constructor-super
(recommended)
require `super()` calls in constructors

There are no classes in Elm.

for-direction
(recommended)
enforce " for " loop update clause moving the counter in the right direction.

There are no loops in Elm.

getter-return
(recommended)
enforce `return` statements in getters

Elm functions always return values, there is no optional return statement.

disallow using an async function as a Promise executor

There is no async/await syntax in Elm.

disallow `await` inside of loops

There is no async/await syntax in Elm.

no-class-assign
(recommended)
disallow reassigning class members

There are no classes in Elm.

no-compare-neg-zero
(recommended)
disallow comparing against -0

🪄 This is automatically handled by elm-format.

no-cond-assign
(recommended)
disallow assignment operators in conditional expressions

Elm doesn't support mutating values.

no-const-assign
(recommended)
disallow reassigning `const` variables

Elm forbids name shadowing.

no-constant-condition
(recommended)
disallow constant expressions in conditions

There are corresponding elm-review rules for this:

disallow returning value from constructor

There are no classes in Elm.

no-control-regex
(recommended)
disallow control characters in regular expressions

There is no special support for regular expressions in Elm.

no-debugger
(recommended)
disallow the use of `debugger`

The compiler will report the usages of debugging functions in optimized mode.

no-dupe-args
(recommended)
disallow duplicate arguments in `function` definitions

Elm forbids name shadowing.

no-dupe-class-members
(recommended)
disallow duplicate class members

There are no classes in Elm.

no-dupe-else-if
(recommended)
disallow duplicate conditions in if-else-if chains

There are corresponding elm-review rules for this:

no-dupe-keys
(recommended)
disallow duplicate keys in object literals

The compiler will report duplicate keys.

no-duplicate-case
(recommended)
disallow duplicate case labels

This would be handled using Elm's pattern matching syntax, which makes sure that all cases are handled.

disallow duplicate module imports

🪄 This is automatically handled by elm-format.

disallow empty character classes in regular expressions

There is no special support for regular expressions in Elm.

no-empty-pattern
(recommended)
disallow empty destructuring patterns

There are corresponding elm-review rules for this:

no-ex-assign
(recommended)
disallow reassigning exceptions in `catch` clauses

There are no exceptions in Elm.

no-fallthrough
(recommended)
disallow fallthrough of `case` statements

All Elm expressions are expressions, and there are no individual statements.

no-func-assign
(recommended)
disallow reassigning `function` declarations

Elm doesn't support mutating values.

no-import-assign
(recommended)
disallow assigning to imported bindings

Elm doesn't support mutating values.

no-inner-declarations
(recommended)
disallow variable or `function` declarations in nested blocks

The underlying scoping problems don't apply to Elm.

no-invalid-regexp
(recommended)
disallow invalid regular expression strings in `RegExp` constructors

There is no special support for regular expressions in Elm.

disallow irregular whitespace

🪄 This is automatically handled by elm-format.

no-loss-of-precision
(recommended)
disallow literal numbers that lose precision

🪄 This is automatically handled by elm-format.

disallow characters which are made with multiple code points in character class syntax

There is no special support for regular expressions in Elm.

no-new-symbol
(recommended)
disallow `new` operators with the `Symbol` object

There are no symbols in Elm.

no-obj-calls
(recommended)
disallow calling global object properties as functions

Only functions are allowed to be called.

disallow returning values from Promise executor functions

These functions don't exist in Elm.

no-prototype-builtins
(recommended)
disallow calling some `Object.prototype` methods directly on objects

There are no prototypes in Elm.

no-self-assign
(recommended)
disallow assignments where both sides are exactly the same

The compiler will report variable definitions that depend on themselves, and there is no syntax for re-assigning variables.

disallow comparisons where both sides are exactly the same

There are corresponding elm-review rules for this:

no-setter-return
(recommended)
disallow returning values from setters

There are no getters or setters in Elm.

no-sparse-arrays
(recommended)
disallow sparse arrays

All elements in a List must be of the same type in Elm, you can't have empty elements in a list.

disallow template literal placeholder syntax in regular strings

There are no template literals in Elm.

no-this-before-super
(recommended)
disallow `this`/`super` before calling `super()` in constructors

There are no classes in Elm.

no-undef
(recommended)
disallow the use of undeclared variables unless mentioned in `/*global */` comments

Can't use variables not in scope.

disallow confusing multiline expressions

🪄 This is automatically handled by elm-format.

disallow unmodified loop conditions

There are no loops in Elm.

no-unreachable
(recommended)
disallow unreachable code after `return`, `throw`, `continue`, and `break` statements

All Elm expressions are expressions, and there are no individual statements.

disallow loops with a body that allows only one iteration

There are no loops in Elm.

no-unsafe-finally
(recommended)
disallow control flow statements in `finally` blocks

There are no exceptions in Elm.

no-unsafe-negation
(recommended)
disallow negating the left operand of relational operators

There are no relational operators in Elm.

disallow use of optional chaining in contexts where the `undefined` value is not allowed

There is no null or undefined in Elm.

disallow unused private class members

There are no classes in Elm.

no-unused-vars
(recommended)
disallow unused variables

There are corresponding elm-review rules for this:

disallow the use of variables before they are defined

Elm allows using things before they are defined

disallow useless backreferences in regular expressions

There is no special support for regular expressions in Elm.

disallow assignments that can lead to race conditions due to usage of `await` or `yield`

Elm doesn't support mutating values.

use-isnan
(recommended)
require calls to `isNaN()` when checking for `NaN`

There is only a single function to check for NaN.

valid-typeof
(recommended)
enforce comparing `typeof` expressions against valid strings

This would be handled using Elm's pattern matching syntax, which makes sure that all cases are handled.

Suggestions - 145 (55%)
These rules suggest alternate ways of doing things:
ESLint rule
Description
Elm advice
enforce getter and setter pairs in objects and classes

There are no getters or setters in Elm.

require braces around arrow function bodies

All Elm expressions are expressions, and there are no individual statements.

enforce the use of variables within the scope they are defined

Can't use variables not in scope.

enforce camelcase naming convention

There are corresponding elm-review rules for this:

enforce or disallow capitalization of the first letter of a comment

There is as of yet no equivalent to this rule in the Elm community.

enforce that class methods utilize `this`

There are no concept of this in Elm.

enforce a maximum cyclomatic complexity allowed in a program

There are corresponding elm-review rules for this:

require `return` statements to either always or never specify values

All Elm expressions are expressions, and there are no individual statements.

enforce consistent naming when capturing the current execution context

There are no concept of this in Elm.

enforce consistent brace style for all control statements

All Elm expressions are expressions, and there are no individual statements.

require `default` cases in `switch` statements

This would be handled using Elm's pattern matching syntax, which makes sure that all cases are handled.

enforce default clauses in switch statements to be last

This would be handled using Elm's pattern matching syntax, which makes sure that all cases are handled.

enforce default parameters to be last

Each Elm function has a fixed number of parameters and takes a fixed number of arguments when called.

enforce dot notation whenever possible

There are no dynamic or computed properties in Elm.

require the use of `===` and `!==`

There is only one operator to check for equality.

require function names to match the name of the variable or property to which they are assigned

Elm forbids name shadowing.

require or disallow named `function` expressions

Anonymous functions can't have names.

enforce the consistent use of either `function` declarations or expressions

There is only one way of defining functions.

require grouped accessor pairs in object literals and classes

There are no getters or setters in Elm.

require `for-in` loops to include an `if` statement

There are no loops in Elm.

disallow specified identifiers

There is as of yet no equivalent to this rule in the Elm community.

enforce minimum and maximum identifier lengths

There is as of yet no equivalent to this rule in the Elm community.

require identifiers to match a specified regular expression

There are corresponding elm-review rules for this:

require or disallow initialization in variable declarations

All values need to be initialized when they are declared.

enforce a maximum number of classes per file

There are no classes in Elm.

enforce a maximum depth that blocks can be nested

There are corresponding elm-review rules for this:

enforce a maximum number of lines per file

There is as of yet no equivalent to this rule in the Elm community.

enforce a maximum number of lines of code in a function

There is as of yet no equivalent to this rule in the Elm community.

enforce a maximum depth that callbacks can be nested

There is as of yet no equivalent to this rule in the Elm community.

enforce a maximum number of parameters in function definitions

There is as of yet no equivalent to this rule in the Elm community.

enforce a maximum number of statements allowed in function blocks

All Elm expressions are expressions, and there are no individual statements.

enforce a particular style for multiline comments

There is as of yet no equivalent to this rule in the Elm community.

require constructor names to begin with a capital letter

There are no classes in Elm.

disallow the use of `alert`, `confirm`, and `prompt`

These functions don't exist in Elm.

disallow `Array` constructors

There are no classes in Elm.

disallow bitwise operators

The underlying problem would result in a type error.

disallow the use of `arguments.caller` or `arguments.callee`

These functions don't exist in Elm.

no-case-declarations
(recommended)
disallow lexical declarations in case clauses

This would be handled using Elm's pattern matching syntax, which makes sure that all cases are handled.

disallow arrow functions where they could be confused with comparisons

This would be a type error.

disallow the use of `console`

These functions don't exist in Elm.

disallow `continue` statements

There are no labels in Elm.

no-delete-var
(recommended)
disallow deleting variables

There is no delete keyword.

disallow division operators explicitly at the beginning of regular expressions

There is no special support for regular expressions in Elm.

disallow `else` blocks after `return` statements in `if` statements

All Elm expressions are expressions, and there are no individual statements.

no-empty
(recommended)
disallow empty block statements

All Elm expressions are expressions, and there are no individual statements.

disallow empty functions

All Elm expressions are expressions, and there are no individual statements.

disallow `null` comparisons without type-checking operators

There is no null or undefined in Elm.

disallow the use of `eval()`

There is no eval function in Elm.

disallow extending native types

Elm doesn't allow you to extend existing types.

disallow unnecessary calls to `.bind()`

There are no concept of this in Elm.

no-extra-boolean-cast
(recommended)
disallow unnecessary boolean casts

There are corresponding elm-review rules for this:

disallow unnecessary labels

There are no labels in Elm.

no-extra-semi
(recommended)
disallow unnecessary semicolons

All Elm expressions are expressions, and there are no individual statements.

disallow leading or trailing decimal points in numeric literals

Floating numbers need to have numbers before the dot.

no-global-assign
(recommended)
disallow assignments to native objects or read-only global variables

Elm doesn't support mutating values.

disallow shorthand type conversions

There is no syntax for coercion. Elm requires explicit type conversions.

disallow declarations in the global scope

Can't use variables not in scope.

disallow the use of `eval()`-like methods

There is no eval function in Elm.

disallow inline comments after code

🪄 This is automatically handled by elm-format.

disallow `this` keywords outside of classes or class-like objects

There are no concept of this in Elm.

disallow the use of the `__iterator__` property

There are no loops in Elm.

disallow labels that share a name with a variable

There are no labels in Elm.

disallow labeled statements

There are no labels in Elm.

disallow unnecessary nested blocks

All Elm expressions are expressions, and there are no individual statements.

disallow `if` statements as the only statement in `else` blocks

Can't have a lonely if that doesn't have an else

disallow function declarations that contain unsafe references inside loop statements

There are no loops in Elm.

disallow magic numbers

There is as of yet no equivalent to this rule in the Elm community.

disallow mixed binary operators

This is a proposal for elm-format.

disallow use of chained assignment expressions

Can't declare multiple variables at once.

disallow multiline strings

This is not a valid way of writing strings in Elm.

disallow negated conditions

There is as of yet no equivalent to this rule in the Elm community.

disallow nested ternary expressions

There are no ternary operators, only if expressions which are more readable when nested.

disallow `new` operators outside of assignments or comparisons

There are no classes in Elm.

disallow `new` operators with the `Function` object

There are no classes in Elm.

disallow `Object` constructors

There are no classes in Elm.

disallow `new` operators with the `String`, `Number`, and `Boolean` objects

There are no classes in Elm.

disallow `\8` and `\9` escape sequences in string literals

There is no syntax for literal octal or binary in Elm.

no-octal
(recommended)
disallow octal literals

There is no syntax for literal octal or binary in Elm.

disallow octal escape sequences in string literals

There is no syntax for literal octal or binary in Elm.

disallow reassigning `function` parameters

Elm forbids name shadowing.

disallow the unary operators `++` and `--`

Elm doesn't support mutating values.

disallow the use of the `__proto__` property

There are no prototypes in Elm.

no-redeclare
(recommended)
disallow variable redeclaration

Elm forbids name shadowing.

no-regex-spaces
(recommended)
disallow multiple spaces in regular expressions

There is no special support for regular expressions in Elm.

disallow specified names in exports

There is as of yet no equivalent to this rule in the Elm community.

disallow specified global variables

There is as of yet no equivalent to this rule in the Elm community.

disallow specified modules when loaded by `import`

There are corresponding elm-review rules for this:

disallow certain properties on certain objects

There is as of yet no equivalent to this rule in the Elm community.

disallow specified syntax

There is as of yet no equivalent to this rule in the Elm community.

disallow assignment operators in `return` statements

All Elm expressions are expressions, and there are no individual statements.

disallow unnecessary `return await`

There is no async/await syntax in Elm.

disallow `javascript:` urls

The virtual-dom implementation prevents the execution of arbitrary JavaScript code.

disallow comma operators

There is no such comma operator in Elm.

disallow variable declarations from shadowing variables declared in the outer scope

Elm forbids name shadowing.

disallow identifiers from shadowing restricted names

Elm forbids name shadowing.

disallow ternary operators

There are no ternary operators, only if expressions.

disallow throwing literals as exceptions

There are no exceptions in Elm.

disallow initializing variables to `undefined`

There is no null or undefined in Elm.

disallow the use of `undefined` as an identifier

There is no null or undefined in Elm.

disallow dangling underscores in identifiers

There is as of yet no equivalent to this rule in the Elm community.

disallow ternary operators when simpler alternatives exist

There are no ternary operators, only if expressions.

disallow unused expressions

All Elm expressions are expressions, and there are no individual statements.

no-unused-labels
(recommended)
disallow unused labels

There are no labels in Elm.

disallow unnecessary calls to `.call()` and `.apply()`

These functions don't exist in Elm.

no-useless-catch
(recommended)
disallow unnecessary `catch` clauses

There are no exceptions in Elm.

disallow unnecessary computed property keys in objects and classes

There are no dynamic or computed properties in Elm.

disallow unnecessary concatenation of literals or template literals

There are corresponding elm-review rules for this:

disallow unnecessary constructors

There are no classes in Elm.

no-useless-escape
(recommended)
disallow unnecessary escape characters

🪄 This is automatically handled by elm-format.

disallow renaming import, export, and destructured assignments to the same name

There are corresponding elm-review rules for this:

disallow redundant return statements

All Elm expressions are expressions, and there are no individual statements.

require `let` or `const` instead of `var`

Variables are not defined using a keyword.

disallow `void` operators

There is no void operator.

disallow specified warning terms in comments

There are corresponding elm-review rules for this:

no-with
(recommended)
disallow `with` statements

There is no with command.

require or disallow method and property shorthand syntax for object literals

Shorthands are not available

enforce variables to be declared either together or separately in functions

Every variable is declared separately.

require or disallow newlines around variable declarations

🪄 This is automatically handled by elm-format.

require or disallow assignment operator shorthand where possible

Elm doesn't support mutating values.

require using arrow functions for callbacks

There is only one way to define function expressions.

require `const` declarations for variables that are never reassigned after declared

Variables are not defined using a keyword.

require destructuring from arrays and/or objects

There is as of yet no equivalent to this rule in the Elm community.

disallow the use of `Math.pow` in favor of the `**` operator

There is only the (^) operator in the core language.

enforce using named capture group in regular expression

There is no special support for regular expressions in Elm.

disallow `parseInt()` and `Number.parseInt()` in favor of binary, octal, and hexadecimal literals

There is no syntax for literal octal or binary in Elm.

disallow use of `Object.prototype.hasOwnProperty.call()` and prefer use of `Object.hasOwn()`

Available properties are always known, no need for these functions.

disallow using Object.assign with an object literal as the first argument and prefer the use of object spread instead.

Elm doesn't support mutating values.

require using Error objects as Promise rejection reasons

There are no exceptions in Elm.

disallow use of the `RegExp` constructor in favor of regular expression literals

There is only one function to create a regular expression.

require rest parameters instead of `arguments`

Each Elm function has a fixed number of parameters and takes a fixed number of arguments when called.

require spread operators instead of `.apply()`

Each Elm function has a fixed number of parameters and takes a fixed number of arguments when called.

require template literals instead of string concatenation

There are no template literals in Elm.

require quotes around object literal property names

Property names can't be surrounded with quotes.

enforce the consistent use of the radix argument when using `parseInt()`

Each Elm function has a fixed number of parameters and takes a fixed number of arguments when called.

disallow async functions which have no `await` expression

There is no async/await syntax in Elm.

enforce the use of `u` flag on RegExp

There is no special support for regular expressions in Elm.

require-yield
(recommended)
require generator functions to contain `yield`

There are no generators in Elm.

enforce sorted import declarations within modules

🪄 This is automatically handled by elm-format.

require object keys to be sorted

There are corresponding elm-review rules for this:

require variables within the same declaration block to be sorted

There are corresponding elm-review rules for this:

enforce consistent spacing after the `//` or `/*` in a comment

There is as of yet no equivalent to this rule in the Elm community.

require or disallow strict mode directives

There is no strict mode in Elm.

require symbol descriptions

There are no symbols in Elm.

require `var` declarations be placed at the top of their containing scope

This is somewhat enforced by the design of let declarations.

require or disallow " Yoda " conditions

Elm doesn't support mutating values.

Layout & Formatting - 62 (24%)
These rules care about how the code looks rather than how it executes:
ESLint rule
Description
Elm advice
enforce linebreaks after opening and before closing array brackets

🪄 This is automatically handled by elm-format.

enforce consistent spacing inside array brackets

🪄 This is automatically handled by elm-format.

enforce line breaks after each array element

🪄 This is automatically handled by elm-format.

require parentheses around arrow function arguments

🪄 This is automatically handled by elm-format.

enforce consistent spacing before and after the arrow in arrow functions

🪄 This is automatically handled by elm-format.

disallow or enforce spaces inside of blocks after opening block and before closing block

There are no blocks in Elm.

enforce consistent brace style for blocks

There are no blocks in Elm.

require or disallow trailing commas

There are no trailing commas in Elm.

enforce consistent spacing before and after commas

🪄 This is automatically handled by elm-format.

enforce consistent comma style

🪄 This is automatically handled by elm-format.

enforce consistent spacing inside computed property brackets

There are no dynamic or computed properties in Elm.

enforce consistent newlines before and after dots

🪄 This is automatically handled by elm-format.

require or disallow newline at the end of files

🪄 This is automatically handled by elm-format.

require or disallow spacing between function identifiers and their invocations

🪄 This is automatically handled by elm-format.

enforce line breaks between arguments of a function call

🪄 This is automatically handled by elm-format.

enforce consistent line breaks inside function parentheses

🪄 This is automatically handled by elm-format.

enforce consistent spacing around `*` operators in generator functions

There are no generators in Elm.

enforce the location of arrow function bodies

🪄 This is automatically handled by elm-format.

enforce consistent indentation

🪄 This is automatically handled by elm-format.

enforce the consistent use of either double or single quotes in JSX attributes

There is no support for a JSX-like syntax in Elm.

enforce consistent spacing between keys and values in object literal properties

🪄 This is automatically handled by elm-format.

enforce consistent spacing before and after keywords

🪄 This is automatically handled by elm-format.

enforce position of line comments

🪄 This is automatically handled by elm-format.

enforce consistent linebreak style

🪄 This is automatically handled by elm-format.

require empty lines around comments

🪄 This is automatically handled by elm-format.

require or disallow an empty line between class members

There are no classes in Elm.

enforce a maximum line length

There is as of yet no equivalent to this rule in the Elm community.

enforce a maximum number of statements allowed per line

All Elm expressions are expressions, and there are no individual statements.

enforce newlines between operands of ternary expressions

🪄 This is automatically handled by elm-format.

enforce or disallow parentheses when invoking a constructor with no arguments

There are no classes in Elm.

require a newline after each call in a method chain

🪄 This is automatically handled by elm-format.

disallow unnecessary parentheses

🪄 This is automatically handled by elm-format.

disallow mixed spaces and tabs for indentation

Tabs are forbidden in Elm.

disallow multiple spaces

🪄 This is automatically handled by elm-format.

disallow multiple empty lines

🪄 This is automatically handled by elm-format.

disallow all tabs

Tabs are forbidden in Elm.

disallow trailing whitespace at the end of lines

🪄 This is automatically handled by elm-format.

disallow whitespace before properties

🪄 This is automatically handled by elm-format.

enforce the location of single-line statements

🪄 This is automatically handled by elm-format.

enforce consistent line breaks after opening and before closing braces

🪄 This is automatically handled by elm-format.

enforce consistent spacing inside braces

🪄 This is automatically handled by elm-format.

enforce placing object properties on separate lines

🪄 This is automatically handled by elm-format.

enforce consistent linebreak style for operators

🪄 This is automatically handled by elm-format.

require or disallow padding within blocks

🪄 This is automatically handled by elm-format.

require or disallow padding lines between statements

🪄 This is automatically handled by elm-format.

enforce the consistent use of either backticks, double, or single quotes

🪄 This is automatically handled by elm-format.

enforce spacing between rest and spread operators and their expressions

There is no spread operator.

require or disallow semicolons instead of ASI

All Elm expressions are expressions, and there are no individual statements.

enforce consistent spacing before and after semicolons

All Elm expressions are expressions, and there are no individual statements.

enforce location of semicolons

All Elm expressions are expressions, and there are no individual statements.

enforce consistent spacing before blocks

🪄 This is automatically handled by elm-format.

enforce consistent spacing before `function` definition opening parenthesis

🪄 This is automatically handled by elm-format.

enforce consistent spacing inside parentheses

🪄 This is automatically handled by elm-format.

require spacing around infix operators

🪄 This is automatically handled by elm-format.

enforce consistent spacing before or after unary operators

🪄 This is automatically handled by elm-format.

enforce spacing around colons of switch statements

🪄 This is automatically handled by elm-format.

require or disallow spacing around embedded expressions of template strings

There are no template literals in Elm.

require or disallow spacing between template tags and their literals

There are no template literals in Elm.

require or disallow Unicode byte order mark (BOM)

🪄 This is automatically handled by elm-format.

require parentheses around immediate `function` invocations

There is no iife in Elm.

require parenthesis around regex literals

🪄 This is automatically handled by elm-format.

require or disallow spacing around the `*` in `yield*` expressions

There are no generators in Elm.