Lint source code with ESLint
org.openrewrite.codemods.ESLint
Run ESLint across the code to fix common static analysis issues in the code. This requires the code to have an existing ESLint configuration.
Recipe source
GitHub, Issue Tracker, Maven Central
This recipe is available under the Moderne Source Available License.
Options
Type | Name | Description | Example |
---|---|---|---|
List | patterns | Optional. The lint target files. This can contain any of file paths, directory paths, and glob patterns. | lib/**/*.js |
String | parser | Optional. Parser used by ESLint to parse the source files. Defaults to @typescript-eslint/parser . See ESLint documentation for more details. | esprima |
List | parserOptions | Optional. A list of parser options for ESLint. The format is key: value . Defaults to ecmaVersion: "latest", ecmaFeatures: { jsx: true }, sourceType: "module" . See ESLint documentation for more details. | ecmaVersion: 6, ecmaFeatures: { jsx: true } |
Boolean | allowInlineConfig | Optional. Whether inline config comments are allowed. Defaults to false . See ESLint documentation for more details. | true |
List | envs | Optional. A list of env mappings for ESLint. The format is key: value . | browser: true |
List | globals | Optional. Define global variables for rules that require knowledge of these. | var1, var2: writable |
List | plugins | Optional. A list of plugins for ESLint. | @typescript-eslint, prettier |
List | extend | Optional. A list of extends for ESLint. | eslint:recommended, prettier |
List | rules | Optional. List of rules to be checked by ESLint. Optionally, the severity and other rule options can also be specified as e.g. off , warn or ["error", "always"] . The severity off is useful when the rule is declared by an extended shareable config. For more information, see the ESLint documentation | eqeqeq: warn, multiline-comment-style: ["error", "starred-block"], prettier/prettier |
Boolean | fix | Optional. Automatically fix violations when possible. Defaults to true . | false |
String | configFile | Optional. Allows specifying the full ESLint configuration file contents as multiline JSON. See ESLint documentation for more details. |
Note that this will override any other configuration options. | {}
|
Used by
This recipe is used as part of the following composite recipes:
- A story should not have a redundant name property
- Deprecated hierarchy separator in title property
- Disallow Jasmine globals
- Disallow
new Array()
. - Disallow
parseInt()
andNumber.parseInt()
in favor of binary, octal, and hexadecimal literals - Disallow alias methods
- Disallow arrow functions where they could be confused with comparisons
- Disallow awaiting non-promise values.
- Disallow classes that only have static members.
- Disallow comparing
undefined
usingtypeof
. - Disallow else blocks after return statements in if statements
- Disallow equal signs explicitly at the beginning of regular expressions
- Disallow extra closing tags for components without children
- Disallow extra closing tags for components without children
- Disallow if statements as the only statement in else blocks
- Disallow initializing variables to undefined
- Disallow leading or trailing decimal points in numeric literals
- Disallow member access from
await
expression. - Disallow missing parentheses around multiline JSX
- Disallow missing parentheses around multiline JSX
- Disallow multiple empty lines
- Disallow multiple spaces between inline JSX props
- Disallow multiple spaces between inline JSX props
- Disallow multiple spaces
- Disallow negated conditions.
- Disallow nested ternary expressions.
- Disallow number literals with zero fractions or dangling dots.
- Disallow or enforce spaces inside of blocks after opening block and before closing block in
<template>
- Disallow or enforce spaces inside of blocks after opening block and before closing block
- Disallow problematic leaked values from being rendered
- Disallow redundant return statements
- Disallow renaming import, export, and destructured assignments to the same name
- Disallow returning/yielding
Promise.resolve()
/reject()
inasync
functions or promise callbacks. - Disallow shorthand type conversions
- Disallow target="_blank" attribute without rel="noreferrer"
- Disallow ternary operators when simpler alternatives exist
- Disallow the use of
Math.pow
in favor of the ** operator - Disallow the use of the
null
literal. - Disallow trailing whitespace at the end of lines
- Disallow unnecessary JSX expressions when literals alone are sufficient or enforce JSX expressions on literals in JSX children or attributes
- Disallow unnecessary JSX expressions when literals alone are sufficient or enforce JSX expressions on literals in JSX children or attributes
- Disallow unnecessary calls to
.bind()
- Disallow unnecessary computed property keys in objects and classes
- Disallow unnecessary fragments
- Disallow unnecessary labels
- Disallow unnecessary mustache interpolations
- Disallow unnecessary parentheses in
<template>
- Disallow unnecessary parentheses
- Disallow unnecessary semicolons
- Disallow unnecessary spread.
- Disallow unnecessary v-bind directives
- Disallow unreadable array destructuring.
- Disallow unsupported Vue.js syntax on the specified version
- Disallow usage of this in template
- Disallow usage of unknown DOM property
- Disallow use of
Object.prototype.hasOwnProperty.call()
and prefer use ofObject.hasOwn(
) - Disallow use of deprecated functions from before version 27
- Disallow useless
undefined
. - Disallow useless array
length
check. - Disallow useless fallback when spreading in object literals.
- Disallow using
Object.assign
with an object literal as the first argument and prefer the use of object spread instead - Disallow using jest.mock() factories without an explicit type parameter
- Disallow using the
this
argument in array methods. - Disallow whitespace before properties
- Do not define a title in meta
- Do not use a
for
loop that can be replaced with afor-of
loop. - Do not use leading/trailing space between
console.log
parameters. - Do not use testing-library directly on stories
- Enforce JSX indentation
- Enforce JSX indentation
- Enforce PascalCase for user-defined JSX components
- Enforce Promise or callback style in nextTick
- Enforce a convention in module import order
- Enforce a newline after import statements
- Enforce a particular style for multiline comments
- Enforce a specific function type for function components
- Enforce a specific parameter name in catch clauses.
- Enforce better string content.
- Enforce boolean attributes notation in JSX
- Enforce closing bracket location in JSX
- Enforce closing bracket location in JSX
- Enforce closing tag location for multiline JSX
- Enforce closing tag location for multiline JSX
- Enforce combining multiple
Array#push()
into one call. - Enforce consistent brace style for all control statements
- Enforce consistent brace style for blocks in
<template>
- Enforce consistent brace style for blocks
- Enforce consistent brace style for case clauses.
- Enforce consistent case for text encoding identifiers.
- Enforce consistent comma style in
<template>
- Enforce consistent comma style
- Enforce consistent indentation in HTML comments
- Enforce consistent indentation in
<script>
- Enforce consistent indentation
- Enforce consistent line breaks after opening and before closing braces in
<template>
- Enforce consistent line breaks after opening and before closing braces
- Enforce consistent line breaks inside function parentheses
- Enforce consistent linebreak style for operators in
<template>
- Enforce consistent linebreak style for operators
- Enforce consistent linebreak style
- Enforce consistent linebreaks in curly braces in JSX attributes and expressions
- Enforce consistent linebreaks in curly braces in JSX attributes and expressions
- Enforce consistent newlines before and after dots in
<template>
- Enforce consistent newlines before and after dots
- Enforce consistent relative URL style.
- Enforce consistent spacing after the `//` or `/*` in a comment
- Enforce consistent spacing around `*` operators in generator functions
- Enforce consistent spacing before `function` definition opening parenthesis
- Enforce consistent spacing before and after commas in
<template>
- Enforce consistent spacing before and after commas
- Enforce consistent spacing before and after keywords in
<template>
- Enforce consistent spacing before and after keywords
- Enforce consistent spacing before and after semicolons
- Enforce consistent spacing before and after the arrow in arrow functions in
<template>
- Enforce consistent spacing before and after the arrow in arrow functions
- Enforce consistent spacing before blocks
- Enforce consistent spacing before or after unary operators in
<template>
- Enforce consistent spacing before or after unary operators
- Enforce consistent spacing between keys and values in object literal properties in
<template>
- Enforce consistent spacing between keys and values in object literal properties
- Enforce consistent spacing inside array brackets in
<template>
- Enforce consistent spacing inside array brackets
- Enforce consistent spacing inside braces in
<template>
- Enforce consistent spacing inside braces
- Enforce consistent spacing inside computed property brackets
- Enforce consistent spacing inside parentheses in
<template>
- Enforce consistent spacing inside parentheses
- Enforce consistent usage of destructuring assignment of props, state, and context
- Enforce correct
Error
subclassing. - Enforce dot notation whenever possible in
<template>
- Enforce dot notation whenever possible
- Enforce explicitly comparing the length or size property of a value.
- Enforce line breaks after each array element in
<template>
- Enforce line breaks after each array element
- Enforce line breaks after opening and before closing block-level tags
- Enforce line breaks between arguments of a function call
- Enforce linebreaks after opening and before closing array brackets in
<template>
- Enforce linebreaks after opening and before closing array brackets
- Enforce location of semicolons
- Enforce lowercase test names
- Enforce maximum of props on a single line in JSX
- Enforce maximum of props on a single line in JSX
- Enforce new lines between multi-line properties in Vue components
- Enforce newlines between operands of ternary expressions in
<template>
- Enforce newlines between operands of ternary expressions
- Enforce no spaces between braces.
- Enforce or ban the use of inline type-only markers for named imports
- Enforce or disallow capitalization of the first letter of a comment
- Enforce or disallow parentheses when invoking a constructor with no arguments
- Enforce or disallow spaces around equal signs in JSX attributes
- Enforce or disallow spaces around equal signs in JSX attributes
- Enforce or disallow spaces inside of curly braces in JSX attributes and expressions
- Enforce or disallow spaces inside of curly braces in JSX attributes and expressions
- Enforce order of attributes
- Enforce order of component top-level elements
- Enforce order of component top-level elements
- Enforce order of defineEmits and defineProps compiler macros
- Enforce order of properties in components
- Enforce placing object properties on separate lines in
<template>
- Enforce placing object properties on separate lines
- Enforce propTypes declarations alphabetical sorting
- Enforce proper case for numeric literals.
- Enforce proper position of the first property in JSX
- Enforce proper position of the first property in JSX
- Enforce props alphabetical sorting
- Enforce props alphabetical sorting
- Enforce props indentation in JSX
- Enforce props indentation in JSX
- Enforce props with default values to be optional
- Enforce shorthand or standard form for React fragments
- Enforce sorted import declarations within modules
- Enforce spacing around colons of switch statements
- Enforce spacing before closing bracket in JSX
- Enforce spacing between rest and spread operators and their expressions
- Enforce specific casing for the component naming style in template
- Enforce static class names order
- Enforce test and it usage conventions
- Enforce that props are read-only
- Enforce the casing of component name in components options
- Enforce the consistent use of either backticks, double, or single quotes
- Enforce the consistent use of either double or single quotes in JSX attributes
- Enforce the location of arrow function bodies
- Enforce the location of single-line statements
- Enforce the style of numeric separators by correctly grouping digits.
- Enforce the use of Unicode escapes instead of hexadecimal escapes.
- Enforce the use of
Buffer.from()
andBuffer.alloc()
instead of the deprecatednew Buffer()
. - Enforce the use of
Math.trunc()
instead of bitwise operators. - Enforce the use of
new
for all builtins, exceptString
,Number
,Boolean
,Symbol
, andBigInt
. - Enforce throwing
TypeError
in type checking conditions. - Enforce unified line brake in HTML comments
- Enforce unified spacing in HTML comments
- Enforce use of defineOptions instead of default export.
- Enforce using the digits argument with
Number#toFixed()
. - Enforce using the separator argument with
Array#join()
. - Enforce v-for directive's delimiter style
- Enforce valid titles
- Enforce variables to be declared either together or separately in functions
- Enforce whitespace in and around the JSX opening and closing brackets
- Enforce whitespace in and around the JSX opening and closing brackets
- Enforce writing style for handlers in v-on directives
- Enforces consistent spacing inside TypeScript type generics
- Ensure all imports appear before other statements
- Expect space before the type declaration in the named tuple
- Fix whitespace-insensitive template indentation.
- Forbid empty named import
- Forbid import of modules using absolute paths
- Forbid import statements with CommonJS module.exports
- Forbid importing packages through relative paths
- Forbid namespace (a.k.a. "wildcard"
*
) imports. - Forbid repeated import of the same module in multiple places
- Forbid unnecessary path segments in import and require statements
- Format TypeScript using ESLint Prettier plugin
- Improve regexes by making them shorter, consistent, and safer.
- Indentation for binary operators
- Interactions should be awaited
- Lifecycle methods should be methods on the prototype, not class fields
- Lint TypeScript code using ESLint
- Prefer JavaScript modules (ESM) over CommonJS.
- Prefer
.addEventListener()
and.removeEventListener()
over on-functions. - Prefer
.at()
method for index access andString#charAt()
. - Prefer
.before()
over.insertBefore()
,.replaceWith()
over.replaceChild()
, prefer one of.before()
,.after()
,.append()
or.prepend()
overinsertAdjacentText()
andinsertAdjacentElement()
. - Prefer
.find()
and.findLast()
over the first or last element from.filter()
. - Prefer
.flatMap()
over.map().flat()
. - Prefer
.includes()
over.indexOf()
andArray#some()
when checking for existence or non-existence. - Prefer
.querySelector()
over.getElementById()
,.querySelectorAll()
over.getElementsByClassName()
and.getElementsByTagName()
. - Prefer
.some()
over.filter().length
check and.{find,findLast}()
. - Prefer
Array#flat()
over legacy techniques to flatten arrays. - Prefer
Array#{indexOf,lastIndexOf}()
overArray#{findIndex,findLastIndex}()
when looking for the index of an item. - Prefer
Date.now()
to get the number of milliseconds since the Unix Epoch. - Prefer
KeyboardEvent#key
overKeyboardEvent#keyCode
. - Prefer
Node#append()
overNode#appendChild()
. - Prefer
Number
static properties over global ones. - Prefer
Reflect.apply()
overFunction#apply()
. - Prefer
RegExp#test()
overString#match()
andRegExp#exec()
. - Prefer
Set#has()
overArray#includes()
when checking for existence or non-existence. - Prefer
String#replaceAll()
over regex searches with the global flag. - Prefer
String#slice()
overString#substr()
andString#substring()
. - Prefer
String#startsWith()
&String#endsWith()
overRegExp#test()
. - Prefer
String#trimStart()
/String#trimEnd()
overString#trimLeft()
/String#trimRight()
. - Prefer
childNode.remove()
overparentNode.removeChild(childNode)
. - Prefer
export…from
when re-exporting. - Prefer
for…of
over theforEach
method. - Prefer
switch
over multipleelse-if
. - Prefer await expect(...).resolves over expect(await ...) syntax
- Prefer borrowing methods from the prototype instead of the instance.
- Prefer default parameters over reassignment.
- Prefer mock resolved/rejected shorthands for promises
- Prefer modern Math APIs over legacy patterns.
- Prefer negative index over
.length - index
when possible. - Prefer omitting the catch binding parameter.
- Prefer reading a JSON file as a buffer.
- Prefer ternary expressions over simple
if-else
statements. - Prefer the spread operator over
Array.from()
,Array#concat()
,Array#{slice,toSpliced}()
andString#split('')
. - Prefer using
.dataset
on DOM elements over calling attribute methods. - Prefer using
Object.fromEntries()
to transform a list of key-value pairs into an object. - Prefer using
Set#size
instead ofArray#length
. - Prefer using
String
,Number
,BigInt
,Boolean
, andSymbol
directly. - Prefer using the
node:
protocol when importing Node.js builtin modules. - Prevent abbreviations.
- Recommended ESLint Styling
- Recommended Jest code cleanup
- Recommended Storybook code cleanup
- Recommended svelte code cleanup
- Recommended vue code cleanup
- Require
Array.isArray()
instead ofinstanceof Array
. - Require
let
orconst
instead ofvar
- Require
new
when throwing an error. - Require a newline after each call in a method chain
- Require a specific member delimiter style for interfaces and type literals
- Require braces around arrow function bodies
- Require consistent spacing around type annotations
- Require const declarations for variables that are never reassigned after declared
- Require destructuring from arrays and/or objects
- Require empty lines around comments
- Require escape sequences to use uppercase values.
- Require key attribute for conditionally rendered repeated components
- Require one JSX element per line
- Require one JSX element per line
- Require or disallow "Yoda" conditions
- Require or disallow Unicode byte order mark (BOM)
- Require or disallow an empty line between class members
- Require or disallow assignment operator shorthand where possible
- Require or disallow logical assignment operator shorthand
- Require or disallow method and property shorthand syntax for object literals in
<template>
- Require or disallow method and property shorthand syntax for object literals
- Require or disallow newline at the end of files
- Require or disallow newlines around variable declarations
- Require or disallow newlines between sibling tags in template
- Require or disallow padding lines between blocks
- Require or disallow padding lines between statements
- Require or disallow padding lines in component definition
- Require or disallow padding within blocks
- Require or disallow semicolons instead of ASI
- Require or disallow spacing around embedded expressions of template strings in
<template>
- Require or disallow spacing around embedded expressions of template strings
- Require or disallow spacing around the `` in `yield` expressions
- Require or disallow spacing between function identifiers and their invocations in
<template>
- Require or disallow spacing between function identifiers and their invocations. Alias of `function-call-spacing`.
- Require or disallow spacing between function identifiers and their invocations
- Require or disallow spacing between template tags and their literals
- Require or disallow strict mode directives
- Require or disallow trailing commas in
<template>
- Require or disallow trailing commas
- Require or prevent a new line after jsx elements and expressions.
- Require or prevent a new line after jsx elements and expressions
- Require parentheses around arrow function arguments
- Require parentheses around immediate `function` invocations
- Require parenthesis around regex literals
- Require quotes around object literal property names in
<template>
- Require quotes around object literal property names
- Require spacing around infix operators in
<template>
- Require spacing around infix operators
- Require static class names in template to be in a separate class attribute
- Require template literals instead of string concatenation in
<template>
- Require template literals instead of string concatenation
- Require the use of === and !== in
<template>
- Require the use of
===
and!==
- Require using .only and .skip over f and x
- Require using arrow functions for callbacks
- Require variables within the same declaration block to be sorted
- Stories should use PascalCase
- Story files should have a default export
- Suggest using jest.spyOn()
- Suggest using test.todo
- Suggest using the built-in comparison matchers
- Suggest using toBe() for primitive literals
- Suggest using toContain()
- Suggest using toHaveLength()
- Use destructured variables over properties.
- Use expect from @storybook/jest
- disallow dynamic slot name
- disallow spaces around equal signs in attribute
- disallow to use of the store itself as an operand. Need to use $ prefix or get function.
- disallow unnecessary mustache interpolations
- enforce consistent indentation
- enforce consistent spacing after the <!-- and before the --> in a HTML comment
- enforce order of attributes
- enforce quotes style of HTML attributes
- enforce self-closing style
- enforce the location of first attribute
- enforce the maximum number of attributes per line
- enforce unified spacing in mustache
- enforce use of shorthand syntax in attribute
- enforce use of shorthand syntax in directives
- require class directives instead of ternary expressions
- require or disallow a space before tag's closing brackets
- require style directives instead of style attribute
Usage
This recipe has no required configuration options. It can be activated by adding a dependency on org.openrewrite.recipe:rewrite-codemods
in your build file or by running a shell command (in which case no build changes are needed):
- Gradle
- Gradle init script
- Maven POM
- Maven Command Line
- Moderne CLI
- Add the following to your
build.gradle
file:
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("org.openrewrite.codemods.ESLint")
setExportDatatables(true)
}
repositories {
mavenCentral()
}
dependencies {
rewrite("org.openrewrite.recipe:rewrite-codemods:0.16.1")
}
- Run
gradle rewriteRun
to run the recipe.
- Create a file named
init.gradle
in the root of your project.
initscript {
repositories {
maven { url "https://plugins.gradle.org/m2" }
}
dependencies { classpath("org.openrewrite:plugin:7.12.1") }
}
rootProject {
plugins.apply(org.openrewrite.gradle.RewritePlugin)
dependencies {
rewrite("org.openrewrite.recipe:rewrite-codemods:0.16.1")
}
rewrite {
activeRecipe("org.openrewrite.codemods.ESLint")
setExportDatatables(true)
}
afterEvaluate {
if (repositories.isEmpty()) {
repositories {
mavenCentral()
}
}
}
}
- Run the recipe.
gradle --init-script init.gradle rewriteRun
- Add the following to your
pom.xml
file:
<project>
<build>
<plugins>
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>6.15.0</version>
<configuration>
<exportDatatables>true</exportDatatables>
<activeRecipes>
<recipe>org.openrewrite.codemods.ESLint</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-codemods</artifactId>
<version>0.16.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
- Run
mvn rewrite:run
to run the recipe.
You will need to have Maven installed on your machine before you can run the following command.
mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-codemods:RELEASE -Drewrite.activeRecipes=org.openrewrite.codemods.ESLint -Drewrite.exportDatatables=true
You will need to have configured the Moderne CLI on your machine before you can run the following command.
mod run . --recipe ESLint
If the recipe is not available locally, then you can install it using:
mod config recipes jar install org.openrewrite.recipe:rewrite-codemods:0.16.1
See how this recipe works across multiple open-source repositories
Run this recipe on OSS repos at scale with the Moderne SaaS.

