Skip to content

Commit 0e69a11

Browse files
authored
feat: add eslint verification configuration, add lint CI workflows (anse-app#284)
* feat: add eslint configuration * chore: update pnpm version
1 parent ccd4c97 commit 0e69a11

29 files changed

+2392
-373
lines changed

.eslintignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
dist
2+
public
3+
node_modules
4+
.netlify
5+
.vercel
6+
.github
7+
.changeset

.eslintrc.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module.exports = {
2+
extends: ['@evan-yang', 'plugin:astro/recommended'],
3+
rules: {
4+
'no-console': ['error', { allow: ['error'] }],
5+
'react/display-name': 'off',
6+
'react-hooks/rules-of-hooks': 'off',
7+
'@typescript-eslint/no-use-before-define': 'off',
8+
},
9+
overrides: [
10+
{
11+
files: ['*.astro'],
12+
parser: 'astro-eslint-parser',
13+
parserOptions: {
14+
parser: '@typescript-eslint/parser',
15+
extraFileExtensions: ['.astro'],
16+
},
17+
rules: {
18+
'no-mixed-spaces-and-tabs': ['error', 'smart-tabs'],
19+
},
20+
},
21+
{
22+
// Define the configuration for `<script>` tag.
23+
// Script in `<script>` is assigned a virtual file name with the `.js` extension.
24+
files: ['**/*.astro/*.js', '*.astro/*.js'],
25+
parser: '@typescript-eslint/parser',
26+
rules: {
27+
'prettier/prettier': 'off',
28+
},
29+
},
30+
],
31+
}

.github/workflows/lint.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Lint CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
pull_request:
9+
branches:
10+
- main
11+
12+
jobs:
13+
lint:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
18+
- name: Install pnpm
19+
uses: pnpm/action-setup@v2
20+
21+
- name: Set node
22+
uses: actions/setup-node@v3
23+
with:
24+
node-version: 18.x
25+
cache: pnpm
26+
27+
- name: Install
28+
run: pnpm install --no-frozen-lockfile
29+
30+
- name: Lint
31+
run: pnpm run lint

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
registry=https://registry.npmjs.org/
22
strict-peer-dependencies=false
33
auto-install-peers=true
4+
shamefully-hoist=true

.vscode/extensions.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"recommendations": ["astro-build.astro-vscode"],
2+
"recommendations": ["astro-build.astro-vscode","dbaeumer.vscode-eslint","antfu.unocss"],
33
"unwantedRecommendations": [],
44
}

.vscode/settings.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"editor.codeActionsOnSave": {
3+
"source.fixAll.eslint": true
4+
},
5+
"editor.formatOnSave": false,
6+
"eslint.validate": [
7+
"javascript",
8+
"javascriptreact",
9+
"astro", // Enable .astro
10+
"typescript", // Enable .ts
11+
"typescriptreact" // Enable .tsx
12+
]
13+
}

package.json

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
{
22
"name": "chatgpt-api-demo",
3-
"type": "module",
43
"version": "0.0.1",
4+
"packageManager": "[email protected]",
55
"scripts": {
66
"dev": "astro dev",
77
"start": "astro dev",
88
"build": "astro build",
99
"build:vercel": "OUTPUT=vercel astro build",
1010
"build:netlify": "OUTPUT=netlify astro build",
1111
"preview": "astro preview",
12-
"astro": "astro"
12+
"astro": "astro",
13+
"lint": "eslint . --ext .js,.jsx,.ts,.tsx,.astro",
14+
"lint:fix": "eslint . --ext .js,.jsx,.ts,.tsx,.astro --fix"
1315
},
1416
"dependencies": {
1517
"@astrojs/netlify": "2.0.0",
@@ -18,6 +20,7 @@
1820
"@astrojs/vercel": "^3.1.3",
1921
"@unocss/reset": "^0.50.1",
2022
"astro": "^2.0.15",
23+
"eslint": "^8.36.0",
2124
"eventsource-parser": "^0.1.0",
2225
"highlight.js": "^11.7.0",
2326
"js-sha256": "^0.9.0",
@@ -32,10 +35,13 @@
3235
"devDependencies": {
3336
"@iconify-json/carbon": "^1.1.16",
3437
"@types/markdown-it": "^12.2.3",
38+
"@typescript-eslint/parser": "^5.54.1",
3539
"@unocss/preset-attributify": "^0.50.1",
3640
"@unocss/preset-icons": "^0.50.4",
3741
"@unocss/preset-typography": "^0.50.3",
42+
"eslint-plugin-astro": "^0.24.0",
3843
"punycode": "^2.3.0",
39-
"unocss": "^0.50.1"
44+
"unocss": "^0.50.1",
45+
"@evan-yang/eslint-config": "^1.0.1"
4046
}
4147
}

plugins/vercelDisableBlocks.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export default function plugin() {
33
if (id.includes('pages/api/generate.ts')) {
44
return {
55
code: code.replace(/^.*?#vercel-disable-blocks([\s\S]+?)#vercel-end.*?$/gm, ''),
6-
map: null
6+
map: null,
77
}
88
}
99
}
@@ -13,4 +13,4 @@ export default function plugin() {
1313
enforce: 'pre',
1414
transform,
1515
}
16-
}
16+
}

0 commit comments

Comments
 (0)