Skip to content

Commit

Permalink
Open source react-native-modules ESLint rule
Browse files Browse the repository at this point in the history
Summary:
Open source this ESLint rule so that we can lint our open source NativeModule specs.

Changelog: [Internal]

Reviewed By: shergin, cpojer

Differential Revision: D23791748

fbshipit-source-id: e44444bc87eaa9dc9b7f2b3ed03151798a35e8a5
  • Loading branch information
RSNara authored and facebook-github-bot committed Sep 22, 2020
1 parent 891b6b0 commit 3a6327a
Show file tree
Hide file tree
Showing 19 changed files with 965 additions and 11 deletions.
21 changes: 13 additions & 8 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
"./packages/eslint-config-react-native-community/index.js"
],

"plugins": [
"@react-native/eslint-plugin-codegen"
],

"overrides": [
{
"files": [
"Libraries/**/*.js",
],
rules: {
'@react-native-community/no-haste-imports': 2,
'@react-native-community/error-subclass-name': 2,
'@react-native-community/platform-colors': 2,
"rules": {
"@react-native-community/no-haste-imports": 2,
"@react-native-community/error-subclass-name": 2,
"@react-native-community/platform-colors": 2,
"@react-native/codegen/react-native-modules": 2
}
},
{
Expand All @@ -40,8 +45,8 @@
],
"env": {
"jasmine": true,
"jest": true,
},
},
],
"jest": true
}
}
]
}
1 change: 1 addition & 0 deletions Libraries/Alert/NativeAlertManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type Args = {|

export interface Spec extends TurboModule {
+alertWithArgs: (
// eslint-disable-next-line @react-native/codegen/react-native-modules
args: Args,
callback: (id: number, value: string) => void,
) => void;
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Animated/NativeAnimatedModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type AnimatingNodeConfig = Object;
export interface Spec extends TurboModule {
+startOperationBatch: () => void;
+finishOperationBatch: () => void;

// eslint-disable-next-line @react-native/codegen/react-native-modules
+createAnimatedNode: (tag: number, config: AnimatedNodeConfig) => void;
+getValue: (tag: number, saveValueCallback: SaveValueCallback) => void;
+startListeningToAnimatedNodeValue: (tag: number) => void;
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Animated/NativeAnimatedTurboModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type AnimatingNodeConfig = Object;
export interface Spec extends TurboModule {
+startOperationBatch: () => void;
+finishOperationBatch: () => void;

// eslint-disable-next-line @react-native/codegen/react-native-modules
+createAnimatedNode: (tag: number, config: AnimatedNodeConfig) => void;
+getValue: (tag: number, saveValueCallback: SaveValueCallback) => void;
+startListeningToAnimatedNodeValue: (tag: number) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface Spec extends TurboModule {
* - 'default'
* - 'dark-content'
*/
// eslint-disable-next-line @react-native/codegen/react-native-modules
+setStyle: (statusBarStyle?: ?string) => void;
+setHidden: (hidden: boolean) => void;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface Spec extends TurboModule {
* - 'dark-content'
* - 'light-content'
*/
// eslint-disable-next-line @react-native/codegen/react-native-modules
+setStyle: (statusBarStyle?: ?string, animated: boolean) => void;
/**
* - withAnimation can be: 'none' | 'fade' | 'slide'
Expand Down
1 change: 1 addition & 0 deletions Libraries/Core/NativeExceptionsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface Spec extends TurboModule {
stack: Array<StackFrame>,
exceptionId: number,
) => void;
// eslint-disable-next-line @react-native/codegen/react-native-modules
+reportException?: (data: ExceptionData) => void;
+updateExceptionMessage: (
message: string,
Expand Down
1 change: 1 addition & 0 deletions Libraries/Image/NativeImageEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface Spec extends TurboModule {
+getConstants: () => {||};
+cropImage: (
uri: string,
// eslint-disable-next-line @react-native/codegen/react-native-modules
cropData: Options,
successCallback: (uri: string) => void,
errorCallback: (error: string) => void,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface Spec extends TurboModule {
+buttonNeutral: DialogButtonKey,
|};
+showAlert: (
// eslint-disable-next-line @react-native/codegen/react-native-modules
config: DialogOptions,
onError: (error: string) => void,
onAction: (action: DialogAction, buttonKey?: DialogButtonKey) => void,
Expand Down
1 change: 1 addition & 0 deletions Libraries/PermissionsAndroid/NativePermissionsAndroid.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export type PermissionType =
*/

export interface Spec extends TurboModule {
// eslint-disable-next-line @react-native/codegen/react-native-modules
+checkPermission: (permission: PermissionType) => Promise<boolean>;
+requestPermission: (permission: PermissionType) => Promise<PermissionStatus>;
+shouldShowRequestPermissionRationale: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Notification = {|
|};

export interface Spec extends TurboModule {
+getConstants: () => {...};
+getConstants: () => {||};
+onFinishRemoteNotification: (
notificationId: string,
/**
Expand All @@ -52,6 +52,7 @@ export interface Spec extends TurboModule {
|}) => Promise<Permissions>;
+abandonPermissions: () => void;
+checkPermissions: (callback: (permissions: Permissions) => void) => void;
// eslint-disable-next-line @react-native/codegen/react-native-modules
+presentLocalNotification: (notification: Notification) => void;
+scheduleLocalNotification: (notification: Notification) => void;
+cancelAllLocalNotifications: () => void;
Expand Down
1 change: 1 addition & 0 deletions Libraries/Share/NativeShareModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface Spec extends TurboModule {
+getConstants: () => {||};
+share: (
content: {|title?: string, message?: string|},
// eslint-disable-next-line @react-native/codegen/react-native-modules
dialogTitle?: string,
) => Promise<{|action: string|}>;
}
Expand Down
1 change: 1 addition & 0 deletions Libraries/TurboModule/samples/NativeSampleTurboModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface Spec extends TurboModule {
+getString: (arg: string) => string;
+getArray: (arg: Array<any>) => Array<any>;
+getObject: (arg: Object) => Object;
// eslint-disable-next-line @react-native/codegen/react-native-modules
+getRootTag: (arg: RootTag) => RootTag;
+getValue: (x: number, y: string, z: Object) => Object;
+getValueWithCallback: (callback: (value: string) => void) => void;
Expand Down
23 changes: 23 additions & 0 deletions packages/eslint-plugin-codegen/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
load("@fbsource//tools/build_defs/third_party:yarn_defs.bzl", "yarn_workspace")

yarn_workspace(
name = "yarn-workspace",
srcs = glob(
["**/*.js"],
exclude = [
"**/__fixtures__/**",
"**/__flowtests__/**",
"**/__mocks__/**",
"**/__server_snapshot_tests__/**",
"**/__tests__/**",
"**/node_modules/**",
"**/node_modules/.bin/**",
"**/.*",
"**/.*/**",
"**/.*/.*",
"**/*.xcodeproj/**",
"**/*.xcworkspace/**",
],
),
visibility = ["PUBLIC"],
)
22 changes: 22 additions & 0 deletions packages/eslint-plugin-codegen/__tests__/eslint-tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) Facebook, Inc. and its 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';

const ESLintTester = require('eslint').RuleTester;

ESLintTester.setDefaultConfig({
parser: require.resolve('babel-eslint'),
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
},
});

module.exports = ESLintTester;
Loading

0 comments on commit 3a6327a

Please sign in to comment.