ESLint semi rule doesn't enforce on import statements before class declaration in react-native

巧了我就是萌 提交于 2020-01-15 06:13:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!