Skip to content

Commit

Permalink
chore: upgrade Prettier + regenerate lock file (#5611)
Browse files Browse the repository at this point in the history
* Bump deps

* Run prettier

* Format docs

* Minor refactor

* Collapse objects

* Fix type

* Update lock file
  • Loading branch information
Josh-Cena authored Sep 30, 2021
1 parent 4dbc458 commit 3f1f825
Show file tree
Hide file tree
Showing 70 changed files with 1,534 additions and 1,517 deletions.
5 changes: 3 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ coverage
packages/docusaurus/lib/
packages/docusaurus-*/lib/*
packages/docusaurus-*/lib-next/
packages/docusaurus-init/templates/*/docusaurus.config.js
__fixtures__

website/i18n
website/versions.json
website/docusaurus.config.js

examples/**/package.json
examples/**/sandbox.config.json
examples/
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"arrowParens": "always",
"bracketSpacing": false,
"jsxBracketSameLine": true,
"bracketSameLine": true,
"printWidth": 80,
"proseWrap": "never",
"singleQuote": true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"netlify-cli": "^2.58.0",
"nodemon": "^2.0.13",
"npm-run-all": "^4.1.5",
"prettier": "^2.2.1",
"prettier": "^2.4.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"rimraf": "^3.0.2",
Expand Down
3 changes: 0 additions & 3 deletions packages/docusaurus-init/bin/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#!/usr/bin/env node

// TODO remove when fixed: https://github.com/Stuk/eslint-plugin-header/issues/39
/* eslint-disable header/header */
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ interface PluginOptions {

const createJSX = (node: Image, pathUrl: string) => {
const jsxNode = node;
((jsxNode as unknown) as Literal).type = 'jsx';
((jsxNode as unknown) as Literal).value = `<img ${
(jsxNode as unknown as Literal).type = 'jsx';
(jsxNode as unknown as Literal).value = `<img ${
node.alt ? `alt={"${escapeHtml(node.alt)}"} ` : ''
}${
node.url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ function toAssetRequireNode({
const children = stringifyContent(node);
const title = node.title ? `title="${escapeHtml(node.title)}"` : '';

((node as unknown) as Literal).type = 'jsx';
((node as unknown) as Literal).value = `<a target="_blank" href={${href}}${title}>${children}</a>`;
(node as unknown as Literal).type = 'jsx';
(
node as unknown as Literal
).value = `<a target="_blank" href={${href}}${title}>${children}</a>`;
}

// If the link looks like an asset link, we'll link to the asset,
Expand Down
3 changes: 0 additions & 3 deletions packages/docusaurus-migrate/bin/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#!/usr/bin/env node

// TODO remove when fixed: https://github.com/Stuk/eslint-plugin-header/issues/39
/* eslint-disable header/header */
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
Expand Down
6 changes: 3 additions & 3 deletions packages/docusaurus-migrate/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,9 @@ function migrateVersionedSidebar(
acc: {[key: string]: Array<Record<string, unknown> | string>},
val,
) => {
acc[
val[0].replace(versionRegex, '')
] = (val[1] as Array<SidebarEntry>).map((item) => {
acc[val[0].replace(versionRegex, '')] = (
val[1] as Array<SidebarEntry>
).map((item) => {
if (typeof item === 'string') {
return item.replace(versionRegex, '');
}
Expand Down
25 changes: 15 additions & 10 deletions packages/docusaurus-module-type-aliases/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,21 @@ declare module '@docusaurus/Head' {
}

declare module '@docusaurus/Link' {
import type {CSSProperties, ComponentProps} from 'react';

type NavLinkProps = Partial<import('react-router-dom').NavLinkProps>;
export type LinkProps = NavLinkProps & {
readonly isNavLink?: boolean;
readonly to?: string;
readonly href?: string;
readonly autoAddBaseUrl?: boolean;

// escape hatch in case broken links check is annoying for a specific link
readonly 'data-noBrokenLinkCheck'?: boolean;
};
export type LinkProps = NavLinkProps &
ComponentProps<'a'> & {
readonly className?: string;
readonly style?: CSSProperties;
readonly isNavLink?: boolean;
readonly to?: string;
readonly href?: string;
readonly autoAddBaseUrl?: boolean;

// escape hatch in case broken links check is annoying for a specific link
readonly 'data-noBrokenLinkCheck'?: boolean;
};
const Link: (props: LinkProps) => JSX.Element;
export default Link;
}
Expand All @@ -110,7 +115,7 @@ declare module '@docusaurus/Interpolate' {

export type InterpolateValues<
Str extends string,
Value extends ReactNode
Value extends ReactNode,
> = Record<ExtractInterpolatePlaceholders<Str>, Value>;

// TS function overload: if all the values are plain strings, then interpolate returns a simple string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ describe('collectRedirects', () => {
{
createRedirects: (routePath) => {
if (routePath === '/') {
return ([[`/fromPath`]] as unknown) as string;
return [[`/fromPath`]] as unknown as string;
}
return undefined;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,23 @@ describe('normalizePluginOptions', () => {
test('should reject bad fromExtensions user inputs', () => {
expect(() =>
normalizePluginOptions({
fromExtensions: ([null, undefined, 123, true] as unknown) as string[],
fromExtensions: [null, undefined, 123, true] as unknown as string[],
}),
).toThrowErrorMatchingSnapshot();
});

test('should reject bad toExtensions user inputs', () => {
expect(() =>
normalizePluginOptions({
toExtensions: ([null, undefined, 123, true] as unknown) as string[],
toExtensions: [null, undefined, 123, true] as unknown as string[],
}),
).toThrowErrorMatchingSnapshot();
});

test('should reject bad createRedirects user inputs', () => {
expect(() =>
normalizePluginOptions({
createRedirects: ([
'bad',
'value',
] as unknown) as CreateRedirectsFnOption,
createRedirects: ['bad', 'value'] as unknown as CreateRedirectsFnOption,
}),
).toThrowErrorMatchingSnapshot();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ describe('validateRedirect', () => {

expect(() =>
validateRedirect({
from: (null as unknown) as string,
from: null as unknown as string,
to: '/toSomePath?queryString=xyz',
}),
).toThrowErrorMatchingSnapshot();

expect(() =>
validateRedirect({
from: (['heyho'] as unknown) as string,
from: ['heyho'] as unknown as string,
to: '/toSomePath?queryString=xyz',
}),
).toThrowErrorMatchingSnapshot();
Expand Down
11 changes: 4 additions & 7 deletions packages/docusaurus-plugin-content-blog/src/blogUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export function getBlogTags(blogPosts: BlogPost[]): BlogTags {
});
}

const DATE_FILENAME_REGEX = /^(?<date>\d{4}[-/]\d{1,2}[-/]\d{1,2})[-/]?(?<text>.*?)(\/index)?.mdx?$/;
const DATE_FILENAME_REGEX =
/^(?<date>\d{4}[-/]\d{1,2}[-/]\d{1,2})[-/]?(?<text>.*?)(\/index)?.mdx?$/;

type ParsedBlogFileName = {
date: Date | undefined;
Expand Down Expand Up @@ -199,12 +200,8 @@ async function processBlogSourceFile(

const blogSourceAbsolute = path.join(blogDirPath, blogSourceRelative);

const {
frontMatter,
content,
contentTitle,
excerpt,
} = await parseBlogPostMarkdownFile(blogSourceAbsolute);
const {frontMatter, content, contentTitle, excerpt} =
await parseBlogPostMarkdownFile(blogSourceAbsolute);

const aliasedSource = aliasedSitePath(blogSourceAbsolute, siteDir);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,12 +563,8 @@ describe('versioned site', () => {
options,
});
expect(versionsMetadata.length).toEqual(4);
const [
currentVersion,
version101,
version100,
versionWithSlugs,
] = versionsMetadata;
const [currentVersion, version101, version100, versionWithSlugs] =
versionsMetadata;

const currentVersionTestUtils = createTestUtils({
siteDir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,12 +575,8 @@ describe('versioned website', () => {
const {siteDir, plugin, pluginContentDir} = await loadSite();
const content = await plugin.loadContent!();
expect(content.loadedVersions.length).toEqual(4);
const [
currentVersion,
version101,
version100,
versionWithSlugs,
] = content.loadedVersions;
const [currentVersion, version101, version100, versionWithSlugs] =
content.loadedVersions;

// foo/baz.md only exists in version -1.0.0
expect(findDocById(currentVersion, 'foo/baz')).toBeUndefined();
Expand Down Expand Up @@ -751,13 +747,8 @@ describe('versioned website (community)', () => {
}

test('extendCli - docsVersion', async () => {
const {
siteDir,
routeBasePath,
sidebarPath,
pluginId,
plugin,
} = await loadSite();
const {siteDir, routeBasePath, sidebarPath, pluginId, plugin} =
await loadSite();
const mock = jest
.spyOn(cliDocs, 'cliDocsVersionCommand')
.mockImplementation();
Expand Down Expand Up @@ -1784,12 +1775,11 @@ describe('site with custom sidebar items generator', () => {
});

test('sidebar is autogenerated according to a custom sidebarItemsGenerator', async () => {
const customSidebarItemsGenerator: SidebarItemsGeneratorOption = async () => {
return [
const customSidebarItemsGenerator: SidebarItemsGeneratorOption =
async () => [
{type: 'doc', id: 'API/api-overview'},
{type: 'doc', id: 'API/api-end'},
];
};

const {content} = await loadSite(customSidebarItemsGenerator);
const version = content.loadedVersions[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,11 +646,8 @@ describe('createSidebarsUtils', () => {

const sidebars: Sidebars = {sidebar1, sidebar2};

const {
getFirstDocIdOfFirstSidebar,
getSidebarNameByDocId,
getDocNavigation,
} = createSidebarsUtils(sidebars);
const {getFirstDocIdOfFirstSidebar, getSidebarNameByDocId, getDocNavigation} =
createSidebarsUtils(sidebars);

test('getSidebarNameByDocId', async () => {
expect(getFirstDocIdOfFirstSidebar()).toEqual('doc1');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,8 @@ describe('versioned site, pluginId=default', () => {
}

test('readVersionsMetadata versioned site', async () => {
const {
defaultOptions,
defaultContext,
vCurrent,
v101,
v100,
vwithSlugs,
} = await loadSite();
const {defaultOptions, defaultContext, vCurrent, v101, v100, vwithSlugs} =
await loadSite();

const versionsMetadata = readVersionsMetadata({
options: defaultOptions,
Expand All @@ -342,13 +336,8 @@ describe('versioned site, pluginId=default', () => {
});

test('readVersionsMetadata versioned site with includeCurrentVersion=false', async () => {
const {
defaultOptions,
defaultContext,
v101,
v100,
vwithSlugs,
} = await loadSite();
const {defaultOptions, defaultContext, v101, v100, vwithSlugs} =
await loadSite();

const versionsMetadata = readVersionsMetadata({
options: {...defaultOptions, includeCurrentVersion: false},
Expand All @@ -364,14 +353,8 @@ describe('versioned site, pluginId=default', () => {
});

test('readVersionsMetadata versioned site with version options', async () => {
const {
defaultOptions,
defaultContext,
vCurrent,
v101,
v100,
vwithSlugs,
} = await loadSite();
const {defaultOptions, defaultContext, vCurrent, v101, v100, vwithSlugs} =
await loadSite();

const versionsMetadata = readVersionsMetadata({
options: {
Expand Down Expand Up @@ -424,14 +407,8 @@ describe('versioned site, pluginId=default', () => {
});

test('readVersionsMetadata versioned site with editUrl', async () => {
const {
defaultOptions,
defaultContext,
vCurrent,
v101,
v100,
vwithSlugs,
} = await loadSite();
const {defaultOptions, defaultContext, vCurrent, v101, v100, vwithSlugs} =
await loadSite();

const versionsMetadata = readVersionsMetadata({
options: {
Expand Down Expand Up @@ -474,14 +451,8 @@ describe('versioned site, pluginId=default', () => {
});

test('readVersionsMetadata versioned site with editUrl and editCurrentVersion=true', async () => {
const {
defaultOptions,
defaultContext,
vCurrent,
v101,
v100,
vwithSlugs,
} = await loadSite();
const {defaultOptions, defaultContext, vCurrent, v101, v100, vwithSlugs} =
await loadSite();

const versionsMetadata = readVersionsMetadata({
options: {
Expand Down
10 changes: 4 additions & 6 deletions packages/docusaurus-plugin-content-docs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,8 @@ export default function pluginContentDocs(

// Add sidebar/next/previous to the docs
function addNavData(doc: DocMetadataBase): DocMetadata {
const {
sidebarName,
previousId,
nextId,
} = sidebarsUtils.getDocNavigation(doc.id);
const {sidebarName, previousId, nextId} =
sidebarsUtils.getDocNavigation(doc.id);
const toDocNavLink = (navDocId: string): DocNavLink => {
const {title, permalink, frontMatter} = docsBaseById[navDocId];
return {
Expand Down Expand Up @@ -239,7 +236,8 @@ export default function pluginContentDocs(
(doc) =>
doc.unversionedId === options.homePageId || doc.slug === '/',
);
const firstDocIdOfFirstSidebar = sidebarsUtils.getFirstDocIdOfFirstSidebar();
const firstDocIdOfFirstSidebar =
sidebarsUtils.getFirstDocIdOfFirstSidebar();
if (versionHomeDoc) {
return versionHomeDoc;
} else if (firstDocIdOfFirstSidebar) {
Expand Down
Loading

0 comments on commit 3f1f825

Please sign in to comment.