question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to configure React Native (Expo) project to use AirBnB's React rules via ESLint?

See original GitHub issue

I simply want to set-up the AirBnb’s React (Native) rules via ESLint on a React Native (Expo) project.

I found a ton of contradictory articles how to do that and I got really frustrated. Are there any official set-up guidelines?

Which modules exactly do I need to install with npm and how should my .eslintrc config look like?

PS: Could somebody please add a “question” tag to this issue?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:32
  • Comments:24

github_iconTop GitHub Comments

398reactions
amackintoshcommented, Nov 15, 2017

This is what I do in React and React Native:

Step 1

npm install --save-dev eslint eslint-config-airbnb eslint-plugin-import eslint-plugin-react eslint-plugin-jsx-a11y babel-eslint

Step 2 Backup your eslintrc file in case you want to examine it.

Step 3

eslint --init
  1. Select ‘Use a popular style guide’
  2. Select Airbnb
  3. Select your options, pick JSON type (.eslintrc is the old filename based on my research, but it’s the same thing)
  4. Allow it to update newer versions and/or install packages if it asks

Step 4 Restart your editor

Step 5 Paste this into your .eslintrc.json: and remove my comments which will cause the JSON to blow up

{
    "env": {
        "node": true, // this is the best starting point
        "browser": true, // for react web
        "es6": true // enables es6 features
    },
    "parser": "babel-eslint", // needed to make babel stuff work properly
    "extends": "airbnb"
}

If there are expo eslint settings, they will fit on top of these.

I collected these settings over time, mostly from researching specific JSX and babel related errors and reading.

I’m posting it because no one else has helped you in the past month, and this works. We can now switch the question from, “what is the correct way?”, to the more easy to handle “is this not the correct way?”

28reactions
mostafa-drzcommented, Jan 18, 2018

(Just a quick note on the solution mentioned here) The config @amackintosh shared here works very well for me, but I got the error [eslint] JSX not allowed in files with extension '.js' (react/jsx-filename-extension) (because I use some helper functions in my components for rendering out of the render function of component), I solved this problem by what mentioned here, so my .eslintrc.json is: { "env": { "node": true, "browser": true, "es6": true }, "parser": "babel-eslint", "extends": "airbnb", "rules": { "react/jsx-filename-extension": [ 1, { "extensions": [ ".js", ".jsx" ] } ] } } and everything is working perfect

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add Eslint Support to your React Native Project + React Hooks ...
Recently I came across a requirement where I needed to add eslint support for my one of React Native project. In this article,...
Read more >
How to set up an expo init project with react-native ... - YouTube
react - native init comes with really nice linting rules setup already, ... I was using the newer react - native -community/ eslint...
Read more >
Set up ESLint and Prettier for React Native projects - Three29
A step by step guide on how to set up ESLint and Prettier for React Native projects. Easy to follow instructions with CLI...
Read more >
Set up React JS with ESLint, Prettier and Airbnb
One of the easiest way you can improve your code is to use a linter! Not only improve but also unified...
Read more >
The easiest way to begin with Expo, Typescript, ESLint and ...
Tagged with expo, reactnative, typescript. ... Create the project using the Typescript template ... Install the Airbnb's ESLint packages.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found