Граф коммитов

29 Коммитов

Автор SHA1 Сообщение Дата
Pieter De Baets 988fefc44d Enable react/no-unstable-nested-components rule
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
2022-01-26 04:23:14 -08:00
Andres Suarez 8bd3edec88 Update copyright headers from Facebook to Meta
Reviewed By: aaronabramov

Differential Revision: D33367752

fbshipit-source-id: 4ce94d184485e5ee0a62cf67ad2d3ba16e285c8f
2021-12-30 15:11:21 -08:00
Tom Spencer ae67c5ac45 Disable ESLint `no-undef` for TypeScript files (#32655)
Summary:
The `typescript-eslint` project [recommends that `no-undef` is disabled for TypeScript files](6c3816b383/docs/linting/TROUBLESHOOTING.md (i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors)), since TypeScript itself will perform this check. Disabling this config property has two benefits:

- Undefined variables and types will only be reported once, by the TypeScript compiler. Currently they are reported twice: once by TypeScript, and once by ESLint:

<img width="506" alt="Screenshot 2021-11-24 at 12 38 22" src="https://user-images.githubusercontent.com/820863/143239961-eb8ed709-60f9-490a-bda3-fc581673d56c.png">

- Types that are declared globally by React Native will no longer be erroneously reported as undefined - this is currently the case for some types, e.g. `Blob`:

<img width="419" alt="Screenshot 2021-11-24 at 12 40 04" src="https://user-images.githubusercontent.com/820863/143240213-06428b24-09c8-4f95-8e77-7f4fd160eed1.png">

## 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
-->

[General] [Fixed] - ESLint no-undef rule clashing with TypeScript compiler for TS files

Pull Request resolved: https://github.com/facebook/react-native/pull/32655

Test Plan:
- Before: ESLint reporting on undefined variables in TypeScript files
- After: ESLint no longer reporting on undefined variables in TypeScript files

Reviewed By: GijsWeterings

Differential Revision: D32647147

Pulled By: yungsters

fbshipit-source-id: 070c734ac7a075b556492726c8fecf4fdab65898
2021-12-02 14:43:36 -08:00
Tom Spencer 722a0ff6f8 Fix eslint no-shadow issue with TypeScript enums (#32644)
Summary:
The current ESLint config includes a rule for `no-shadow`. When authoring using TypeScript, the [typescript-eslint docs](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/no-shadow.md) mention that the base `no-shadow` rule should be disabled in favour of `typescript-eslint/no-shadow`, otherwise false positives can be reported. In my case, I was experiencing the same symptoms as described in [this issue](https://github.com/typescript-eslint/typescript-eslint/issues/2552).

## 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
-->

[General] [Fixed] - ESLint `no-shadow` rule returning false positive for TypeScript enums

Pull Request resolved: https://github.com/facebook/react-native/pull/32644

Test Plan:
Before config changes:

<img width="631" alt="Screenshot 2021-11-22 at 21 02 31" src="https://user-images.githubusercontent.com/820863/142934803-ef1343d6-46ab-4495-9ea5-957f7ec404fc.png">

After changes:

<img width="486" alt="Screenshot 2021-11-22 at 21 03 28" src="https://user-images.githubusercontent.com/820863/142934914-a151656a-a37e-4ffb-9db5-ed9fb93543c7.png">

Reviewed By: GijsWeterings

Differential Revision: D32618393

Pulled By: yungsters

fbshipit-source-id: c69d5cff7210c22c84a0791bde62674efc6aa027
2021-12-01 14:09:34 -08:00
Tim Yung cf763cdf81 RN: Upgrade ESLint Packages (#32560)
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
2021-11-09 13:16:42 -08:00
Xuan Huang a8e2415a91 Type global queueMicrotask
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
2021-08-26 01:06:44 -07:00
Moti Zilberman e0aec42efd Allow single-line template literals without placeholders in test files
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
2021-05-04 12:33:26 -07:00
maltoze 35b6d2e52b Add FileReader to eslint globals (#30766)
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
2021-02-08 12:23:08 -08:00
maltoze 2aab894acf Add AbortController to eslint globals (#30691)
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
2021-01-23 13:37:39 -08:00
Moti Zilberman 8c8172f143 Upgrade react/jsx-no-comment-textnodes lint to an error
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
2020-12-17 08:49:04 -08:00
Sonny Piers 7a13a1a88f Add URLSearchParams and Headers to eslint globals (#27853)
Summary:
Fix eslint complaining about `URLSearchParams` and `Headers` not being defined.
Pull Request resolved: https://github.com/facebook/react-native/pull/27853

Differential Revision: D19577641

Pulled By: cpojer

fbshipit-source-id: 7019d1519523c7b99a201c6e0b78d0035c9b35a6
2020-01-27 02:30:29 -08:00
Sonny Piers ff9def41ff Add URL to eslint globals. (#27674)
Summary:
Fix eslint complaining about URL not being defined.
Pull Request resolved: https://github.com/facebook/react-native/pull/27674

Differential Revision: D19296779

Pulled By: cpojer

fbshipit-source-id: a62efdf0a5ad40c9575b9fa0f94156f1574cb018
2020-01-06 21:51:34 -08:00
Stanislav f6a62f9ae2 Add Intl to eslint globals. (#27082)
Summary:
Fix `'Intl' is not defined. eslint(no-undef)` warning by eslint: see https://github.com/facebook/react-native/issues/27076
Pull Request resolved: https://github.com/facebook/react-native/pull/27082

Differential Revision: D18298548

Pulled By: cpojer

fbshipit-source-id: c07af711086d79d214bfbbe2bba6f396628c96c1
2019-11-04 08:14:29 -08:00
Tim Yung 03f5951b45 RN: Permit Inline Styles in Tests
Summary:
Configures ESLint in React Native to permit inline styles in tests. Because, why not.

Changelog:
[Internal]

Reviewed By: TheSavior

Differential Revision: D18290625

fbshipit-source-id: 111c7fd2972179536487b94bd7b14f34167ea8c7
2019-11-03 18:02:00 -08:00
dr2009 af8ea06bb4 Add WebSocket to eslint globals (#27044)
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
2019-10-30 08:32:52 -07:00
Christoph Nakazawa 55e974d9fa Revert D18173919: fix(eslint-config): Clashes with prettier
Differential Revision:
D18173919

Original commit changeset: b333469652b4

fbshipit-source-id: 819d484101be132ae3f2d3bf8e3ba008a9d91d83
2019-10-29 13:18:49 -07:00
Kyle Roach e4b62bb139 fix(eslint-config): Clashes with prettier (#26847)
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
2019-10-28 13:17:09 -07:00
Moti Zilberman 90977b0e00 Enable no-useless-escape lint rule
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
2019-10-11 05:56:06 -07:00
Kant d2b92fffb1 Use eslint-plugin-prettier recommended config (#25674)
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
2019-08-09 06:41:41 -07:00
Rodinei Fagundes 76af5f9163 Add ErrorUtils to global variables (#25947)
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
2019-08-06 03:49:20 -07:00
Jacob Lee e78c01375a Allow jest globals in __mocks__ directories (#25738)
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
2019-07-26 03:37:29 -07:00
James Ide 33ee6f8b99 Add a lint rule to disallow Haste imports (#25058)
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
2019-05-30 07:45:16 -07:00
Matt Oakes 65eea9d1f8 Set the Prettier config so it is not forced on users of @react-native-community/eslint-config (#24635)
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
2019-04-29 09:44:51 -07:00
Eli White ec3adae99a Turn on react-hooks/exhaustive-deps in FBSource
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
2019-04-01 08:20:18 -07:00
satyajit.happy b49fdd19e4 Add typescript support to the ESLint config (#24100)
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
2019-03-25 21:28:26 -07:00
michalchudziak c8e26e6ac4 Fix eslint glob for `.test.js` and `.spec.js` files. (#24088)
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
2019-03-21 08:39:39 -07:00
michalchudziak 395197dafe Add .eslintrc to RN project template (#23901)
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
2019-03-21 07:14:23 -07:00
Matt Hargett e67aa427a8 Eliminate eslint npm version mismatch warnings and bump some to latest (#23969)
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
2019-03-19 11:14:30 -07:00
michalchudziak 1ed2b82693 Rename eslint config to 'eslint-config-react-native-community' (#23718)
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
2019-03-03 20:39:43 -08:00