Skip to content

Commit 37c58e2

Browse files
committed
TCA-1179 - apply linting rules over dev-center code
1 parent 42c187b commit 37c58e2

File tree

18 files changed

+111
-98
lines changed

18 files changed

+111
-98
lines changed

src-ts/tools/dev-center/dev-center-lib/MarkdownDoc/LayoutDocHeader.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@ interface LayoutDocHeaderProps {
77
title?: string
88
}
99

10-
export const LayoutDocHeader: React.FC<LayoutDocHeaderProps> = props => {
11-
const { title = '', subtitle = '' }: LayoutDocHeaderProps = props
12-
13-
return (
14-
<header>
15-
<h1 className={styles.title}>{title}</h1>
16-
<hr className={styles.divider} />
17-
<h2 className={styles.subtitle}>{subtitle}</h2>
18-
</header>
19-
)
20-
}
10+
const LayoutDocHeader: React.FC<LayoutDocHeaderProps> = props => (
11+
<header>
12+
<h1 className={styles.title}>{props.title}</h1>
13+
<hr className={styles.divider} />
14+
<h2 className={styles.subtitle}>{props.subtitle}</h2>
15+
</header>
16+
)
2117

2218
export default LayoutDocHeader

src-ts/tools/dev-center/dev-center-lib/MarkdownDoc/MarkdownDoc.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@ interface MarkdownDocProps {
99
toc: TOC
1010
}
1111

12-
export const MarkdownDoc: React.FC<MarkdownDocProps> = props => {
13-
const { doc, toc, disableToc = false }: MarkdownDocProps = props
14-
15-
return (
16-
<LayoutDoc disableToc={disableToc} toc={toc}>
17-
{doc}
18-
</LayoutDoc>
19-
)
20-
}
12+
const MarkdownDoc: React.FC<MarkdownDocProps> = props => (
13+
<LayoutDoc disableToc={props.disableToc ?? false} toc={props.toc}>
14+
{props.doc}
15+
</LayoutDoc>
16+
)
2117

2218
export default MarkdownDoc

src-ts/tools/dev-center/dev-center-lib/MarkdownDoc/MarkdownLink.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ interface MarkdownLinkProps {
99
href: string
1010
}
1111

12-
export const MarkdownLink: React.FC<MarkdownLinkProps> = props => {
13-
const { children, href }: MarkdownLinkProps = props
14-
return (
15-
<div className={styles.linkBlock}>
16-
<span className={styles.label}>LINK</span>
17-
<span className={styles.divider} />
18-
<span className={styles.link}>{children}</span>
19-
<CopyButton text={href} />
20-
</div>
21-
)
22-
}
12+
export const MarkdownLink: React.FC<MarkdownLinkProps> = props => (
13+
<div className={styles.linkBlock}>
14+
<span className={styles.label}>LINK</span>
15+
<span className={styles.divider} />
16+
<span className={styles.link}>{props.children}</span>
17+
<CopyButton text={props.href} />
18+
</div>
19+
)
2320

2421
export default MarkdownLink

src-ts/tools/dev-center/dev-center-lib/MarkdownDoc/TableOfContents.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ export const TableOfContents: React.FC<TableOfContentsProps> = props => {
1212
number,
1313
React.Dispatch<React.SetStateAction<number>>
1414
] = React.useState(-1)
15-
const { toc }: { toc: TOC } = props
16-
const items: TOC = React.useMemo(() => toc.filter(item => item.level === 2 || item.level === 3), [toc])
15+
const items: TOC = React.useMemo(() => props.toc.filter(item => item.level === 2 || item.level === 3), [props.toc])
1716

1817
const navRef: React.RefObject<HTMLElement> = React.createRef<HTMLElement>()
1918

