Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .eslintrc to RN project template #23901

Closed
wants to merge 5 commits into from
Closed

Add .eslintrc to RN project template #23901

wants to merge 5 commits into from

Conversation

michalchudziak
Copy link
Contributor

@michalchudziak michalchudziak commented Mar 13, 2019

Summary

The goal of this PR is to enable eslint checks in the projects generated by react-native init command. I added template/_eslintrc file, that would be replaced in an initialized project with .eslintrc file. This PR comes in parallel with react-native-community/cli#229

Changelog

[General] [Added] - Added .eslintrc file to generated template.

Test Plan

  1. Check out to this branch.

  2. Follow setup from https://github.com/react-native-community/react-native-cli/blob/master/CONTRIBUTING.md

react-native init TestProject
cd TestProject && yarn lint

Expected result:
Eslint check ran with no issues found.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 13, 2019
kelset
kelset previously approved these changes Mar 13, 2019
Copy link
Contributor

@kelset kelset left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

"extends": "@react-native-community",

"env": {
"jest": true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest something like this:

  overrides: {
    files: ['**/__tests__/**/*.js', '**/?(*.)(spec|test).js'],
    env: {
      jest: true,
      'jest/globals': true,
    },
  },

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @satya164, I think it's a good point.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add it to community config itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think keeping eslint test runner configuration within the project is ok. Jest is integrated into RN template, but other projects might depend on a different test runner. I'm fine with both solutions tho.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michalchudziak can we put it into the eslint config? I think that's better, especially since people can create a project without Jest still and it makes this a bit confusing.

"env": {
"jest": true
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a newline here.

Copy link
Contributor

@cpojer cpojer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move the Jest specific setting to the community config.

@matthargett
Copy link
Contributor

The .eslintrc configuration file is deprecated according to eslint docs:
https://eslint.org/docs/user-guide/configuring#configuration-file-formats

My preference would be to use .eslintrc.js, so we can add comments, but .eslintrc.json would be fine if someone feels strongly otherwise.

@cpojer
Copy link
Contributor

cpojer commented Mar 15, 2019

Let's do .js.

Quick question: what happens to existing projects with an .eslintrc.js when they upgrade? Will this file be ignored or will it lead to merge conflicts?

@kelset
Copy link
Contributor

kelset commented Mar 18, 2019

Quick question: what happens to existing projects with an .eslintrc.js when they upgrade? Will this file be ignored or will it lead to merge conflicts?

cc @pvinis do you know what will happen?

@pvinis
Copy link
Contributor

pvinis commented Mar 18, 2019

It will be a merge conflict, which is fine. Many people have their own, so it's good to see what they have and what the template suggests. The only weird case I see is if people have eslint json and we have eslint js, that might lead to some funkiness, but I don't think there are many things we can do here besides announce it to people.

@@ -12,6 +12,8 @@ module.exports = {

env: {
es6: true,
jest: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be under overrides like:

  overrides: {
    files: ['**/__tests__/**/*.js', '**/?(*.)(spec|test).js'],
    env: {
      jest: true,
      'jest/globals': true,
    },
  },

I think adding all jest globals to the normal env isn't great.

@@ -24,6 +24,14 @@ module.exports = {
'jest',
],

overrides: {
files: ['**/__tests__/**/*.js', '**/?(*.)(spec|test).js'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should include TS and TSX files as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thymikee Are you sure that's something we want to add? TSEslint configuration on the project side will be required anyway. It seems logical to keep it on the project side for the projects that use TS.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eslint now supports TS (or is planning to) so it makes sense.

Copy link
Contributor

@satya164 satya164 Mar 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't we also need to add the parser as well? Otherwise, ESLint will fail to parse no?

Reference https://github.com/facebook/jest/blob/master/.eslintrc.js#L15

PS: I agree it'll be great to have this by default

Copy link
Contributor

@cpojer cpojer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, let's ship it. I removed the TS stuff again based on @satya164's comment. Let's figure this out later.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpojer is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @michalchudziak in 395197d.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Mar 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants