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 ofsetName,setDesc,setText,appendTextorsetTitlecalled on anything; - thetextproperty of an options object passed tocreateEl,createDivorcreateSpan.
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.
Variables
Section titled “Variables”| 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. |