Repository navigation
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-checkingreports acheckCallbackoreditorCheckCallbackinaddCommand()that never reads itscheckingparameter. Obsidian calls it withcheckingset totrueto 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 therecommendedconfig (#248).no-await-chainablereportsawaitof aSettingor a UI component (ButtonComponent,TextComponentand the otherBaseComponentsubclasses), and returning one from an async function. Theirthen(cb)is for chaining: it callscbwith the object and returns the object, so promise resolution calls it again forever, theawaitnever settles and the app stops responding.@typescript-eslint/await-thenabledoes not catch it, because the objects are thenables. It is an error in therecommendedconfig, for TypeScript files (#249).
Changed
no-unsupported-apinames the fix in its report: raiseminAppVersionto the version the API needs, or guard the use withrequireApiVersion()and that version. Below 0.13.21, which first hasrequireApiVersion(), it suggests a check that the API exists instead, and for a superclass, such asclass extends AbstractInputSuggest, or a newer signature that no such check proves, only raisingminAppVersion(#250).ui/sentence-case,ui/sentence-case-jsonandui/sentence-case-locale-moduleadd theacronymsoption to the built-in acronyms instead of replacing them, so adding one no longer means listing all the built-in ones again. The newreplaceDefaultAcronyms: truereplaces them, asacronymsdid. 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-docadvisesactiveDocument.body, and offers it as a suggestion, for an element the code puts indocument.bodyonly 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 toappendChild(),append(),prepend(),insertBefore()orinsertAdjacentElement()and also removes. The suggestion rewrites everydocument.bodycall for that element at once,removeChild()andcontains()included, and is offered on each of them or on none: moving only theappendChild()left aremoveChild()in afinallyor a cleanup callback on the main window's body, where it threwNotFoundErrorin a popout window. It reported these as state of the whole window, told the author to set them up in each window fromworkspace.on("window-open"), and offered nothing. An element that is never removed, and anything put indocument.head, are still reported that way (#278, #289).
Fixed
- Fixes and suggestions that changed what correct code does, or did not compile:
no-global-thisandprefer-window-timersno longer rewrite towindowwhere TypeScript has narrowedwindowto a type without the property, which did not compile (TS2339):globalThis.setTimeout(cb, 100)in theelseofif ("requestIdleCallback" in window)becamewindow.setTimeout(…)on awindowof typenever, sinceWindowdeclaresrequestIdleCallback. The same goes for code afterif ("requestIdleCallback" in window) return;, and fortypeof windowandwindow instanceof Xchecks that rule the window out. Both rules still report the call there, with neither a fix nor a suggestion (#288).prefer-window-timersno longer rewritesactiveWindow.clearTimeout(id)andactiveWindow.clearInterval(id)towindowautomatically, and offers it as a suggestion instead. A timer ID belongs to the window that set the timer: whereactiveWindow.setTimeout()in a popout window set it,window.clearTimeout(id)did not clear it (#266).prefer-window-timersno longer rewritesactiveWindow.setTimeout()andactiveWindow.setInterval()towindowautomatically where their ID is kept, as inthis.id = activeWindow.setInterval(…), and offers it as a suggestion instead. The matchingactiveWindow.clearInterval(this.id)gets only a suggestion, so after--fixthe 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 innew Promise((resolve) => activeWindow.setTimeout(resolve, ms)), it is still fixed: with type information, that is a callback whose type returnsvoid; without it, a Promise executor or aforEach()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 doesno-global-thisthere: the worker has nowindow(#273, #286).- The recommended config treats a file named
worker.ts(orworker.jsand the other extensions), such assrc/worker.ts, as web worker code, like*.worker.ts.prefer-window-timersrewrote itssetTimeout()towindow.setTimeout(), andno-global-thisitsglobalThistowindow, which a worker does not have (#267). object-assignno longer suggestsObject.assign({}, DEFAULT_SETTINGS, o)where the call is the body of an arrow function whose caller throws the result away, as inoverrides.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 returnsvoid; without it,forEach()or a Promise executor (#271, #286).prefer-instanceofno longer autofixes a check whose value may be null behind a type assertion or declaration, which turned a check that wasfalseinto one that throws. WithstrictNullChecks, that is a value cast to a type withoutnullfrom one that may be null, such asconst next = e.relatedTarget as HTMLElement; without it, also a cast, a variable with a type annotation set from a nullable call, such asconst 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 aNodeclass whose constructor needs arguments, is no longer reported:el.instanceOf(Widget)did not compile, andinstanceoffinds 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-elno longer reportsdocument.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 oftypeof createDiv === 'function' ? createDiv() : document.createElement('div'), a branch fortypeof activeDocument === 'undefined', and thecatchof atrythat callscreateEl(). It fixed them to the helper, which throws aReferenceErrorexactly there. Where a comment sits between or around the arguments, such ascreateElement(/* TODO */ 'p'), the replacement, which would drop it, is offered as a suggestion instead of a fix.prefer-active-docoffers noactiveDocumentin such a fallback either (#276).settings-tab/no-problematic-settings-headingsreports a "General" or plugin-name heading only at the top of the settings tab, where nothing comes before it indisplay(). A heading right after an unconditionalthis.containerEl.empty()counts as at the top, whatever ran before theempty(). 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-apino longer reportsworkspace.requestSaveLayout();below 0.16.0. It was a() => voidbefore 0.16.0 typed it aDebouncer, and a call that passes nothing and ignores the result works on both. Reading its result, or callingcancel()on it, is still reported (#286).no-unsupported-apirecognises 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 fromimport * as obsidian, a check compared withtrue, a feature check held in aconst, and areadonlyfield initialized withrequireApiVersion()that the file assigns nowhere else also count as guards (#283).no-unsupported-apireads a type alias in a member's type as the type it stands for when it compares the member with older typings.View.iconandView.getIcon()were typedstringbefore 1.1.0 typed themIconName, which istype IconName = string, sothis.icon = "dice"in anItemViewwas reported as needing 1.1.0. It also treats the body of anonUserEnable()override, which only Obsidian 1.7.2 and later calls, as running on 1.7.2, as it does foronPaneMenu(), sothis.app.workspace.ensureSideLeaf()there is no longer reported (#275).no-static-styles-assignmentno longer reports a fixed value written to astyleobject that, by type, is not an element's inline style, such as a plugin's ownsettings.style.theme = "compact". It matched anyx.style.propby name. With type information, astyleobject is now reported where its type is aCSSStyleDeclaration, has itscssTextorsetProperty(), or cannot tell, such asany; without it, as before, every one is (#272).no-nodejs-modulescounts an early exit in aswitchcase as a guard for the rest of that case, as one in a block is, socase "a": if (Platform.isMobile) return; require("fs");is no longer reported. It still guards nothing in the cases after it, whichswitchcan enter directly (#279).no-forbidden-elementsno longer reports a<style>or<link>in an iframe's document, whichstyles.cssdoes not reach, so that it is the only way to style it: one created oniframe.contentWindow.document, or created elsewhere and only inserted into the iframe's document, as iniframe.contentDocument.head.appendChild(style). Only one created oniframe.contentDocumentwas allowed (#280).editor-drop-pasteno longer reports a handler that lets Obsidian insert the content and changes it afterwards, as inwindow.setTimeout(() => editor.setValue(tidy(editor.getValue()))): one that writes to its editor only in a callback tosetTimeout(),then()and the like, or after anawait, and does not readevt.clipboardDataorevt.dataTransfer. It told such a handler to callevt.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
.cjsfilemoduleandexports.no-undefreportedmodule.exportsinjest.config.jsandrelease.config.cjs, andprocessand__dirnamein a script, as not defined. The typescript-eslint config the recommended config extends reads a.cjsfile as an ES module, somoduleandexportswere missing there too (#282). commands/no-plugin-name-in-command-nameno 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-idno longer reports such a command's ID, aszoom-in, and no longer suggests an ID that leaves only a word such asinorout(#284).commands/no-command-in-command-nameno 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-idreports a last "command" in the ID, as increate-slash-command, only where the command's name does without the word (#284).ui/sentence-case,ui/sentence-case-jsonandui/sentence-case-locale-moduleno 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 defaultloosemode, 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+, andignoreWordsapplies to the parts of a hyphenated word, as in "Dataview-powered" (#285).
- Findings the rules missed before:
prefer-active-docreportsdocument.createElementNS(svgNamespace, …)whereminAppVersionis 0.15.0 or later but older than 1.1.0, which first hascreateSvg(). It left the call toprefer-create-el, which does not report it below that version, so neither rule did (#270).no-unsupported-apireports a call toWorkspace.duplicateLeaf(leaf)whose result is used, such asconst 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 returnedPromise<void>until 0.13.8, so the result wasundefined. A call that discards the result, and a use of the method as a value, still need only 0.9.7 (#259).no-unsupported-apireportsEditorand the other declarations first in the 0.11.7 typings, such asMarkdownEditView, below 0.11.7 instead of 0.11.0. The obsidian-api commit that added them still named 0.11.0 in itspackage.json, so as that version's last commit it dated them 0.11.0, released a month earlier (#259).no-unsupported-apireports a global the app declares, such asactiveDocument, behindactiveDocument || document,if (activeDocument)oractiveDocument != null, which it counted as checked: below 0.15.0 reading it throws aReferenceError, so onlytypeof activeDocumentchecks it (#283).no-forbidden-elementsno 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 orel.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 indocument.head.insertAdjacentElement("beforeend", style)ordocument.head.appendChild(style), is reported too, andinsertAdjacentElement()into a shadow root counts as inserting into it (#260).no-nodejs-modulesreportsrequire?.("fs"): the bundle's ownrequireexists 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 putsrequireon the global object. Atrywhosecatchalways throws, as incatch (e) { throw e; }, no longer counts as a guard for arequire()or an awaitedimport()in it, since it hands the failure on (#261).editor-drop-pastereports a handler that writes to its editor even when it passes the event toconsole.log()or anotherconsolemethod. 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-filereportsvault.delete(file, force)with aforcethat is not a literal, and branches that differ only inforce, such asif (isFolder) vault.delete(file, true); else vault.delete(file);.forceonly letsdelete()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, asvault.trash(file, this.settings.useSystemTrash)does. As before,delete()gets no suggestion (#263).settings-tab/no-deprecated-display,settings-tab/prefer-update-over-displayandsettings-tab/require-displayread aminAppVersionwithout a patch version, such as"1.13", as1.13.0, asno-unsupported-apidoes. They did nothing for such a version (#268).validate-manifestchecks the words in theid,nameanddescriptionwithout 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-headingsno longer stops the whole ESLint run whenmanifest.jsonhas anamethat is not a string, such as"name": 123. It threwTypeError: 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-assignmentno longer stops the whole ESLint run onel.style.setProperty()called without arguments, which threwTypeError: Cannot read properties of undefined (reading 'type')(#264).ui/sentence-case,ui/sentence-case-jsonandui/sentence-case-locale-moduleignore an empty string in thebrands,acronymsandignoreWordsoptions. Withbrands: [""], 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-nameandcommands/no-command-in-command-nametake 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-jsonandui/sentence-case-locale-moduletreat anignoreRegexthat is not a valid regular expression as a configuration error that names it, instead of throwing aSyntaxErroron 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).