From 8a16681b73f7882cdc763b426dff76ded1145a63 Mon Sep 17 00:00:00 2001 From: Tetsuaki Hamano Date: Fri, 8 Mar 2024 11:05:20 +0900 Subject: [PATCH] Update eslint rules --- .eslintrc.js | 4 +--- .../accept-suggestion-on-enter.js | 2 +- .../empty-selection-clipboard.js | 2 +- .../editor-config/editor-options/find/loop.js | 2 +- .../find/seed-search-string-from-selection.js | 2 +- .../editor-config/editor-options/folding.js | 2 +- .../editor-config/editor-options/hover.js | 2 +- .../editor-options/minimap/enabled.js | 2 +- .../editor-options/quick-suggestions.js | 2 +- .../editor-config/editor-settings/emmet.js | 2 +- src/classic-editor/index.js | 24 ++++++++++--------- src/components/monaco-editor.js | 1 + src/lib/loader.js | 2 +- 13 files changed, 25 insertions(+), 24 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 33286f2..d176fac 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -5,12 +5,10 @@ module.exports = { jQuery: true, }, rules: { + 'react/jsx-boolean-value': 'error', 'import/no-extraneous-dependencies': 'off', 'import/no-unresolved': 'off', - 'no-nested-ternary': 'off', - 'no-unused-expressions': 'off', '@wordpress/no-unsafe-wp-apis': 'off', - 'jsdoc/require-param-type': 0, 'prettier/prettier': [ 'error', { diff --git a/src/admin/editor-config/editor-options/accept-suggestion-on-enter.js b/src/admin/editor-config/editor-options/accept-suggestion-on-enter.js index 748c791..210353d 100644 --- a/src/admin/editor-config/editor-options/accept-suggestion-on-enter.js +++ b/src/admin/editor-config/editor-options/accept-suggestion-on-enter.js @@ -50,7 +50,7 @@ export default function AcceptSuggestionOnEnter() { } ) } isToggle - defaultToggle={ true } + defaultToggle value={ editorOptions.acceptSuggestionOnEnter } /> diff --git a/src/admin/editor-config/editor-options/empty-selection-clipboard.js b/src/admin/editor-config/editor-options/empty-selection-clipboard.js index f014914..0ddbaf4 100644 --- a/src/admin/editor-config/editor-options/empty-selection-clipboard.js +++ b/src/admin/editor-config/editor-options/empty-selection-clipboard.js @@ -41,7 +41,7 @@ export default function EmptySelectionClipboard() { onChange={ onChange } title={ title } isToggle - defaultToggle={ true } + defaultToggle image={ 'editor-options/empty-selection-clipboard.gif' } value={ editorOptions.emptySelectionClipboard } /> diff --git a/src/admin/editor-config/editor-options/find/loop.js b/src/admin/editor-config/editor-options/find/loop.js index a54e4c1..b83d5af 100644 --- a/src/admin/editor-config/editor-options/find/loop.js +++ b/src/admin/editor-config/editor-options/find/loop.js @@ -44,7 +44,7 @@ export default function FindLoop() { 'custom-html-block-extension' ) } isToggle - defaultToggle={ true } + defaultToggle image={ 'editor-options/find/loop.gif' } value={ editorOptions.find.loop } /> diff --git a/src/admin/editor-config/editor-options/find/seed-search-string-from-selection.js b/src/admin/editor-config/editor-options/find/seed-search-string-from-selection.js index eda2db6..fd0a396 100644 --- a/src/admin/editor-config/editor-options/find/seed-search-string-from-selection.js +++ b/src/admin/editor-config/editor-options/find/seed-search-string-from-selection.js @@ -44,7 +44,7 @@ export default function FindSeedSearchStringFromSelection() { onChange={ onChange } title={ title } isToggle - defaultToggle={ true } + defaultToggle image={ 'editor-options/find/seed-search-string-from-selection.gif' } value={ editorOptions.find.seedSearchStringFromSelection } /> diff --git a/src/admin/editor-config/editor-options/folding.js b/src/admin/editor-config/editor-options/folding.js index d1d7a31..97f8b14 100644 --- a/src/admin/editor-config/editor-options/folding.js +++ b/src/admin/editor-config/editor-options/folding.js @@ -41,7 +41,7 @@ export default function Folding() { 'custom-html-block-extension' ) } isToggle - defaultToggle={ true } + defaultToggle image={ 'editor-options/folding.gif' } value={ editorOptions.folding } /> diff --git a/src/admin/editor-config/editor-options/hover.js b/src/admin/editor-config/editor-options/hover.js index 35e4af7..b88bd03 100644 --- a/src/admin/editor-config/editor-options/hover.js +++ b/src/admin/editor-config/editor-options/hover.js @@ -37,7 +37,7 @@ export default function Hover() { onChange={ onChange } title={ title } isToggle - defaultToggle={ true } + defaultToggle image={ 'editor-options/hover.gif' } value={ editorOptions.hover } /> diff --git a/src/admin/editor-config/editor-options/minimap/enabled.js b/src/admin/editor-config/editor-options/minimap/enabled.js index 7a9d8c1..2a6c1cc 100644 --- a/src/admin/editor-config/editor-options/minimap/enabled.js +++ b/src/admin/editor-config/editor-options/minimap/enabled.js @@ -48,7 +48,7 @@ export default function MinimapEnabled() { 'custom-html-block-extension' ) } isToggle - defaultToggle={ true } + defaultToggle image={ 'editor-options/minimap/enabled.gif' } value={ editorOptions.minimap.enabled } /> diff --git a/src/admin/editor-config/editor-options/quick-suggestions.js b/src/admin/editor-config/editor-options/quick-suggestions.js index c4d3f10..f587573 100644 --- a/src/admin/editor-config/editor-options/quick-suggestions.js +++ b/src/admin/editor-config/editor-options/quick-suggestions.js @@ -46,7 +46,7 @@ export default function QuickSuggestions() { 'custom-html-block-extension' ) } isToggle - defaultToggle={ true } + defaultToggle image={ 'editor-options/quick-suggestions.gif' } value={ editorOptions.quickSuggestions } /> diff --git a/src/admin/editor-config/editor-settings/emmet.js b/src/admin/editor-config/editor-settings/emmet.js index 5c5072e..480f17f 100644 --- a/src/admin/editor-config/editor-settings/emmet.js +++ b/src/admin/editor-config/editor-settings/emmet.js @@ -69,7 +69,7 @@ export default function Emmet() { } isToggle - defaultToggle={ true } + defaultToggle image={ 'editor-settings/emmet.gif' } value={ editorSettings.emmet } /> diff --git a/src/classic-editor/index.js b/src/classic-editor/index.js index d87bb34..1739c88 100644 --- a/src/classic-editor/index.js +++ b/src/classic-editor/index.js @@ -80,9 +80,8 @@ initLoader().then( ( monaco ) => { textarea.value = editorValue; // Change editor area height. - // eslint-disable-next-line no-shadow - const contentHeight = Math.max( 300, window.editor.getContentHeight() ); - monacoEditorContainer.style.height = `${ contentHeight }px`; + const newContentHeight = Math.max( 300, window.editor.getContentHeight() ); + monacoEditorContainer.style.height = `${ newContentHeight }px`; } ); // Enable Emmet. @@ -105,10 +104,14 @@ initLoader().then( ( monaco ) => { } ); // Catch the Ctrl+S command to save draft or publish post. - // eslint-disable-next-line no-bitwise - window.editor.addCommand( monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_S, () => { - !! draftButton ? draftButton.click() : publishButton.click(); - } ); + window.editor.addCommand( + // eslint-disable-next-line no-bitwise + monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_S, + () => { + // eslint-disable-next-line no-unused-expressions + !! draftButton ? draftButton.click() : publishButton.click(); + } + ); // Load webfont. const font = fontFamily.find( ( data ) => editorOptions.fontFamily === data.name ); @@ -222,10 +225,9 @@ initLoader().then( ( monaco ) => { }; // Get cursor position info for the editor. - // eslint-disable-next-line no-shadow - const getEditorPosition = ( textarea ) => { - const linesContent = textarea.value.split( '\n' ); - let selectionStart = textarea.selectionStart; + const getEditorPosition = ( element ) => { + const linesContent = element.value.split( '\n' ); + let selectionStart = element.selectionStart; let lineNumber = 1; let column = 0; diff --git a/src/components/monaco-editor.js b/src/components/monaco-editor.js index c34ad39..7bef4e7 100644 --- a/src/components/monaco-editor.js +++ b/src/components/monaco-editor.js @@ -92,6 +92,7 @@ export default function MonacoEditor( { }, 500 ); return () => { + // eslint-disable-next-line no-unused-expressions editorRef ? disposeEditor() : cancelable.cancel(); clearInterval( interval ); }; diff --git a/src/lib/loader.js b/src/lib/loader.js index a5c5647..be76bb5 100644 --- a/src/lib/loader.js +++ b/src/lib/loader.js @@ -26,7 +26,7 @@ function makeCancelable( promise ) { /** * Custom monaco editor loader which is a customized version of @monaco-editor/loader. * - * @param targetWindow The window object to load the editor. + * @param {Object} targetWindow The window object to load the editor. * @see https://github.com/suren-atoyan/monaco-loader */ export default function initLoader( targetWindow = window ) {