refactor: fix a lot of errors in type-aware linting (#7477)

This commit is contained in:
Joshua Chen 2022-05-24 15:40:26 +08:00 committed by GitHub
parent 222bf3c091
commit bf1513a3e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
120 changed files with 407 additions and 364 deletions

View file

@ -89,6 +89,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => {
},
readingTime: ({content, defaultReadingTime}) =>
defaultReadingTime({content}),
truncateMarker: /<!--\s*truncate\s*-->/,
} as PluginOptions,
);
@ -128,6 +129,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => {
},
readingTime: ({content, defaultReadingTime}) =>
defaultReadingTime({content}),
truncateMarker: /<!--\s*truncate\s*-->/,
} as PluginOptions,
);

View file

@ -76,7 +76,7 @@ const getPlugin = async (
editUrl: BaseEditUrl,
...pluginOptions,
},
}) as PluginOptions,
}),
);
};

View file

@ -74,7 +74,7 @@ function getSampleTranslationFilesTranslated() {
}
describe('getContentTranslationFiles', () => {
it('returns translation files matching snapshot', async () => {
it('returns translation files matching snapshot', () => {
expect(getSampleTranslationFiles()).toMatchSnapshot();
});
});

View file

@ -44,7 +44,11 @@ const AuthorsMapSchema = Joi.object<AuthorsMap>()
});
export function validateAuthorsMap(content: unknown): AuthorsMap {
return Joi.attempt(content, AuthorsMapSchema);
const {error, value} = AuthorsMapSchema.validate(content);
if (error) {
throw error;
}
return value;
}
export async function getAuthorsMap(params: {

View file

@ -264,7 +264,7 @@ async function processBlogSourceFile(
const title = frontMatter.title ?? contentTitle ?? parsedBlogFileName.text;
const description = frontMatter.description ?? excerpt ?? '';
const slug = frontMatter.slug || parsedBlogFileName.slug;
const slug = frontMatter.slug ?? parsedBlogFileName.slug;
const permalink = normalizeUrl([baseUrl, routeBasePath, slug]);
@ -323,7 +323,7 @@ async function processBlogSourceFile(
defaultReadingTime,
})
: undefined,
truncated: truncateMarker?.test(content) || false,
truncated: truncateMarker.test(content),
authors,
frontMatter,
},

View file

@ -176,10 +176,6 @@ export default async function pluginContentBlog(
},
async contentLoaded({content: blogContents, actions}) {
if (!blogContents) {
return;
}
const {
blogListComponent,
blogPostComponent,
@ -500,11 +496,7 @@ export default async function pluginContentBlog(
},
injectHtmlTags({content}) {
if (!content.blogPosts.length) {
return {};
}
if (!options.feedOptions?.type) {
if (!content.blogPosts.length || !options.feedOptions.type) {
return {};
}

View file

@ -34,5 +34,5 @@ export default function markdownLoader(
finalContent = truncate(finalContent, markdownLoaderOptions.truncateMarker);
}
return callback?.(null, finalContent);
return callback(null, finalContent);
}

View file

@ -136,9 +136,6 @@ export function validateOptions({
validate,
options,
}: OptionValidationContext<Options, PluginOptions>): PluginOptions {
const validatedOptions = validate(
PluginOptionSchema,
options,
) as PluginOptions;
const validatedOptions = validate(PluginOptionSchema, options);
return validatedOptions;
}