The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.
Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.
Data Tables
- ESLintMessages
- SourcesFileResults
- SourcesFileErrors
- RecipeRunStats
ESLint messages
org.openrewrite.codemods.ESLintMessages
Errors and warnings as reported by ESLint.
Column Name | Description |
---|---|
Source Path | The source path of the file. |
Rule ID | ESLint Rule ID. |
Severity | Either Warning or Error . |
Fatal | Is this a fatal error (like a parse error). |
Message | The message created by the rule. |
Line | Line in source file this message pertains to. |
Column | Column in source file this message pertains to. |
Source files that had results
org.openrewrite.table.SourcesFileResults
Source files that were modified by the recipe run.
Column Name | Description |
---|---|
Source path before the run | The source path of the file before the run. null when a source file was created during the run. |
Source path after the run | A recipe may modify the source path. This is the path after the run. null when a source file was deleted during the run. |
Parent of the recipe that made changes | In a hierarchical recipe, the parent of the recipe that made a change. Empty if this is the root of a hierarchy or if the recipe is not hierarchical at all. |
Recipe that made changes | The specific recipe that made a change. |
Estimated time saving | An estimated effort that a developer to fix manually instead of using this recipe, in unit of seconds. |
Cycle | The recipe cycle in which the change was made. |
Source files that errored on a recipe
org.openrewrite.table.SourcesFileErrors
The details of all errors produced by a recipe run.
Column Name | Description |
---|---|
Source path | The file that failed to parse. |
Recipe that made changes | The specific recipe that made a change. |
Stack trace | The stack trace of the failure. |
Recipe performance
org.openrewrite.table.RecipeRunStats
Statistics used in analyzing the performance of recipes.
Column Name | Description |
---|---|
The recipe | The recipe whose stats are being measured both individually and cumulatively. |
Source file count | The number of source files the recipe ran over. |
Source file changed count | The number of source files which were changed in the recipe run. Includes files created, deleted, and edited. |
Cumulative scanning time (ns) | The total time spent across the scanning phase of this recipe. |
99th percentile scanning time (ns) | 99 out of 100 scans completed in this amount of time. |
Max scanning time (ns) | The max time scanning any one source file. |
Cumulative edit time (ns) | The total time spent across the editing phase of this recipe. |
99th percentile edit time (ns) | 99 out of 100 edits completed in this amount of time. |
Max edit time (ns) | The max time editing any one source file. |