在编码时,我没有使用eslint。现在,我安装了它,它使我的编辑器充满了漂亮的/错误的错误,这些错误似乎绝不会使我的代码更漂亮。我正在寻找解决此问题的方法。
prettierrc.js:
module.exports = {
bracketSpacing: true,
jsxBracketSameLine: false,
singleQuote: true,
trailingComma: 'all',
};
eslintrc.js:
module.exports = {
root: true,
extends: '@react-native-community',
};
最后是一些示例代码:
import React, {Component} from 'react';
import {View, Text, Picker} from 'react-native';
import {connect} from 'react-redux';
import {employeeUpdate} from '../actions';
import {CardSection, Input} from './common';
class EmployeeForm extends Component {
render(){
return (
<View>
<CardSection>
<Input
label="Name"
placeholder="Marco"
value={this.props.name}
onChangeText={value => this.props.employeeUpdate({prop: 'name', value})}
/>
</CardSection>
<CardSection>
<Input
label="Phone"
placeholder="555-5555"
value={this.props.phone}
onChangeText={value => this.props.employeeUpdate({prop: 'phone', value })}
/>
</CardSection>
<CardSection style={{ flexDirection: 'row'}}>
<Text style={styles.pickerTextStyle}>Shift</Text>
<Picker
style={{flex: 1}}
selectedValue={this.props.shift}
onValueChange={value => this.props.employeeUpdate({prop: 'shift', value})}
>
<Picker.Item label="Monday" value="Monday" />
<Picker.Item label="Tuesday" value="Tuesday"/>
<Picker.Item label="Wednesday" value="Wednesday"/>
<Picker.Item label="Thursday" value="Thursday"/>
<Picker.Item label="Friday" value="Friday"/>
<Picker.Item label="Saturday" value="Saturday"/>
<Picker.Item label="Sunday" value="Sunday"/>
</Picker>
</CardSection>
</View>
);
}
}
我只是想消除该错误,因为烦人的是,成千上万的红点试图使我的代码“更漂亮”,但这没有实现。
答案 0 :(得分:26)
您可以禁用 eslintrc.js配置文件中的漂亮内容,而不是禁用文件的lint:
module.exports = {
root: true,
extends: '@react-native-community',
rules: {
'prettier/prettier': 0,
},
};
答案 1 :(得分:0)
尝试将其添加到文件顶部:
/* eslint-disable */