Summary:
Dynamic nested components can cause tricky performance issues in React, as the reconciler will not be able to reuse the previously mounted component tree.
Changelog: [General] [Added] Added linter warning config for unstable nested components
Reviewed By: motiz88
Differential Revision: D33767283
fbshipit-source-id: 869ece99dc63cc3a150bae882d26df8541e8db59
Summary:
Upgrades ESLint to v7.28.0. This is the latest version before v8.0.0, which would be a more involved upgrade.
Upgrades all ESLint-related dependencies to their latest version, except for [eslint-plugin-flowtype](https://github.com/gajus/eslint-plugin-flowtype/). This is because eslint-plugin-flowtype@8.0.0 dropped support for ESLint v7.
Configures ESLint for Metro to extend `plugin:prettier/recommended`.
## Changelog
[General][Changed] - Upgraded packages to the latest versions for ESLint v7.
Pull Request resolved: https://github.com/facebook/react-native/pull/32560
Test Plan:
Run this on an open source checkout of `facebook/react-native`:
```
# See no new errors or warnings.
$ yarn run lint
```
Run this internally:
```
$ js1 test xplat/js/tools/__tests__/dependency-constraints-test.js
```
Verify linting works:
```
js1 lint xplat/js/RKJSModules/Libraries/Core/
```
Reviewed By: lunaleaps
Differential Revision: D32258399
Pulled By: yungsters
fbshipit-source-id: d11b3fc3e33770157a90f3dee352cf80b39c442c
Summary:
Changelog: [Internal]
This diff
- add `queueMicrotask` to eslint and metro so it's globally available.
- add `queueMicrotask` to the global libdef of react native so the type
is available to `global.queueMicrotask` (which is common) as well.
Reviewed By: yungsters
Differential Revision: D30158144
fbshipit-source-id: 00a62193b838745c91179ff1e983636200560690
Summary:
Our ESLint configuration currently disallows template literals that can be expressed using plain string syntax (with single quotes). Jest's inline snapshots feature sometimes produces such template literals. This not only adds unnecessary friction from the linter, but can break subsequent snapshot updates in a test file (after accepting the ESLint autofix).
This conflict between Jest and ESLint is a known issue (https://github.com/facebook/jest/issues/10164) with no upstream fix. Here we relax the linter's settings to allow all template literals in test files. Ideally we could allow them *only* in inline snapshots, but this is a reasonable approximation.
Changelog: [Internal]
Reviewed By: MichaReiser
Differential Revision: D28120785
fbshipit-source-id: c6c6c0ab8a3b8aca14df06f430b777cef42cd554
Summary:
Fix eslint complaining about FileReader not being defined.
## Changelog
<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->
[Internal] [Fixed] - Fix eslint complaining about FileReader not being defined.
Pull Request resolved: https://github.com/facebook/react-native/pull/30766
Reviewed By: TheSavior
Differential Revision: D26318564
Pulled By: PeteTheHeat
fbshipit-source-id: d08c040f872cca3cbb26e8bf753a1acb3931d294
Summary:
Fix eslint complaining about AbortController not being defined.
## Changelog
<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->
Pull Request resolved: https://github.com/facebook/react-native/pull/30691
Reviewed By: TheSavior
Differential Revision: D25926479
Pulled By: mdvacca
fbshipit-source-id: aee7ef3e46331a389085e26eb3b601e9a6cf0910
Summary:
Upgrades the severity of the [`react/jsx-no-comment-textnodes`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-comment-textnodes.md) lint rule from warning to error.
The higher severity is warranted because, in React Native code in particular, rendering an unintended text node is likely to throw an error at runtime (unless it happens to be wrapped in `<Text />`).
Furthermore, this lint is highly actionable because there's always a workaround that is less ambiguous:
1. If intending to write a comment (likely), wrap it in curly braces:
`<>{ /* this is a comment */ }</>`
2. If intending to write an actual text node beginning with `//` or `/*` (unlikely), wrap it in curly braces and quotes:
`<>{'/* this is a text node */'}</>`
Changelog: [Internal]
Reviewed By: GijsWeterings
Differential Revision: D25615642
fbshipit-source-id: d5a59989b04c244111071893efc546083641ac54
Summary:
WebSocket is giving an error by eslint. ('WebSocket is not defined').
[websocket-support](https://facebook.github.io/react-native/docs/network#websocket-support)
## Changelog
[General] [Fixed] - Add WebSocket to eslint globals
Pull Request resolved: https://github.com/facebook/react-native/pull/27044
Test Plan: Run eslint on a react native project using WebSocket. Eslint verification should pass.
Differential Revision: D18223891
Pulled By: cpojer
fbshipit-source-id: c4adfde07078133930aa0ed80be5615d128f4148
Summary:
Currently, react-native-community config package extends from prettier/recommended which comes with default settings from prettier. However there are still some eslint rules in the config that either clash or duplicate the settings from prettier.
This results in eslint fixing the formatting and then prettier undoing it. This PR removes the style specific rules from eslint and place them in the prettier section.
## Changelog
[General] [Fixed] - Remove style rules from eslint config for prettier options
Pull Request resolved: https://github.com/facebook/react-native/pull/26847
Test Plan:
I created a repo for you to test with https://github.com/iRoachie/eslint-bug-replicate. You can see that running `yarn lint --fix` will never fix the issue. Eslint will complain about double quotes and subsequently after fixing it will complain about single quotes.
Here's a gif of the behaviour (vscode eslint plugin `"eslint.autoFixOnSave": true`):
![Kapture 2019-10-13 at 23 34 15](https://user-images.githubusercontent.com/5962998/66728290-ff80da00-ee11-11e9-8993-4d1b679c270b.gif)
Differential Revision: D18173919
Pulled By: cpojer
fbshipit-source-id: b333469652b4c8e72287718af94378505e9b7d59
Summary: See https://eslint.org/docs/rules/no-useless-escape. Useless escapes can reflect a mismatch between the intended and actual effect of a backslash in a literal.
Reviewed By: rubennorte
Differential Revision: D17876784
fbshipit-source-id: 7641b1f2227b92e1e91469adc0d0d990a64109cf
Summary:
I created a new test project today using RN 0.60.3 and saw that prettier is now used with eslint. After looking at the `react-native-community` eslint config, I notice that it wasn't using the [recommended configuration](https://github.com/prettier/eslint-plugin-prettier#recommended-configuration) of `eslint-plugin-prettier`
This PR adds the `eslint-config-prettier` to avoid conflicts between eslint and prettier, it also adds the `prettier/react` config to avoid problems with the `eslint-plugin-react`.
## Changelog
[General] [Changed] - Use eslint-plugin-prettier recommended config
Pull Request resolved: https://github.com/facebook/react-native/pull/25674
Test Plan: - ✅ Ensure there is no difference on this repo (no ESLint errors, same number of warnings, and no changes when running prettier).
Differential Revision: D16666178
Pulled By: cpojer
fbshipit-source-id: 70f81db793866acc88388b7b00a496aab5e0b156
Summary:
ErrorUtils is giving an error by eslint. ('ErrorUtils is not defined').
## Changelog
[General] [Fixed] - Add ErrorUtils to eslint globals
Pull Request resolved: https://github.com/facebook/react-native/pull/25947
Test Plan: Run eslint on a react native project using ErrorUtils. Eslint verification should pass.
Differential Revision: D16666163
Pulled By: cpojer
fbshipit-source-id: c20c4e21fe06c6863dcfc167d6d03c6217ae1235
Summary:
The `__mocks__` directories should be treated the same as `__tests__`
for the purpose of linting. See https://jestjs.io/docs/en/manual-mocks
## Changelog
[Internal] [Changed] - eslint: allow jest globals in `__mocks__` directories
Pull Request resolved: https://github.com/facebook/react-native/pull/25738
Test Plan:
I installed the updated package locally in my project and verified
that the `no-undef` rule no longer fires for references to `jest` in
`__mocks__` directories.
Differential Revision: D16515546
Pulled By: osdnk
fbshipit-source-id: ae78b95d33d1b48ffa4aafa7a53c83e152d176b2
Summary:
This is an ESLint plugin that infers whether an import looks like a Haste module name. To keep the linter fast and simple, it does not look in the Haste map. Instead, it looks for uppercase characters in single-name import paths, since npm has disallowed uppercase letters in package names for a long time. There are some false negatives (e.g. "merge" is a Haste module and this linter rule would not pick it up) but those are about 1.1% of the module names in the RN repo, and unit tests and integration tests will fail anyway once Haste is turned off.
You can disable the lint rule on varying granular levels with ESLint's normal disabling/enabling mechanisms.
Also rewrote more Haste imports so that the linter passes (i.e. fixed lint errors as part of this PR).
## Changelog
[General] [Changed] - Add a lint rule to disallow Haste imports
Pull Request resolved: https://github.com/facebook/react-native/pull/25058
Differential Revision: D15515826
Pulled By: cpojer
fbshipit-source-id: d58a3c30dfe0887f8a530e3393af4af5a1ec1cac
Summary:
This fixes an issue where the Prettier config was set to the `fb` (Facebook) values for all users of the `react-native-community/eslint-config` package. This was due to [this line](8f186b84ae/packages/eslint-config-react-native-community/index.js (L219)) in the config file.
It was causing issues like these:
* Errors when using newer versions of `eslint-plugin-prettier` (you had to use a version that was >1 year old): https://github.com/facebook/react-native/issues/24564
* Errors due to the Prettier parser being forced to be `flow` when using Typescript: https://github.com/typescript-eslint/typescript-eslint/issues/481
This PR:
* Changes that line to remove the explicit `fb` config so users can set their own.
* Moves the React Native Prettier config to `.prettierrc` so ESLint, Prettier, and code editors can all read from the same place.
* Upgrades both `prettier` and the `eslint-plugin-prettier` to the latest versions.
[General] [Fixed] - Stopped the Prettier config being set for all users of react-native-community/eslint-config
Pull Request resolved: https://github.com/facebook/react-native/pull/24635
Differential Revision: D15122200
Pulled By: cpojer
fbshipit-source-id: 56bae8a7f2d8e133b1d808091a6b73302b94d2ed
Summary: Looks like there are already a bunch of issues in the codebase because this wasn't on.
Reviewed By: cpojer
Differential Revision: D14701084
fbshipit-source-id: 09ff8e0d905b81fbe08c41d4f58758479b38187b
Summary:
This adds TypeScript support to the community ESLint config. Our babel preset supports TypeScript by default, so it's nice to have TypeScript support pre-configured in the ESLint config too.
Note: Users need to install `typescript` in their project for linting to work for TypeScript files.
[General] [Added] - Add TypeScript support to the ESLint config
Pull Request resolved: https://github.com/facebook/react-native/pull/24100
Differential Revision: D14597127
Pulled By: cpojer
fbshipit-source-id: dfbf1b97061ed6e8c46aa49adb21630f5acdb5d1
Summary:
Existing glob might not work very well with `spec.js` and `test.js` files unless they're placed in `__tests__` directory. This PR aims to bring back the support of `jest` globals in these files, even if they're outside of `__tests__` directory.
[General] [Fixed] - Fixed globs for `spec.js` and `test.js` files.
Pull Request resolved: https://github.com/facebook/react-native/pull/24088
Differential Revision: D14562085
Pulled By: cpojer
fbshipit-source-id: 543d67e3f8a154256f454b34ccc68bb070197a75
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 https://github.com/react-native-community/react-native-cli/pull/229
[General] [Added] - Added `.eslintrc` file to generated template.
Pull Request resolved: https://github.com/facebook/react-native/pull/23901
Differential Revision: D14561084
Pulled By: cpojer
fbshipit-source-id: 6eb717bf03c45d83ae8a393e6a0abb79e1e2f915
Summary:
I was annoyed by warnings from yarn/npm about eslint peer dependencies not being met, so I dived in to try and get rid of some of them. Sometimes it meant bumping a plugin, but then that plugin needed a newer babel-eslint, so it was a dance.
Some we can't easily update to latest (eslint-plugin-prettier) because the rule format has changed a bit. Happy to do that in this PR if folks think its a good idea. eslint-config-fbjs itself needs to be updated and republished to eliminate the last few warnings.
There are a few new warnings (the repo wasn't linting cleanly for me from the start). I can fix those in this PR, or a separate one, based on people's preferences.
[internal] [chore] - Eliminate some peer dependency warnings and bump some eslint packages to latest.
Pull Request resolved: https://github.com/facebook/react-native/pull/23969
Differential Revision: D14519076
Pulled By: cpojer
fbshipit-source-id: aa44cfd05814d7b79069414aa78d089e448c2235
Summary:
Renamed `eslint-config-react-native` to `eslint-config-react-native-community`, due to the fact, that initial name is already taken on `npm`. Additionally, I added very simple `README.md` file, to prepare the package to be published.
[General] [Changed] - Changed `eslint-config-react-native` name to `eslint-config-react-native-community`
Pull Request resolved: https://github.com/facebook/react-native/pull/23718
Differential Revision: D14298553
Pulled By: cpojer
fbshipit-source-id: bad5a42502ccdebf5f95d8217187be23bbf8f26c