Skip to content

linters/eslint-rules/plugin-name-as-code-in-ui

ESLint rule: plugin-name-as-code-in-ui

Reports an Obsidian plugin’s display name inside a string that is shown in UI as plain text. In UI the name is built as a <code> element instead: appendCodeBlock() into a DocumentFragment, or createFragmentWithCodeBlocks() with asCodeBlock(), from @mnaoumov/obsidian-lib’s html-element.ts, and the fragment is what is passed on.

Detection is best effort, by call shape, without type information. A string literal or template literal (or a + concatenation or ? : branch made of them) is read when it is:

  • the first argument of new Notice(...); - the first argument of setName, setDesc, setText, appendText or setTitle called on anything; - the text property of an options object passed to createEl, createDiv or createSpan.

There is no autofix: splitting a string around the name and building a fragment is a rewrite of the call, and often of a translation key, which needs judgement. A command name, a ribbon tooltip and a window title cannot hold markup, so the calls that set them (addCommand, addRibbonIcon, document.title) are not read at all.

Variable Description
MESSAGE_ID Message ID reported for a plugin name inside a UI string.
pluginNameAsCodeInUi ESLint rule requiring a plugin name shown in UI to be built as a <code> element.