在我的.eslintrc文件中,prefer-const
的值已設置爲2,並且我沒有覆蓋文件中的規則。ESLint:即使變量未被重新分配,prefer-const也不會拋出錯誤
所有的規則似乎工作正常。即使prefer-const
規則似乎工作正常。但是,就這個特定的代碼而言,它並不會給我帶來任何錯誤。我不重新分配值,我期望eslint拋出一個錯誤。我正在使用Atom作爲編輯器。
/**
* Main render function
*/
render: function() {
// TODO: Show title based on the modal being opened i.e if New FAQ Modal
// is opened show NEW FAQ else show the title of the FAQ.
let title = "";
return (
<Modal title={title}
className="faq-modal"
loading={this.state.isModalLoading}
hideHeader={this.state.isModalLoading}
width="900px" />
);
}
原子:1.12.9 棉短絨(原子):1.11.8 棉短絨-eslint(原子):8.1.2 eslint:2.7.0,
有趣。刪除'Modal'上的'title'屬性,那麼它會拋出一個錯誤。不知道爲什麼 – Venugopal
當我將你的代碼片段粘貼到http://eslint.org/demo/並選擇prefer-const時,它會警告標題。 –
@Venugopal你說得對。我得到2個錯誤。 1.'title'已定義,但從未使用 2.'title'永遠不會被重新分配,而是使用'const'。 奇怪。不知道爲什麼會這樣。 –