Skip to content

Commit 5258ef4

Browse files
committed
Address eslint warnings.
1 parent 2e3353d commit 5258ef4

21 files changed

+155
-127
lines changed

config/webpack-css.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ export const cssWebpackConfig: Configuration = {
9393
new RemoveEmptyScriptsPlugin(),
9494
new MiniCssExtractPlugin({
9595
filename: ({ chunk }) =>
96-
chunk?.name ?
97-
`${chunk.name}.css`
96+
chunk?.name
97+
? `${chunk.name}.css`
9898
.replace(/^codemirror-theme-/, 'editor-themes/')
99-
.replace(/-css\.css$/, '.css') :
100-
'[name].css'
99+
.replace(/-css\.css$/, '.css')
100+
: '[name].css'
101101
}),
102102
new RtlCssPlugin({
103103
entries: new Set(['manage-css', 'edit-css'])

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default eslintTs.config(
6464
'@stylistic/no-mixed-spaces-and-tabs': ['error', 'smart-tabs'],
6565
'@stylistic/no-tabs': ['error', { allowIndentationTabs: true }],
6666
'@stylistic/object-property-newline': ['error', { allowAllPropertiesOnSameLine: true }],
67-
'@stylistic/operator-linebreak': ['error', 'after'],
67+
'@stylistic/operator-linebreak': ['error', 'before'],
6868
'@stylistic/padded-blocks': ['error', 'never'],
6969
'@stylistic/quote-props': ['error', 'consistent-as-needed'],
7070
'@stylistic/quotes': ['error', 'single', { avoidEscape: true }],

src/js/components/SnippetForm/SnippetEditor/CodeEditorShortcuts.tsx

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import classnames from 'classnames'
33
import React from 'react'
44
import { KEYBOARD_KEYS } from '../../../types/KeyboardShortcut'
55
import { isMacOS } from '../../../utils/general'
6-
import type { KeyboardShortcut } from '../../../types/KeyboardShortcut'
6+
import type { KeyboardKey, KeyboardShortcut } from '../../../types/KeyboardShortcut'
77

88
const shortcuts: Record<string, KeyboardShortcut> = {
99
saveChanges: {
@@ -70,6 +70,30 @@ const shortcuts: Record<string, KeyboardShortcut> = {
7070

7171
const SEP = _x('-', 'keyboard shortcut separator', 'code-snippets')
7272

73+
const ModifierKey: React.FC<{ modifier: KeyboardKey }> = ({ modifier }) => {
74+
switch (modifier) {
75+
case 'Ctrl':
76+
case 'Cmd':
77+
return (
78+
<>
79+
<kbd className="pc-key">{KEYBOARD_KEYS.Ctrl}</kbd>
80+
<kbd className="mac-key">{KEYBOARD_KEYS.Cmd}</kbd>
81+
{SEP}
82+
</>
83+
)
84+
85+
case 'Option':
86+
return (
87+
<span className="mac-key">
88+
<kbd className="mac-key">{KEYBOARD_KEYS.Option}</kbd>{SEP}
89+
</span>
90+
)
91+
92+
default:
93+
return <><kbd>{KEYBOARD_KEYS[modifier]}</kbd>{SEP}</>
94+
}
95+
}
96+
7397
export interface CodeEditorShortcutsProps {
7498
editorTheme: string
7599
}
@@ -88,17 +112,7 @@ export const CodeEditorShortcuts: React.FC<CodeEditorShortcutsProps> = ({ editor
88112
<td>
89113
{(Array.isArray(mod) ? mod : [mod]).map(modifier =>
90114
<span key={modifier}>
91-
{'Ctrl' === modifier || 'Cmd' === modifier ?
92-
<>
93-
<kbd className="pc-key">{KEYBOARD_KEYS.Ctrl}</kbd>
94-
<kbd className="mac-key">{KEYBOARD_KEYS.Cmd}</kbd>
95-
{SEP}
96-
</> :
97-
'Option' === mod ?
98-
<span className="mac-key">
99-
<kbd className="mac-key">{KEYBOARD_KEYS.Option}</kbd>{SEP}
100-
</span> :
101-
<><kbd>{KEYBOARD_KEYS[modifier]}</kbd>{SEP}</>}
115+
<ModifierKey modifier={modifier} />
102116
</span>
103117
)}
104118
<kbd>{KEYBOARD_KEYS[key]}</kbd>

src/js/components/SnippetForm/SnippetEditor/SnippetEditor.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ const SnippetTypeTab: React.FC<SnippetTypeTabProps> = ({
3333
'nav-tab-active': tabType === currentType,
3434
'nav-tab-inactive': isProType(tabType) && !isLicensed()
3535
})}
36-
{...isProType(tabType) && !isLicensed() ?
37-
{
36+
{...isProType(tabType) && !isLicensed()
37+
? {
3838
title: __('Learn more about Code Snippets Pro.', 'code-snippets'),
3939
href: 'https://codesnippets.pro/pricing/',
4040
target: '_blank',
4141
onClick: event => {
4242
event.preventDefault()
4343
openUpgradeDialog()
4444
}
45-
} :
46-
{
45+
}
46+
: {
4747
href: addQueryArgs(window.location.href, { type: tabType }),
4848
onClick: event => {
4949
event.preventDefault()
@@ -105,8 +105,8 @@ const SnippetTypeTabs: React.FC<SnippetTypeTabsProps> = ({
105105
openUpgradeDialog={openUpgradeDialog}
106106
/>)}
107107

108-
{!isLicensed() ?
109-
<a
108+
{!isLicensed()
109+
? <a
110110
className="button button-large nav-tab-button nav-tab-inactive go-pro-button"
111111
href="https://codesnippets.pro/pricing/"
112112
title="Find more about Pro"
@@ -117,8 +117,8 @@ const SnippetTypeTabs: React.FC<SnippetTypeTabsProps> = ({
117117
>
118118
{_x('Upgrade to ', 'Upgrade to Pro', 'code-snippets')}
119119
<span className="badge">{_x('Pro', 'Upgrade to Pro', 'code-snippets')}</span>
120-
</a> :
121-
null}
120+
</a>
121+
: null}
122122
</h2>
123123
)
124124
}
@@ -136,13 +136,15 @@ export const SnippetEditor: React.FC<SnippetEditorProps> = ({ openUpgradeDialog
136136
<h2>
137137
<label htmlFor="snippet_code">
138138
{`${__('Code', 'code-snippets')} `}
139-
{snippet.id ?
140-
<span className="snippet-type-badge" data-snippet-type={snippetType}>{snippetType}</span> : null}
139+
{snippet.id
140+
? <span className="snippet-type-badge" data-snippet-type={snippetType}>{snippetType}</span>
141+
: null}
141142
</label>
142143
</h2>
143144

144-
{snippet.id || window.CODE_SNIPPETS_EDIT?.isPreview || !codeEditorInstance ? '' :
145-
<SnippetTypeTabs
145+
{snippet.id || window.CODE_SNIPPETS_EDIT?.isPreview || !codeEditorInstance
146+
? ''
147+
: <SnippetTypeTabs
146148
snippetType={snippetType}
147149
codeEditor={codeEditorInstance.codemirror}
148150
openUpgradeDialog={openUpgradeDialog}

src/js/components/SnippetForm/buttons/ActionButtons.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ export const ActionButtons: React.FC = () => {
1212
<p className="submit">
1313
<SubmitButton />
1414

15-
{snippet.id ?
16-
<>
15+
{snippet.id
16+
? <>
1717
<ExportButtons />
1818
<DeleteButton />
19-
</> : ''}
19+
</>
20+
: ''}
2021

2122
{isWorking ? <Spinner /> : ''}
2223
</p>

src/js/components/SnippetForm/buttons/ExportButtons.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export const ExportButtons: React.FC = () => {
4141
{__('Export', 'code-snippets')}
4242
</Button>
4343

44-
{window.CODE_SNIPPETS_EDIT?.enableDownloads ?
45-
<Button
44+
{window.CODE_SNIPPETS_EDIT?.enableDownloads
45+
? <Button
4646
name="export_snippet_code"
4747
onClick={() => {
4848
api.exportCode(snippet)
@@ -53,7 +53,8 @@ export const ExportButtons: React.FC = () => {
5353
disabled={isWorking}
5454
>
5555
{__('Export Code', 'code-snippets')}
56-
</Button> : ''}
56+
</Button>
57+
: ''}
5758
</>
5859
)
5960
}

src/js/components/SnippetForm/buttons/SubmitButtons.tsx

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ const SaveAndExecuteButton: React.FC<SubmitButtonProps> = ({ inlineButtons, ...p
2929
title={inlineButtons ? __('Save Snippet and Execute Once', 'code-snippets') : undefined}
3030
{...props}
3131
>
32-
{inlineButtons ?
33-
__('Execute Once', 'code-snippets') :
34-
__('Save Changes and Execute Once', 'code-snippets')}
32+
{inlineButtons
33+
? __('Execute Once', 'code-snippets')
34+
: __('Save Changes and Execute Once', 'code-snippets')}
3535
</Button>
3636

3737
const DeactivateButton: React.FC<SubmitButtonProps> = ({ inlineButtons, ...props }) =>
@@ -40,9 +40,9 @@ const DeactivateButton: React.FC<SubmitButtonProps> = ({ inlineButtons, ...props
4040
title={inlineButtons ? __('Save Snippet and Deactivate', 'code-snippets') : undefined}
4141
{...props}
4242
>
43-
{inlineButtons ?
44-
__('Deactivate', 'code-snippets') :
45-
__('Save Changes and Deactivate', 'code-snippets')}
43+
{inlineButtons
44+
? __('Deactivate', 'code-snippets')
45+
: __('Save Changes and Deactivate', 'code-snippets')}
4646
</Button>
4747

4848
const ActivateButton: React.FC<SubmitButtonProps> = ({ inlineButtons, ...props }) =>
@@ -51,9 +51,9 @@ const ActivateButton: React.FC<SubmitButtonProps> = ({ inlineButtons, ...props }
5151
title={inlineButtons ? __('Save Snippet and Activate', 'code-snippets') : undefined}
5252
{...props}
5353
>
54-
{inlineButtons ?
55-
__('Activate', 'code-snippets') :
56-
__('Save Changes and Activate', 'code-snippets')}
54+
{inlineButtons
55+
? __('Activate', 'code-snippets')
56+
: __('Save Changes and Activate', 'code-snippets')}
5757
</Button>
5858

5959
interface ActivateOrDeactivateButtonProps {
@@ -111,9 +111,11 @@ const validateSnippet = (snippet: Snippet): undefined | string => {
111111
}
112112

113113
const shouldActivateByDefault = (snippet: Snippet, inlineButtons?: boolean): boolean =>
114-
!inlineButtons && !!window.CODE_SNIPPETS_EDIT?.activateByDefault &&
115-
!snippet.active && 'single-use' !== snippet.scope &&
116-
(!snippet.shared_network || !isNetworkAdmin())
114+
!inlineButtons
115+
&& !!window.CODE_SNIPPETS_EDIT?.activateByDefault
116+
&& !snippet.active
117+
&& 'single-use' !== snippet.scope
118+
&& (!snippet.shared_network || !isNetworkAdmin())
117119

118120
interface SubmitConfirmDialogProps {
119121
isOpen: boolean
@@ -159,8 +161,8 @@ export const SubmitButton: React.FC<SubmitButtonsProps> = ({ inlineButtons }) =>
159161
}
160162

161163
return <>
162-
{activateByDefault ? null :
163-
<SaveChangesButton
164+
{activateByDefault ? null
165+
: <SaveChangesButton
164166
primary={!inlineButtons}
165167
onClick={() => handleSubmit(submitSnippet)}
166168
disabled={isWorking}
@@ -176,8 +178,8 @@ export const SubmitButton: React.FC<SubmitButtonsProps> = ({ inlineButtons }) =>
176178
onDeactivate={() => handleSubmit(submitAndDeactivateSnippet)}
177179
/>
178180

179-
{activateByDefault ?
180-
<SaveChangesButton
181+
{activateByDefault
182+
? <SaveChangesButton
181183
onClick={() => handleSubmit(submitSnippet)}
182184
disabled={isWorking}
183185
inlineButtons={inlineButtons}

src/js/components/SnippetForm/fields/DescriptionEditor.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ export const DescriptionEditor: React.FC = () => {
6060
domReady(() => initializeEditor(onChange))
6161
}, [onChange])
6262

63-
return window.CODE_SNIPPETS_EDIT?.enableDescription ?
64-
<div className="snippet-description-container">
63+
return window.CODE_SNIPPETS_EDIT?.enableDescription
64+
? <div className="snippet-description-container">
6565
<h2>
6666
<label htmlFor={EDITOR_ID}>
6767
{__('Description', 'code-snippets')}
@@ -77,6 +77,6 @@ export const DescriptionEditor: React.FC = () => {
7777
rows={window.CODE_SNIPPETS_EDIT.descEditorOptions.rows}
7878
cols={40}
7979
>{snippet.desc}</textarea>
80-
</div> :
81-
null
80+
</div>
81+
: null
8282
}

src/js/components/SnippetForm/fields/PriorityInput.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import { useSnippetForm } from '../../../hooks/useSnippetForm'
66
export const PriorityInput: React.FC = () => {
77
const { snippet, setSnippet, isReadOnly } = useSnippetForm()
88

9-
return 'html' === getSnippetType(snippet) ? null :
10-
<p
9+
return 'html' === getSnippetType(snippet)
10+
? null
11+
: <p
1112
className="snippet-priority"
1213
title={__('Snippets with a lower priority number will run before those with a higher number.', 'code-snippets')}
1314
>

src/js/components/SnippetForm/fields/ScopeInput.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import { useSnippetForm } from '../../../hooks/useSnippetForm'
1010
import { truncateWords } from '../../../utils/text'
1111
import type { ShortcodeAtts } from '../../../utils/shortcodes'
1212
import type { SnippetScope } from '../../../types/Snippet'
13-
import type { Dispatch, SetStateAction} from 'react'
13+
import type { Dispatch, SetStateAction } from 'react'
14+
15+
const MAX_SHORTCODE_NAME_WORDS = 3
1416

1517
const SHORTCODE_TAG = 'code_snippet'
1618

@@ -96,16 +98,16 @@ const ShortcodeInfo: React.FC = () => {
9698
shortcodes: false
9799
}))
98100

99-
return 'content' === snippet.scope ?
100-
<>
101+
return 'content' === snippet.scope
102+
? <>
101103
<p className="description">
102104
{__('There are multiple options for inserting this snippet into a post, page or other content.', 'code-snippets')}
103105
{' '}
104-
{snippet.id ?
106+
{snippet.id
105107
// eslint-disable-next-line @stylistic/max-len
106-
__('You can copy the below shortcode, or use the Classic Editor button, Block editor (Pro) or Elementor widget (Pro).', 'code-snippets') :
108+
? __('You can copy the below shortcode, or use the Classic Editor button, Block editor (Pro) or Elementor widget (Pro).', 'code-snippets')
107109
// eslint-disable-next-line @stylistic/max-len
108-
__('After saving, you can copy a shortcode, or use the Classic Editor button, Block editor (Pro) or Elementor widget (Pro).', 'code-snippets')}
110+
: __('After saving, you can copy a shortcode, or use the Classic Editor button, Block editor (Pro) or Elementor widget (Pro).', 'code-snippets')}
109111
{' '}
110112
<ExternalLink
111113
href={__('https://help.codesnippets.pro/article/50-inserting-snippets', 'code-snippets')}
@@ -114,11 +116,11 @@ const ShortcodeInfo: React.FC = () => {
114116
</ExternalLink>
115117
</p>
116118

117-
{snippet.id ?
118-
<>
119+
{snippet.id
120+
? <>
119121
<ShortcodeTag atts={{
120122
id: snippet.id,
121-
name: truncateWords(snippet.name),
123+
name: truncateWords(snippet.name, MAX_SHORTCODE_NAME_WORDS),
122124
network: snippet.network ?? isNetworkAdmin(),
123125
...options
124126
}} />
@@ -133,8 +135,10 @@ const ShortcodeInfo: React.FC = () => {
133135
['shortcodes', __('Evaluate additional shortcode tags', 'code-snippets')]
134136
]}
135137
/>
136-
</> : null}
137-
</> : null
138+
</>
139+
: null}
140+
</>
141+
: null
138142
}
139143

140144
export const ScopeInput: React.FC = () => {

0 commit comments

Comments
 (0)