From 853cefca7555cafde1d356f01b3a674f583df118 Mon Sep 17 00:00:00 2001 From: Opender Singh Date: Sat, 7 Aug 2021 20:03:56 +1200 Subject: [PATCH] React ESLint rules (#3884) --- .eslintrc.js | 10 +++++++ .../app/ui/components/analytics.tsx | 6 +++-- .../ui/components/base/dropdown/dropdown.tsx | 15 +++++++---- .../app/ui/components/base/modal.tsx | 3 ++- .../ui/components/buttons/settings-button.tsx | 3 ++- .../ui/components/codemirror/code-editor.tsx | 6 +++-- .../app/ui/components/cookie-list.tsx | 18 ++++++++----- .../components/dropdowns/account-dropdown.tsx | 3 ++- .../dropdowns/environments-dropdown.tsx | 9 ++++--- .../dropdowns/git-sync-dropdown.tsx | 3 ++- .../grpc-method-dropdown.tsx | 3 ++- .../components/dropdowns/method-dropdown.tsx | 6 +++-- .../dropdowns/remote-workspaces-dropdown.tsx | 3 ++- .../dropdowns/request-actions-dropdown.tsx | 3 ++- .../dropdowns/response-history-dropdown.tsx | 3 ++- .../ui/components/dropdowns/sync-dropdown.tsx | 6 +++-- .../dropdowns/workspace-card-dropdown.tsx | 3 ++- .../dropdowns/workspace-dropdown.tsx | 12 ++++++--- .../ui/components/editors/auth/asap-auth.tsx | 9 ++++--- .../ui/components/editors/auth/aws-auth.tsx | 6 +++-- .../ui/components/editors/auth/basic-auth.tsx | 9 ++++--- .../components/editors/auth/bearer-auth.tsx | 9 ++++--- .../components/editors/auth/digest-auth.tsx | 6 +++-- .../ui/components/editors/auth/hawk-auth.tsx | 15 +++++++---- .../ui/components/editors/auth/ntlm-auth.tsx | 6 +++-- .../components/editors/auth/o-auth-1-auth.tsx | 12 ++++++--- .../components/editors/auth/o-auth-2-auth.tsx | 21 ++++++++++----- .../components/editors/body/file-editor.tsx | 3 ++- .../ui/components/editors/password-editor.tsx | 6 +++-- .../export-requests/request-group-row.tsx | 3 ++- .../graph-ql-explorer-type.tsx | 3 ++- .../graph-ql-explorer/graph-ql-explorer.tsx | 9 ++++--- .../ui/components/key-value-editor/row.tsx | 27 ++++++++++++------- .../app/ui/components/markdown-preview.tsx | 2 +- .../modals/add-key-combination-modal.tsx | 3 ++- .../components/modals/code-prompt-modal.tsx | 3 ++- .../components/modals/generate-code-modal.tsx | 3 ++- .../components/modals/git-branches-modal.tsx | 15 +++++++---- .../components/modals/git-staging-modal.tsx | 6 +++-- .../modals/payment-notification-modal.tsx | 6 +++-- .../app/ui/components/modals/prompt-modal.tsx | 3 ++- .../components/modals/proto-files-modal.tsx | 3 ++- .../modals/request-create-modal.tsx | 9 ++++--- .../modals/request-render-error-modal.tsx | 3 ++- .../modals/request-settings-modal.tsx | 15 +++++++---- .../modals/request-switcher-modal.tsx | 6 +++-- .../modals/response-debug-modal.tsx | 3 ++- .../modals/space-settings-modal.tsx | 3 ++- .../components/modals/sync-branches-modal.tsx | 18 ++++++++----- .../components/modals/sync-delete-modal.tsx | 3 ++- .../components/modals/sync-history-modal.tsx | 3 ++- .../ui/components/modals/sync-merge-modal.tsx | 3 ++- .../workspace-environments-edit-modal.tsx | 15 +++++++---- .../modals/workspace-settings-modal.tsx | 24 +++++++++++------ .../app/ui/components/page-layout.tsx | 6 +++-- .../panes/placeholder-request-pane.tsx | 9 ++++--- .../app/ui/components/panes/request-pane.tsx | 24 +++++++++++------ .../app/ui/components/panes/response-pane.tsx | 3 ++- .../proto-file/proto-directory-list-item.tsx | 3 ++- .../proto-file/proto-file-list-item.tsx | 9 ++++--- .../ui/components/rendered-query-string.tsx | 3 ++- .../app/ui/components/rendered-text.tsx | 3 ++- .../app/ui/components/request-url-bar.tsx | 15 +++++++---- .../app/ui/components/settings/account.tsx | 9 ++++--- .../app/ui/components/settings/general.tsx | 21 ++++++++++----- .../app/ui/components/settings/plugins.tsx | 15 +++++++---- .../app/ui/components/settings/shortcuts.tsx | 6 +++-- .../components/sidebar/sidebar-children.tsx | 3 ++- .../sidebar/sidebar-request-group-row.tsx | 9 ++++--- .../sidebar/sidebar-request-row.tsx | 6 +++-- .../app/ui/components/sidebar/sidebar.tsx | 3 ++- .../ui/components/tags/grpc-status-tag.tsx | 3 ++- .../app/ui/components/tags/grpc-tag.tsx | 3 ++- .../app/ui/components/tags/method-tag.tsx | 6 +++-- .../app/ui/components/tags/size-tag.tsx | 3 ++- .../app/ui/components/tags/status-tag.tsx | 3 ++- .../app/ui/components/tags/time-tag.tsx | 3 ++- .../app/ui/components/tags/url-tag.tsx | 3 ++- .../ui/components/templating/tag-editor.tsx | 18 ++++++++----- .../insomnia-app/app/ui/components/toast.tsx | 9 ++++--- .../app/ui/components/tooltip.tsx | 6 +++-- .../viewers/grpc-tabbed-messages.tsx | 6 +++-- .../ui/components/viewers/response-error.tsx | 6 +++-- .../viewers/response-headers-viewer.tsx | 6 +++-- .../components/viewers/response-multipart.tsx | 12 ++++++--- .../ui/components/viewers/response-viewer.tsx | 6 +++-- .../app/ui/components/wrapper-analytics.tsx | 3 ++- .../app/ui/components/wrapper-debug.tsx | 3 ++- .../app/ui/components/wrapper-design.tsx | 6 +++-- .../app/ui/components/wrapper-migration.tsx | 6 +++-- .../app/ui/components/wrapper-onboarding.tsx | 3 ++- .../app/ui/components/wrapper-unit-test.tsx | 14 ++++++---- .../src/button/circle-button.stories.tsx | 3 ++- .../src/dropdown/dropdown-item.tsx | 3 ++- .../src/dropdown/dropdown.stories.tsx | 3 ++- .../src/dropdown/dropdown.tsx | 6 +++-- .../src/list-group/list-group.stories.tsx | 24 +++++++++++------ .../list-group/unit-test-request-selector.tsx | 3 ++- .../insomnia-components/src/notice-table.tsx | 6 +++-- .../src/sidebar/sidebar-filter.tsx | 3 ++- .../src/sidebar/sidebar-header.tsx | 3 ++- .../src/sidebar/sidebar-panel.tsx | 3 ++- .../src/sidebar/sidebar-paths.tsx | 3 ++- .../src/sidebar/sidebar-requests.tsx | 6 +++-- .../src/sidebar/sidebar.stories.tsx | 18 ++++++++----- .../src/svg-icon.stories.tsx | 6 +++-- packages/insomnia-components/src/switch.tsx | 5 ++-- packages/insomnia-components/src/tooltip.tsx | 3 ++- 108 files changed, 523 insertions(+), 258 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 12b361761c..2e0c0fc18e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -97,6 +97,16 @@ module.exports = { 'react/jsx-indent': ['error', 2], 'react/jsx-indent-props': ['error', 2], 'react/prop-types': 'off', + 'react/function-component-definition': ['error', { + 'namedComponents': 'arrow-function', + 'unnamedComponents': 'arrow-function', + }], + 'react/jsx-max-props-per-line': ['error', { 'maximum': 1, 'when': 'multiline' }], + 'react/jsx-closing-bracket-location': ['error', 'line-aligned'], + 'react/prefer-stateless-function': 'warn', // TODO: fix this and change to error + 'react/jsx-key': ['error', { 'checkFragmentShorthand': true }], + 'react/no-array-index-key': 'warn', + 'react/self-closing-comp': 'error', 'react-hooks/exhaustive-deps': 'error', 'react-hooks/rules-of-hooks': 'error', diff --git a/packages/insomnia-app/app/ui/components/analytics.tsx b/packages/insomnia-app/app/ui/components/analytics.tsx index bef190f38c..8b29d8b300 100644 --- a/packages/insomnia-app/app/ui/components/analytics.tsx +++ b/packages/insomnia-app/app/ui/components/analytics.tsx @@ -48,13 +48,15 @@ class Analytics extends PureComponent { radius="3px" size="medium" variant="contained" - onClick={this._handleClickEnableAnalytics}> + onClick={this._handleClickEnableAnalytics} + > Share Usage Analytics diff --git a/packages/insomnia-app/app/ui/components/base/dropdown/dropdown.tsx b/packages/insomnia-app/app/ui/components/base/dropdown/dropdown.tsx index d3d570b487..96b5228c5c 100644 --- a/packages/insomnia-app/app/ui/components/base/dropdown/dropdown.tsx +++ b/packages/insomnia-app/app/ui/components/base/dropdown/dropdown.tsx @@ -381,7 +381,8 @@ class Dropdown extends PureComponent { className={classnames({ active, hide, - })}> + })} + > {child} , ); @@ -412,7 +413,8 @@ class Dropdown extends PureComponent {
+ aria-hidden={!open} + >
{ tabIndex={-1} className={classnames('dropdown__list', { 'dropdown__list--filtering': filterVisible, - })}> + })} + >
{
    + })} + > {dropdownItems}
