Skip to content

0.6.0

Latest

Choose a tag to compare

@saberzero1 saberzero1 released this 14 Nov 20:18
Immutable release. Only release title and notes can be modified.
0.6.0
a998a59

Upgrading from 0.5.x? See Upgrading to 0.6.0 for what changes.

Fixes found by linting the community plugins, about 10,300, with 0.5.1. The number of findings
barely changes: on those plugins, 0.6.0 reports about 0.2% fewer. What changes is mostly what
--fix and suggestions do. Rewrites that did not compile or changed what correct code does, such
as window.setTimeout() where TypeScript has narrowed window, a timer ID cleared on another
window than the one that set it, or a settings heading removed from the middle of the tab, are now
suggestions or left alone, so --fix leaves a few more findings to resolve by hand. Two new
rules: no-await-chainable, an error, reports await of a Setting or UI component, which never
settles, and commands/check-callback-uses-checking warns about a checkCallback that ignores
checking. One option changes: the sentence-case rules' acronyms adds to the built-in acronyms
instead of replacing them. See Upgrading to 0.6.0.

Added

  • commands/check-callback-uses-checking reports a checkCallback or editorCheckCallback in addCommand() that never reads its checking parameter. Obsidian calls it with checking set to true to ask whether the command is available, for example while the command palette is open, so such a callback runs its action on every check. It warns in the recommended config (#248).
  • no-await-chainable reports await of a Setting or a UI component (ButtonComponent, TextComponent and the other BaseComponent subclasses), and returning one from an async function. Their then(cb) is for chaining: it calls cb with the object and returns the object, so promise resolution calls it again forever, the await never settles and the app stops responding. @typescript-eslint/await-thenable does not catch it, because the objects are thenables. It is an error in the recommended config, for TypeScript files (#249).

Changed

  • no-unsupported-api names the fix in its report: raise minAppVersion to the version the API needs, or guard the use with requireApiVersion() and that version. Below 0.13.21, which first has requireApiVersion(), it suggests a check that the API exists instead, and for a superclass, such as class extends AbstractInputSuggest, or a newer signature that no such check proves, only raising minAppVersion (#250).
  • ui/sentence-case, ui/sentence-case-json and ui/sentence-case-locale-module add the acronyms option to the built-in acronyms instead of replacing them, so adding one no longer means listing all the built-in ones again. The new replaceDefaultAcronyms: true replaces them, as acronyms did. URI, UTC, GMT, ISO, OCR, TTS, RTL, LTR, AWS, MCP, RGB, RGBA, HSL, EPUB, ICS and OPML are now built in, and "TODO" in capitals is kept like "REST" (#285).
  • prefer-active-doc advises activeDocument.body, and offers it as a suggestion, for an element the code puts in document.body only for a moment, such as a download link (document.body.appendChild(a); a.click(); a.remove();) or a textarea for copying text: one it passes to appendChild(), append(), prepend(), insertBefore() or insertAdjacentElement() and also removes. The suggestion rewrites every document.body call for that element at once, removeChild() and contains() included, and is offered on each of them or on none: moving only the appendChild() left a removeChild() in a finally or a cleanup callback on the main window's body, where it threw NotFoundError in a popout window. It reported these as state of the whole window, told the author to set them up in each window from workspace.on("window-open"), and offered nothing. An element that is never removed, and anything put in document.head, are still reported that way (#278, #289).

Fixed

  • Fixes and suggestions that changed what correct code does, or did not compile:
    • no-global-this and prefer-window-timers no longer rewrite to window where TypeScript has narrowed window to a type without the property, which did not compile (TS2339): globalThis.setTimeout(cb, 100) in the else of if ("requestIdleCallback" in window) became window.setTimeout(…) on a window of type never, since Window declares requestIdleCallback. The same goes for code after if ("requestIdleCallback" in window) return;, and for typeof window and window instanceof X checks that rule the window out. Both rules still report the call there, with neither a fix nor a suggestion (#288).
    • prefer-window-timers no longer rewrites activeWindow.clearTimeout(id) and activeWindow.clearInterval(id) to window automatically, and offers it as a suggestion instead. A timer ID belongs to the window that set the timer: where activeWindow.setTimeout() in a popout window set it, window.clearTimeout(id) did not clear it (#266).
    • prefer-window-timers no longer rewrites activeWindow.setTimeout() and activeWindow.setInterval() to window automatically where their ID is kept, as in this.id = activeWindow.setInterval(…), and offers it as a suggestion instead. The matching activeWindow.clearInterval(this.id) gets only a suggestion, so after --fix the timer was set on the main window but cleared on whichever window was active, and might never be cleared. Where nothing can keep the ID, because the timer is the body of an arrow function whose caller ignores the result, as in new Promise((resolve) => activeWindow.setTimeout(resolve, ms)), it is still fixed: with type information, that is a callback whose type returns void; without it, a Promise executor or a forEach() callback. A timer in a function whose source the file turns into a string, as for an inline web worker (new Blob([(${body.toString()})()])), also gets a suggestion, as does no-global-this there: the worker has no window (#273, #286).
    • The recommended config treats a file named worker.ts (or worker.js and the other extensions), such as src/worker.ts, as web worker code, like *.worker.ts. prefer-window-timers rewrote its setTimeout() to window.setTimeout(), and no-global-this its globalThis to window, which a worker does not have (#267).
    • object-assign no longer suggests Object.assign({}, DEFAULT_SETTINGS, o) where the call is the body of an arrow function whose caller throws the result away, as in overrides.forEach((o) => Object.assign(DEFAULT_SETTINGS, o)). The code relies on the defaults being changed there, and with {} the call did nothing. With type information, such a caller is one whose callback type returns void; without it, forEach() or a Promise executor (#271, #286).
    • prefer-instanceof no longer autofixes a check whose value may be null behind a type assertion or declaration, which turned a check that was false into one that throws. With strictNullChecks, that is a value cast to a type without null from one that may be null, such as const next = e.relatedTarget as HTMLElement; without it, also a cast, a variable with a type annotation set from a nullable call, such as const input: Element = root.querySelector("input"), and a class field without an initializer that the constructor does not set. These now get the ?.instanceOf() suggestion. A check against an abstract class, or against a Node class whose constructor needs arguments, is no longer reported: el.instanceOf(Widget) did not compile, and instanceof finds a plugin's own class in every window. A check with a comment outside its operands is offered as a suggestion only, since the fix dropped the comment (#277).
    • prefer-create-el no longer reports document.createElement() and the other native calls in a fallback for where Obsidian's helpers are missing, as in a browser or under jsdom: the other branch of typeof createDiv === 'function' ? createDiv() : document.createElement('div'), a branch for typeof activeDocument === 'undefined', and the catch of a try that calls createEl(). It fixed them to the helper, which throws a ReferenceError exactly there. Where a comment sits between or around the arguments, such as createElement(/* TODO */ 'p'), the replacement, which would drop it, is offered as a suggestion instead of a fix. prefer-active-doc offers no activeDocument in such a fallback either (#276).
    • settings-tab/no-problematic-settings-headings reports a "General" or plugin-name heading only at the top of the settings tab, where nothing comes before it in display(). A heading right after an unconditional this.containerEl.empty() counts as at the top, whatever ran before the empty(). Lower down, as in a "General" section after an "Appearance" one, the heading starts a section of its own, and its fix removed it, which put that section's settings under the heading before it. The plugin's name is compared whole, so for a plugin named "Style Settings" a "Style" heading is no longer reported and removed. "settings" or "options" as what a verb acts on, as in "Export and import settings" or "Reset all settings", is no longer reported (#274, #286).
  • Fewer findings on correct code:
    • no-unsupported-api no longer reports workspace.requestSaveLayout(); below 0.16.0. It was a () => void before 0.16.0 typed it a Debouncer, and a call that passes nothing and ignores the result works on both. Reading its result, or calling cancel() on it, is still reported (#286).
    • no-unsupported-api recognises more guards. A read with a fallback, app.renderContext ?? null, works like the || it already allowed, and an optional access, app.secretStorage?.getSecret("token"), reads the newer member safely and runs the rest of the chain only on a release that has it, so neither member is reported. requireApiVersion() imported under another name or called from import * as obsidian, a check compared with true, a feature check held in a const, and a readonly field initialized with requireApiVersion() that the file assigns nowhere else also count as guards (#283).
    • no-unsupported-api reads a type alias in a member's type as the type it stands for when it compares the member with older typings. View.icon and View.getIcon() were typed string before 1.1.0 typed them IconName, which is type IconName = string, so this.icon = "dice" in an ItemView was reported as needing 1.1.0. It also treats the body of an onUserEnable() override, which only Obsidian 1.7.2 and later calls, as running on 1.7.2, as it does for onPaneMenu(), so this.app.workspace.ensureSideLeaf() there is no longer reported (#275).
    • no-static-styles-assignment no longer reports a fixed value written to a style object that, by type, is not an element's inline style, such as a plugin's own settings.style.theme = "compact". It matched any x.style.prop by name. With type information, a style object is now reported where its type is a CSSStyleDeclaration, has its cssText or setProperty(), or cannot tell, such as any; without it, as before, every one is (#272).
    • no-nodejs-modules counts an early exit in a switch case as a guard for the rest of that case, as one in a block is, so case "a": if (Platform.isMobile) return; require("fs"); is no longer reported. It still guards nothing in the cases after it, which switch can enter directly (#279).
    • no-forbidden-elements no longer reports a <style> or <link> in an iframe's document, which styles.css does not reach, so that it is the only way to style it: one created on iframe.contentWindow.document, or created elsewhere and only inserted into the iframe's document, as in iframe.contentDocument.head.appendChild(style). Only one created on iframe.contentDocument was allowed (#280).
    • editor-drop-paste no longer reports a handler that lets Obsidian insert the content and changes it afterwards, as in window.setTimeout(() => editor.setValue(tidy(editor.getValue()))): one that writes to its editor only in a callback to setTimeout(), then() and the like, or after an await, and does not read evt.clipboardData or evt.dataTransfer. It told such a handler to call evt.preventDefault(), which would cancel the paste or drop it relies on. A handler that reads the content and inserts it later, such as after an upload, is still reported (#281).
    • The recommended config gives test files and tool configs, which run in Node, the Node globals even where the plugin is not desktop-only, and every .cjs file module and exports. no-undef reported module.exports in jest.config.js and release.config.cjs, and process and __dirname in a script, as not defined. The typescript-eslint config the recommended config extends reads a .cjs file as an ES module, so module and exports were missing there too (#282).
    • commands/no-plugin-name-in-command-name no longer reports a command name that starts with the plugin name as a word of the sentence, with a word in lower case after it, as in "Zoom in" of the plugin "Zoom". commands/no-plugin-id-in-command-id no longer reports such a command's ID, as zoom-in, and no longer suggests an ID that leaves only a word such as in or out (#284).
    • commands/no-command-in-command-name no longer reports "command" as the last word after only a space, as in "Create slash command" or "Edit shell command", where it is the noun the command acts on; its suggestion would have renamed them "Create slash" and "Edit shell". commands/no-command-in-command-id reports a last "command" in the ID, as in create-slash-command, only where the command's name does without the word (#284).
    • ui/sentence-case, ui/sentence-case-json and ui/sentence-case-locale-module no longer lowercase words that keep a capital in English: the pronoun "I" ("Ask me before I delete a note"), weekdays, months and languages ("Week starts on Monday", "Translate to Japanese"), key names ("Press Enter", "Hold Shift", and "Tab" or "Home" where the words around them make them a key), letter ranges ("Name (A-Z)", "Sort A to Z") and, in the default loose mode, words in capitals that are not listed acronyms ("Copy Obsidian URI", "Use UTC time"), unless the whole text is in capitals. Keyboard shortcuts written with hyphens (Ctrl-S, Cmd-Shift-P) are skipped like those written with +, and ignoreWords applies to the parts of a hyphenated word, as in "Dataview-powered" (#285).
  • Findings the rules missed before:
    • prefer-active-doc reports document.createElementNS(svgNamespace, …) where minAppVersion is 0.15.0 or later but older than 1.1.0, which first has createSvg(). It left the call to prefer-create-el, which does not report it below that version, so neither rule did (#270).
    • no-unsupported-api reports a call to Workspace.duplicateLeaf(leaf) whose result is used, such as const copy = await workspace.duplicateLeaf(leaf), below 0.13.8. The overload is in the 0.9.7 typings, which allowed it from there, but it returned Promise<void> until 0.13.8, so the result was undefined. A call that discards the result, and a use of the method as a value, still need only 0.9.7 (#259).
    • no-unsupported-api reports Editor and the other declarations first in the 0.11.7 typings, such as MarkdownEditView, below 0.11.7 instead of 0.11.0. The obsidian-api commit that added them still named 0.11.0 in its package.json, so as that version's last commit it dated them 0.11.0, released a month earlier (#259).
    • no-unsupported-api reports a global the app declares, such as activeDocument, behind activeDocument || document, if (activeDocument) or activeDocument != null, which it counted as checked: below 0.15.0 reading it throws a ReferenceError, so only typeof activeDocument checks it (#283).
    • no-forbidden-elements no longer takes a variable for a shadow root by its name alone: const shadowRoot = document.head; shadowRoot.createEl("style") adds a <style> to the document's head, and is now reported. The name still counts where nothing else tells what the variable holds, such as an untyped parameter or el.getRootNode(); a declaration, a type annotation or, with type information, the variable's type decides first. A <style> or <link> created in a shadow root and then moved into the document, as in document.head.insertAdjacentElement("beforeend", style) or document.head.appendChild(style), is reported too, and insertAdjacentElement() into a shadow root counts as inserting into it (#260).
    • no-nodejs-modules reports require?.("fs"): the bundle's own require exists on mobile too, so the optional call still runs there and throws for a Node.js module. window.require?.("fs") stays allowed, since only the desktop app puts require on the global object. A try whose catch always throws, as in catch (e) { throw e; }, no longer counts as a guard for a require() or an awaited import() in it, since it hands the failure on (#261).
    • editor-drop-paste reports a handler that writes to its editor even when it passes the event to console.log() or another console method. Such a call only prints the event and neither checks nor cancels it, but it was counted as handing the event to a function that might (#262).
    • prefer-file-manager-trash-file reports vault.delete(file, force) with a force that is not a literal, and branches that differ only in force, such as if (isFolder) vault.delete(file, true); else vault.delete(file);. force only lets delete() remove a folder that is not empty, and the file is gone for good either way, but the rule skipped such calls as if the plugin let the user choose where deleted files go, as vault.trash(file, this.settings.useSystemTrash) does. As before, delete() gets no suggestion (#263).
    • settings-tab/no-deprecated-display, settings-tab/prefer-update-over-display and settings-tab/require-display read a minAppVersion without a patch version, such as "1.13", as 1.13.0, as no-unsupported-api does. They did nothing for such a version (#268).
    • validate-manifest checks the words in the id, name and description without the invisible characters that could hide them, such as a zero-width space, a soft hyphen or a bidi control, so "Obs\u200Bidian Sync" is reported as using "Obsidian" (#269).
  • Crashes, hangs and slow runs:
    • settings-tab/no-problematic-settings-headings no longer stops the whole ESLint run when manifest.json has a name that is not a string, such as "name": 123. It threw TypeError: pluginName.toLowerCase is not a function; now it skips only the plugin-name check, and the "settings" and "general" checks still report (#251).
    • no-static-styles-assignment no longer stops the whole ESLint run on el.style.setProperty() called without arguments, which threw TypeError: Cannot read properties of undefined (reading 'type') (#264).
    • ui/sentence-case, ui/sentence-case-json and ui/sentence-case-locale-module ignore an empty string in the brands, acronyms and ignoreWords options. With brands: [""], a text that is empty or starts with a character other than a letter or digit, such as "(Open) settings", made the rule loop forever, and the lint run never finished (#265).
    • The suggestions of commands/no-plugin-name-in-command-name and commands/no-command-in-command-name take linear time on a name made of many labels, as "Command: " repeated. They took quadratic time, minutes on a name of a few hundred kilobytes (#284).
    • ui/sentence-case, ui/sentence-case-json and ui/sentence-case-locale-module treat an ignoreRegex that is not a valid regular expression as a configuration error that names it, instead of throwing a SyntaxError on the first string checked. A long run of time-format tokens with no AM/PM token, as "h:".repeat(40000), takes linear time; it took quadratic time, 3 seconds at 80 KB (#285).