禁用jsx中的eslint错误

Var*_*pta 2 reactjs eslint react-jsx react-native

我在我的一个react-native组件中有以下JSX

        <TouchableOpacity onPress={this.onEnableNotifications} style={{marginHorizontal: 10}}>
          <Image source={require('../../img/ic_warning.png')} style={{tintColor: colorThemes.Blue.red}}/>
        </TouchableOpacity>
Run Code Online (Sandbox Code Playgroud)

我收到以下ESLint错误:

'require' is not defined. (no-undef)
Run Code Online (Sandbox Code Playgroud)

我尝试过添加行{ // eslint-disable-line no-undef },Image但这会产生解析错误.我怎样才能为这一行摆脱这个错误.

Eld*_*ell 8

在您的.eslintrc文件上:

{
    "globals":{
        "require": true
    }
}
Run Code Online (Sandbox Code Playgroud)


Ste*_*fan 5

为了禁用带有 jsx 内注释的 eslint 警告,请使用

{ /* eslint-disable no-undef */ }
     <div>element causing warning </div>
{ /* eslint-enable no-undef */ }
Run Code Online (Sandbox Code Playgroud)

单行注释不起作用:

{ /* eslint-disable-line no-undef */ }
Run Code Online (Sandbox Code Playgroud)

另请参阅

https://github.com/eslint/eslint/issues/7030