为什么在这种情况下 eslint 4.17.0 我的错误号永远不会被重新分配。改用'const'。(首选常量)。为什么我需要使用const?请解释我我无法理解。
let test = {
'number': 1,
'string': 'asd',
};
test.number = 99;
console.log(test.number);
// output: 99
Run Code Online (Sandbox Code Playgroud)
脚本
{
"parser": "babel-eslint",
"env": {
"browser": true
},
"extends": [
"google"
],
"rules": {
"prefer-const": 2
},
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
}
}
Run Code Online (Sandbox Code Playgroud)
eslint 问题
[eslint] 'test' is never reassigned. Use 'const' insted. (prefer-const)
Run Code Online (Sandbox Code Playgroud) 如标题所述,eslint是否有可能在所有规则上显示警告而不是错误?如果该信息相关,我正在使用Standard JS。
谢谢!
任何人都可以弄清楚我如何解决 linter 错误。这段代码已经过测试并且运行良好。唯一的问题是我无法将它部署在云功能基础架构上。
我确定 .eslintrc 文件有问题。任何人都可以帮助我了解如何使用传播运算符。
这是 linter 抛出错误的地方:
const rightChoices = _.map(snapshot.val(), (val, questionId) => {
return { ...val, questionId};
})
Run Code Online (Sandbox Code Playgroud)
这是我的 .eslintrc 文件:
{
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true,
"experimentalObjectRestSpread": true
}
}
"plugins":[
"promise"
],
"extends": "eslint:recommended",
"rules": {
// Removed rule "disallow the use of console" from recommended eslint rules
"no-console": "off",
// Removed rule "disallow multiple spaces in regular expressions" from recommended eslint rules
"no-regex-spaces": "off",
// Removed rule "disallow …
Run Code Online (Sandbox Code Playgroud) 我正在使用 vscode 和 eslint。eslint 控制台显示以下内容:
[Info - 3:31:14 PM] ESLint server stopped.
[Info - 3:31:14 PM] ESLint server running in node v10.2.0
[Info - 3:31:14 PM] ESLint server is running.
[Info - 3:31:15 PM] ESLint library loaded from:
/usr/local/lib/node_modules/eslint/lib/api.js
Run Code Online (Sandbox Code Playgroud)
所以 eslint 似乎正在加载并运行。但是,我的项目根目录中有一个.eslintrc
包含规则的文件,并且 vscode 没有向我显示任何 linting 错误。
我该如何调试这个?
当 jsx 跨越多行时,什么 eslint 规则更喜欢前者而不是后者?目前更漂亮正在将首选更改为不首选
const preferred = (
<tag
prop={hi}
another={test}
\>
);
const notPreferred = (<tag
prop={hi}
Another={test}
\>
);
Run Code Online (Sandbox Code Playgroud) 我用来eslint-import-resolver-webpack
让我的 eslint 知道我的 webpack 别名。
但是我仍然有一个问题:
eslint 正在报告:Absolute imports should come before relative imports. eslint(import/first)
如何让 eslint 理解我的别名导入是相对导入而不是绝对导入?
以下是有关我的设置的更多信息:
| source
- | app
- | containers
- | CalendarContainer.js
| .eslintrc
| webpack.config.dev.js
| webpack.config.resolve.js
Run Code Online (Sandbox Code Playgroud)
webpack.config.dev.js
| source
- | app
- | containers
- | CalendarContainer.js
| .eslintrc
| webpack.config.dev.js
| webpack.config.resolve.js
Run Code Online (Sandbox Code Playgroud)
webpack.config.resolve.js
const resolveConfig = require('./webpack.config.resolve')
const appConfig = {
// lots of config,
...resolveConfig // to have the resolve key with aliases underneath …
Run Code Online (Sandbox Code Playgroud) 我在 Vue CLI 和 Typescript 中使用 Vue。
我从 vuex 文件导入接口并将其用于mapState
类型注释。
但是 eslint 显示了一个错误。
'State' is defined but never used. eslint(no-unused-vars)
Run Code Online (Sandbox Code Playgroud)
代码
'State' is defined but never used. eslint(no-unused-vars)
Run Code Online (Sandbox Code Playgroud)
.eslintrc.js
import { Component, Vue } from 'vue-property-decorator';
import { mapState } from 'vuex';
import { State } from '@/store/index';
@Component({
computed: mapState<State>({
cards: (state: State) => state.user.cards,
})
})
export default class Home extends Vue {}
Run Code Online (Sandbox Code Playgroud)
我应该怎么做才能看到 eslint 错误?
我有文件夹结构:
my_project
|------ modules.private
| |------ broker_module
| |------ BrokerModule.js
|
|------ src
| |------ AppService
| |------ AppService.js
|
| |------ Components
| |------ ScreenLogin.js
|
Run Code Online (Sandbox Code Playgroud)
我需要限制所有区域的 module.private 的绝对导入,除了“./src/AppService”。
情况无错误。Linted 文件是“./src/AppService/AppService.js”:
// NO ERROR
import { BrokerModule } from 'broker_module';
Run Code Online (Sandbox Code Playgroud)
有错误的情况。Linted 文件是“./src/componets/ScreenLogin.js”:
// Error: can not import broker_module to restricted zone
import { BrokerModule } from 'broker_module';
Run Code Online (Sandbox Code Playgroud)
我已经尝试过https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-restricted-paths.md,并制定了如下规则:
// the rule is interpreted like you can not import to target zone './src/components' from 'from': 'broker_module'
'rules': { …
Run Code Online (Sandbox Code Playgroud) 有没有办法允许{}
(一个空对象)同时保持其余部分不变?
"object-curly-newline": [
"error",
{
"ObjectExpression": "always",
"ObjectPattern": { "multiline": true },
"ImportDeclaration": { "multiline": true, "minProperties": 4 },
"ExportDeclaration": "never"
}
]
Run Code Online (Sandbox Code Playgroud) 我试图弄清楚如何防止函数Public
在另一个文件中未使用时被创建。
我试图为此寻找规则,但我似乎找不到一个,最接近的是使用explicit-member-accessibility
.
到目前为止,我已经尝试通过这样做来解决它
"@typescript-eslint/explicit-member-accessibility": [
"warn",
{
"accessibility": "explicit",
"overrides": {
"accessors": "off",
"constructors": "no-public",
"methods": "explicit",
"properties": "off",
"parameterProperties": "off"
}
}
]
Run Code Online (Sandbox Code Playgroud)
但它的问题在于它要求您Public
在每个公共方法之前编写。这还需要在现有代码库中编辑大量代码。
如果可能的话,我希望 eslint 能够以这种方式格式化代码
class childClass extends baseClass {
//public method belonging to base class
//should be `public` since it is used in another file
baseClassMethod() {
//some code
}
//private method only accessible within the child class
//should be `private` since it isn't used outside the file
private childClassMethod() …
Run Code Online (Sandbox Code Playgroud) eslintrc ×10
eslint ×6
javascript ×4
reactjs ×2
typescript ×2
constants ×1
firebase ×1
import ×1
jsx ×1
let ×1
react-native ×1
standardjs ×1
vue.js ×1
webpack ×1
webpack-4 ×1