mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-10 23:02:56 +02:00
refactor: reduce ESLint warnings / better typing (#5242)
* Fix code block children type Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Add return type Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Add types Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Fix return types Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Fix details type Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Fix type Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
This commit is contained in:
parent
a59378ba87
commit
9e615eff02
9 changed files with 38 additions and 21 deletions
|
@ -62,7 +62,7 @@ const getHighlightDirectiveRegex = (
|
|||
return new RegExp(`^\\s*(?:${commentPattern})\\s*$`);
|
||||
};
|
||||
// select comment styles based on language
|
||||
const highlightDirectiveRegex = (lang) => {
|
||||
const highlightDirectiveRegex = (lang: string) => {
|
||||
switch (lang) {
|
||||
case 'js':
|
||||
case 'javascript':
|
||||
|
@ -119,11 +119,12 @@ export default function CodeBlock({
|
|||
const prismTheme = usePrismTheme();
|
||||
|
||||
// In case interleaved Markdown (e.g. when using CodeBlock as standalone component).
|
||||
const content = Array.isArray(children) ? children.join('') : children;
|
||||
const content = Array.isArray(children)
|
||||
? children.join('')
|
||||
: (children as string);
|
||||
|
||||
if (metastring && highlightLinesRangeRegex.test(metastring)) {
|
||||
// Tested above
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const highlightLinesRange = metastring.match(highlightLinesRangeRegex)![1];
|
||||
highlightLines = rangeParser(highlightLinesRange).filter((n) => n > 0);
|
||||
}
|
||||
|
@ -145,7 +146,7 @@ export default function CodeBlock({
|
|||
const directiveRegex = highlightDirectiveRegex(language);
|
||||
// go through line by line
|
||||
const lines = content.replace(/\n$/, '').split('\n');
|
||||
let blockStart;
|
||||
let blockStart: number;
|
||||
// loop through lines
|
||||
for (let index = 0; index < lines.length; ) {
|
||||
const line = lines[index];
|
||||
|
@ -169,7 +170,7 @@ export default function CodeBlock({
|
|||
break;
|
||||
|
||||
case 'highlight-end':
|
||||
range += `${blockStart}-${lineNumber - 1},`;
|
||||
range += `${blockStart!}-${lineNumber - 1},`;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue