Skip to content

Commit cf67336

Browse files
authored
add pre-commit hooks to run prettier and eslint (#317)
1 parent 8b8b04b commit cf67336

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2434
-1527
lines changed

.pre-commit-config.yaml

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ repos:
55
name: autoflake
66
entry: autoflake
77
language: system
8-
"types": [ python ]
8+
"types": [python]
99
require_serial: true
1010
files: &files ^(sqlmesh/|tests/|web/|examples/|setup.py)
1111
- id: isort
1212
name: isort
1313
entry: isort
1414
language: system
15-
"types": [ python ]
15+
"types": [python]
1616
files: *files
1717
require_serial: true
1818
- id: black
@@ -33,6 +33,38 @@ repos:
3333
name: mypy
3434
language: system
3535
entry: mypy
36-
"types": [ python ]
36+
"types": [python]
3737
files: *files
3838
require_serial: true
39+
- repo: https://github.com/pre-commit/mirrors-prettier
40+
rev: "cafd550"
41+
hooks:
42+
- id: prettier
43+
name: prettier
44+
files: ^(web/client)
45+
entry: prettier --write
46+
exclude: ^(web/client/node_modules)
47+
require_serial: true
48+
language: node
49+
- repo: https://github.com/pre-commit/mirrors-eslint
50+
rev: "5d73b35"
51+
hooks:
52+
- id: eslint
53+
name: eslint
54+
files: ^(web/client)
55+
exclude: ^(web/client/node_modules)
56+
entry: eslint --fix
57+
additional_dependencies:
58+
[
59+
"@typescript-eslint/eslint-plugin",
60+
"@typescript-eslint/parser",
61+
eslint@8.31.0,
62+
eslint-config-prettier@8.6.0,
63+
eslint-config-standard-with-typescript@27.0.1,
64+
eslint-plugin-import@2.27.4,
65+
eslint-plugin-n@15.6.1,
66+
eslint-plugin-promise@6.1.1,
67+
eslint-plugin-react@7.32.0,
68+
]
69+
require_serial: true
70+
language: node

web/client/.eslintrc.cjs

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

web/client/.eslintrc.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const OFF = 0
2+
const ERROR = 2
3+
4+
module.exports = {
5+
root: true,
6+
env: {
7+
browser: true,
8+
es2021: true,
9+
},
10+
extends: ['plugin:react/recommended', 'standard-with-typescript', 'prettier'],
11+
parser: '@typescript-eslint/parser',
12+
parserOptions: {
13+
tsconfigRootDir: __dirname,
14+
project: './tsconfig.json',
15+
},
16+
plugins: ['react', '@typescript-eslint'],
17+
rules: {
18+
'react/jsx-uses-react': OFF,
19+
'react/react-in-jsx-scope': OFF,
20+
'@typescript-eslint/naming-convention': [
21+
ERROR,
22+
{
23+
selector: 'variable',
24+
format: ['camelCase', 'PascalCase', 'UPPER_CASE', 'snake_case'],
25+
},
26+
],
27+
},
28+
ignorePatterns: ['src/api/client.ts'],
29+
settings: {
30+
react: {
31+
version: '18.2',
32+
},
33+
},
34+
}

web/client/.prettierrc.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
arrowParens: 'avoid',
3+
embeddedLanguageFormatting: 'auto',
4+
endOfLine: 'lf',
5+
htmlWhitespaceSensitivity: 'css',
6+
insertPragma: false,
7+
jsxSingleQuote: false,
8+
printWidth: 80,
9+
proseWrap: 'always',
10+
quoteProps: 'as-needed',
11+
requirePragma: false,
12+
semi: false,
13+
singleQuote: true,
14+
tabWidth: 2,
15+
trailingComma: 'all',
16+
useTabs: false,
17+
singleAttributePerLine: true,
18+
}

