Compare commits

..

24 commits

Author SHA1 Message Date
1aa3371ff6 rename 2026-02-14 23:49:36 +01:00
Lishid
dc2fa22c4d
Fix typo in ESLint plugin link 2025-12-30 13:09:48 -05:00
Johannes Theiner
2323eddbb1
Merge pull request #164 from joethei/master
Include eslint config
2025-12-18 11:53:40 +01:00
Johannes Theiner
911b773800 Merge remote-tracking branch 'upstream/master'
# Conflicts:
#	README.md
#	src/main.ts
2025-11-14 15:24:54 +01:00
Johannes Theiner
123fc4a870 update eslint plugin version
remove builtin-modules external dependency
2025-11-14 14:28:33 +01:00
Johannes Theiner
0eca98adda update package.json 2025-11-10 22:27:46 +01:00
Johannes Theiner
92cba25647 update sample plugin with eslint instructions 2025-11-10 12:26:07 +01:00
Johannes Theiner
9984b040b6 remove testing code 2025-10-17 12:36:26 +02:00
Johannes Theiner
e2a64e0534
Merge pull request #151 from adamu/main
Prefix unused variables with _
2025-09-17 18:12:44 +02:00
Johannes Theiner
8933f6ce64
Merge pull request #142 from johannrichard/declutter-version-bump
build: only write new minAppVersion requirements to `versions.json`
2025-09-17 17:54:33 +02:00
Steph Ango
db97f5f629
Merge pull request #155 from obsidianmd/agents-md
AGENTS.md
2025-09-05 09:12:10 -07:00
Adam Millerchip
f16c1401b3 Prefix unused variables with _ 2025-08-28 14:38:40 +09:00
Johannes Theiner
fa2fac56be Remove node 18 from action 2025-07-04 13:29:58 +02:00
Johannes Theiner
e0485eb3ba add lock file to repo 2025-07-04 13:28:27 +02:00
Johannes Theiner
dbc9096f81 Add lint action 2025-07-04 13:27:53 +02:00
Johannes Theiner
90290a8af5 Update to use released eslint plugin 2025-07-03 12:00:06 +02:00
Johannes Theiner
68ab547f2c Update to use released eslint plugin 2025-06-02 12:10:29 +02:00
Johann Richard
3fe07677b5
build: only write new minAppVersion requirements to versions.json
Only add a new version requirements if `minAppVersion` is not already in `versions.json`. Should declutter `versions.json`.
2025-04-28 08:38:38 +02:00
Johannes Theiner
ba04056938
Merge remote-tracking branch 'origin/master' 2025-01-02 16:48:30 +01:00
Johannes Theiner
55f5080882
Add linting of dependencies, throwing errors when including using telemetry libraries 2025-01-02 16:48:03 +01:00
Johannes Theiner
20002ffc65
Merge branch 'obsidianmd:master' into master 2024-11-20 17:02:47 +01:00
Johannes Theiner
fa15a2558e
Merge remote-tracking branch 'origin/master'
# Conflicts:
#	tsconfig.json
2024-07-31 23:00:52 +02:00
Johannes Theiner
15e343739e
Add stylelint and configure eslint to add custom plugin.
- Split up main.ts into multiple files.
2024-07-31 22:59:59 +02:00
Johannes Theiner
b9a0e401e0
configure eslint 2024-02-29 13:18:14 +01:00
13 changed files with 5341 additions and 132 deletions

View file

@ -1,3 +0,0 @@
node_modules/
main.js

View file

@ -1,23 +0,0 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"env": { "node": true },
"plugins": [
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"parserOptions": {
"sourceType": "module"
},
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["error", { "args": "none" }],
"@typescript-eslint/ban-ts-comment": "off",
"no-prototype-builtins": "off",
"@typescript-eslint/no-empty-function": "off"
}
}

28
.github/workflows/lint.yml vendored Normal file
View file

@ -0,0 +1,28 @@
name: Node.js build
on:
push:
branches: ["**"]
pull_request:
branches: ["**"]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x, 22.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- run: npm ci
- run: npm run build --if-present
- run: npm run lint

View file

