2022-06-16 17:12:58 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*
|
|
|
|
* @format
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2022-09-27 16:22:58 +00:00
|
|
|
const path = require('node:path');
|
|
|
|
|
|
|
|
require('eslint-plugin-lint').load(path.join(__dirname, 'tools/eslint/rules'));
|
|
|
|
|
2022-06-16 17:12:58 +00:00
|
|
|
module.exports = {
|
|
|
|
root: true,
|
|
|
|
|
2022-11-25 13:44:17 +00:00
|
|
|
extends: ['@react-native'],
|
2022-06-16 17:12:58 +00:00
|
|
|
|
2022-09-27 16:22:58 +00:00
|
|
|
plugins: ['@react-native/eslint-plugin-specs', 'lint'],
|
2022-06-16 17:12:58 +00:00
|
|
|
|
|
|
|
overrides: [
|
2023-05-10 22:46:34 +00:00
|
|
|
// overriding the JS config from @react-native/eslint-config to ensure
|
2022-06-16 17:12:58 +00:00
|
|
|
// that we use hermes-eslint for all js files
|
|
|
|
{
|
2024-04-29 12:04:26 +00:00
|
|
|
files: ['*.js', '*.js.flow', '*.jsx'],
|
2022-06-16 17:12:58 +00:00
|
|
|
parser: 'hermes-eslint',
|
|
|
|
rules: {
|
|
|
|
// These rules are not required with hermes-eslint
|
|
|
|
'ft-flow/define-flow-type': 0,
|
|
|
|
'ft-flow/use-flow-type': 0,
|
2024-10-18 00:06:20 +00:00
|
|
|
'lint/sort-imports': 1,
|
2022-06-16 17:12:58 +00:00
|
|
|
// flow handles this check for us, so it's not required
|
|
|
|
'no-undef': 0,
|
|
|
|
},
|
|
|
|
},
|
2023-08-18 14:48:56 +00:00
|
|
|
{
|
|
|
|
files: ['package.json'],
|
|
|
|
parser: 'jsonc-eslint-parser',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
files: ['package.json'],
|
|
|
|
rules: {
|
|
|
|
'lint/react-native-manifest': 2,
|
|
|
|
},
|
|
|
|
},
|
2023-06-07 20:44:13 +00:00
|
|
|
{
|
|
|
|
files: ['flow-typed/**/*.js'],
|
|
|
|
rules: {
|
|
|
|
'lint/valid-flow-typed-signature': 2,
|
|
|
|
'no-unused-vars': 0,
|
|
|
|
quotes: 0,
|
|
|
|
},
|
|
|
|
},
|
2022-06-16 17:12:58 +00:00
|
|
|
{
|
2024-01-22 17:47:08 +00:00
|
|
|
files: [
|
|
|
|
'packages/react-native/Libraries/**/*.js',
|
|
|
|
'packages/react-native/src/**/*.js',
|
|
|
|
],
|
2022-06-16 17:12:58 +00:00
|
|
|
rules: {
|
2022-11-25 13:44:17 +00:00
|
|
|
'@react-native/platform-colors': 2,
|
2022-06-16 17:12:58 +00:00
|
|
|
'@react-native/specs/react-native-modules': 2,
|
2022-09-27 21:37:29 +00:00
|
|
|
'lint/no-haste-imports': 2,
|
2022-09-27 16:22:58 +00:00
|
|
|
'lint/no-react-native-imports': 2,
|
2022-09-27 21:37:29 +00:00
|
|
|
'lint/require-extends-error': 2,
|
2022-06-16 17:12:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
files: [
|
|
|
|
'**/__fixtures__/**/*.js',
|
|
|
|
'**/__mocks__/**/*.js',
|
|
|
|
'**/__tests__/**/*.js',
|
2023-03-17 12:03:25 +00:00
|
|
|
'packages/react-native/jest/**/*.js',
|
2022-06-16 17:12:58 +00:00
|
|
|
'packages/rn-tester/**/*.js',
|
|
|
|
],
|
|
|
|
globals: {
|
|
|
|
// Expose some Jest globals for test helpers
|
|
|
|
afterAll: true,
|
|
|
|
afterEach: true,
|
|
|
|
beforeAll: true,
|
|
|
|
beforeEach: true,
|
|
|
|
expect: true,
|
|
|
|
jest: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
files: ['**/__tests__/**/*-test.js'],
|
|
|
|
env: {
|
|
|
|
jasmine: true,
|
|
|
|
jest: true,
|
|
|
|
},
|
|
|
|
},
|
2022-09-19 19:26:00 +00:00
|
|
|
{
|
2022-09-27 14:11:10 +00:00
|
|
|
files: ['**/*.{ts,tsx}'],
|
2022-09-19 19:26:00 +00:00
|
|
|
parser: '@typescript-eslint/parser',
|
|
|
|
plugins: ['@typescript-eslint/eslint-plugin'],
|
|
|
|
rules: {
|
|
|
|
'@typescript-eslint/no-unused-vars': 'off',
|
|
|
|
'react-native/no-inline-styles': 'off',
|
|
|
|
'@typescript-eslint/no-shadow': 'off',
|
|
|
|
'no-self-compare': 'off',
|
|
|
|
'react/self-closing-comp': 'off',
|
|
|
|
},
|
|
|
|
},
|
2023-03-08 08:14:56 +00:00
|
|
|
{
|
|
|
|
files: ['**/*.d.ts'],
|
|
|
|
plugins: ['redundant-undefined'],
|
|
|
|
rules: {
|
feature: Update `Image.getSize/getSizeWithHeaders ` methods to return a promise (#42895)
Summary:
`Image.getSize/getSizeWithHeaders` are still working in old fashioned "callback" way
```tsx
Image.getSize(uri, function success(width,height) { }, function failure(){ } ); // undefined
Image.getSizeWithHeaders(uri, headers, function success(width,height) { }, function failure(){ } ); // undefined
```
But in 2024 more developers prefer use async/await syntax for asynchronous operations
So, in this PR I added support for Promise API with **backward compatibility**, modern way:
```tsx
Image.getSize(uri).then(({width,height}) => { }); // Promise
Image.getSizeWithHeaders(uri, headers).then(({width,height}) => { }); // Promise
```
bypass-github-export-checks
## Changelog:
[GENERAL] [ADDED] - `Image.getSize/getSizeWithHeaders` method returns a promise if you don't pass a `success` callback
Pull Request resolved: https://github.com/facebook/react-native/pull/42895
Test Plan:
1. ts: New test cases added in typescript tests
2. runtime: you can create a new project and put code from this PR into the next files
a. `node_modules/react-native/Libraries/Image/Image.android.js`
b. `node_modules/react-native/Libraries/Image/Image.ios.js`
Reviewed By: javache
Differential Revision: D53919431
Pulled By: cipolleschi
fbshipit-source-id: 508b201e17e0ffda2e67aa5292bf9906b88d09c5
2024-02-27 09:54:30 +00:00
|
|
|
'no-dupe-class-members': 'off',
|
2023-03-08 08:14:56 +00:00
|
|
|
'redundant-undefined/redundant-undefined': [
|
|
|
|
'error',
|
|
|
|
{followExactOptionalPropertyTypes: true},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2022-06-16 17:12:58 +00:00
|
|
|
],
|
|
|
|
};
|