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

This commit is contained in:
TfTHacker 2021-10-30 20:04:07 +02:00 committed by GitHub
parent 02ac033b15
commit 6fdd374cb8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 9 deletions

2
.eslintignore Normal file
View file

@ -0,0 +1,2 @@
npm node_modules
build

22
.eslintrc Normal file
View file

@ -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"
}
}

3
.gitignore vendored
View file

@ -1,3 +1,6 @@
# vscode
.vscode
# Intellij
*.iml
.idea

View file

@ -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

12
main.ts
View file

@ -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();

View file

@ -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"
}
}