@ -7,7 +7,7 @@ The repo depends on the latest plugin API (obsidian.d.ts) in TypeScript Definiti
This sample plugin demonstrates some of the basic functionality the plugin API can do. This sample plugin demonstrates some of the basic functionality the plugin API can do.
- Adds a ribbon icon, which shows a Notice when clicked. - Adds a ribbon icon, which shows a Notice when clicked.
- Adds a command "Open Sample Modal" which opens a Modal. - Adds a command "Open modal (simple)" which opens a Modal.
- Adds a plugin setting tab to the settings page. - Adds a plugin setting tab to the settings page.
- Registers a global click event and output 'click' to the console. - Registers a global click event and output 'click' to the console.
- Registers a global interval which logs 'setInterval' to the console. - Registers a global interval which logs 'setInterval' to the console.
@ -55,15 +55,11 @@ Quick starting guide for new plugin devs:
- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/your-plugin-id/`. - Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/your-plugin-id/`.
## Improve code quality with eslint (optional) ## Improve code quality with eslint
- [ESLint](https://eslint.org/) is a tool that analyzes your code to quickly find problems. You can run ESLint against your plugin to find common bugs and ways to improve your code. - [ESLint](https://eslint.org/) is a tool that analyzes your code to quickly find problems. You can run ESLint against your plugin to find common bugs and ways to improve your code.
- To use eslint with this project, make sure to install eslint from terminal: - This project already has eslint preconfigured, you can invoke a check by running`npm run lint`
- `npm install -g eslint` - Together with a custom eslint [plugin](https://github.com/obsidianmd/eslint-plugin) for Obsidan specific code guidelines.
- To use eslint to analyze this project use this command: - A GitHub action is preconfigured to automatically lint every commit on all branches.
- `eslint main.ts`
- eslint will then create a report with suggestions for code improvement by file and line number.
- If your source code is in a folder, such as `src`, you can use eslint with this command to analyze all files in that folder:
- `eslint ./src/`
## Funding URL ## Funding URL
@ -91,4 +87,4 @@ If you have multiple URLs, you can also do:
## API Documentation ## API Documentation
See https://github.com/obsidianmd/obsidian-api See https://docs.obsidian.md

View file

@ -1,6 +1,6 @@
import esbuild from "esbuild"; import esbuild from "esbuild";
import process from "process"; import process from "process";
import builtins from "builtin-modules"; import { builtinModules } from 'node:module';
const banner = const banner =
`/* `/*
@ -15,7 +15,7 @@ const context = await esbuild.context({
banner: { banner: {
js: banner, js: banner,
}, },
entryPoints: ["main.ts"], entryPoints: ["src/main.ts"],
bundle: true, bundle: true,
external: [ external: [
"obsidian", "obsidian",
@ -31,7 +31,7 @@ const context = await esbuild.context({
"@lezer/common", "@lezer/common",
"@lezer/highlight", "@lezer/highlight",
"@lezer/lr", "@lezer/lr",
...builtins], ...builtinModules],
format: "cjs", format: "cjs",
target: "es2018", target: "es2018",
logLevel: "info", logLevel: "info",

34
eslint.config.mts Normal file
View file

@ -0,0 +1,34 @@
import tseslint from 'typescript-eslint';
import obsidianmd from "eslint-plugin-obsidianmd";
import globals from "globals";
import { globalIgnores } from "eslint/config";
export default tseslint.config(
{
languageOptions: {
globals: {
...globals.browser,
},
parserOptions: {
projectService: {
allowDefaultProject: [
'eslint.config.js',
'manifest.json'
]
},
tsconfigRootDir: import.meta.dirname,
extraFileExtensions: ['.json']
},
},
},
...obsidianmd.configs.recommended,
globalIgnores([
"node_modules",
"dist",
"esbuild.config.mjs",
"eslint.config.js",
"version-bump.mjs",
"versions.json",
"main.js",
]),
);

View file

@ -1,11 +1,11 @@
{ {
"id": "sample-plugin", "id": "bible-verse-parser",
"name": "Sample Plugin", "name": "Bible Verse Parser",
"version": "1.0.0", "version": "0.1.0",
"minAppVersion": "0.15.0", "minAppVersion": "0.15.0",
"description": "Demonstrates some of the capabilities of the Obsidian API.", "description": "Pastes the bible verses to the particular regex format.",
"author": "Obsidian", "author": "abelmalzew",
"authorUrl": "https://obsidian.md", "authorUrl": "https://github.com/f0tt3r",
"fundingUrl": "https://obsidian.md/pricing", "fundingUrl": "https://github.com/f0tt3r",
"isDesktopOnly": false "isDesktopOnly": false
} }

5162
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -3,22 +3,27 @@
"version": "1.0.0", "version": "1.0.0",
"description": "This is a sample plugin for Obsidian (https://obsidian.md)", "description": "This is a sample plugin for Obsidian (https://obsidian.md)",
"main": "main.js", "main": "main.js",
"type": "module",
"scripts": { "scripts": {
"dev": "node esbuild.config.mjs", "dev": "node esbuild.config.mjs",
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
"version": "node version-bump.mjs && git add manifest.json versions.json" "version": "node version-bump.mjs && git add manifest.json versions.json",
"lint": "eslint ."
}, },
"keywords": [], "keywords": [],
"author": "", "license": "0-BSD",
"license": "MIT",
"devDependencies": { "devDependencies": {
"@types/node": "^16.11.6", "@types/node": "^16.11.6",
"@typescript-eslint/eslint-plugin": "5.29.0", "esbuild": "0.25.5",
"@typescript-eslint/parser": "5.29.0", "eslint-plugin-obsidianmd": "0.1.9",
"builtin-modules": "3.3.0", "globals": "14.0.0",
"esbuild": "0.17.3",
"obsidian": "latest",
"tslib": "2.4.0", "tslib": "2.4.0",
"typescript": "4.7.4" "typescript": "^5.8.3",
"typescript-eslint": "8.35.1",
"@eslint/js": "9.30.1",
"jiti": "2.6.1"
},
"dependencies": {
"obsidian": "latest"
} }
} }

View file

@ -1,15 +1,8 @@
import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian'; import {App, Editor, MarkdownView, Modal, Notice, Plugin} from 'obsidian';
import {DEFAULT_SETTINGS, MyPluginSettings, SampleSettingTab} from "./settings";
// Remember to rename these classes and interfaces! // Remember to rename these classes and interfaces!
interface MyPluginSettings {
mySetting: string;
}
const DEFAULT_SETTINGS: MyPluginSettings = {
mySetting: 'default'
}
export default class MyPlugin extends Plugin { export default class MyPlugin extends Plugin {
settings: MyPluginSettings; settings: MyPluginSettings;
@ -17,38 +10,35 @@ export default class MyPlugin extends Plugin {
await this.loadSettings(); await this.loadSettings();
// This creates an icon in the left ribbon. // This creates an icon in the left ribbon.
const ribbonIconEl = this.addRibbonIcon('dice', 'Sample Plugin', (evt: MouseEvent) => { this.addRibbonIcon('dice', 'Sample', (evt: MouseEvent) => {
// Called when the user clicks the icon. // Called when the user clicks the icon.
new Notice('This is a notice!'); new Notice('This is a notice!');
}); });
// Perform additional things with the ribbon
ribbonIconEl.addClass('my-plugin-ribbon-class');
// This adds a status bar item to the bottom of the app. Does not work on mobile apps. // This adds a status bar item to the bottom of the app. Does not work on mobile apps.
const statusBarItemEl = this.addStatusBarItem(); const statusBarItemEl = this.addStatusBarItem();
statusBarItemEl.setText('Status Bar Text'); statusBarItemEl.setText('Status bar text');
// This adds a simple command that can be triggered anywhere // This adds a simple command that can be triggered anywhere
this.addCommand({ this.addCommand({
id: 'open-sample-modal-simple', id: 'open-modal-simple',
name: 'Open sample modal (simple)', name: 'Open modal (simple)',
callback: () => { callback: () => {
new SampleModal(this.app).open(); new SampleModal(this.app).open();
} }
}); });
// This adds an editor command that can perform some operation on the current editor instance // This adds an editor command that can perform some operation on the current editor instance
this.addCommand({ this.addCommand({
id: 'sample-editor-command', id: 'replace-selected',
name: 'Sample editor command', name: 'Replace selected content',
editorCallback: (editor: Editor, view: MarkdownView) => { editorCallback: (editor: Editor, view: MarkdownView) => {
console.log(editor.getSelection()); editor.replaceSelection('Sample editor command');
editor.replaceSelection('Sample Editor Command');
} }
}); });
// This adds a complex command that can check whether the current state of the app allows execution of the command // This adds a complex command that can check whether the current state of the app allows execution of the command
this.addCommand({ this.addCommand({
id: 'open-sample-modal-complex', id: 'open-modal-complex',
name: 'Open sample modal (complex)', name: 'Open modal (complex)',
checkCallback: (checking: boolean) => { checkCallback: (checking: boolean) => {
// Conditions to check // Conditions to check
const markdownView = this.app.workspace.getActiveViewOfType(MarkdownView); const markdownView = this.app.workspace.getActiveViewOfType(MarkdownView);
@ -62,6 +52,7 @@ export default class MyPlugin extends Plugin {
// This command will only show up in Command Palette when the check function returns true // This command will only show up in Command Palette when the check function returns true
return true; return true;
} }
return false;
} }
}); });
@ -71,19 +62,19 @@ export default class MyPlugin extends Plugin {
// If the plugin hooks up any global DOM events (on parts of the app that doesn't belong to this plugin) // If the plugin hooks up any global DOM events (on parts of the app that doesn't belong to this plugin)
// Using this function will automatically remove the event listener when this plugin is disabled. // Using this function will automatically remove the event listener when this plugin is disabled.
this.registerDomEvent(document, 'click', (evt: MouseEvent) => { this.registerDomEvent(document, 'click', (evt: MouseEvent) => {
console.log('click', evt); new Notice("Click");
}); });
// When registering intervals, this function will automatically clear the interval when the plugin is disabled. // When registering intervals, this function will automatically clear the interval when the plugin is disabled.
this.registerInterval(window.setInterval(() => console.log('setInterval'), 5 * 60 * 1000)); this.registerInterval(window.setInterval(() => console.log('setInterval'), 5 * 60 * 1000));
} }
onunload() { onunload() {
} }
async loadSettings() { async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData() as Partial<MyPluginSettings>);
} }
async saveSettings() { async saveSettings() {
@ -97,7 +88,7 @@ class SampleModal extends Modal {
} }
onOpen() { onOpen() {
const {contentEl} = this; let {contentEl} = this;
contentEl.setText('Woah!'); contentEl.setText('Woah!');
} }
@ -106,29 +97,3 @@ class SampleModal extends Modal {
contentEl.empty(); contentEl.empty();
} }
} }
class SampleSettingTab extends PluginSettingTab {
plugin: MyPlugin;
constructor(app: App, plugin: MyPlugin) {
super(app, plugin);
this.plugin = plugin;
}
display(): void {
const {containerEl} = this;
containerEl.empty();
new Setting(containerEl)
.setName('Setting #1')
.setDesc('It\'s a secret')
.addText(text => text
.setPlaceholder('Enter your secret')
.setValue(this.plugin.settings.mySetting)
.onChange(async (value) => {
this.plugin.settings.mySetting = value;
await this.plugin.saveSettings();
}));
}
}

36
src/settings.ts Normal file
View file

@ -0,0 +1,36 @@
import {App, PluginSettingTab, Setting} from "obsidian";
import MyPlugin from "./main";
export interface MyPluginSettings {
mySetting: string;
}
export const DEFAULT_SETTINGS: MyPluginSettings = {
mySetting: 'default'
}
export class SampleSettingTab extends PluginSettingTab {
plugin: MyPlugin;
constructor(app: App, plugin: MyPlugin) {
super(app, plugin);
this.plugin = plugin;
}
display(): void {
const {containerEl} = this;
containerEl.empty();
new Setting(containerEl)
.setName('Settings #1')
.setDesc('It\'s a secret')
.addText(text => text
.setPlaceholder('Enter your secret')
.setValue(this.plugin.settings.mySetting)
.onChange(async (value) => {
this.plugin.settings.mySetting = value;
await this.plugin.saveSettings();
}));
}
}

View file

@ -1,16 +1,22 @@
{ {
"compilerOptions": { "compilerOptions": {
"baseUrl": ".", "baseUrl": "src",
"inlineSourceMap": true, "inlineSourceMap": true,
"inlineSources": true, "inlineSources": true,
"module": "ESNext", "module": "ESNext",
"target": "ES6", "target": "ES6",
"allowJs": true, "allowJs": true,
"noImplicitAny": true, "noImplicitAny": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"moduleResolution": "node", "moduleResolution": "node",
"importHelpers": true, "importHelpers": true,
"noUncheckedIndexedAccess": true,
"isolatedModules": true, "isolatedModules": true,
"strictNullChecks": true, "strictNullChecks": true,
"strictBindCallApply": true,
"allowSyntheticDefaultImports": true,
"useUnknownInCatchVariables": true,
"lib": [ "lib": [
"DOM", "DOM",
"ES5", "ES5",
@ -19,6 +25,6 @@
] ]
}, },
"include": [ "include": [
"**/*.ts" "src/**/*.ts"
] ]
} }

