Questions tagged [eslint]
The pluggable linting utility for JavaScript and related frameworks.
eslint
6,933
questions
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 ...
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 ...
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 ...
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: &...
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 ...
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,...
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 ...
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');...
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?
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 ...
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 } =...
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) !== '...
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 ...
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 ...
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'.
...
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....
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-...
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 ...
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 ...
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({
...
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 ...
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 ...
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/...
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
{
...
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 ...
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.
...
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:
...
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&...
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 ...
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 ...
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 ...
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}/>
<...
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 ...
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": ["...
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 ...
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 ...
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 ...
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 ...
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:
&...
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 ...
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, ...
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 ...
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: ...
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 ...
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....
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 ...
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 = {
"...
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 ...
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?
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="...