From 2c5fa193541eb8b74974731d01312f73951bca17 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 18 Apr 2020 20:26:32 +0300 Subject: style: correct some errors with eslint --fix --- src/lib/Markdown/CodeBlock.tsx | 6 +++--- src/lib/Markdown/Content.tsx | 27 ++++++++++++++------------- src/lib/Markdown/Markdown.tsx | 6 +++--- src/lib/Markdown/Section.tsx | 28 +++++++++++++++------------- src/lib/Markdown/SyntacticSpan.tsx | 18 +++++++++--------- src/lib/Markdown/Text.tsx | 2 +- 6 files changed, 45 insertions(+), 42 deletions(-) (limited to 'src/lib/Markdown') 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 = ({ rawLines }) => { {rawLines.map(line =>
{line}
)} ); -} +}; 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(``); 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 = ({ rawLines }) => { if (!rawLines.length) return null; @@ -41,7 +42,7 @@ const Content: React.FC = ({ rawLines }) => { if (denotesCodeBlock(line)) { const closeIndex = rawLines.findIndex(line => denotesCodeBlock(line)); const codeBlockLines = rawLines.splice(0, closeIndex + 1).slice(0, closeIndex); - buffer = + buffer = ; } 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 = ({ rawLines }) => { const closeIndex = denotesClosingHtml(line, tag) ? -1 : rawLines.findIndex(line => denotesClosingHtml(line, tag)); const htmlLines = rawLines.splice(0, closeIndex + 1); htmlLines.unshift(line); - buffer =
; + buffer =
; } else if ((buffer = denotesSelfClosingHtml(line)) !== null) { const match = buffer[0]; const [before, after] = line.split(match); buffer = ( <> -
+
); @@ -72,7 +73,7 @@ const Content: React.FC = ({ rawLines }) => { } else if (denotesClosingHtml(line, '')) { buffer = null; } else { - buffer =

+ buffer =

; } return ( @@ -81,7 +82,7 @@ const Content: React.FC = ({ 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 = ({ data, url }) => { const [markdown, setMarkdown] = useState(data || ''); @@ -24,7 +24,7 @@ const Markdown: React.FC = ({ data, url }) => { const baseUrl = url?.slice(0, url.lastIndexOf('/')) || ''; const lines = markdown.split(/\r?\n/).map(line => resolveUrls(line, baseUrl)); - return
+ return
; }; 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 = ({ rawLines, level = 0 }) => { const childrenSectionLines = rawLines.reduce((sections: string[][], line: string) => { @@ -23,20 +23,22 @@ const ChildrenSections: React.FC = ({ rawLines, level = 0 }) => { } return sections; }, []); - const children = childrenSectionLines.map(sectionLines =>
); - return <> {children} ; -} + const children = childrenSectionLines.map(sectionLines =>
); + return <>{children}; +}; const Section: React.FC = ({ 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 ( - <> - - - - ) + if (!level) { + return ( + <> + + + + ); + } const sectionName = rawContent.splice(0, 1)[0].slice(level).trim(); const deeperLevel = getHeaderLevel(rawLines[0]); @@ -46,7 +48,7 @@ const Section: React.FC = ({ rawLines, level = 0 }) => { ); -} +}; 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 = { 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 = ({ span }) => { if (matchItalic) return {matchItalic[1]}; const matchStrikeThrough = span.match(regex.strikeThrough.local); - if (matchStrikeThrough) return {matchStrikeThrough[1]}; + if (matchStrikeThrough) return {matchStrikeThrough[1]}; if (span.match(regex.rawLink.global)) return {span}; 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 = ({ line }) => { return <>{line.split(splitter).map(span => )}; -} +}; export default Text; -- cgit v1.2.3 From 9272b0af3d7b2fba4738a341a1f2776243e0e515 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 18 Apr 2020 20:44:55 +0300 Subject: style: manually fix some errors --- src/lib/Markdown/Content.tsx | 12 +++++++----- src/lib/Markdown/Markdown.tsx | 11 +++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) (limited to 'src/lib/Markdown') diff --git a/src/lib/Markdown/Content.tsx b/src/lib/Markdown/Content.tsx index d64720b..88409fa 100644 --- a/src/lib/Markdown/Content.tsx +++ b/src/lib/Markdown/Content.tsx @@ -40,17 +40,19 @@ const Content: React.FC = ({ rawLines }) => { let buffer; if (denotesCodeBlock(line)) { - const closeIndex = rawLines.findIndex(line => denotesCodeBlock(line)); + const closeIndex = rawLines.findIndex(rawLine => denotesCodeBlock(rawLine)); const codeBlockLines = rawLines.splice(0, closeIndex + 1).slice(0, closeIndex); buffer = ; } else if (denotesDottedList(line)) { - const closeIndex = rawLines.findIndex(line => !denotesDottedList(line)); + const closeIndex = rawLines.findIndex(rawLine => !denotesDottedList(rawLine)); const dottedListLines = rawLines.splice(0, closeIndex).slice(0, closeIndex); dottedListLines.unshift(line); buffer =
    {dottedListLines.map(li =>
  • )}
; } else if ((buffer = denotesOpenHtml(line))) { const tag = buffer; - const closeIndex = denotesClosingHtml(line, tag) ? -1 : rawLines.findIndex(line => denotesClosingHtml(line, tag)); + const closeIndex = denotesClosingHtml(line, tag) ? -1 : rawLines.findIndex( + rawLine => denotesClosingHtml(rawLine, tag), + ); const htmlLines = rawLines.splice(0, closeIndex + 1); htmlLines.unshift(line); buffer =
; @@ -65,8 +67,8 @@ const Content: React.FC = ({ rawLines }) => { ); } else if (declaresNoLineBreak(line)) { - const closeIndex = rawLines.findIndex(line => !declaresNoLineBreak(line)); - const lineBreakLines = rawLines.splice(0, closeIndex).map(line => line.slice(0, -2)); + const closeIndex = rawLines.findIndex(rawLine => !declaresNoLineBreak(rawLine)); + const lineBreakLines = rawLines.splice(0, closeIndex).map(rawLine => rawLine.slice(0, -2)); lineBreakLines.unshift(line.slice(0, -2)); lineBreakLines.push(rawLines.splice(0, 1)[0]); buffer =

{lineBreakLines.map(lineBreakLine => )}

; diff --git a/src/lib/Markdown/Markdown.tsx b/src/lib/Markdown/Markdown.tsx index 68967c5..cfcf117 100644 --- a/src/lib/Markdown/Markdown.tsx +++ b/src/lib/Markdown/Markdown.tsx @@ -8,10 +8,13 @@ interface PropTypes { url?: string; } -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})`); -}; +const resolveUrls = (line: string, baseUrl: string): string => line.replace( + /src="(?!http)(.*)"[\s>]/, + (match, url) => `src="${baseUrl}/${url}?sanitize=true"`, +).replace( + /\[(.*\]?.*)\]\((?!http)(.+?)\)/, + (match, text, url) => `[${text}](${baseUrl}/${url})`, +); const Markdown: React.FC = ({ data, url }) => { const [markdown, setMarkdown] = useState(data || ''); -- cgit v1.2.3 From 8e4a483fb7d1ebdfc950c1cc456ae2d4bd558147 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 18 Apr 2020 20:52:31 +0300 Subject: style: fix remaining errors --- src/lib/Markdown/Section.tsx | 2 +- src/lib/Markdown/SyntacticSpan.tsx | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src/lib/Markdown') diff --git a/src/lib/Markdown/Section.tsx b/src/lib/Markdown/Section.tsx index f554062..fc208b1 100644 --- a/src/lib/Markdown/Section.tsx +++ b/src/lib/Markdown/Section.tsx @@ -11,7 +11,7 @@ interface PropTypes extends ParserPropTypes { const getHeaderLevel = (header: string): number => { if (!header) return 0; let level = 0; - while (header[level] === '#') level++; + while (header[level] === '#') level += 1; return level; }; diff --git a/src/lib/Markdown/SyntacticSpan.tsx b/src/lib/Markdown/SyntacticSpan.tsx index bdce3f7..11cc024 100644 --- a/src/lib/Markdown/SyntacticSpan.tsx +++ b/src/lib/Markdown/SyntacticSpan.tsx @@ -28,6 +28,7 @@ const regex: Record = { local: /!?\[(.*\]?.*)\]\((.+?)\)/, }, rawLink: { + // eslint-disable-next-line max-len global: /((?:(?:[A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www\.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)(?:(?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[.!/\\\w]*))?)/, local: /&^/, }, @@ -68,7 +69,7 @@ const SyntacticSpan: React.FC = ({ span }) => { const matchEmoji = span.match(regex.emoji.local); if (matchEmoji) { - const emoji = emojiList.find(emoji => emoji.name === matchEmoji[1]); + const emoji = emojiList.find(e => e.name === matchEmoji[1]); return {emoji ? emoji.char : span}; } -- cgit v1.2.3