Update .editorconfig and yarn format:fix

This commit is contained in:
INOUE Takuya 2023-01-19 01:33:52 +09:00
parent 27c0d04b66
commit 60ee7cd215
9 changed files with 232 additions and 223 deletions

View File

@ -5,6 +5,6 @@ root = true
charset = utf-8 charset = utf-8
end_of_line = lf end_of_line = lf
insert_final_newline = true insert_final_newline = true
indent_style = tab indent_style = space
indent_size = 4 indent_size = 2
tab_width = 4 tab_width = 2

View File

@ -2,9 +2,7 @@
"root": true, "root": true,
"parser": "@typescript-eslint/parser", "parser": "@typescript-eslint/parser",
"env": { "node": true }, "env": { "node": true },
"plugins": [ "plugins": ["@typescript-eslint"],
"@typescript-eslint"
],
"extends": [ "extends": [
"eslint:recommended", "eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/eslint-recommended",
@ -20,4 +18,4 @@
"no-prototype-builtins": "off", "no-prototype-builtins": "off",
"@typescript-eslint/no-empty-function": "off" "@typescript-eslint/no-empty-function": "off"
} }
} }

View File

@ -1,17 +1,17 @@
import esbuild from "esbuild"; import esbuild from 'esbuild'
import process from "process"; import process from 'process'
import builtins from 'builtin-modules' import builtins from 'builtin-modules'
const banner = const banner = `/*
`/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin if you want to view the source, please visit the github repository of this plugin
*/ */
`; `
const prod = (process.argv[2] === 'production'); const prod = process.argv[2] === 'production'
esbuild.build({ esbuild
.build({
banner: { banner: {
js: banner, js: banner,
}, },
@ -31,12 +31,14 @@ esbuild.build({
'@lezer/common', '@lezer/common',
'@lezer/highlight', '@lezer/highlight',
'@lezer/lr', '@lezer/lr',
...builtins], ...builtins,
],
format: 'cjs', format: 'cjs',
watch: !prod, watch: !prod,
target: 'es2018', target: 'es2018',
logLevel: "info", logLevel: 'info',
sourcemap: prod ? false : 'inline', sourcemap: prod ? false : 'inline',
treeShaking: true, treeShaking: true,
outfile: 'main.js', outfile: 'main.js',
}).catch(() => process.exit(1)); })
.catch(() => process.exit(1))

View File

@ -1,137 +1,153 @@
import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian'; import {
App,
Editor,
MarkdownView,
Modal,
Notice,
Plugin,
PluginSettingTab,
Setting,
} from 'obsidian'
// Remember to rename these classes and interfaces! // Remember to rename these classes and interfaces!
interface MyPluginSettings { interface MyPluginSettings {
mySetting: string; mySetting: string
} }
const DEFAULT_SETTINGS: MyPluginSettings = { const DEFAULT_SETTINGS: MyPluginSettings = {
mySetting: 'default' mySetting: 'default',
} }
export default class MyPlugin extends Plugin { export default class MyPlugin extends Plugin {
settings: MyPluginSettings; settings: MyPluginSettings
async onload() { async onload() {
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) => { const ribbonIconEl = this.addRibbonIcon(
'dice',
'Sample Plugin',
(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 // Perform additional things with the ribbon
ribbonIconEl.addClass('my-plugin-ribbon-class'); 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-sample-modal-simple',
name: 'Open sample modal (simple)', name: 'Open sample 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: 'sample-editor-command',
name: 'Sample editor command', name: 'Sample editor command',
editorCallback: (editor: Editor, view: MarkdownView) => { editorCallback: (editor: Editor, view: MarkdownView) => {
console.log(editor.getSelection()); 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-sample-modal-complex',
name: 'Open sample modal (complex)', name: 'Open sample 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)
if (markdownView) { if (markdownView) {
// If checking is true, we're simply "checking" if the command can be run. // 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. // If checking is false, then we want to actually perform the operation.
if (!checking) { if (!checking) {
new SampleModal(this.app).open(); new SampleModal(this.app).open()
} }
// 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
} }
} },
}); })
// This adds a settings tab so the user can configure various aspects of the plugin // This adds a settings tab so the user can configure various aspects of the plugin
this.addSettingTab(new SampleSettingTab(this.app, this)); this.addSettingTab(new SampleSettingTab(this.app, this))
// 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); console.log('click', evt)
}); })
// 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())
} }
async saveSettings() { async saveSettings() {
await this.saveData(this.settings); await this.saveData(this.settings)
} }
} }
class SampleModal extends Modal { class SampleModal extends Modal {
constructor(app: App) { constructor(app: App) {
super(app); super(app)
} }
onOpen() { onOpen() {
const {contentEl} = this; const { contentEl } = this
contentEl.setText('Woah!'); contentEl.setText('Woah!')
} }
onClose() { onClose() {
const {contentEl} = this; const { contentEl } = this
contentEl.empty(); contentEl.empty()
} }
} }
class SampleSettingTab extends PluginSettingTab { class SampleSettingTab extends PluginSettingTab {
plugin: MyPlugin; plugin: MyPlugin
constructor(app: App, plugin: MyPlugin) { constructor(app: App, plugin: MyPlugin) {
super(app, plugin); super(app, plugin)
this.plugin = plugin; this.plugin = plugin
} }
display(): void { display(): void {
const {containerEl} = this; const { containerEl } = this
containerEl.empty(); containerEl.empty()
containerEl.createEl('h2', {text: 'Settings for my awesome plugin.'}); containerEl.createEl('h2', { text: 'Settings for my awesome plugin.' })
new Setting(containerEl) new Setting(containerEl)
.setName('Setting #1') .setName('Setting #1')
.setDesc('It\'s a secret') .setDesc("It's a secret")
.addText(text => text .addText((text) =>
text
.setPlaceholder('Enter your secret') .setPlaceholder('Enter your secret')
.setValue(this.plugin.settings.mySetting) .setValue(this.plugin.settings.mySetting)
.onChange(async (value) => { .onChange(async (value) => {
console.log('Secret: ' + value); console.log('Secret: ' + value)
this.plugin.settings.mySetting = value; this.plugin.settings.mySetting = value
await this.plugin.saveSettings(); await this.plugin.saveSettings()
})); })
)
} }
} }

View File

@ -11,14 +11,7 @@
"importHelpers": true, "importHelpers": true,
"isolatedModules": true, "isolatedModules": true,
"strictNullChecks": true, "strictNullChecks": true,
"lib": [ "lib": ["DOM", "ES5", "ES6", "ES7"]
"DOM",
"ES5",
"ES6",
"ES7"
]
}, },
"include": [ "include": ["**/*.ts"]
"**/*.ts"
]
} }

View File

@ -1,14 +1,14 @@
import { readFileSync, writeFileSync } from "fs"; 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")); let 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")); let versions = JSON.parse(readFileSync('versions.json', 'utf8'))
versions[targetVersion] = minAppVersion; versions[targetVersion] = minAppVersion
writeFileSync("versions.json", JSON.stringify(versions, null, "\t")); writeFileSync('versions.json', JSON.stringify(versions, null, '\t'))