问题描述
我正在尝试通过定义非常基本的规则将ESLint集成到我们的本机项目中。我首先定义了 semi
规则。到目前为止,一切似乎还可以,除了带有类声明的.js文件。如果我不对输入语句使用分号,则 semi
规则不会引发警告或错误。
.eslintrc.json
{
plugins:[ react, react-native],
parserOptions:{
sourceType:模块,
ecmaFeatures:{
jsx:true
}
},
rules:{
jsx-quotes:[
error,
prefer-double
],
半:[
错误,
始终]
}
}
.js文件示例。
import React,{Component} from'反应';
导入{易于操作,查看,样式表,动画}来自'react-native'
导入{connect}来自'react-redux'
导入{NavigationActions}来自'react-navigation'
import {updateLicense}从'../actions'
类SomeContainer扩展组件{
somefunction(){}
}
另一方面,如果没有类声明(仅 import
和 export
语句)抱怨缺少分号。
有什么想法吗?非常感谢您的帮助!
我从 airbnb
样式,并带有 babel-eslint
选项。所以,我加了;
extends: airbnb,
parser: babel-eslint ,
行插入 .eslintrc
文件。 / p>
I am trying to integrate ESLint on our react-native project by defining the very basic rules. I started with defining semi
rule. Everything seems ok so far except for the .js files which has a class declaration. semi
rule doesn't throw warning or error if I don't use semi-colon for import statements.
.eslintrc.json
{
"plugins":["react", "react-native"],
"parserOptions": {
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules":{
"jsx-quotes": [
"error",
"prefer-double"
],
"semi": [
"error",
"always"]
}
}
Example .js file.
import React, { Component } from 'react';
import { Easing, View, StyleSheet, Animated } from 'react-native'
import { connect } from 'react-redux'
import { NavigationActions } from 'react-navigation'
import { updateLicense } from '../actions'
class SomeContainer extends Component {
somefunction() {}
}
On the other hand, if there is no class declaration (just import
and export
statements) it complains about lacking semi-colons.
Any ideas? Thanks a lot for your help!
The problem gone after I started to extend configuration from airbnb
style with babel-eslint
option. So, I added;
"extends": "airbnb",
"parser": "babel-eslint",
lines into .eslintrc
file.
这篇关于ESLint半规则不会在React-native中的类声明之前对导入语句强制执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!