javascript - ESLint 使用 `obj?.fn()` 可选链接抛出 no-unused-expressions
问题描述
为什么 eslint 会扔inputRef.current?.focus()
?我是否使用了错误的可选链接?
Expected an assignment or function call and instead saw an expression. eslint no-unused-expressions
这是我的配置(第一个在我的工作区的包中,第二个在我的工作区的根目录中):
{
"env": {
"es6": true,
"shared-node-browser": true
},
"extends": [
"universe/native",
"eslint:recommended"
],
"plugins": [
"@typescript-eslint"
],
"rules": {
"require-atomic-updates": 0
}
}
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
// Required for certain syntax usages
"ecmaVersion": 2017
},
"env": {
"es6": true,
"node": true,
"jest": true
},
"extends": [
"plugin:prettier/recommended"
],
"plugins": [
"prettier",
"@typescript-eslint",
"promise",
"babel"
],
"rules": {
"prettier/prettier": "error",
// Warn against shorthand type conversions
"no-implicit-coercion": 1,
// Require using Error objects as Promise rejection reasons
"prefer-promise-reject-errors": 2,
// Enforce “for” loop update clause moving the counter in the right direction
"for-direction": 2,
// Enforce return statements in getters
"getter-return": 2,
// Disallow await inside of loops
"no-await-in-loop": 2,
// Disallow comparing against -0
"no-compare-neg-zero": 2,
// Warn against catch clause parameters from shadowing variables in the outer scope
"no-catch-shadow": 1,
// Disallow identifiers from shadowing restricted names
"no-shadow-restricted-names": 2,
// Enforce return statements in callbacks of array methods
"callback-return": 2,
// Require error handling in callbacks
"handle-callback-err": 2,
// Warn against string concatenation with __dirname and __filename
"no-path-concat": 1,
// Prefer using arrow functions for callbacks
"prefer-arrow-callback": 1,
// Return inside each then() to create readable and reusable Promise chains.
// Forces developers to return console logs and http calls in promises.
"promise/always-return": 2,
//Enforces the use of catch() on un-returned promises
"promise/catch-or-return": 2,
// Warn against nested then() or catch() statements
"promise/no-nesting": 1
}
}
解决方案
推荐阅读
- python - Python AWS - 从已发送电子邮件中获取RawMessageContent
- xamarin - SkiaSharp 在可点击的路径上制作位图
- c# - UNITY - 玩家控制器不向鼠标光标移动
- python - 使用 Python 根据数据更改 SQL UPDATE 语句
- ios - AppDelegate 未提供 UIViewController
- python-3.x - 使用 Python 优化排序任务
- c# - 如何在不调用基本默认构造函数的情况下实例化继承的类
- node.js - 如何使用 node/express 控制台记录 api 调用的 url
- html - 修复 IE 中 mat-expansion-indicator 的位置
- php - 使用准备好的语句验证来自 MySQL 数据库的散列密码