Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update eslint and connect with prettier #386

Merged
merged 3 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
npm node_modules
build
build
main.js

jest.config.js

.eslintrc.js
33 changes: 25 additions & 8 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
{
"root": true,
"ignorePatterns": [
"**.js"
],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"plugins": [
"@typescript-eslint",
"prettier"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"parserOptions": {
"sourceType": "module"
"sourceType": "module",
"project": "./tsconfig.json"
},
"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"
"prettier/prettier": "error",
"@typescript-eslint/ban-ts-comment": "warn",
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}
],
"@typescript-eslint/no-explicit-any": [
"warn"
],
// allow prettier to use SmartTabs
"no-mixed-spaces-and-tabs": "off"
}
}
}
46 changes: 31 additions & 15 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
name: GitHub Actions
run-name: Unit testing ${{ github.actor }} changes
on: [push]
run-name: PR "${{ github.event.pull_request.title }}" CI Checks
on:
push:
pull_request:
types: [opened, synchronize]
jobs:
"run-unit-tests":
name: "Run unit tests"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: "Use node version"
uses: actions/setup-node@v3
with:
node-version-file: .nvmrc
- name: "Install dependencies"
run: npm install
- name: Run tests
run: npm run test
"run-unit-tests":
name: "Run unit tests"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: "Use node version"
uses: actions/setup-node@v3
with:
node-version-file: .nvmrc
- name: "Install dependencies"
run: npm install
- name: Run tests
run: npm run test
"lint":
name: "Checking for linting errors"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: "Use node version"
uses: actions/setup-node@v3
with:
node-version-file: .nvmrc
- name: "Install dependencies"
run: npm install
- name: Checking linter
run: npm run lint
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.11
20.6.0
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"useTabs": true,
"overrides": [
{
"files": ".prettierrc",
"files": [".prettierrc", ".eslintrc"],
"options": { "parser": "json" }
}
]
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,13 @@ This plugin is developed in my free time. If you've found it useful, it would ma
Note that you in no way have to feel any pressure to do this. The plugin is completely free, and will remain free in the unforeseeable future.

[<img style="float:left" src="https://cdn.ko-fi.com/cdn/kofi3.png?v=3" width="200">](https://ko-fi.com/oleeskild)

## Local development

1. Clone this repository into `.obsidian` of your vault (it is recommended to use a test-vault instead of your own!)
2. (for best compatability, use node version manager and run `nvm install && nvm use`)
3. Install dependencies with `npm install`
4. Run with `npm run dev`
5. You should now be able to enable the plugin in obsidian

Note: this repository uses prettier and eslint to enforce code formatting and style. It is recommended to install these to your IDE for automatic formatting and error highlighting.
17 changes: 11 additions & 6 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ const DEFAULT_SETTINGS: DigitalGardenSettings = {
};

export default class DigitalGarden extends Plugin {
settings: DigitalGardenSettings;
appVersion: string;
settings!: DigitalGardenSettings;
appVersion!: string;

publishModal: PublishModal;
publishModal!: PublishModal;

async onload() {
this.appVersion = this.manifest.version;
Expand Down Expand Up @@ -114,8 +114,8 @@ export default class DigitalGarden extends Plugin {
const activeFile = this.app.workspace.getActiveFile();
const event = this.app.metadataCache.on(
"changed",
async (file, data, cache) => {
if (file.path === activeFile.path) {
async (file, _data, _cache) => {
if (file.path === activeFile?.path) {
const successfullyPublished =
await this.publishSingleNote();
if (successfullyPublished) {
Expand Down Expand Up @@ -338,10 +338,15 @@ export default class DigitalGarden extends Plugin {
}
}
async addPublishFlag() {
const activeFile = this.app.workspace.getActiveFile();
if (activeFile === null) {
new Notice("No active file!");
return;
}
const engine = new ObsidianFrontMatterEngine(
this.app.vault,
this.app.metadataCache,
this.app.workspace.getActiveFile(),
activeFile,
);
engine.set("dg-publish", true).apply();
}
Expand Down
Loading