web/client/index.html

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
1-
<!DOCTYPE html>
2-
<html lang="en" >
1+
<!doctype html>
2+
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
5-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
5+
<meta
6+
name="viewport"
7+
content="width=device-width, initial-scale=1.0"
8+
/>
69
<title>Tobiko</title>
7-
<link rel="preconnect" href="https://fonts.googleapis.com">
8-
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
10+
<link
11+
rel="preconnect"
12+
href="https://fonts.googleapis.com"
13+
/>
14+
<link
15+
rel="preconnect"
16+
href="https://fonts.gstatic.com"
17+
crossorigin
18+
/>
919
<link
1020
href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap"
11-
rel="stylesheet">
21+
rel="stylesheet"
22+
/>
1223
</head>
1324
<body class="h-full w-full">
14-
<div id="root" class="h-full w-full flex flex-col justify-start"></div>
15-
<script type="module" src="/src/main.tsx"></script>
25+
<div
26+
id="root"
27+
class="h-full w-full flex flex-col justify-start"
28+
></div>
29+
<script
30+
type="module"
31+
src="/src/main.tsx"
32+
></script>
1633
</body>
1734
</html>

web/client/orval.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineConfig } from 'orval';
1+
import { defineConfig } from 'orval'
22

33
export default defineConfig({
44
'sqlmesh-api': {

web/client/package-lock.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/client/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
{
22
"name": "tobiko",
3-
"private": true,
43
"version": "0.0.0",
5-
"type": "module",
4+
"engines": {
5+
"node": "18",
6+
"npm": "8"
7+
},
68
"scripts": {
79
"dev": "npm run generate:api && vite",
810
"build": "npm run generate:api && tsc && vite build",
911
"preview": "vite preview",
1012
"prettier": "prettier --write .",
11-
"lint:fix": "eslint --fix",
13+
"lint:fix": "eslint --fix .",
1214
"format": "npm run prettier && npm run lint:fix",
1315
"test": "vitest",
1416
"generate:api": "orval --config ./orval.config.ts"
File renamed without changes.

web/client/src/api/channels.ts

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,65 @@
1-
import { isNil } from "../utils"
1+
import { isNil } from '../utils'
2+
3+
type ChannelCallback = (
4+
data: any,
5+
channel: EventSource,
6+
unsubscribe: () => void,
7+
) => void
28

39
const channels = new Map<string, EventSource>()
410

5-
export function useChannel(topic: string, callback: any): [() => void, () => EventSource | undefined, () => boolean] {
11+
export function useChannel(
12+
topic: string,
13+
callback: ChannelCallback,
14+
): [() => void, () => EventSource | undefined, () => boolean] {
615
return [
716
() => subscribe(topic, callback),
817
() => channels.get(topic),
9-
() => channels.delete(topic)
18+
() => channels.delete(topic),
1019
]
1120
}
1221

13-
function subscribe(topic: string, callback: any) {
22+
function subscribe(
23+
topic: string,
24+
callback: ChannelCallback,
25+
): EventSource | undefined {
1426
if (isNil(topic)) return
1527

16-
let channel = channels.get(topic)
28+
cleanUpChannel(topic, callback)
29+
30+
channels.set(topic, getEventSource(topic))
31+
32+
const channel = channels.get(topic)
33+
34+
channel?.addEventListener('message', handleChannelMessage(topic, callback))
35+
36+
return channel
37+
}
38+
39+
function cleanUpChannel(topic: string, callback: ChannelCallback): void {
40+
const channel = channels.get(topic)
1741

1842
channel?.close()
43+
channel?.removeEventListener('message', handleChannelMessage(topic, callback))
1944

20-
channels.set(topic, getEventSource(topic))
45+
channels.delete(topic)
46+
}
47+
48+
function handleChannelMessage(
49+
topic: string,
50+
callback: ChannelCallback,
51+
): (e: MessageEvent) => void {
52+
return (event: MessageEvent) => {
53+
if (isNil(topic) || isNil(callback) || isNil(event.data)) return
2154

22-
channel = channels.get(topic)
55+
const channel = channels.get(topic)
2356

24-
if (channel == null) return
57+
if (channel == null) return
2558

26-
channel.onmessage = (event: any) => {
27-
callback && callback(JSON.parse(event.data), channel, () => channels.delete(topic))
59+
callback(JSON.parse(event.data), channel, () => channels.delete(topic))
2860
}
2961
}
3062

31-
function getEventSource(topic: string) {
63+
function getEventSource(topic: string): EventSource {
3264
return new EventSource(topic)
3365
}

0 commit comments

Comments
 (0)