问题
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!
回答1:
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.
来源:https://stackoverflow.com/questions/54180565/eslint-semi-rule-doesnt-enforce-on-import-statements-before-class-declaration-i