Skip to content

Commit 8c42ffd

Browse files
authored
chore: add eslint rule and lint-staged (#24)
* chore: add lint-staged * chore: add eslint rule * fix: ci config * chore: add lock file * chore: change ci config * chore: change ci config * chore: remove github action config
1 parent 94a121d commit 8c42ffd

26 files changed

+34866
-202
lines changed

.eslintrc.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "next/core-web-vitals",
2+
"extends": ["next", "prettier"],
33
"rules": {
44
"semi": [2, "never"],
55
"space-before-blocks": "error",
@@ -19,6 +19,9 @@
1919
"code": 120,
2020
"ignorePattern": "className"
2121
}
22-
]
22+
],
23+
"react/jsx-max-props-per-line": [2, { "maximum": 1, "when": "multiline" }],
24+
"react/jsx-closing-bracket-location":[2, "after-props"],
25+
"react/jsx-indent-props": [2, 2]
2326
}
2427
}

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ artifacts
4646
# contract type generation
4747
/contracts/types
4848

49-
package-lock.json
50-
5149
version.js
5250
yarn.lock
5351
*_bak
52+
.eslintcache

.husky/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_

.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx lint-staged

components/AddLinkDialog.tsx

+8-16
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ export function AddLinkDialog({ open, close, save }: AddLinkDialogProps) {
1919
enterTo="transform scale-100 opacity-100"
2020
leave="transition duration-75 ease-out"
2121
leaveFrom="transform scale-100 opacity-100"
22-
leaveTo="transform scale-95 opacity-0"
23-
>
22+
leaveTo="transform scale-95 opacity-0">
2423
<Dialog
2524
as="div"
2625
className="fixed inset-0 z-10 overflow-y-auto"
27-
onClose={close}
28-
>
26+
onClose={close}>
2927
<div className="min-h-screen px-4 text-center">
3028
<Transition.Child
3129
as={Fragment}
@@ -34,16 +32,14 @@ export function AddLinkDialog({ open, close, save }: AddLinkDialogProps) {
3432
enterTo="opacity-100"
3533
leave="ease-in duration-200"
3634
leaveFrom="opacity-100"
37-
leaveTo="opacity-0"
38-
>
35+
leaveTo="opacity-0">
3936
<Dialog.Overlay className="fixed inset-0 bg-grey-100" />
4037
</Transition.Child>
4138

4239
{/* This element is to trick the browser into centering the modal contents. */}
4340
<span
4441
className="inline-block h-screen align-middle"
45-
aria-hidden="true"
46-
>
42+
aria-hidden="true">
4743
&#8203;
4844
</span>
4945
<Transition.Child
@@ -53,29 +49,25 @@ export function AddLinkDialog({ open, close, save }: AddLinkDialogProps) {
5349
enterTo="opacity-100 scale-100"
5450
leave="ease-in duration-200"
5551
leaveFrom="opacity-100 scale-100"
56-
leaveTo="opacity-0 scale-95"
57-
>
52+
leaveTo="opacity-0 scale-95">
5853
<div className="inline-block w-full max-w-md p-6 my-8 overflow-hidden text-left align-middle transition-all transform bg-white shadow-xl rounded-2xl">
5954
<Dialog.Title
6055
as="h3"
61-
className="text-lg font-medium leading-6 text-gray-900"
62-
>
56+
className="text-lg font-medium leading-6 text-gray-900">
6357
Provider a Link
6458
</Dialog.Title>
6559
<div className="mt-2">
6660
<input
6761
onChange={e => setUrl(e.target.value)}
6862
type='text'
6963
placeholder="Link"
70-
className="w-full bg-white rounded border border-gray-300 focus:border-indigo-500 focus:ring-2 focus:ring-indigo-200 text-base outline-none text-gray-700 py-1 px-3 leading-8 transition-colors duration-200 ease-in-out"
71-
/>
64+
className="w-full bg-white rounded border border-gray-300 focus:border-indigo-500 focus:ring-2 focus:ring-indigo-200 text-base outline-none text-gray-700 py-1 px-3 leading-8 transition-colors duration-200 ease-in-out"/>
7265
</div>
7366
<div className="mt-4">
7467
<button
7568
type="button"
7669
className="inline-flex justify-center px-4 py-2 text-sm font-medium text-blue-900 bg-blue-100 border border-transparent rounded-md hover:bg-blue-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-blue-500"
77-
onClick={() => save(url)}
78-
>
70+
onClick={() => save(url)}>
7971
Save
8072
</button>
8173
</div>

components/ArticleItem.tsx

+12-4
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,23 @@ export const ArticleItem = memo<ArticleItemProps>(({ imageURL, tags, authors, na
1212
return (
1313
<div className="p-4 md:w-1/3">
1414
<div className="h-full border-2 border-gray-200 border-opacity-60 rounded-lg overflow-hidden">
15-
<img className="lg:h-48 md:h-36 w-full object-cover object-center" src={imageURL} alt={name} />
15+
<img className="lg:h-48 md:h-36 w-full object-cover object-center"
16+
src={imageURL}
17+
alt={name}/>
1618
<div className="p-6">
1719
<h2 className="tracking-widest text-xs title-font font-medium text-gray-400 mb-1">{ tags }</h2>
1820
<h1 className="title-font text-lg font-medium text-gray-900 mb-3">{ name }</h1>
1921
<p className="leading-relaxed mb-3">{ authors }</p>
2022
<div className="flex items-center flex-wrap ">
21-
<a className="text-indigo-500 inline-flex items-center md:mb-2 lg:mb-0" href={"/article?cid=" + path}>Goto
22-
<svg className="w-4 h-4 ml-2" viewBox="0 0 24 24" stroke="currentColor" strokeWidth="2"
23-
fill="none" strokeLinecap="round" strokeLinejoin="round">
23+
<a className="text-indigo-500 inline-flex items-center md:mb-2 lg:mb-0"
24+
href={"/article?cid=" + path}>Goto
25+
<svg className="w-4 h-4 ml-2"
26+
viewBox="0 0 24 24"
27+
stroke="currentColor"
28+
strokeWidth="2"
29+
fill="none"
30+
strokeLinecap="round"
31+
strokeLinejoin="round">
2432
<path d="M5 12h14"/>
2533
<path d="M12 5l7 7-7 7"/>
2634
</svg>

components/Editor.tsx

+34-24
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export const Editor = memo<EditorProps>(({ account, article, publishLink, cid })
151151
setCachedTags([...newValue])
152152
}
153153

154-
const onSubmit = async(data: IFormInputs) => {
154+
const onSubmit = async (data: IFormInputs) => {
155155
let imageURL
156156
let filesize
157157
let filename
@@ -240,15 +240,16 @@ export const Editor = memo<EditorProps>(({ account, article, publishLink, cid })
240240

241241
return (
242242
<div className='relative w-full flex justify-center p-6'>
243-
<form style={{ width: '720px' }} onSubmit={handleSubmit(onSubmit, onError)}>
243+
<form style={{ width: '720px' }}
244+
onSubmit={handleSubmit(onSubmit, onError)}>
244245
<div className='inline-flex absolute -top-10 right-2 items-center'>
245-
<Menu as="div" className="relative inline-block text-left">
246+
<Menu as="div"
247+
className="relative inline-block text-left">
246248
<div>
247249
<Menu.Button className="px-2 flex items-center">
248250
<ExclamationIcon
249251
className="w-8 h-8"
250-
aria-hidden="true"
251-
/>
252+
aria-hidden="true"/>
252253
</Menu.Button>
253254
</div>
254255
<Transition
@@ -258,8 +259,7 @@ export const Editor = memo<EditorProps>(({ account, article, publishLink, cid })
258259
enterTo="transform opacity-100 scale-100"
259260
leave="transition ease-in duration-75"
260261
leaveFrom="transform opacity-100 scale-100"
261-
leaveTo="transform opacity-0 scale-95"
262-
>
262+
leaveTo="transform opacity-0 scale-95">
263263
<Menu.Items
264264
className="absolute right-0 w-80 mt-2 origin-top-right bg-white divide-y divide-gray-100 rounded-md shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none">
265265
<div className="px-6 py-8">
@@ -294,8 +294,7 @@ export const Editor = memo<EditorProps>(({ account, article, publishLink, cid })
294294
setValue('description', cache)
295295
trigger()
296296
}
297-
}}
298-
>
297+
}}>
299298
{`Publish${isSubmitting ? '...' :''}`}
300299
</button>
301300
</div>
@@ -304,41 +303,52 @@ export const Editor = memo<EditorProps>(({ account, article, publishLink, cid })
304303
{
305304
!preview &&
306305
<div className="inline-flex bg-gray-200 text-gray-500 rounded-full px-2 cursor-pointer">
307-
<svg viewBox="0 0 24 24" className="w-3">
306+
<svg viewBox="0 0 24 24"
307+
className="w-3">
308308
<path
309309
d="M12 1.5v21M1.5 12h21"
310310
stroke="#343F44"
311311
strokeLinecap="round"
312312
strokeLinejoin="round"
313313
fill="none"
314-
fillRule="evenodd"
315-
/>
314+
fillRule="evenodd"/>
316315
</svg>
317316
<span className="inline-block p-1 text-sm">
318317
Add feature image
319318
</span>
320319
</div>
321320
}
322-
<input type="file" name="Asset" className="hidden" {...register("files")} />
321+
<input type="file"
322+
name="Asset"
323+
className="hidden"
324+
{...register("files")}/>
323325
{
324326
preview &&
325-
<img className="lg:h-48 md:h-36 w-full object-cover object-center cursor-pointer" src={preview} />
327+
<img className="lg:h-48 md:h-36 w-full object-cover object-center cursor-pointer"
328+
src={preview} />
326329
}
327330
</label>
328331
</div>
329332
<div className="pt-12">
330333
<TextareaAutosize
331334
placeholder="Give a title"
332-
className="border-0 outline-0 text-5xl w-full resize-none" {...register("name")}
333-
/>
335+
className="border-0 outline-0 text-5xl w-full resize-none"
336+
{...register("name")}/>
334337
</div>
335338
<div className="my-6 mb-4">
336339
<div className="text-gray-800 flex items-center">
337340
<div className="w-8 h-8 rounded-full inline-flex items-center justify-center bg-gray-200 text-gray-400">
338-
<svg fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="2"
339-
className="w-4 h-4" viewBox="0 0 24 24">
341+
<svg fill="none"
342+
stroke="currentColor"
343+
strokeLinecap="round"
344+
strokeLinejoin="round"
345+
strokeWidth="2"
346+
className="w-4 h-4"
347+
viewBox="0 0 24 24">
340348
<path d="M20 21v-2a4 4 0 00-4-4H8a4 4 0 00-4 4v2"/>
341-
<circle cx="12" cy="7" r="4"/>
349+
<circle cx="12"
350+
cy="7"
351+
r="4"/>
342352
</svg>
343353
</div>
344354
<span
@@ -353,8 +363,7 @@ export const Editor = memo<EditorProps>(({ account, article, publishLink, cid })
353363
}
354364
placeholder="Input Authors"
355365
onChange={handleAuthorsChange}
356-
options={authorsInLocal ?? []}
357-
/>
366+
options={authorsInLocal ?? []}/>
358367
</div>
359368
<div className="pt-3 flex justify-start items-center text-gray-500">
360369
<span>Tags:</span>
@@ -366,13 +375,14 @@ export const Editor = memo<EditorProps>(({ account, article, publishLink, cid })
366375
placeholder="Input Post Tags"
367376
onChange={handleTagsChange}
368377
// @ts-ignore
369-
options={tagsInLocal ?? []}
370-
/>
378+
options={tagsInLocal ?? []}/>
371379
</div>
372380
</div>
373381
<Tiptap initValue={article?.description} />
374382
</form>
375-
<Dialog as='div' open={isOpen} onClose={() => setIsOpen(false)}>
383+
<Dialog as='div'
384+
open={isOpen}
385+
onClose={() => setIsOpen(false)}>
376386
<Dialog.Overlay />
377387

378388
<Dialog.Title>Deactivate account</Dialog.Title>

components/Layout.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { Footer } from "./Footer"
33

44
export const Layout =memo( ({ children }) => {
55
return (
6-
<main style={{ minHeight: 'calc(100vh - 140px)' }} className='flex flex-col justify-between'>
6+
<main style={{ minHeight: 'calc(100vh - 140px)' }}
7+
className='flex flex-col justify-between'>
78
{ children }
89
<Footer />
910
</main>

components/Navigation.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ export const Navigation = () => {
3939
<div className="flex mt-4 grow flex-wrap">
4040
{ config.map((item) => {
4141
return (
42-
<Link key={item.path} href={item.path}>
43-
<a className={`mr-4 text-pink-500 _nav ${ isActivePath(item.path) && 'current'}`} id="_home">
42+
<Link key={item.path}
43+
href={item.path}>
44+
<a className={`mr-4 text-pink-500 _nav ${ isActivePath(item.path) && 'current'}`}
45+
id="_home">
4446
{item.name}
4547
</a>
4648
</Link>

components/Tiptap.tsx

+20-21
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,22 @@ export const Tiptap = ({ initValue }: TiptapProps) => {
8181

8282
return (
8383
<div>
84-
{editor && <BubbleMenu editor={editor} pluginKey={'menu'}>
85-
<MenuUI editor={editor} openHyperLinkDialog={() => setOpenHyperDialog(true)} />
84+
{editor && <BubbleMenu editor={editor}
85+
pluginKey={'menu'}>
86+
<MenuUI editor={editor}
87+
openHyperLinkDialog={() => setOpenHyperDialog(true)} />
8688
</BubbleMenu>}
87-
<UploadImageDialog open={openImageDialog} close={() => setOpenImageDialog(false)} save={handleImage} />
88-
<AddLinkDialog open={openHyperLinkDialog} close={() => setOpenHyperDialog(false)} save={handleHyperLink} />
89+
<UploadImageDialog open={openImageDialog}
90+
close={() => setOpenImageDialog(false)}
91+
save={handleImage}/>
92+
<AddLinkDialog open={openHyperLinkDialog}
93+
close={() => setOpenHyperDialog(false)}
94+
save={handleHyperLink}/>
8995
<EditorContent editor={editor} />
9096
<div className='fixed bottom-6 inset-x-0'>
9197
<div className="flex justify-center">
92-
<FixedMenuUI editor={editor} openImageDialog={() => setOpenImageDialog(true)} />
98+
<FixedMenuUI editor={editor}
99+
openImageDialog={() => setOpenImageDialog(true)} />
93100
</div>
94101
</div>
95102
</div>
@@ -103,23 +110,20 @@ const FixedMenuUI = ({ editor, openImageDialog }: {editor: Editor, openImageDial
103110
<div className="p-2 text-gray-800">
104111
<button
105112
onClick={(e) => { editor.chain().focus().toggleBulletList().run(); e.preventDefault() }}
106-
className={editor.isActive('bulletList') ? 'is-active' : ''}
107-
>
113+
className={editor.isActive('bulletList') ? 'is-active' : ''}>
108114
Bullet list
109115
</button>
110116
</div>
111117
<div className="p-2 text-gray-800">
112118
<button
113119
onClick={(e) => {editor.chain().focus().toggleOrderedList().run(); e.preventDefault()}}
114-
className={editor.isActive('orderedList') ? 'is-active' : ''}
115-
>
120+
className={editor.isActive('orderedList') ? 'is-active' : ''}>
116121
Order list
117122
</button>
118123
</div>
119124
<div className="p-2 text-gray-800">
120125
<button
121-
onClick={(e) => { e.preventDefault(); openImageDialog()}}
122-
>
126+
onClick={(e) => { e.preventDefault(); openImageDialog()}}>
123127
Image
124128
</button>
125129
</div>
@@ -134,40 +138,35 @@ const MenuUI = ({ editor, openHyperLinkDialog }: {editor: Editor, openHyperLinkD
134138
<div className="p-2 text-gray-800">
135139
<button
136140
onClick={() => editor.chain().focus().toggleHeading({ level: 1 }).run()}
137-
className={editor.isActive('h-1') ? 'is-active' : ''}
138-
>
141+
className={editor.isActive('h-1') ? 'is-active' : ''}>
139142
h1
140143
</button>
141144
</div>
142145
<div className="p-2 text-gray-800">
143146
<button
144147
onClick={() => editor.chain().focus().toggleHeading({ level: 2 }).run()}
145-
className={editor.isActive('h-2') ? 'is-active' : ''}
146-
>
148+
className={editor.isActive('h-2') ? 'is-active' : ''}>
147149
h2
148150
</button>
149151
</div>
150152
<div className="p-2 text-gray-800">
151153
<button
152154
onClick={e => {e.preventDefault(); openHyperLinkDialog() }}
153-
className={editor.isActive('link') ? 'is-active' : ''}
154-
>
155+
className={editor.isActive('link') ? 'is-active' : ''}>
155156
link
156157
</button>
157158
</div>
158159
<div className="p-2 text-gray-800">
159160
<button
160161
onClick={() => editor.chain().focus().toggleBold().run()}
161-
className={editor.isActive('bold') ? 'is-active' : ''}
162-
>
162+
className={editor.isActive('bold') ? 'is-active' : ''}>
163163
bold
164164
</button>
165165
</div>
166166
<div className="p-2 text-gray-800">
167167
<button
168168
onClick={() => editor.chain().focus().toggleItalic().run()}
169-
className={editor.isActive('italic') ? 'is-active' : ''}
170-
>
169+
className={editor.isActive('italic') ? 'is-active' : ''}>
171170
italic
172171
</button>
173172
</div>

0 commit comments

Comments
 (0)