obsidian-semantic

Log | Files | Refs | README

commit 6fdd374cb8e46505dcef70ff249b48b16c4a659b
parent 02ac033b15fd158638ecc650cdbd0cea6b94d77a
Author: TfTHacker <69121180+TfTHacker@users.noreply.github.com>
Date:   Sat, 30 Oct 2021 20:04:07 +0200

Adding eslint for code .\src\ (#17)


Diffstat:
A.eslintignore | 3+++
A.eslintrc | 23+++++++++++++++++++++++
M.gitignore | 3+++
MREADME.md | 13++++++++++++-
Mmain.ts | 12++++++------
Mpackage.json | 6++++--
6 files changed, 51 insertions(+), 9 deletions(-)

diff --git a/.eslintignore b/.eslintignore @@ -0,0 +1,2 @@ +npm node_modules +build +\ No newline at end of file diff --git a/.eslintrc b/.eslintrc @@ -0,0 +1,22 @@ +{ + "root": true, + "parser": "@typescript-eslint/parser", + "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" + } + } +\ No newline at end of file diff --git a/.gitignore b/.gitignore @@ -1,3 +1,6 @@ +# vscode +.vscode + # Intellij *.iml .idea diff --git a/README.md b/README.md @@ -33,7 +33,7 @@ Quick starting guide for new plugin devs: - Update your `manifest.json` with your new version number, such as `1.0.1`, and the minimum Obsidian version required for your latest release. - Update your `versions.json` file with `"new-plugin-version": "minimum-obsidian-version"` so older versions of Obsidian can download an older version of your plugin that's compatible. - Create new GitHub release using your new version number as the "Tag version". Use the exact version number, don't include a prefix `v`. See here for an example: https://github.com/obsidianmd/obsidian-sample-plugin/releases -- Upload the files `manifest.json`, `main.js`, `styles.css` as binary attachments. +- Upload the files `manifest.json`, `main.js`, `styles.css` as binary attachments. Note: The manifest.json file must be in two places, first the root path of your repository and also in the release. - Publish the release. ### Adding your plugin to the community plugin list @@ -52,6 +52,17 @@ Quick starting guide for new plugin devs: - Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/your-plugin-id/`. +### Improve code quality with eslint (optional) +- [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: + - `npm install -g eslint` +- To use eslint to analyze this project use this command: + - `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\` + + ### API Documentation See https://github.com/obsidianmd/obsidian-api diff --git a/main.ts b/main.ts @@ -15,7 +15,7 @@ export default class MyPlugin extends Plugin { await this.loadSettings(); // This creates an icon in the left ribbon. - let ribbonIconEl = this.addRibbonIcon('dice', 'Sample Plugin', (evt: MouseEvent) => { + const ribbonIconEl = this.addRibbonIcon('dice', 'Sample Plugin', (evt: MouseEvent) => { // Called when the user clicks the icon. new Notice('This is a notice!'); }); @@ -23,7 +23,7 @@ export default class MyPlugin extends Plugin { ribbonIconEl.addClass('my-plugin-ribbon-class'); // This adds a status bar item to the bottom of the app. Does not work on mobile apps. - let statusBarItemEl = this.addStatusBarItem(); + const statusBarItemEl = this.addStatusBarItem(); statusBarItemEl.setText('Status Bar Text'); // This adds a simple command that can be triggered anywhere @@ -49,7 +49,7 @@ export default class MyPlugin extends Plugin { name: 'Open sample modal (complex)', checkCallback: (checking: boolean) => { // Conditions to check - let markdownView = this.app.workspace.getActiveViewOfType(MarkdownView); + const markdownView = this.app.workspace.getActiveViewOfType(MarkdownView); if (markdownView) { // If checking is true, we're simply "checking" if the command can be run. // If checking is false, then we want to actually perform the operation. @@ -95,12 +95,12 @@ class SampleModal extends Modal { } onOpen() { - let {contentEl} = this; + const {contentEl} = this; contentEl.setText('Woah!'); } onClose() { - let {contentEl} = this; + const {contentEl} = this; contentEl.empty(); } } @@ -114,7 +114,7 @@ class SampleSettingTab extends PluginSettingTab { } display(): void { - let {containerEl} = this; + const {containerEl} = this; containerEl.empty(); diff --git a/package.json b/package.json @@ -12,9 +12,11 @@ "license": "MIT", "devDependencies": { "@types/node": "^16.11.1", - "esbuild": "0.13.8", + "esbuild": "0.13.11", "obsidian": "^0.12.17", "tslib": "2.3.1", - "typescript": "4.4.4" + "typescript": "4.4.4", + "@typescript-eslint/eslint-plugin": "^5.2.0", + "@typescript-eslint/parser": "^5.2.0" } }