chore: clean up ESLint config, enable a few rules (#6514)

* chore: clean up ESLint config, enable a few rules

* enable max-len for comments

* fix build
This commit is contained in:
Joshua Chen 2022-01-31 10:31:24 +08:00 committed by GitHub
parent b8ccb869f1
commit aa446b7a9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
167 changed files with 1157 additions and 960 deletions

View file

@ -7,11 +7,6 @@
import Joi from './Joi';
// Enhance the default Joi.string() type so that it can convert number to strings
// If user use front matter "tag: 2021", we shouldn't need to ask the user to write "tag: '2021'"
// Also yaml tries to convert patterns like "2019-01-01" to dates automatically
// see https://github.com/facebook/docusaurus/issues/4642
// see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
const JoiFrontMatterString: Joi.Extension = {
type: 'string',
base: Joi.string(),
@ -23,4 +18,12 @@ const JoiFrontMatterString: Joi.Extension = {
return {value};
},
};
/**
* Enhance the default Joi.string() type so that it can convert number to
* strings. If user use front matter "tag: 2021", we shouldn't need to ask her
* to write "tag: '2021'". Also yaml tries to convert patterns like "2019-01-01"
* to dates automatically.
* @see https://github.com/facebook/docusaurus/issues/4642
* @see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
*/
export const JoiFrontMatter: typeof Joi = Joi.extend(JoiFrontMatterString);

View file

@ -43,13 +43,9 @@ function testMarkdownPluginSchemas(schema: Joi.Schema) {
});
testOK(undefined);
testOK([function () {}]);
testOK([[function () {}, {attr: 'val'}]]);
testOK([
[function () {}, {attr: 'val'}],
function () {},
[function () {}, {attr: 'val'}],
]);
testOK([() => {}]);
testOK([[() => {}, {attr: 'val'}]]);
testOK([[() => {}, {attr: 'val'}], () => {}, [() => {}, {attr: 'val'}]]);
testFail(null);
testFail(false);
@ -58,8 +54,8 @@ function testMarkdownPluginSchemas(schema: Joi.Schema) {
testFail([false]);
testFail([3]);
testFail([[]]);
testFail([[function () {}, undefined]]);
testFail([[function () {}, true]]);
testFail([[() => {}, undefined]]);
testFail([[() => {}, true]]);
}
describe('validation schemas', () => {

View file

@ -48,7 +48,8 @@ describe('validateFrontMatter', () => {
});
// Fix Yaml trying to convert strings to numbers automatically
// We only want to deal with a single type in the final front matter (not string | number)
// We only want to deal with a single type in the final front matter
// (not string | number)
test('should convert number values to string when string schema', () => {
const schema = Joi.object<{test: string}>({
test: JoiFrontMatter.string(),
@ -60,7 +61,8 @@ describe('validateFrontMatter', () => {
});
// Helps to fix Yaml trying to convert strings to dates automatically
// We only want to deal with a single type in the final front matter (not string | Date)
// We only want to deal with a single type in the final front matter
// (not string | Date)
test('should convert date values when string schema', () => {
const schema = Joi.object<{test: string}>({
test: JoiFrontMatter.string(),

View file

@ -31,7 +31,8 @@ export const AdmonitionsSchema = Joi.object().default({});
// Joi is such a pain, good luck to annoying trying to improve this
export const URISchema = Joi.alternatives(
Joi.string().uri({allowRelative: true}),
// This custom validation logic is required notably because Joi does not accept paths like /a/b/c ...
// This custom validation logic is required notably because Joi does not
// accept paths like /a/b/c ...
Joi.custom((val, helpers) => {
try {
// eslint-disable-next-line no-new

View file

@ -58,12 +58,11 @@ export function normalizePluginOptions<T extends {id?: string}>(
if (isValidationDisabledEscapeHatch) {
logger.error(error);
return options as T;
} else {
throw error;
}
throw error;
}
return value!; // TODO remove ! this in TS 4.6, see https://twitter.com/sebastienlorber/status/1481950042277793793
return value!; // TODO remove this ! in TS 4.6, see https://twitter.com/sebastienlorber/status/1481950042277793793
}
export function normalizeThemeConfig<T>(
@ -86,11 +85,10 @@ export function normalizeThemeConfig<T>(
if (isValidationDisabledEscapeHatch) {
logger.error(error);
return themeConfig as T;
} else {
throw error;
}
throw error;
}
return value!; // TODO remove ! this in TS 4.6, see https://twitter.com/sebastienlorber/status/1481950042277793793
return value!; // TODO remove this ! in TS 4.6
}
export function validateFrontMatter<T>(
@ -120,5 +118,5 @@ ${errorDetails.map(({message}) => message)}
throw error;
}
return value!; // TODO remove ! this in TS 4.6, see https://twitter.com/sebastienlorber/status/1481950042277793793
return value!; // TODO remove this ! in TS 4.6
}