Skip to content

Commit

Permalink
RN: Cleanup Existing ESLint Warnings
Browse files Browse the repository at this point in the history
Summary:
Sometime over the past few months (and with changes such as migrating to the `hermes-eslint` parser), a bunch of lint warnings crept into the codebase.

This does a pass to clean them all up, ignore generated files, and refactor some code to be... better.

There should be no observable behavior changes as a result of this.

Changelog:
[Internal]

Reviewed By: NickGerleman

Differential Revision: D38646643

fbshipit-source-id: a7b55d1e4cd5700340cc5c21f928baf3ea1d5a58
  • Loading branch information
yungsters authored and roryabraham committed Aug 17, 2022
1 parent 08642ea commit 0d55ccf
Show file tree
Hide file tree
Showing 23 changed files with 45 additions and 32 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
bots/node_modules
docs/generatedComponentApiDocs.js
flow/
flow-typed/
Libraries/Renderer/*
Libraries/vendor/**/*
node_modules/
Expand Down
1 change: 0 additions & 1 deletion IntegrationTests/AppEventsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class AppEventsTest extends React.Component<{...}, State> {
NativeAppEventEmitter.addListener('testEvent', this.receiveEvent);
const event = {data: TEST_PAYLOAD, ts: Date.now()};
TestModule.sendAppEvent('testEvent', event);
// eslint-disable-next-line react/no-did-mount-set-state
this.setState({sent: event});
}

Expand Down
7 changes: 4 additions & 3 deletions Libraries/Animated/animations/SpringAnimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

'use strict';

const AnimatedValue = require('../nodes/AnimatedValue');
const AnimatedValueXY = require('../nodes/AnimatedValueXY');
const AnimatedInterpolation = require('../nodes/AnimatedInterpolation');
import type AnimatedValue from '../nodes/AnimatedValue';
import type AnimatedValueXY from '../nodes/AnimatedValueXY';
import type AnimatedInterpolation from '../nodes/AnimatedInterpolation';

const Animation = require('./Animation');
const SpringConfig = require('../SpringConfig');

Expand Down
7 changes: 4 additions & 3 deletions Libraries/Animated/animations/TimingAnimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

'use strict';

const AnimatedValue = require('../nodes/AnimatedValue');
const AnimatedValueXY = require('../nodes/AnimatedValueXY');
const AnimatedInterpolation = require('../nodes/AnimatedInterpolation');
import type AnimatedValue from '../nodes/AnimatedValue';
import type AnimatedValueXY from '../nodes/AnimatedValueXY';
import type AnimatedInterpolation from '../nodes/AnimatedInterpolation';

const Animation = require('./Animation');

const {shouldUseNativeDriver} = require('../NativeAnimatedHelper');
Expand Down
3 changes: 2 additions & 1 deletion Libraries/Animated/nodes/AnimatedAddition.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

'use strict';

import type AnimatedNode from './AnimatedNode';

const AnimatedInterpolation = require('./AnimatedInterpolation');
const AnimatedNode = require('./AnimatedNode');
const AnimatedValue = require('./AnimatedValue');
const AnimatedWithChildren = require('./AnimatedWithChildren');

Expand Down
3 changes: 2 additions & 1 deletion Libraries/Animated/nodes/AnimatedDiffClamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

'use strict';

import type AnimatedNode from './AnimatedNode';

const AnimatedInterpolation = require('./AnimatedInterpolation');
const AnimatedNode = require('./AnimatedNode');
const AnimatedWithChildren = require('./AnimatedWithChildren');

import type {InterpolationConfigType} from './AnimatedInterpolation';
Expand Down
3 changes: 2 additions & 1 deletion Libraries/Animated/nodes/AnimatedInterpolation.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

'use strict';

const AnimatedNode = require('./AnimatedNode');
import type AnimatedNode from './AnimatedNode';

const AnimatedWithChildren = require('./AnimatedWithChildren');
const NativeAnimatedHelper = require('../NativeAnimatedHelper');

Expand Down
3 changes: 2 additions & 1 deletion Libraries/Animated/nodes/AnimatedModulo.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

'use strict';

import type AnimatedNode from './AnimatedNode';

const AnimatedInterpolation = require('./AnimatedInterpolation');
const AnimatedNode = require('./AnimatedNode');
const AnimatedWithChildren = require('./AnimatedWithChildren');

import type {InterpolationConfigType} from './AnimatedInterpolation';
Expand Down
3 changes: 2 additions & 1 deletion Libraries/Animated/nodes/AnimatedMultiplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

'use strict';

import type AnimatedNode from './AnimatedNode';

const AnimatedInterpolation = require('./AnimatedInterpolation');
const AnimatedNode = require('./AnimatedNode');
const AnimatedValue = require('./AnimatedValue');
const AnimatedWithChildren = require('./AnimatedWithChildren');

Expand Down
3 changes: 2 additions & 1 deletion Libraries/Animated/nodes/AnimatedSubtraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

'use strict';

import type AnimatedNode from './AnimatedNode';

const AnimatedInterpolation = require('./AnimatedInterpolation');
const AnimatedNode = require('./AnimatedNode');
const AnimatedValue = require('./AnimatedValue');
const AnimatedWithChildren = require('./AnimatedWithChildren');

Expand Down
3 changes: 2 additions & 1 deletion Libraries/Animated/nodes/AnimatedTracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

'use strict';

const AnimatedValue = require('./AnimatedValue');
import type AnimatedValue from './AnimatedValue';

