Skip to content

Commit 9d8326b

Browse files
add eslint / prettier - streamline docs repos
1 parent 85ae1f2 commit 9d8326b

File tree

7 files changed

+123
-0
lines changed

7 files changed

+123
-0
lines changed

.github/workflows/lint.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Lint
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
paths:
8+
- '**/*.astro'
9+
- '**/*.ts'
10+
- '**/*.tsx'
11+
- '**/*.js'
12+
- '**/*.md'
13+
- 'package.json'
14+
- 'package-lock.json'
15+
- '.github/workflows/lint.yml'
16+
17+
jobs:
18+
lint:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Setup Node
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: 20
28+
29+
- name: Install dependencies
30+
run: npm install
31+
32+
- name: Lint and check formatting
33+
run: npm run lint

.prettierignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.github
2+
.astro
3+
node_modules
4+
dist
5+
**/*.min.css
6+
**/*.min.js

.prettierrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"trailingComma": "none",
5+
"plugins": ["prettier-plugin-astro"],
6+
"overrides": [
7+
{
8+
"files": "**/*.astro",
9+
"options": {
10+
"parser": "astro"
11+
}
12+
}
13+
]
14+
}

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,24 @@ git clone https://github.com/interledger/docs-styleguide.git
6060
```
6161

6262
3. After you're done with your changes and have tested that all is well, feel free to make a pull request and it will get reviewed, and hopefully merged into the source code. The version will get bumped and all the sites will have to make an update to their dependencies as well.
63+
64+
## Local development
65+
66+
All commands are run from the root of the project, from a terminal:
67+
68+
| Command | Action |
69+
| :------------------- | :----------------------------------------------- |
70+
| `npm install` | Installs dependencies |
71+
| `npm run format` | Format code and fix linting issues |
72+
| `npm run lint` | Check code formatting and linting |
73+
74+
You can substitute the `npm` commands with whatever package manager your workflow uses.
75+
76+
### 🔍 Code Formatting
77+
78+
This project uses [ESLint](https://eslint.org/) for code linting and [Prettier](https://prettier.io/) for code formatting. Before submitting a pull request, please ensure your code is properly formatted:
79+
80+
1. **Fix issues**: Run `npm run format` to automatically format code and fix linting issues.
81+
2. **Check before pushing**: Run `npm run lint` to verify everything passes (CI will also run this).
82+
83+
ESLint is configured to work with TypeScript and Astro files. The configuration extends recommended rules from ESLint, TypeScript ESLint, and Astro ESLint plugins, and integrates with Prettier to avoid conflicts.

eslint.config.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import js from '@eslint/js'
2+
import globals from 'globals'
3+
import tseslint from 'typescript-eslint'
4+
import { defineConfig, globalIgnores } from 'eslint/config'
5+
import eslintConfigPrettier from 'eslint-config-prettier/flat'
6+
import eslintPluginAstro from 'eslint-plugin-astro'
7+
8+
export default defineConfig([
9+
{
10+
files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
11+
plugins: { js },
12+
extends: ['js/recommended'],
13+
languageOptions: { globals: { ...globals.browser, ...globals.node } }
14+
},
15+
tseslint.configs.recommended,
16+
eslintPluginAstro.configs.recommended,
17+
globalIgnores(['dist', '.astro', 'node_modules', 'public', '**/*.min.js']),
18+
{
19+
rules: {
20+
'no-console': 'error',
21+
'@typescript-eslint/no-unused-vars': [
22+
'error',
23+
{ argsIgnorePattern: '^_' }
24+
],
25+
'@typescript-eslint/no-explicit-any': 'error',
26+
'astro/no-set-text-directive': 'error'
27+
}
28+
},
29+
eslintConfigPrettier
30+
])

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"index.ts"
1212
],
1313
"scripts": {
14+
"lint": "prettier --check '**/*.{js,mjs,ts,tsx,json,md,mdx,astro}' && eslint --max-warnings=0 .",
15+
"format": "prettier --write '**/*.{js,mjs,ts,tsx,json,md,mdx,astro}' && eslint --max-warnings=0 --fix .",
1416
"test": "echo \"Error: no test specified\" && exit 1"
1517
},
1618
"author": "Interledger <tech@interledger.org>",
@@ -21,5 +23,19 @@
2123
},
2224
"dependencies": {
2325
"mermaid": "^11.12.1"
26+
},
27+
"devDependencies": {
28+
"@eslint/js": "^9.39.1",
29+
"@typescript-eslint/parser": "^8.48.0",
30+
"astro": "^5.16.0",
31+
"astro-eslint-parser": "^1.2.2",
32+
"eslint": "^9.39.1",
33+
"eslint-config-prettier": "^10.1.8",
34+
"eslint-plugin-astro": "^1.5.0",
35+
"globals": "^16.5.0",
36+
"prettier": "3.6.2",
37+
"prettier-plugin-astro": "0.14.1",
38+
"typescript": "^5.8.2",
39+
"typescript-eslint": "^8.48.0"
2440
}
2541
}

tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "astro/tsconfigs/strict"
3+
}

0 commit comments

Comments
 (0)