Skip to content

Commit 2323edd

Browse files
authored
Merge pull request #164 from joethei/master
Include eslint config
2 parents e2a64e0 + 911b773 commit 2323edd

File tree

11 files changed

+5326
-122
lines changed

11 files changed

+5326
-122
lines changed

.eslintignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.eslintrc

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/workflows/lint.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Node.js build
2+
3+
on:
4+
push:
5+
branches: ["**"]
6+
pull_request:
7+
branches: ["**"]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [20.x, 22.x]
16+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
- name: Use Node.js ${{ matrix.node-version }}
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
cache: "npm"
25+
- run: npm ci
26+
- run: npm run build --if-present
27+
- run: npm run lint
28+

README.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The repo depends on the latest plugin API (obsidian.d.ts) in TypeScript Definiti
77

88
This sample plugin demonstrates some of the basic functionality the plugin API can do.
99
- Adds a ribbon icon, which shows a Notice when clicked.
10-
- Adds a command "Open Sample Modal" which opens a Modal.
10+
- Adds a command "Open modal (simple)" which opens a Modal.
1111
- Adds a plugin setting tab to the settings page.
1212
- Registers a global click event and output 'click' to the console.
1313
- Registers a global interval which logs 'setInterval' to the console.
@@ -55,15 +55,11 @@ Quick starting guide for new plugin devs:
5555

5656
- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/your-plugin-id/`.
5757

58-
## Improve code quality with eslint (optional)
58+
## Improve code quality with eslint
5959
- [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.
60-
- To use eslint with this project, make sure to install eslint from terminal:
61-
- `npm install -g eslint`
62-
- To use eslint to analyze this project use this command:
63-
- `eslint main.ts`
64-
- eslint will then create a report with suggestions for code improvement by file and line number.
65-
- 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:
66-
- `eslint ./src/`
60+
- This project already has eslint preconfigured, you can invoke a check by running`npm run lint`
61+
- Together with a custom eslint [plugin](https://github.com/eslint-plugin) for Obsidan specific code guidelines.
62+
- A GitHub action is preconfigured to automatically lint every commit on all branches.
6763

6864
## Funding URL
6965

@@ -91,4 +87,4 @@ If you have multiple URLs, you can also do:
9187

9288
## API Documentation
9389

94-
See https://github.com/obsidianmd/obsidian-api
90+
See https://docs.obsidian.md

esbuild.config.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import esbuild from "esbuild";
22
import process from "process";
3-
import builtins from "builtin-modules";
3+
import { builtinModules } from 'node:module';
44

55
const banner =
66
`/*
@@ -15,7 +15,7 @@ const context = await esbuild.context({
1515
banner: {
1616
js: banner,
1717
},
18-
entryPoints: ["main.ts"],
18+
entryPoints: ["src/main.ts"],
1919
bundle: true,
2020
external: [
2121
"obsidian",
@@ -31,7 +31,7 @@ const context = await esbuild.context({
3131
"@lezer/common",
3232
"@lezer/highlight",
3333
"@lezer/lr",
34-
...builtins],
34+
...builtinModules],
3535
format: "cjs",
3636
target: "es2018",
3737
logLevel: "info",

eslint.config.mts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import tseslint from 'typescript-eslint';
2+
import obsidianmd from "eslint-plugin-obsidianmd";
3+
import globals from "globals";
4+
import { globalIgnores } from "eslint/config";
5+
6+
export default tseslint.config(
7+
{
8+
languageOptions: {
9+
globals: {
10+
...globals.browser,
11+
},
12+
parserOptions: {
13+
projectService: {
14+
allowDefaultProject: [
15+
'eslint.config.js',
16+
'manifest.json'
17+
]
18+
},
19+
tsconfigRootDir: import.meta.dirname,
20+
extraFileExtensions: ['.json']
21+
},
22+
},
23+
},
24+
...obsidianmd.configs.recommended,
25+
globalIgnores([
26+
"node_modules",
27+
"dist",
28+
"esbuild.config.mjs",
29+
"eslint.config.js",
30+
"version-bump.mjs",
31+
"versions.json",
32+
"main.js",
33+
]),
34+
);

0 commit comments

Comments
 (0)