Skip to main content

Questions tagged [eslint]

The pluggable linting utility for JavaScript and related frameworks.

Filter by
Sorted by
Tagged with
1983 votes
14 answers
1.6m views

Turning off eslint rule for a specific line

In order to turn off linting rule for a particular line in JSHint we use the following rule: /* jshint ignore:start*/ $scope.someVar = ConstructorFunction(); /* jshint ignore:end */ I have been ...
runtimeZero's user avatar
  • 27.5k
856 votes
23 answers
1.2m views

How to fix missing dependency warning when using useEffect React Hook

With React 16.8.6 (it was good on previous version 16.8.3), I get this error when I attempt to prevent an infinite loop on a fetch request: ./src/components/BusinessesList.js Line 51: React Hook ...
russ's user avatar
  • 8,603
802 votes
19 answers
707k views

Turning off eslint rule for a specific file

Is it possible to turn off the eslint rule for the whole file? Something such as: // eslint-disable-file no-use-before-define (Analogous to eslint-disable-line.) It happens to me quite often, that ...
Tomas Kulich's user avatar
  • 15.2k
381 votes
29 answers
461k views

"parserOptions.project" has been set for @typescript-eslint/parser

I created a new React Native project with --template typescript I deleted the template directory which came as part of the boilerplate. I then proceeded to add ESLint: module.exports = { parser: &...
Dan's user avatar
  • 8,534
379 votes
21 answers
410k views

Eslint: How to disable "unexpected console statement" in Node.js?

I'm using eslint with Sublime Text 3 and I am writing gulpfile.js. /*eslint-env node*/ var gulp = require('gulp'); gulp.task('default', function(){ console.log('default task'); }); But eslint ...
Jean Y.C. Yang's user avatar
376 votes
24 answers
431k views

Using eslint with typescript - Unable to resolve path to module

I have this import in my file app.spec.ts: import app from './app'; Which causes this Typescript error 2:17 error Unable to resolve path to module './app' import/no-unresolved ./app.ts does exist,...
Maxime Dupré's user avatar
374 votes
14 answers
202k views

How to use ESLint with Jest

I'm attempting to use the ESLint linter with the Jest testing framework. Jest tests run with some globals like jest, which I'll need to tell the linter about; but the tricky thing is the directory ...
Retsam's user avatar
  • 32.6k
366 votes
11 answers
241k views

ESLint: "error Parsing error: The keyword 'const' is reserved"

I am getting this error from ESLint: error Parsing error: The keyword 'const' is reserved from this code: const express = require('express'); const app = express(); const _ = require('underscore');...
opike's user avatar
  • 7,485
334 votes
6 answers
288k views

Disable eslint rules for folder

Is there a way to disable specific rules for a folder? For example, I don't want to have required JSDoc comments for all my test files in the test folder. Is there a way to do this?
DevNebulae's user avatar
  • 4,826
329 votes
25 answers
506k views

Expected linebreaks to be 'LF' but found 'CRLF' linebreak-style

When using eslint in the gulp project i have encountered a problem with error like this Expected linebreaks to be 'LF' but found 'CRLF' linebreak-style and I am using Windows environment for the ...
SaiKiran's user avatar
  • 6,474
327 votes
19 answers
670k views

ESLint Parsing error: Unexpected token

With this code: import React from 'react'; import { Link } from 'react-router'; import { View, NavBar } from 'amazeui-touch'; import * as Pages from '../components'; const { Home, ...Components } =...
DongYao's user avatar
  • 3,311
304 votes
8 answers
229k views

Object.hasOwnProperty() yields the ESLint 'no-prototype-builtins' error: how to fix?

I am using the following logic to get the i18n string of the given key. export function i18n(key) { if (entries.hasOwnProperty(key)) { return entries[key]; } else if (typeof (Canadarm) !== '...
booYah's user avatar
  • 3,049
278 votes
9 answers
198k views

No restricted globals

I am using React and Redux to develop a webapp and when I started up my project I got this: Line 13: Unexpected use of 'location' no-restricted-globals Search for the keywords to learn more about ...
Martin Nordström's user avatar
273 votes
14 answers
207k views

Parsing error: Cannot read file '.../tsconfig.json'.eslint

The error Parsing error: Cannot read file '.../tsconfig.json'.eslint shows in all .ts files in the src folder including index.ts. I have no idea how to set up configs. The issue just shows a red line ...
Darren Zou's user avatar
  • 3,601
272 votes
10 answers
106k views

TSLint extension throwing errors in my Angular application running in Visual Studio Code

I recently started seeing, what seems like, TSLint errors. They look like this: Not using the local TSLint version found for '/Users/myname/myproject/client/src/app/likes/likee/likee.component.ts'. ...
chuckd's user avatar
  • 14.1k
252 votes
7 answers
126k views

ESLint: TypeError: this.libOptions.parse is not a function

I was getting started with Next.js on WebStorm 2022.2.1 Build #WS-222.3739.57. I created a new Next.js project with TypeScript enabled, and that's all. The error is shown below: TypeError: this....
Thebluedragon's user avatar
247 votes
2 answers
120k views

How to disable multiple rules for eslint nextline

I have this code: const subTotal = orderInfo.details.reduce((acc, cv) => acc += Number(cv.price) * Number(cv.quantity), 0); I want to disable two ESLint types of checks for this line, no-return-...
shubham choudhary's user avatar
244 votes
25 answers
533k views

React eslint error missing in props validation

I have the next code, eslint throw: react/prop-types onClickOut; is missing in props validation react/prop-types children; is missing in props validation propTypes was defined but eslint does not ...
cristian camilo cedeño gallego's user avatar
232 votes
6 answers
148k views

ESLint - "window" is not defined. How to allow global variables in package.json

I am assigning a property to the global window object, but when I run eslint, I get this: "window" is not defined I see this here in the eslint docs: the following defines window as a ...
chevin99's user avatar
  • 5,038
229 votes
12 answers
116k views

ESLint - 'process' is not defined

I am using ESLinter for a simple node project. Below is the only code I have in index.js: const express = require('express'); const app = express(); app.get('/', (req, res) => { res.send({ ...
ArunKolhapur's user avatar
  • 6,555
228 votes
2 answers
58k views

What's the difference between prettier-eslint, eslint-plugin-prettier and eslint-config-prettier?

I want to use Prettier and ESLint together, but I experienced some conflicts just by using them one after another. I see that there are these three packages that seem to allow them to be used in ...
Yangshun Tay's user avatar
  • 52.2k
227 votes
40 answers
507k views

ESLint not working in VS Code?

ESLint is not working for me in VS Code. I have the plugin installed in VS Code, and ESLint itself as a developer dependency in my package.json, which I have installed as well. I modified the ...
John Landon's user avatar
  • 2,421
208 votes
7 answers
543k views

How to run eslint --fix from npm script

I am trying to add lint-fix in my package.json. My basic lint is "lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs" I did try "lint-fix": "eslint --fix --ext .js,.vue src test/unit/...
Marek Urbanowicz's user avatar
205 votes
12 answers
205k views

Typescript eslint - Missing file extension "ts" import/extensions

I have a simple Node/Express app made with Typescript. And eslint give me the error Missing file extension "ts" for "./lib/env" import/extensions Here is my .eslintrc file { ...
Nolat's user avatar
  • 2,181
202 votes
13 answers
171k views

ESLint - Error: Must use import to load ES Module

I am currently setting up a boilerplate with React, TypeScript, styled components, Webpack, etc., and I am getting an error when trying to run ESLint: Error: Must use import to load ES Module Here ...
red house 87's user avatar
  • 2,265
201 votes
7 answers
116k views

module is not defined and process is not defined in eslint in visual studio code

I have installed eslint in my machine and i have used visual studio code i have certain modules and process to be exported When i try to use "module" or "process" it shows it was working fine before. ...
MaTHwoG's user avatar
  • 2,041
197 votes
5 answers
79k views

ESLint Unexpected use of isNaN

I'm trying to use the isNaN global function inside an arrow function in a Node.js module but I'm getting this error: [eslint] Unexpected use of 'isNaN'. (no-restricted-globals) This is my code: ...
Elias Garcia's user avatar
  • 7,202
194 votes
2 answers
153k views

ESLint couldn't find the config "prettier" to extend from

I am trying to format my code using eslint but when I run npm run lint -f I get this output: Oops! Something went wrong! :( ESLint: 6.8.0. ESLint couldn't find the config "prettier&...
Reynier Rivero's user avatar
192 votes
6 answers
105k views

Eslint says all enums in Typescript app are "already declared in the upper scope"

Starting a new application, I installed eslint and configured it with the following configs, but every time I create an enum it says it had already been defined. Even nonsense strings. Other variable ...
Adam James's user avatar
  • 4,141
190 votes
17 answers
113k views

'React' was used before it was defined

I am working with create-react-app + typescript + eslint application and during build have such error: Line 1:8: 'React' was used before it was defined @typescript-eslint/no-use-before-define Code ...
Alexey Nazarov's user avatar
189 votes
2 answers
194k views

Understanding the React Hooks 'exhaustive-deps' lint rule

I'm having a hard time understanding the 'exhaustive-deps' lint rule. I already read this post and this post but I could not find an answer. Here is a simple React component with the lint issue: const ...
Logan Wlv's user avatar
  • 3,574
178 votes
6 answers
280k views

Component definition is missing display name react/display-name

How do I add a display name to this? export default () => <Switch> <Route path="/login" exact component={LoginApp}/> <Route path="/faq" exact component={FAQ}/> <...
David's user avatar
  • 3,903
167 votes
4 answers
213k views

Disable typescript-eslint plugin rule (no-explicit-any) with inline comment

I have an eslint error that comes from the @typescript-eslint plugin. Unexpected any. Specify a different type.eslint(@typescript-eslint/no-explicit-any) This is the no-implicit-any rule. In just ...
cham's user avatar
  • 9,934
167 votes
14 answers
231k views

ESLint - Configuring "no-unused-vars" for TypeScript

I use ESLint in all of my TypeScript projects with the following settings: "extends": ["airbnb", "prettier", 'plugin:vue/recommended'], "plugins": ["...
Rins's user avatar
  • 1,961
165 votes
13 answers
244k views

How to avoid no-param-reassign when setting a property on a DOM object

I have a method which's main purpose is to set a property on a DOM object function (el) { el.expando = {}; } I use AirBnB's code style which makes ESLint throw a no-param-reassign error: error ...
Lukas's user avatar
  • 10.1k
162 votes
7 answers
55k views

How to disable JavaScript build error in Visual Studio 2017?

I just updated Visual Studio 2017 from RC to final. I didn’t get the following error but recently I get this error. In building the project, I get the following error and it prevents the web project ...
Mohammad Dayyan's user avatar
161 votes
8 answers
85k views

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 ...
Stephen Senjaya's user avatar
161 votes
2 answers
112k views

Global variables in Javascript and ESLint

I have got multiple javascript files and I have defined some global variable in a file which loads before the others. As a consequence all of the files loaded after the first have access to the global ...
marco_sap's user avatar
  • 1,809
160 votes
4 answers
97k views

How is ESLint integrated into Create React App?

When I run npx create-react-app some-name, a bare-bones React project is created for me. When I then peek into package.json, there seems to be some evidence of ESLint being present, as there is this: &...
lkbaerenfaenger's user avatar
159 votes
19 answers
102k views

Line 0: Parsing error: Cannot read property 'map' of undefined

Currently starting up the server on my client side, the error above is what I have been getting. I am using TypeScript, ReactJS, ESLint. I can't seem to go forward since this error has been haunting ...
Jon Hernandez's user avatar
157 votes
8 answers
132k views

JSX not allowed in files with extension ' .js' with eslint-config-airbnb

I've installed eslint-config-airbnb that is supposed to pre configure ESLINT for React: Our default export contains all of our ESLint rules, including ECMAScript 6+ and React. It requires eslint, ...
Mendes's user avatar
  • 18.2k
150 votes
17 answers
216k views

ESLint with React gives `no-unused-vars` errors

I've setup eslint & eslint-plugin-react. When I run ESLint, the linter returns no-unused-vars errors for each React component. I'm assuming it's not recognizing that I'm using JSX or React ...
Don P's user avatar
  • 62.5k
150 votes
5 answers
97k views

ESLint dollar($) is not defined. (no-undef)

I added ESLint to my project. Everything is fine, except when it comes to the symbol $. $("#ID").hide(); I get this error: [eslint] '$' is not defined. (no-undef) My .eslintrc.json (note: ...
spbsmile's user avatar
  • 1,605
150 votes
3 answers
75k views

How to disable warn about some unused params, but keep "@typescript-eslint/no-unused-vars" rule

I want to disable no unused params warning in some cases but keep "unused vars" rule. For example here I would want to leave arguments in place to see what is passed to resolver: const Query ...
ZiiMakc's user avatar
  • 35k
148 votes
11 answers
196k views

How to disable ESLint react/prop-types rule in a file?

I'm using React and ESLint with eslint-plugin-react. I want to disable the prop-types rule in one file. var React = require('react'); var Model = require('./ComponentModel'); var Component = React....
cuadraman's user avatar
  • 15.1k
146 votes
1 answer
33k views

Javascript re-assign let variable with destructuring [duplicate]

In my React app I am using airbnb's eslint style guide which will throw an error if I do not use destructuing. In the situation below, I first use let to assign the two variables latitude and ...
Phil Mok's user avatar
  • 3,970
141 votes
15 answers
239k views

Parsing Error The Keyword import is Reserved (SublimeLinter-contrib-eslint)

I have a problem with eslint, it gives me [Parsing Error The keyword import is reserve] this is only occur in sublime, in atom editor work well. I have eslint .eslintrc.js module.exports = { "...
pedro luis's user avatar
  • 1,695
139 votes
14 answers
151k views

How can I fix this violation of this 'react/no-unescaped-entitie' of an ESLint rule?

This is my code: const func = () => { return ( <div > you're free </div> )} Somehow ESLint flags the line "you're free" with error error HTML entities ...
Anthony Kong's user avatar
  • 39.8k
139 votes
3 answers
28k views

What's the difference between plugins and extends in eslint?

I don't understand why we have plugins and extends. What is the difference between them and do I need one or the other?
jingteng's user avatar
  • 2,501
137 votes
10 answers
118k views

'v-slot' directive doesn't support any modifier

I am using Vuetify's datatable, we have different slots with some props for example below <template #header.data-table-select="{ on, props }"> <v-simple-checkbox color="...
Dhiraj Wakchaure's user avatar

1
2 3 4 5
139