const AnimatedNode = require('./AnimatedNode');
const {
generateNewAnimationId,
Expand Down
2 changes: 1 addition & 1 deletion Libraries/BatchedBridge/MessageQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ class MessageQueue {
return (
// $FlowFixMe[cannot-resolve-name]
typeof DebuggerInternal !== 'undefined' &&
DebuggerInternal.shouldPauseOnThrow === true // eslint-disable-line no-undef
DebuggerInternal.shouldPauseOnThrow === true
);
}

Expand Down
3 changes: 2 additions & 1 deletion Libraries/Blob/FileReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
* @format
*/

const Blob = require('./Blob');
import type Blob from './Blob';

const EventTarget = require('event-target-shim');

import NativeFileReaderModule from './NativeFileReaderModule';
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Blob/URL.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @flow
*/

const Blob = require('./Blob');
import type Blob from './Blob';

import NativeBlobModule from './NativeBlobModule';

Expand Down
2 changes: 1 addition & 1 deletion Libraries/Events/EventPolyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class EventPolyfill implements IEvent {
}

// Assertion magic for polyfill follows.
declare var checkEvent: Event;
declare var checkEvent: Event; // eslint-disable-line no-unused-vars

/*::
// This can be a strict mode error at runtime so put it in a Flow comment.
Expand Down
3 changes: 0 additions & 3 deletions Libraries/JSInspector/JSInspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ interface Agent {
// Flow doesn't support static declarations in interface
type AgentClass = Class<Agent> & {DOMAIN: string, ...};

declare function __registerInspectorAgent(type: AgentClass): void;
declare function __inspectorTimestamp(): number;

const JSInspector = {
registerAgent(type: AgentClass) {
if (global.__registerInspectorAgent) {
Expand Down
1 change: 1 addition & 0 deletions Libraries/LogBox/Data/parseLogBoxLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import parseErrorStack from '../../Core/Devtools/parseErrorStack';
const BABEL_TRANSFORM_ERROR_FORMAT =
/^(?:TransformError )?(?:SyntaxError: |ReferenceError: )(.*): (.*) \((\d+):(\d+)\)\n\n([\s\S]+)/;
const BABEL_CODE_FRAME_ERROR_FORMAT =
// eslint-disable-next-line no-control-regex
/^(?:TransformError )?(?:.*):? (?:.*?)(\/.*): ([\s\S]+?)\n([ >]{2}[\d\s]+ \|[\s\S]+|\u{001b}[\s\S]+)/u;
const METRO_ERROR_FORMAT =
/^(?:InternalError Metro has encountered an error:) (.*): (.*) \((\d+):(\d+)\)\n\n([\s\S]+)/u;
Expand Down
2 changes: 1 addition & 1 deletion Libraries/StyleSheet/StyleSheetTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

const AnimatedNode = require('../Animated/nodes/AnimatedNode');
import type AnimatedNode from '../Animated/nodes/AnimatedNode';

import type {NativeColorValue} from './PlatformColorValueTypes';

Expand Down
2 changes: 1 addition & 1 deletion Libraries/StyleSheet/private/_TransformStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @format
*/

const AnimatedNode = require('../../Animated/nodes/AnimatedNode');
import type AnimatedNode from '../../Animated/nodes/AnimatedNode';

export type ____TransformStyle_Internal = $ReadOnly<{|
/**
Expand Down
8 changes: 8 additions & 0 deletions interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@

'use strict';

// NOTE: Hmm... I don't think declaring variables within this module actually
// accomplishes anything besides documenting that these globals are exepcted to
// exist. So I think the correct "fix" to this lint warning is to delete this
// entire file. But in lieu of doing that... no harm for now in keeping this
// file around, even if it is only for documentation purposes. ¯\_(ツ)_/¯

/* eslint-disable no-unused-vars */

declare var __DEV__: boolean;

declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: any; /*?{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import type {
} from '../../../CodegenSchema';

import type {AliasResolver} from '../Utils';
import type {StructCollector} from './StructCollector';

const invariant = require('invariant');
const {StructCollector} = require('./StructCollector');
const {getNamespacedStructName} = require('./Utils');
const {capitalize} = require('../../Utils');
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,7 @@ describe('Flow Module Parser', () => {
describe('Primitive Element Types', () => {
PRIMITIVES.forEach(([FLOW_TYPE, PARSED_TYPE_NAME]) => {
it(`should parse methods that have ${RETURN_TYPE_DESCRIPTION} return of type 'Array<${FLOW_TYPE}>'`, () => {
const [elementType, module] =
parseArrayElementReturnType(FLOW_TYPE);
const [elementType] = parseArrayElementReturnType(FLOW_TYPE);
expect(elementType.type).toBe(PARSED_TYPE_NAME);
});
});
Expand Down
10 changes: 4 additions & 6 deletions scripts/codegen/__tests__/generate-specs-cli-executor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,18 @@

const sut = require('../generate-specs-cli-executor');
const fixtures = require('../__test_fixtures__/fixtures');
const path = require('path');
const {normalize} = require('path');

describe('generateSpec', () => {
it('invokes RNCodegen with the right params', () => {
const platform = 'ios';
const libraryType = 'all';
const schemaPath = './';
const componentsOutputDir = path.normalize(
const componentsOutputDir = normalize(
'app/ios/build/generated/ios/react/renderer/components/library',
);
const modulesOutputDir = path.normalize(
'app/ios/build/generated/ios/library',
);
const outputDirectory = path.normalize('app/ios/build/generated/ios');
const modulesOutputDir = normalize('app/ios/build/generated/ios/library');
const outputDirectory = normalize('app/ios/build/generated/ios');
const libraryName = 'library';
const packageName = 'com.library';
const generators = ['componentsIOS', 'modulesIOS'];
Expand Down

0 comments on commit 0d55ccf

Please sign in to comment.