diff --git a/.eslintrc.yaml b/.eslintrc.yaml index db85b143dd..a4967d170e 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -656,6 +656,7 @@ rules: unicorn/catch-error-name: [0] unicorn/consistent-destructuring: [2] unicorn/consistent-empty-array-spread: [2] + unicorn/consistent-existence-index-check: [2] unicorn/consistent-function-scoping: [2] unicorn/custom-error-definition: [0] unicorn/empty-brace-spaces: [2] @@ -732,10 +733,12 @@ rules: unicorn/prefer-dom-node-text-content: [2] unicorn/prefer-event-target: [2] unicorn/prefer-export-from: [0] + unicorn/prefer-global-this: [0] unicorn/prefer-includes: [2] unicorn/prefer-json-parse-buffer: [0] unicorn/prefer-keyboard-event-key: [2] unicorn/prefer-logical-operator-over-ternary: [2] + unicorn/prefer-math-min-max: [2] unicorn/prefer-math-trunc: [2] unicorn/prefer-modern-dom-apis: [0] unicorn/prefer-modern-math-apis: [2] diff --git a/web_src/js/features/comp/ComboMarkdownEditor.js b/web_src/js/features/comp/ComboMarkdownEditor.js index 70e92de0c9..65ca7db882 100644 --- a/web_src/js/features/comp/ComboMarkdownEditor.js +++ b/web_src/js/features/comp/ComboMarkdownEditor.js @@ -363,7 +363,7 @@ class ComboMarkdownEditor { const lineStart = Math.max(0, value.lastIndexOf('\n', start - 1) + 1); // Find the end and extract the line. const lineEnd = value.indexOf('\n', start); - const line = value.slice(lineStart, lineEnd < 0 ? value.length : lineEnd); + const line = value.slice(lineStart, lineEnd === -1 ? value.length : lineEnd); // Match any whitespace at the start + any repeatable prefix + exactly one space after. const prefix = line.match(/^\s*((\d+)[.)]\s|[-*+]\s+(\[[ x]\]\s?)?|(>\s+)+)?/); diff --git a/web_src/js/features/eventsource.sharedworker.js b/web_src/js/features/eventsource.sharedworker.js index 62581cf687..15d028ea0c 100644 --- a/web_src/js/features/eventsource.sharedworker.js +++ b/web_src/js/features/eventsource.sharedworker.js @@ -28,7 +28,7 @@ class Source { deregister(port) { const portIdx = this.clients.indexOf(port); - if (portIdx < 0) { + if (portIdx === -1) { return this.clients.length; } this.clients.splice(portIdx, 1); diff --git a/web_src/js/utils.js b/web_src/js/utils.js index ce0fb66343..8805b702c8 100644 --- a/web_src/js/utils.js +++ b/web_src/js/utils.js @@ -3,13 +3,13 @@ import {encode, decode} from 'uint8-to-base64'; // transform /path/to/file.ext to file.ext export function basename(path = '') { const lastSlashIndex = path.lastIndexOf('/'); - return lastSlashIndex < 0 ? path : path.substring(lastSlashIndex + 1); + return lastSlashIndex === -1 ? path : path.substring(lastSlashIndex + 1); } // transform /path/to/file.ext to .ext export function extname(path = '') { const lastPointIndex = path.lastIndexOf('.'); - return lastPointIndex < 0 ? '' : path.substring(lastPointIndex); + return lastPointIndex === -1 ? '' : path.substring(lastPointIndex); } // test whether a variable is an object diff --git a/web_src/js/utils/dom.js b/web_src/js/utils/dom.js index 44adc795c5..54f7335186 100644 --- a/web_src/js/utils/dom.js +++ b/web_src/js/utils/dom.js @@ -155,7 +155,7 @@ export function autosize(textarea, {viewportMarginBottom = 0} = {}) { const isBorderBox = computedStyle.boxSizing === 'border-box'; const borderAddOn = isBorderBox ? topBorderWidth + bottomBorderWidth : 0; - const adjustedViewportMarginBottom = bottom < viewportMarginBottom ? bottom : viewportMarginBottom; + const adjustedViewportMarginBottom = Math.min(bottom, viewportMarginBottom); const curHeight = parseFloat(computedStyle.height); const maxHeight = curHeight + bottom - adjustedViewportMarginBottom;