gpt4 book ai didi

javascript - ESLint 定义前不使用

转载 作者:可可西里 更新时间:2023-11-01 02:53:27 24 4
gpt4 key购买 nike

如何让 ESLint 规则(no-use-before-define)在这些情况下不发出警告;

class App extends React.Component {
render() { return <div>{messages.helloWorld}</div> }
}

const messages = { helloWorld: 'Hello world!' }

这是一个简化的示例,但我真的很想在每个组件文件的底部定义消息(按照惯例)。

最佳答案

看来您可能对此规则的 variables 选项感兴趣。您可以阅读有关该选项的信息 here .

This flag determines whether or not the rule checks variable declarations in upper scopes. If this is true, the rule warns every reference to a variable before the variable declaration. Otherwise, the rule ignores a reference if the declaration is in an upper scope, while still reporting the reference if it's in the same scope as the declaration.

你可以在你的.eslintrc中配置它,like so ...

{
"no-use-before-define": ["error", { "variables": false }]
}

这将使该规则对其他事物保持启用状态,例如同一范围内的类、函数和变量,但会放宽对上层范围内变量的限制。

关于javascript - ESLint 定义前不使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42981070/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com