Prefer non-null assertions

Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
This commit is contained in:
Josh-Cena 2021-06-18 21:23:07 +08:00
parent 2dc74ddc3f
commit e7e9fa78e0
No known key found for this signature in database
GPG key ID: C37145B818BDB68F
7 changed files with 9 additions and 10 deletions

View file

@ -92,6 +92,7 @@ module.exports = {
'no-unused-vars': OFF, 'no-unused-vars': OFF,
'no-nested-ternary': WARNING, 'no-nested-ternary': WARNING,
'@typescript-eslint/no-empty-function': OFF, '@typescript-eslint/no-empty-function': OFF,
'@typescript-eslint/no-non-null-assertion': OFF, // Have to use type assertion anyways
'@typescript-eslint/no-unused-vars': [ERROR, {argsIgnorePattern: '^_'}], '@typescript-eslint/no-unused-vars': [ERROR, {argsIgnorePattern: '^_'}],
'@typescript-eslint/ban-ts-comment': [ '@typescript-eslint/ban-ts-comment': [
ERROR, ERROR,

View file

@ -32,7 +32,7 @@ import {LoadContext} from '@docusaurus/types';
import {validateBlogPostFrontMatter} from './blogFrontMatter'; import {validateBlogPostFrontMatter} from './blogFrontMatter';
export function truncate(fileString: string, truncateMarker: RegExp): string { export function truncate(fileString: string, truncateMarker: RegExp): string {
return fileString.split(truncateMarker, 1).shift() as string; return fileString.split(truncateMarker, 1).shift()!;
} }
export function getSourceToPermalink( export function getSourceToPermalink(

View file

@ -75,7 +75,7 @@ export type ActiveDocContext = {
}; };
export const getLatestVersion = (data: GlobalPluginData): Version => { export const getLatestVersion = (data: GlobalPluginData): Version => {
return data.versions.find((version) => version.isLast) as GlobalVersion; return data.versions.find((version) => version.isLast)!;
}; };
// Note: return undefined on doc-unrelated pages, // Note: return undefined on doc-unrelated pages,

View file

@ -253,9 +253,7 @@ export default function pluginContentDocs(
if (versionHomeDoc) { if (versionHomeDoc) {
return versionHomeDoc; return versionHomeDoc;
} else if (firstDocIdOfFirstSidebar) { } else if (firstDocIdOfFirstSidebar) {
return docs.find( return docs.find((doc) => doc.id === firstDocIdOfFirstSidebar)!;
(doc) => doc.id === firstDocIdOfFirstSidebar,
) as DocMetadata;
} else { } else {
return docs[0]; return docs[0];
} }

View file

@ -97,7 +97,7 @@ function parseBreadcrumb(
): {parents: string[]; tail: string} { ): {parents: string[]; tail: string} {
return { return {
parents: take(breadcrumb, breadcrumb.length - 1), parents: take(breadcrumb, breadcrumb.length - 1),
tail: last(breadcrumb) as string, tail: last(breadcrumb)!,
}; };
} }

View file

@ -35,7 +35,7 @@ function getNavbarTranslationFile(navbar: Navbar): TranslationFileContent {
) )
.keyBy((navbarItem) => `item.label.${navbarItem.label}`) .keyBy((navbarItem) => `item.label.${navbarItem.label}`)
.mapValues((navbarItem) => ({ .mapValues((navbarItem) => ({
message: navbarItem.label as string, message: navbarItem.label!,
description: `Navbar item with label ${navbarItem.label}`, description: `Navbar item with label ${navbarItem.label}`,
})) }))
.value(); .value();
@ -78,7 +78,7 @@ function getFooterTranslationFile(footer: Footer): TranslationFileContent {
) )
.keyBy((link) => `link.title.${link.title}`) .keyBy((link) => `link.title.${link.title}`)
.mapValues((link) => ({ .mapValues((link) => ({
message: link.title as string, message: link.title!,
description: `The title of the footer links column with title=${link.title} in the footer`, description: `The title of the footer links column with title=${link.title} in the footer`,
})) }))
.value(); .value();
@ -90,7 +90,7 @@ function getFooterTranslationFile(footer: Footer): TranslationFileContent {
) )
.keyBy((linkItem) => `link.item.label.${linkItem.label}`) .keyBy((linkItem) => `link.item.label.${linkItem.label}`)
.mapValues((linkItem) => ({ .mapValues((linkItem) => ({
message: linkItem.label as string, message: linkItem.label!,
description: `The label of footer link with label=${ description: `The label of footer link with label=${
linkItem.label linkItem.label
} linking to ${linkItem.to ?? linkItem.href}`, } linking to ${linkItem.to ?? linkItem.href}`,

View file

@ -309,7 +309,7 @@ ${Object.keys(registry)
const siteMetadata: DocusaurusSiteMetadata = { const siteMetadata: DocusaurusSiteMetadata = {
docusaurusVersion: getPackageJsonVersion( docusaurusVersion: getPackageJsonVersion(
join(__dirname, '../../package.json'), join(__dirname, '../../package.json'),
) as string, )!,
siteVersion: getPackageJsonVersion(join(siteDir, 'package.json')), siteVersion: getPackageJsonVersion(join(siteDir, 'package.json')),
pluginVersions: {}, pluginVersions: {},
}; };