diff options
author | eug-vs <eug-vs@keemail.me> | 2020-04-18 20:26:32 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-04-18 20:26:32 +0300 |
commit | 2c5fa193541eb8b74974731d01312f73951bca17 (patch) | |
tree | 4cbc833a14487543d9ef38e66f6028d82f3978af | |
parent | 9941754be106accd5ea8ce4b6f8229dd6f4afc9b (diff) | |
download | react-benzin-2c5fa193541eb8b74974731d01312f73951bca17.tar.gz |
style: correct some errors with eslint --fix
-rw-r--r-- | src/index.tsx | 73 | ||||
-rw-r--r-- | src/lib/Benzin/Benzin.tsx | 8 | ||||
-rw-r--r-- | src/lib/ContentSection/ContentSection.tsx | 7 | ||||
-rw-r--r-- | src/lib/Header/Header.tsx | 48 | ||||
-rw-r--r-- | src/lib/Markdown/CodeBlock.tsx | 6 | ||||
-rw-r--r-- | src/lib/Markdown/Content.tsx | 27 | ||||
-rw-r--r-- | src/lib/Markdown/Markdown.tsx | 6 | ||||
-rw-r--r-- | src/lib/Markdown/Section.tsx | 28 | ||||
-rw-r--r-- | src/lib/Markdown/SyntacticSpan.tsx | 18 | ||||
-rw-r--r-- | src/lib/Markdown/Text.tsx | 2 | ||||
-rw-r--r-- | src/lib/SmartList/SmartList.tsx | 3 | ||||
-rw-r--r-- | src/lib/Window/Window.tsx | 5 | ||||
-rw-r--r-- | src/lib/Window/WindowSurface.tsx | 6 | ||||
-rw-r--r-- | src/react-app-env.d.ts | 2 |
14 files changed, 121 insertions, 118 deletions
diff --git a/src/index.tsx b/src/index.tsx index a9a7012..ac7bfc2 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -27,23 +27,23 @@ const useStyles = makeStyles(theme => ({ display: 'flex', justifyContent: 'center', marginTop: theme.spacing(4), - } + }, })); -const Icon = <img src={icon} width="32px" height="37px" alt="logo"/> +const Icon = <img src={icon} width="32px" height="37px" alt="logo" />; const headerContents = { home: null, - 'spacevim': null, + spacevim: null, 'material-ui': null, - 'custom': null, + custom: null, 'live preview': null, }; const pageMap: Record<string, string> = { home: 'https://raw.githubusercontent.com/eug-vs/react-benzin/develop/README.md', - 'spacevim': 'https://raw.githubusercontent.com/spacevim/spacevim/master/README.md', + spacevim: 'https://raw.githubusercontent.com/spacevim/spacevim/master/README.md', 'material-ui': 'https://raw.githubusercontent.com/mui-org/material-ui/master/README.md', }; @@ -54,11 +54,11 @@ const CustomPage: React.FC = () => { const handleParseUrl = (): void => { setUrl(inputEl.current?.value || ''); - } + }; return ( <> - <ContentSection sectionName="Render custom markdown document" level={2} > + <ContentSection sectionName="Render custom markdown document" level={2}> <p> This should be a link to a valid markdown file. Response should give the file contents. If you copy README file from GitHub, make sure you provide link to raw view. @@ -72,14 +72,14 @@ const CustomPage: React.FC = () => { label="Markdown url" /> </p> - <Button variant="contained" color="secondary" onClick={handleParseUrl} > + <Button variant="contained" color="secondary" onClick={handleParseUrl}> Render! </Button> </ContentSection> <Markdown url={url} /> </> ); -} +}; interface LivePropTypes { setLivePreviewData: (livePreviewData: string) => void; @@ -90,11 +90,11 @@ const LivePreviewPage: React.FC<LivePropTypes> = ({ setLivePreviewData }) => { const handleRender = (): void => { setLivePreviewData(inputEl.current?.value || ''); - } + }; return ( <> - <ContentSection sectionName="Markdown live preview" level={2} > + <ContentSection sectionName="Markdown live preview" level={2}> <p> Start typing and see your text rendered on the left window! We recommend starting with # Header. </p> @@ -111,8 +111,8 @@ const LivePreviewPage: React.FC<LivePropTypes> = ({ setLivePreviewData }) => { </p> </ContentSection> </> - ) -} + ); +}; const App: React.FC = () => { @@ -122,7 +122,7 @@ const App: React.FC = () => { const handleGoLivePreview = (): void => { setPage('live preview'); - } + }; const url = pageMap[page]; const fileName = url?.slice(url.lastIndexOf('/') + 1); @@ -153,35 +153,34 @@ const App: React.FC = () => { <Window type="primary"> <div className={classes.window}> { - (page === 'custom') ? - <CustomPage /> - : - (page === 'live preview') ? - <Markdown data={livePreviewData || '# Start typing in the right window!'} /> - : - <Markdown url={url} /> + (page === 'custom') + ? <CustomPage /> + : (page === 'live preview') + ? <Markdown data={livePreviewData || '# Start typing in the right window!'} /> + : <Markdown url={url} /> } </div> </Window> <Window type="secondary" name="Feature preview"> <div className={classes.window}> { - (page === 'live preview') ? - <LivePreviewPage setLivePreviewData={setLivePreviewData} /> - : - <> - <Markdown data={info} /> - <p className={classes.promoButton}> - <Button - variant="contained" - color="primary" - size="large" - onClick={handleGoLivePreview} - > - Try it yourself! - </Button> - </p> - </> + (page === 'live preview') + ? <LivePreviewPage setLivePreviewData={setLivePreviewData} /> + : ( + <> + <Markdown data={info} /> + <p className={classes.promoButton}> + <Button + variant="contained" + color="primary" + size="large" + onClick={handleGoLivePreview} + > + Try it yourself! + </Button> + </p> + </> + ) } </div> </Window> diff --git a/src/lib/Benzin/Benzin.tsx b/src/lib/Benzin/Benzin.tsx index 83ed0b0..bc436f7 100644 --- a/src/lib/Benzin/Benzin.tsx +++ b/src/lib/Benzin/Benzin.tsx @@ -8,9 +8,9 @@ import 'typeface-roboto'; declare module '@material-ui/core/styles/createPalette' { interface TypeBackground { - elevation1: string; - elevation2: string; - elevation3: string; + elevation1: string; + elevation2: string; + elevation3: string; } } @@ -34,7 +34,7 @@ const benzinTheme = createMuiTheme({ text: { primary: '#f4f4f4', secondary: 'rgba(255, 255, 255, 0.6)', - } + }, }, }); diff --git a/src/lib/ContentSection/ContentSection.tsx b/src/lib/ContentSection/ContentSection.tsx index ba8b882..6b27bba 100644 --- a/src/lib/ContentSection/ContentSection.tsx +++ b/src/lib/ContentSection/ContentSection.tsx @@ -3,7 +3,7 @@ import React from 'react'; import { Typography, Divider, - makeStyles + makeStyles, } from '@material-ui/core'; @@ -30,18 +30,17 @@ const ContentSection: React.FC<PropTypes> = ({ sectionName, children, level = 0 if (level > 6) level = 6; type Variant = 'h3' | 'h4' | 'h5' | 'h6'; - const variant: Variant = 'h' + level as Variant; + const variant: Variant = `h${level}` as Variant; return ( <> <Typography variant={variant}>{sectionName}</Typography> - <Divider variant="middle"/> + <Divider variant="middle" /> <Typography component="div" className={classes.content}> {children} </Typography> </> ); - }; diff --git a/src/lib/Header/Header.tsx b/src/lib/Header/Header.tsx index 233eacb..58be989 100644 --- a/src/lib/Header/Header.tsx +++ b/src/lib/Header/Header.tsx @@ -40,13 +40,15 @@ const useStyles = makeStyles(theme => ({ '& svg': { marginRight: theme.spacing(1), marginBottom: '0 !important', - } - } - } + }, + }, + }, })); -const Header: React.FC<PropTypes> = ({ logo, contents, page, setPage }) => { +const Header: React.FC<PropTypes> = ({ + logo, contents, page, setPage, +}) => { const classes = useStyles(); const handleChange = (event: React.ChangeEvent<{}>, newPage: string): void => { @@ -54,25 +56,25 @@ const Header: React.FC<PropTypes> = ({ logo, contents, page, setPage }) => { }; return ( - <AppBar position="sticky" className={classes.root}> - <Toolbar> - {logo.icon} - <Typography variant="h5" className={classes.logo} color="primary"> - {logo.title} - </Typography> - <Tabs onChange={handleChange} value={page}> - {contents && Object.keys(contents).map((item: string) => ( - <Tab - label={item} - icon={contents[item] as JSX.Element} - value={item} - className={classes.tab} - key={item} - /> - ))} - </Tabs> - </Toolbar> - </AppBar> + <AppBar position="sticky" className={classes.root}> + <Toolbar> + {logo.icon} + <Typography variant="h5" className={classes.logo} color="primary"> + {logo.title} + </Typography> + <Tabs onChange={handleChange} value={page}> + {contents && Object.keys(contents).map((item: string) => ( + <Tab + label={item} + icon={contents[item] as JSX.Element} + value={item} + className={classes.tab} + key={item} + /> + ))} + </Tabs> + </Toolbar> + </AppBar> ); }; diff --git a/src/lib/Markdown/CodeBlock.tsx b/src/lib/Markdown/CodeBlock.tsx index 5b8edec..394458e 100644 --- a/src/lib/Markdown/CodeBlock.tsx +++ b/src/lib/Markdown/CodeBlock.tsx @@ -1,8 +1,8 @@ import React from 'react'; -import { ParserPropTypes } from './types'; import { Paper } from '@material-ui/core'; import { makeStyles } from '@material-ui/core/styles'; +import { ParserPropTypes } from './types'; const useStyles = makeStyles(theme => ({ root: { @@ -10,7 +10,7 @@ const useStyles = makeStyles(theme => ({ padding: theme.spacing(1), overflowX: 'auto', fontFamily: 'Monospace', - scrollbarColor: 'auto' + scrollbarColor: 'auto', }, })); @@ -21,7 +21,7 @@ const CodeBlock: React.FC<ParserPropTypes> = ({ rawLines }) => { {rawLines.map(line => <pre>{line}</pre>)} </Paper> ); -} +}; export default CodeBlock; diff --git a/src/lib/Markdown/Content.tsx b/src/lib/Markdown/Content.tsx index 5816214..d64720b 100644 --- a/src/lib/Markdown/Content.tsx +++ b/src/lib/Markdown/Content.tsx @@ -6,31 +6,32 @@ import { ParserPropTypes } from './types'; const denotesCodeBlock = (line: string): boolean => { - return line.match(/^\s*```.*$/) !== null; } + return line.match(/^\s*```.*$/) !== null; +}; const denotesDottedList = (line: string): boolean => { return line.match(/^ ?[-*] .*$/) !== null; -} +}; -const denotesOpenHtml= (line: string): string => { +const denotesOpenHtml = (line: string): string => { const regex = /<([^/\s]*)[^<]*[^/]>/g; const match = regex.exec(line); return match ? match[1] : ''; -} +}; -const denotesClosingHtml= (line: string, tag: string): boolean => { +const denotesClosingHtml = (line: string, tag: string): boolean => { const regex = new RegExp(`</${tag}[^<]*>`); return line.match(regex) !== null; -} +}; const denotesSelfClosingHtml = (line: string): string[] | null => { const regex = /(<[^/\s]*[^<]*\/>)/g; return line.match(regex); -} +}; const declaresNoLineBreak = (line: string): boolean => { return line.match(/\\\|$/) !== null; -} +}; const Content: React.FC<ParserPropTypes> = ({ rawLines }) => { if (!rawLines.length) return null; @@ -41,7 +42,7 @@ const Content: React.FC<ParserPropTypes> = ({ rawLines }) => { if (denotesCodeBlock(line)) { const closeIndex = rawLines.findIndex(line => denotesCodeBlock(line)); const codeBlockLines = rawLines.splice(0, closeIndex + 1).slice(0, closeIndex); - buffer = <CodeBlock rawLines={codeBlockLines} /> + buffer = <CodeBlock rawLines={codeBlockLines} />; } else if (denotesDottedList(line)) { const closeIndex = rawLines.findIndex(line => !denotesDottedList(line)); const dottedListLines = rawLines.splice(0, closeIndex).slice(0, closeIndex); @@ -52,14 +53,14 @@ const Content: React.FC<ParserPropTypes> = ({ rawLines }) => { const closeIndex = denotesClosingHtml(line, tag) ? -1 : rawLines.findIndex(line => denotesClosingHtml(line, tag)); const htmlLines = rawLines.splice(0, closeIndex + 1); htmlLines.unshift(line); - buffer = <div dangerouslySetInnerHTML={{ __html: htmlLines.join('\n') }}></div>; + buffer = <div dangerouslySetInnerHTML={{ __html: htmlLines.join('\n') }} />; } else if ((buffer = denotesSelfClosingHtml(line)) !== null) { const match = buffer[0]; const [before, after] = line.split(match); buffer = ( <> <Text line={before} /> - <div dangerouslySetInnerHTML={{ __html: match }}></div> + <div dangerouslySetInnerHTML={{ __html: match }} /> <Text line={after} /> </> ); @@ -72,7 +73,7 @@ const Content: React.FC<ParserPropTypes> = ({ rawLines }) => { } else if (denotesClosingHtml(line, '')) { buffer = null; } else { - buffer = <p><Text line={line} /></p> + buffer = <p><Text line={line} /></p>; } return ( @@ -81,7 +82,7 @@ const Content: React.FC<ParserPropTypes> = ({ rawLines }) => { <Content rawLines={rawLines} /> </> ); -} +}; export default Content; diff --git a/src/lib/Markdown/Markdown.tsx b/src/lib/Markdown/Markdown.tsx index 82e889c..68967c5 100644 --- a/src/lib/Markdown/Markdown.tsx +++ b/src/lib/Markdown/Markdown.tsx @@ -10,8 +10,8 @@ interface PropTypes { const resolveUrls = (line: string, baseUrl: string): string => { return line.replace(/src="(?!http)(.*)"[\s>]/, (match, url, offset, string) => `src="${baseUrl}/${url}?sanitize=true"`) - .replace(/\[(.*\]?.*)\]\((?!http)(.+?)\)/, (match, text, url, offset, string) => `[${text}](${baseUrl}/${url})`); -} + .replace(/\[(.*\]?.*)\]\((?!http)(.+?)\)/, (match, text, url, offset, string) => `[${text}](${baseUrl}/${url})`); +}; const Markdown: React.FC<PropTypes> = ({ data, url }) => { const [markdown, setMarkdown] = useState<string>(data || ''); @@ -24,7 +24,7 @@ const Markdown: React.FC<PropTypes> = ({ data, url }) => { const baseUrl = url?.slice(0, url.lastIndexOf('/')) || ''; const lines = markdown.split(/\r?\n/).map(line => resolveUrls(line, baseUrl)); - return <Section rawLines={lines} /> + return <Section rawLines={lines} />; }; diff --git a/src/lib/Markdown/Section.tsx b/src/lib/Markdown/Section.tsx index 1fcc46f..f554062 100644 --- a/src/lib/Markdown/Section.tsx +++ b/src/lib/Markdown/Section.tsx @@ -1,6 +1,6 @@ import React from 'react'; -import ContentSection from '../ContentSection/ContentSection'; import { Typography } from '@material-ui/core'; +import ContentSection from '../ContentSection/ContentSection'; import Content from './Content'; import { ParserPropTypes } from './types'; @@ -11,9 +11,9 @@ interface PropTypes extends ParserPropTypes { const getHeaderLevel = (header: string): number => { if (!header) return 0; let level = 0; - while(header[level] === '#') level++; + while (header[level] === '#') level++; return level; -} +}; const ChildrenSections: React.FC<PropTypes> = ({ rawLines, level = 0 }) => { const childrenSectionLines = rawLines.reduce((sections: string[][], line: string) => { @@ -23,20 +23,22 @@ const ChildrenSections: React.FC<PropTypes> = ({ rawLines, level = 0 }) => { } return sections; }, []); - const children = childrenSectionLines.map(sectionLines => <Section rawLines={sectionLines} level={level}/>); - return <> {children} </>; -} + const children = childrenSectionLines.map(sectionLines => <Section rawLines={sectionLines} level={level} />); + return <>{children}</>; +}; const Section: React.FC<PropTypes> = ({ rawLines, level = 0 }) => { const deeperLevelIndex = rawLines.findIndex(line => line.match(`^#{${level + 1},} .*$`)); const rawContent = rawLines.splice(0, (deeperLevelIndex < 0) ? rawLines.length : deeperLevelIndex); - if (!level) return ( - <> - <Typography> <Content rawLines={rawContent} /> </Typography> - <ChildrenSections rawLines={rawLines} level={getHeaderLevel(rawLines[0])}/> - </> - ) + if (!level) { + return ( + <> + <Typography><Content rawLines={rawContent} /></Typography> + <ChildrenSections rawLines={rawLines} level={getHeaderLevel(rawLines[0])} /> + </> + ); + } const sectionName = rawContent.splice(0, 1)[0].slice(level).trim(); const deeperLevel = getHeaderLevel(rawLines[0]); @@ -46,7 +48,7 @@ const Section: React.FC<PropTypes> = ({ rawLines, level = 0 }) => { <ChildrenSections rawLines={rawLines} level={deeperLevel} /> </ContentSection> ); -} +}; export default Section; diff --git a/src/lib/Markdown/SyntacticSpan.tsx b/src/lib/Markdown/SyntacticSpan.tsx index f3c2125..bdce3f7 100644 --- a/src/lib/Markdown/SyntacticSpan.tsx +++ b/src/lib/Markdown/SyntacticSpan.tsx @@ -19,24 +19,24 @@ interface Emoji { const enclosureRegex = (e: string): RegexPair => ({ local: new RegExp(`${e}([^${e}]+)${e}`), - global: new RegExp(`(${e}[^${e}]+${e})`) + global: new RegExp(`(${e}[^${e}]+${e})`), }); const regex: Record<string, RegexPair> = { conceal: { global: /(!?\[.+?\]\(.+?\))(?!])/g, - local: /!?\[(.*\]?.*)\]\((.+?)\)/ + local: /!?\[(.*\]?.*)\]\((.+?)\)/, }, rawLink: { global: /((?:(?:[A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www\.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)(?:(?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[.!/\\\w]*))?)/, - local: /&^/ + local: /&^/, }, emoji: enclosureRegex(':'), bold: enclosureRegex('\\*\\*'), italic: enclosureRegex('\\*'), code: enclosureRegex('`'), strikeThrough: enclosureRegex('~~'), -} +}; const splitter = new RegExp(Object.values(regex).map(pair => pair.global.source).join('|')); @@ -46,13 +46,13 @@ Object.keys(emojiLib).forEach(name => emojiList.push({ name, char: emojiLib[name const useStyles = makeStyles(theme => ({ code: { background: theme.palette.background.default, - borderRadius: theme.spacing(.5), - padding: theme.spacing(.5), + borderRadius: theme.spacing(0.5), + padding: theme.spacing(0.5), fontFamily: 'Monospace', }, image: { maxWidth: '100%', - maxHeight: '100%' + maxHeight: '100%', }, })); @@ -82,12 +82,12 @@ const SyntacticSpan: React.FC<PropTypes> = ({ span }) => { if (matchItalic) return <i>{matchItalic[1]}</i>; const matchStrikeThrough = span.match(regex.strikeThrough.local); - if (matchStrikeThrough) return <span style={{textDecoration: 'line-through' }}>{matchStrikeThrough[1]}</span>; + if (matchStrikeThrough) return <span style={{ textDecoration: 'line-through' }}>{matchStrikeThrough[1]}</span>; if (span.match(regex.rawLink.global)) return <Link href={span}>{span}</Link>; return <>{span}</>; -} +}; export { splitter }; diff --git a/src/lib/Markdown/Text.tsx b/src/lib/Markdown/Text.tsx index e287dee..be715fd 100644 --- a/src/lib/Markdown/Text.tsx +++ b/src/lib/Markdown/Text.tsx @@ -7,7 +7,7 @@ interface PropTypes { const Text: React.FC<PropTypes> = ({ line }) => { return <>{line.split(splitter).map(span => <SyntacticSpan span={span} />)}</>; -} +}; export default Text; diff --git a/src/lib/SmartList/SmartList.tsx b/src/lib/SmartList/SmartList.tsx index 22cd3b2..c86c127 100644 --- a/src/lib/SmartList/SmartList.tsx +++ b/src/lib/SmartList/SmartList.tsx @@ -21,8 +21,7 @@ interface Size { const SmartList: React.FC<PropTypes> = ({ itemSize, itemCount, renderItem }) => { - - const ResizedList: React.FC<Size> = ({ width, height}) => ( + const ResizedList: React.FC<Size> = ({ width, height }) => ( <FixedSizeList height={height} width={width} diff --git a/src/lib/Window/Window.tsx b/src/lib/Window/Window.tsx index 6821593..beaa672 100644 --- a/src/lib/Window/Window.tsx +++ b/src/lib/Window/Window.tsx @@ -47,12 +47,13 @@ const Window: React.FC<PropTypes> = ({ type, name, children }) => { size={size} position={position} > - {name && + {name + && ( <div> <Typography variant="h5" className={classes.header}>{name}</Typography> <Divider /> </div> - } + )} {children} </WindowSurface> ); diff --git a/src/lib/Window/WindowSurface.tsx b/src/lib/Window/WindowSurface.tsx index a65e398..1900901 100644 --- a/src/lib/Window/WindowSurface.tsx +++ b/src/lib/Window/WindowSurface.tsx @@ -22,7 +22,7 @@ const useStyles = makeStyles(theme => ({ '& a.MuiTypography-root': { color: theme.palette.primary.light, }, - } + }, })); @@ -32,12 +32,12 @@ const WindowSurface: React.FC<PropTypes> = ({ size, position, children }) => { return ( <Paper variant="outlined" - style={{...size, ...position}} + style={{ ...size, ...position }} className={classes.surface} > {children} </Paper> - ) + ); }; diff --git a/src/react-app-env.d.ts b/src/react-app-env.d.ts index 6431bc5..30da896 100644 --- a/src/react-app-env.d.ts +++ b/src/react-app-env.d.ts @@ -1 +1 @@ -/// <reference types="react-scripts" /> +// / <reference types="react-scripts" /> |