$("#ID").hide();
Run Code Online (Sandbox Code Playgroud)
我将ESLint添加到我的项目中.
一切都很好,除了符号$
.
我收到错误: [eslint] '$' is not defined. (no-undef)
我的.eslintrc.json
:
{
"env": {
"browser": true,
"commonjs": true,
"es6": true
},
"extends": [
"eslint:recommended"
],
"parserOptions": {
"sourceType": "module"
},
"plugins": [
"dollar-sign",
"jquery"
],
"rules": {
"indent": [
"error" ,
"tab"
],
"linebreak-style": [
"error",
"windows"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
],
"jquery/no-ajax": 2,
"jquery/no-animate": 2,
"jquery/no-attr": 2,
"jquery/no-bind": 2,
"jquery/no-class": 2,
"jquery/no-clone": 2,
"jquery/no-closest": 2,
"jquery/no-css": 2,
"jquery/no-data": 2, …
Run Code Online (Sandbox Code Playgroud) 当我运行 时npx create-react-app ...
,正在为我创建一个简单的 React 项目。然后当我查看 时package.json
,似乎有一些 ESLint 存在的证据,因为有这样的:
"eslintConfig": {
"extends": "react-app"
},
Run Code Online (Sandbox Code Playgroud)
然而,每当我将 ESLint 作为开发依赖项安装并配置它时——就像我通常所做的那样——,VS Code 似乎会选择它。在这种情况下,VS Code 似乎没有意识到存在/配置了任何类型的 linter。这并不奇怪,因为 ESLint 不是我刚刚生成的 React 项目的依赖项——至少不是根据package.json
. 当我尝试eslint .
在项目的根目录中运行时,它显示“找不到命令”。
我试图通过扩展它来为这个 ESLint 配置注入活力,所以现在我有了:
"eslintConfig": {
"extends": ["react-app", "eslint:recommended", "google"],
"rules": {
"semi": ["error", "always"],
"quotes": ["error", "double"]
}
},
Run Code Online (Sandbox Code Playgroud)
这没有任何改变。我以一种我知道它违反上述配置的方式操作源代码,但是,我没有收到任何不法行为的信号。
这让我想到一个简单的问题:
生成的项目是否create-react-app
带有某种 ESLint 配置,如果是,我该如何正确启用和扩展它?
当我提到在搜索“create react app eslint”时出现的排名第一的谷歌点击- 我显然已经阅读过 - 让我澄清我的意思:
ESLint 显然是以一种不同的方式集成到 Create React App 中,而不是像这样 …
javascript reactjs eslint visual-studio-code create-react-app
我想一起使用Prettier和ESLint,但我只是通过一个接一个地运行它们而遇到了一些冲突.我看到有这三个包似乎允许它们串联使用:
prettier-eslint
eslint-plugin-prettier
eslint-config-prettier
但是,我不确定使用哪个,因为这些包名都包含eslint
和prettier
.
我应该使用哪个?
我正在使用Grunt作为我的构建工具和ESLint作为我正在处理的应用程序的linting工具.我也在使用Underscore节点包,并在我的应用程序中使用它.不幸的是,当我在我的代码上运行ESLint时,它认为_是以下行中的未定义变量:
return _.pluck(objects, nameColumn);
这是它给我的错误:
78:21 error "_" is not defined no-undef
我不想禁用ESLint的no-undef规则,我尝试安装Underscore插件,但我仍然收到此错误.如果其他人有任何想法尝试这个,我会非常感激!
如果有任何进一步的信息,我可以帮助任何人帮助我解决这个问题,请告诉我!
更新到 CRA 5.0.0 后,我在编译过程中遇到此错误:
\nERROR in Plugin "react" was conflicted between ".eslintrc.json" and "BaseConfig \xc2\xbb "..\\react-app\\node_modules\\eslint-config-react-app\\base.js".\n
Run Code Online (Sandbox Code Playgroud)\n我的 eslint 配置是:
\n{\n "env": {\n "browser": true,\n "es2021": true\n },\n "extends": [\n "plugin:react/recommended",\n "airbnb",\n "plugin:react/jsx-runtime"\n ],\n "parser": "@typescript-eslint/parser",\n "parserOptions": {\n "ecmaFeatures": {\n "jsx": true\n },\n "ecmaVersion": 12,\n "sourceType": "module"\n },\n "plugins": [\n "react",\n "@typescript-eslint"\n ],\n "rules": {...}\n}\n
Run Code Online (Sandbox Code Playgroud)\n有任何解决方案/修复吗?
\n我在 VS Code 中使用 ESLint 时在所有 TypeScript 文件上收到以下两个错误:
Definition for rule 'import/extensions' was not found.eslint(import/extensions)
Definition for rule 'import/no-extraneous-dependencies' was not found.eslint(import/no-extraneous-dependencies)
Run Code Online (Sandbox Code Playgroud)
VSC 问题窗格的屏幕截图:
关于不同的模块有很多类似的问题,甚至还有一些关于 的问题import/extensions
,但建议的解决方案都没有帮助。我都试过了。在输入这个问题时,我还尝试了 Stack Overflow 建议的每个线程中发布的每个解决方案。
这是我的.eslintrc.json
:
{
"env": {
"es2021": true,
"node": true
},
"extends": [
"airbnb-typescript/base",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module",
"project": "./tsconfig.json"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/no-use-before-define": "off"
}
}
Run Code Online (Sandbox Code Playgroud)
package.json
:
{
"name": "graph-userdata-gateway",
"version": "1.0.0",
"description": "Gateway for PowerApps …
Run Code Online (Sandbox Code Playgroud) typescript eslint visual-studio-code eslint-config-airbnb eslintrc
我设置eslint
及eslint-plugin-react
.
当我运行ESLint时,linter返回no-unused-vars
每个React组件的错误.
我假设它没有意识到我正在使用JSX或React语法.有任何想法吗?
例:
app.js
import React, { Component } from 'react';
import Header from './header.js';
export default class App extends Component {
render() {
return (
<div>
<Header />
{this.props.children}
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
Linter错误:
/my_project/src/components/app.js
1:8 error 'React' is defined but never used no-unused-vars
2:8 error 'Header' is defined but never used no-unused-vars
Run Code Online (Sandbox Code Playgroud)
这是我的.eslintrc.json
档案:
{
"env": {
"browser": true,
"es6": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true, …
Run Code Online (Sandbox Code Playgroud) Parsing error: Unexpected token =
当我尝试lint我的Es6类时,ESLint会抛出一个错误.在eslint中启用胖箭头类方法我缺少什么配置参数?
样本类:
class App extends React.Component{
...
handleClick = (evt) => {
...
}
}
Run Code Online (Sandbox Code Playgroud)
.eslint
{
"ecmaFeatures": {
"jsx": true,
"modules":true,
"arrowFunctions":true,
"classes":true,
"spread":true,
},
"env": {
"browser": true,
"node": true,
"es6": true
},
"rules": {
"strict": 0,
"no-underscore-dangle": 0,
"quotes": [
2,
"single"
],
}
}
Run Code Online (Sandbox Code Playgroud) Warning: React version not specified in eslint-plugin-react settings. See https://github.com/jsx-eslint/eslint-plugin-react#configuration .
运行 eslint 时显示 Git bash 。
create-react-app my-app
cd app
npm install eslint --save-dev
npx eslint --init
npx eslint .
Run Code Online (Sandbox Code Playgroud)
{
...
"dependencies": {
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
...
"devDependencies": {
"eslint": "^8.18.0",
"eslint-plugin-react": "^7.30.1"
}
}
Run Code Online (Sandbox Code Playgroud)
我试图寻找解决方案但失败了。我恳请您的帮助。
我尝试在 WebStrom 中使用 ESLint,但它不起作用并显示错误:
ESLint:解析错误:此实验性语法需要启用以下解析器插件之一:“jsx、flow、typescript”(2:9)。
这是我的.eslintrc
和package.json
设置。我应该做什么来修复错误?
包.json
{
"name": "raonair-frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"eslint-config-react-app": "^6.0.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"prepare": "husky install"
},
"parser": "babel-eslint",
"eslintConfig": {
"extends": [
"react-app",
"airbnb",
"plugin:flowtype/recommended"
],
"plugins": [
"flowtype"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not …
Run Code Online (Sandbox Code Playgroud) eslint eslint-config-airbnb eslintrc babel-eslint prettier-eslint
eslint ×10
javascript ×5
reactjs ×5
ecmascript-6 ×2
eslintrc ×2
angularjs ×1
babel-eslint ×1
gruntjs ×1
jquery ×1
jsx ×1
prettier ×1
typescript ×1