@@ -453,7 +457,8 @@ class Dropdown extends PureComponent { ref={this._setRef} onClick={this._handleClick} tabIndex={-1} - onMouseDown={Dropdown._handleMouseDown}> + onMouseDown={Dropdown._handleMouseDown} + > {finalChildren}
diff --git a/packages/insomnia-app/app/ui/components/base/modal.tsx b/packages/insomnia-app/app/ui/components/base/modal.tsx index a4d902e01f..1418ac832c 100644 --- a/packages/insomnia-app/app/ui/components/base/modal.tsx +++ b/packages/insomnia-app/app/ui/components/base/modal.tsx @@ -178,7 +178,8 @@ class Modal extends PureComponent { className={classes} style={styles} aria-hidden={!open} - onClick={this._handleClick}> + onClick={this._handleClick} + >
diff --git a/packages/insomnia-app/app/ui/components/buttons/settings-button.tsx b/packages/insomnia-app/app/ui/components/buttons/settings-button.tsx index 32504f7b14..426c829e3d 100644 --- a/packages/insomnia-app/app/ui/components/buttons/settings-button.tsx +++ b/packages/insomnia-app/app/ui/components/buttons/settings-button.tsx @@ -22,7 +22,8 @@ const SettingsButton: FunctionComponent = ({ className, settings }) => ( Preferences ( ) - }> + } + > diff --git a/packages/insomnia-app/app/ui/components/codemirror/code-editor.tsx b/packages/insomnia-app/app/ui/components/codemirror/code-editor.tsx index fbbd67b05b..c9804abf1a 100644 --- a/packages/insomnia-app/app/ui/components/codemirror/code-editor.tsx +++ b/packages/insomnia-app/app/ui/components/codemirror/code-editor.tsx @@ -1205,7 +1205,8 @@ class CodeEditor extends Component { key="prettify" className="btn btn--compact" title="Auto-format request body whitespace" - onClick={this._handleBeautify}> + onClick={this._handleBeautify} + > Beautify {contentTypeName} , ); @@ -1233,7 +1234,8 @@ class CodeEditor extends Component { className={classnames('editor__container', 'input', className)} style={styles} onClick={onClick} - onMouseLeave={onMouseLeave}> + onMouseLeave={onMouseLeave} + >