@@ -51,7 +50,7 @@ export const TableOfContents: React.FC<TableOfContentsProps> = props => {
5150
<ul>
5251
{items.map((item, index) => (
5352
<li
54-
key={`${item.title}-${index}`}
53+
key={`${item.title}-${index as any}`}
5554
className={`${styles.navListItem} ${
5655
index === activeIndex ? styles.active : ''
5756
}`}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
export * from './LayoutDocHeader'
1+
export { default as LayoutDocHeader } from './LayoutDocHeader'
22
export * from './markdownRenderer'
33

4-
export * from './MarkdownDoc'
5-
export { default } from './MarkdownDoc'
4+
export { default as MarkdownDoc } from './MarkdownDoc'

src-ts/tools/dev-center/dev-center-lib/MarkdownDoc/markdownRenderer/renderer.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// Ignore linting in this file for now
2+
// as there are way too many errors and unclear code
3+
// TODO: we need to cleanup the code and fix linting for this file
4+
/* eslint-disable */
5+
16
import * as React from 'react'
27
import { marked, Renderer as MarkedRenderer } from 'marked'
38
import _ from 'lodash'

src-ts/tools/dev-center/dev-center-lib/MarkdownDoc/markdownRenderer/util.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ export function renderMarkdown(
3636
.replace(/`/g, '')
3737
.trim(),
3838
}
39-
: { title, s }
39+
: { s: '', title: '' }
4040
}
4141

4242
const { title, s }: ReturnType<typeof getTitle> = getTitle(markdown)
43-
markdown = title ? s : markdown
43+
const markdownTitle: string = title ? s : markdown
4444

4545
const opts: MarkdownRenderOptions = { ...defaultOptions, ...options }
4646
const result: ReturnType<Renderer['render']> = renderer.render(
47-
markdown,
47+
markdownTitle,
4848
opts,
4949
)
5050
const { toc }: { toc: NonNullable<MarkdownRenderOptions['toc']> }
5151
= opts as { toc: NonNullable<MarkdownRenderOptions['toc']> }
5252

53-
return { doc: result, toc, title }
53+
return { doc: result, title, toc }
5454
}

src-ts/tools/dev-center/dev-center-lib/hooks/useMarkdown.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as React from 'react'
2+
import { noop } from 'lodash'
23

34
import {
45
MarkdownResult,
@@ -42,7 +43,7 @@ export default function useMarkdown({ uri }: UseMarkdownProps): {
4243
.then(text => {
4344
setMarkdown(text)
4445
})
45-
.catch(() => {})
46+
.catch(noop)
4647
}, [uri])
4748

4849
React.useEffect(() => {

src-ts/tools/dev-center/dev-center-pages/community-app/getting-started/GettingStartedGuide.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import * as React from 'react'
22

33
import { Breadcrumb, BreadcrumbItemModel, ContentLayout } from '../../../../../lib'
44
import { toolTitle } from '../../../dev-center.routes'
5-
import LayoutDocHeader from '../../../dev-center-lib/MarkdownDoc/LayoutDocHeader'
6-
import MarkdownDoc from '../../../dev-center-lib/MarkdownDoc'
5+
import { LayoutDocHeader, MarkdownDoc } from '../../../dev-center-lib/MarkdownDoc'
76
import useMarkdown from '../../../dev-center-lib/hooks/useMarkdown'
87

98
import gettingStartedGuide from './GettingStartedGuide.md'
@@ -17,7 +16,11 @@ export const GettingStartedGuide: React.FC = () => {
1716
], [title])
1817

1918
return (
20-
<ContentLayout contentClass={styles.contentLayout} outerClass={styles['contentLayout-outer']} innerClass={styles['contentLayout-inner']}>
19+
<ContentLayout
20+
contentClass={styles.contentLayout}
21+
outerClass={styles['contentLayout-outer']}
22+
innerClass={styles['contentLayout-inner']}
23+
>
2124

2225
<Breadcrumb items={breadcrumb} />
2326
<LayoutDocHeader title={title} subtitle='Getting started Guide' />

src-ts/tools/dev-center/dev-center-pages/community-app/landing-page/dev-center-articles-section/ArticleCard/ArticleCard.tsx

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ import { BlogPost, ThriveArticle } from '../models'
99

1010
import styles from './ArticleCard.module.scss'
1111

12-
interface ArticleCardProps {
13-
article: ThriveArticle | BlogPost
14-
className?: string
15-
isMain: boolean
16-
}
17-
1812
interface ArticleDetails {
1913
author: string
2014
image: string
@@ -44,25 +38,27 @@ function getArticleContent(
4438
article: ThriveArticle | BlogPost,
4539
isThrive: boolean,
4640
): string {
47-
return isThrive ? article.content : article.contentSnippet
41+
return isThrive ? (article as ThriveArticle).content : (article as BlogPost).contentSnippet
4842
}
4943

5044
function getArticleDetails(article: ThriveArticle | BlogPost): ArticleDetails {
5145
const isThrive: boolean = isThriveArticle(article)
52-
const isVideo: boolean = isThrive && article.type === 'Video'
46+
const thriveArticle: ThriveArticle = article as ThriveArticle
47+
const blogPost: BlogPost = article as BlogPost
48+
const isVideo: boolean = isThrive && thriveArticle.type === 'Video'
5349

5450
const tagText: string = getTagText(isThrive, isVideo)
5551

5652
const content: string = getArticleContent(article, isThrive)
5753
const regex: RegExp = /(<([^>]+)>)/gi
5854
const summary: string = content.replace(regex, '') // Remove html from the content string
5955
const url: string = isThrive
60-
? `${EnvironmentConfig.TOPCODER_URLS.THRIVE_PAGE}/articles/${article.slug}`
61-
: article.link
62-
const author: string = !isThrive ? article.creator : ''
56+
? `${EnvironmentConfig.TOPCODER_URLS.THRIVE_PAGE}/articles/${thriveArticle.slug}`
57+
: blogPost.link
58+
const author: string = !isThrive ? blogPost.creator : ''
6359
const image: string = isThrive
64-
? article.featuredImage.fields.file.url
65-
: article.featuredImage
60+
? thriveArticle.featuredImage.fields.file.url
61+
: blogPost.featuredImage
6662

6763
return {
6864
author,
@@ -83,12 +79,14 @@ function getOuterClass(isMain: boolean, className: string): string {
8379
)
8480
}
8581

86-
const ArticleCard: FC<ArticleCardProps> = ({
87-
article,
88-
isMain,
89-
className = '',
90-
}) => {
91-
const outerClass: string = getOuterClass(isMain, className)
82+
interface ArticleCardProps {
83+
article: ThriveArticle | BlogPost
84+
className?: string
85+
isMain: boolean
86+
}
87+
88+
const ArticleCard: FC<ArticleCardProps> = props => {
89+
const outerClass: string = getOuterClass(props.isMain, props.className ?? '')
9290
const {
9391
isThrive,
9492
isVideo,
@@ -97,7 +95,7 @@ const ArticleCard: FC<ArticleCardProps> = ({
9795
url,
9896
author,
9997
image,
100-
}: ArticleDetails = getArticleDetails(article)
98+
}: ArticleDetails = getArticleDetails(props.article)
10199

102100
return (
103101
<div
@@ -106,7 +104,7 @@ const ArticleCard: FC<ArticleCardProps> = ({
106104
>
107105
<div
108106
className={styles.innerContainer}
109-
onClick={() => openArticle(url)}
107+
onClick={function handleOpenArticle() { openArticle(url) }}
110108
>
111109
{isThrive && isVideo && (
112110
<IconSolid.PlayIcon className={styles.playButton} />
@@ -116,17 +114,17 @@ const ArticleCard: FC<ArticleCardProps> = ({
116114
<DevCenterTag text={tagText} />
117115
{isThrive && (
118116
<span className='font-tc-white body-small'>
119-
{article.readTime}
117+
{(props.article as ThriveArticle).readTime}
120118
</span>
121119
)}
122120
</div>
123-
{isMain ? (
121+
{props.isMain ? (
124122
<h2 className={classNames('font-tc-white', 'details')}>
125-
{article.title}
123+
{props.article.title}
126124
</h2>
127125
) : (
128126
<h4 className='font-tc-white details'>
129-
{article.title}
127+
{props.article.title}
130128
</h4>
131129
)}
132130
{!isThrive && (
@@ -140,7 +138,7 @@ const ArticleCard: FC<ArticleCardProps> = ({
140138
{author}
141139
</span>
142140
)}
143-
{isMain && (
141+
{props.isMain && (
144142
<>
145143
<span
146144
className={classNames(

0 commit comments

Comments
 (0)