2
votes

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
try with this rule "semi": [2, "always"]Zeeshan Ansari
@ZeeshanAnsari I tried but it didn't work. I also figured out that none of the rules work if there is a class definition in any .js filequartaela
I think you should define render method to display something in Text then check because linter is not working on that file cause of syntax errorZeeshan Ansari
and if you are using the vscode so you can install eslint plugin for best practice.Zeeshan Ansari
This config+example works as expected for me in Sublime. You might want to make sure you have the latest versions installed.David Hellsing

1 Answers

0
votes

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.