View file

@ -3,12 +3,15 @@ import { readFileSync, writeFileSync } from "fs";
const targetVersion = process.env.npm_package_version; const targetVersion = process.env.npm_package_version;
// read minAppVersion from manifest.json and bump version to target version // read minAppVersion from manifest.json and bump version to target version
let manifest = JSON.parse(readFileSync("manifest.json", "utf8")); const manifest = JSON.parse(readFileSync("manifest.json", "utf8"));
const { minAppVersion } = manifest; const { minAppVersion } = manifest;
manifest.version = targetVersion; manifest.version = targetVersion;
writeFileSync("manifest.json", JSON.stringify(manifest, null, "\t")); writeFileSync("manifest.json", JSON.stringify(manifest, null, "\t"));
// update versions.json with target version and minAppVersion from manifest.json // update versions.json with target version and minAppVersion from manifest.json
let versions = JSON.parse(readFileSync("versions.json", "utf8")); // but only if the target version is not already in versions.json
versions[targetVersion] = minAppVersion; const versions = JSON.parse(readFileSync('versions.json', 'utf8'));
writeFileSync("versions.json", JSON.stringify(versions, null, "\t")); if (!Object.values(versions).includes(minAppVersion)) {
versions[targetVersion] = minAppVersion;
writeFileSync('versions.json', JSON.stringify(versions, null, '\t'));
}