Questions tagged [eslint]

The pluggable linting utility for JavaScript and related frameworks.

ESLint is a JavaScript linting tool.

It differs from other linters in that every rule is a separate plugin and you can add more during runtime.

User interface

ESLint is a CLI tool and runs directly from a terminal/command prompt. It may be used as a standalone tool or integrated with an automated task runner such as Grunt (through plugins such as eslint-grunt and grunt-eslint). It can also be integrated with majority of modern editors that support JavaScript. For the list of integrations see ESLint site

Resources


See also

6637 questions
96
votes
21 answers

React site warning: The href attribute requires a valid address. Provide a valid, navigable address as the href value jsx-a11y/anchor-is-valid

I am getting a warning on a React site I built ./src/components/layout/Navbar.js [1] Line 31: The href attribute requires a valid address. Provide a valid, navigable address as the href value jsx-a11y/anchor-is-valid on the following code: …
msm1089
  • 1,314
  • 1
  • 8
  • 19
96
votes
4 answers

ESLint ignore specific rule for a specific directory

Is it possible with ESLint to ignore one specific rule for an entire directory? In my case, I would like to ignore import/prefer-default-export for a directory named commonComponents
Kevin Amiranoff
  • 13,440
  • 11
  • 59
  • 90
96
votes
2 answers

allow semi colons in javascript eslint

I have following .eslintrc { "extends": "standard" } I have following code in my javascript file import React from 'react'; Above line of code is incorrect according to eslint. It gives following complain. "; Extra…
Om3ga
  • 30,465
  • 43
  • 141
  • 221
94
votes
3 answers

Error while loading rule '@typescript-eslint/dot-notation'

Today I run eslint,two script "lint-staged": "lint-staged", "eslint": "eslint --ext .tsx,.ts --fix ./src -c .eslintrc.js", When I run npm run eslint // it's ok When I run npm run lint-staged // it's wrong lint-staged's result ; > lint-staged ❯…
leofu
  • 941
  • 1
  • 6
  • 6
93
votes
6 answers

eslint throws `no-undef` errors when linting Jest test files

I'm using Jest to write some specs and ESLint to lint the styling. For my foo.spec.js tests, eslint keeps throwing the following errors. It seems to think that jest, beforeEach, afterEach, etc... are not defined in that file. 11:1 error …
user2490003
  • 10,706
  • 17
  • 79
  • 155
90
votes
6 answers

Avoid no-shadow eslint error with mapDispatchToProps

I have the following component that triggers a no-shadow ESlint error on the FilterButton props. import { setFilter } from '../actions/filter'; function FilterButton({ setFilter }) { return (
Kerumen
  • 4,193
  • 2
  • 19
  • 33
90
votes
6 answers

Nice way to get rid of no-unused-expressions linter error with chai

In my Chai tests I often find myself wanting to use their assertions that are something like .to.be.empty, .to.be.true e.t.c., because I find them to be cleaner to read than .to.be.length(1) or .to.be.equal(true). However, this breaks my linter (I'm…
Ben Hare
  • 4,365
  • 5
  • 27
  • 44
89
votes
3 answers

eslint object-shorthand error with variable passed in

I have the following function that is setting up a select2 plugin, which needs selects to stay open if they are multiple but closed if they are not: function setUpSelects($selects, closeOnSelect) { $selects.each((i, item) => { const $item =…
Pete
  • 57,112
  • 28
  • 117
  • 166
88
votes
2 answers

ESLint's "no-undef" rule is calling my use of Underscore an undefined variable

I am using Grunt as my Build Tool and ESLint as my linting tool for an app I am working on. I am also using the Underscore Node package, and have made use of it in my app. Unfortunately, when I run ESLint on my code, it thinks that _ is an undefined…
turner
  • 1,667
  • 2
  • 13
  • 21
87
votes
2 answers

JSX not allowed in files with extension '.tsx'eslint(react/jsx-filename-extension)

In .tsx file, why does eslint report: JSX not allowed in files with extension '.tsx'eslint(react/jsx-filename-extension) How can I update the eslint config can resolve this message:
Baochang Li
  • 891
  • 1
  • 6
  • 7
87
votes
5 answers

How can I suppress the "No files matching the pattern" message in ESLint?

In my CI setup, I have a test that runs eslint against all JS files. If no JS files exist, it's currently throwing an error. I'd prefer if it'd succeeded when no JS files exist. Is this possible? $ eslint "./src/assets/scripts/**/*.js" Oops!…
JacobTheDev
  • 17,318
  • 25
  • 95
  • 158
87
votes
5 answers

How to tell eslint that you prefer single quotes around your strings

I'm new to eslint and it's spewing out a ton of errors telling me to use doublequotes: error Strings must use doublequote That's not my preference. I've got an .eslintrc file set up with the basics: { "env": { "node": 1 } } I'd like to…
Antonius Bloch
  • 2,311
  • 2
  • 14
  • 14
86
votes
8 answers

How to add a keyboard listener to my onClick handler?

I have the following: class MyTextArea extends React.Component { handleClick = () => { this.focus(); } focus = () => this.ref.focus; handleRef = (component) => { this.ref = component; }; render() { return (
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
85
votes
27 answers

Error when deploying react app and it keeps sayings << Plugin "react" was conflicted between "package.json » eslint-config-react-app » >>

I have been having a little bit of issues when deploying my create react app, as it fails to compile and tells me Plugin "react" was conflicted between "package.json » eslint-config-react-app » I was wondering if somebody has encountered the same…
Ruben
  • 875
  • 1
  • 3
  • 6
84
votes
6 answers

Prettier 3.0.0 TypeError: prettier.resolveConfig.sync is not a function

The error triggered after I run this command: npx eslint "the code directory" This is the first several line of the error TypeError: prettier.resolveConfig.sync is not a function Occurred while linting *the first line of the first code directory* …
Stephen Senjaya
  • 855
  • 1
  • 2
  • 6