Skip to content

chore(deps): update dependency prettier to v3 #2260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .prettierrc.cjs → .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
* @type {import('prettier').Options}
*/
module.exports = {
plugins: [require.resolve('prettier-plugin-organize-imports')],
plugins: ['prettier-plugin-organize-imports'],
singleQuote: true,
trailingComma: 'es5',
overrides: [
{
files: '*.json5',
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
"@algolia/client-search": "~4.19.1",
"@types/markdown-it": "~12.2.3",
"@types/node": "~20.4.1",
"@types/prettier": "~2.7.3",
"@types/react": "~18.2.17",
"@types/sanitize-html": "~2.9.0",
"@types/semver": "~7.5.0",
Expand All @@ -105,18 +104,18 @@
"cypress": "~12.17.0",
"esbuild": "~0.18.11",
"eslint": "~8.44.0",
"eslint-config-prettier": "~8.8.0",
"eslint-config-prettier": "~8.9.0",
"eslint-define-config": "~1.21.0",
"eslint-gitignore": "~0.1.0",
"eslint-plugin-deprecation": "~1.4.1",
"eslint-plugin-jsdoc": "~46.4.3",
"eslint-plugin-prettier": "~4.2.1",
"eslint-plugin-prettier": "~5.0.0",
"eslint-plugin-vitest": "~0.2.6",
"glob": "~10.3.3",
"npm-run-all": "~4.1.5",
"picocolors": "~1.0.0",
"prettier": "2.8.8",
"prettier-plugin-organize-imports": "~3.2.2",
"prettier": "3.0.0",
"prettier-plugin-organize-imports": "~3.2.3",
"react": "~18.2.0",
"react-dom": "~18.2.0",
"rimraf": "~5.0.1",
Expand Down
880 changes: 519 additions & 361 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

22 changes: 12 additions & 10 deletions scripts/apidoc/apiDocsWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ editLink: false
* @param deprecated The deprecation message.
* @param methods The methods of the module.
*/
export function writeApiDocsModule(
export async function writeApiDocsModule(
moduleName: string,
lowerModuleName: string,
comment: string,
deprecated: string | undefined,
methods: Method[]
): ModuleSummary {
writeApiDocsModulePage(
): Promise<ModuleSummary> {
await writeApiDocsModulePage(
moduleName,
lowerModuleName,
comment,
Expand Down Expand Up @@ -85,13 +85,13 @@ export function writeApiDocsModule(
* @param comment The module comments.
* @param methods The methods of the module.
*/
function writeApiDocsModulePage(
async function writeApiDocsModulePage(
moduleName: string,
lowerModuleName: string,
comment: string,
deprecated: string | undefined,
methods: Method[]
): void {
): Promise<void> {
// Write api docs page
let content = `
<script setup>
Expand Down Expand Up @@ -131,7 +131,7 @@ function writeApiDocsModulePage(
.join('')}
`.replace(/\n +/g, '\n');

content = vitePressInFileOptions + formatMarkdown(content);
content = vitePressInFileOptions + (await formatMarkdown(content));

writeFileSync(resolve(pathOutputDir, `${lowerModuleName}.md`), content);
}
Expand Down Expand Up @@ -164,7 +164,7 @@ function writeApiDocsModuleData(
*
* @param pages The pages to write into the index.
*/
export function writeApiPagesIndex(pages: Page[]): void {
export async function writeApiPagesIndex(pages: Page[]): Promise<void> {
// Write api-pages.ts
console.log('Updating api-pages.ts');
pages.splice(0, 0, { text: 'Overview', link: '/api/' });
Expand All @@ -174,7 +174,7 @@ export function writeApiPagesIndex(pages: Page[]): void {
export const apiPages = ${JSON.stringify(pages)};
`.replace(/\n +/, '\n');

apiPagesContent = formatTypescript(apiPagesContent);
apiPagesContent = await formatTypescript(apiPagesContent);

writeFileSync(pathDocsApiPages, apiPagesContent);
}
Expand Down Expand Up @@ -217,7 +217,9 @@ export function writeApiSearchIndex(pages: ModuleSummary[]): void {
*
* @param project The typedoc project.
*/
export function writeSourceBaseUrl(project: ProjectReflection): void {
export async function writeSourceBaseUrl(
project: ProjectReflection
): Promise<void> {
const baseUrl = extractSourceBaseUrl(
project.getChildrenByKind(ReflectionKind.Class)[0]
);
Expand All @@ -228,7 +230,7 @@ export function writeSourceBaseUrl(project: ProjectReflection): void {
export const sourceBaseUrl = '${baseUrl}';
`.replace(/\n +/, '\n');

content = formatTypescript(content);
content = await formatTypescript(content);

writeFileSync(resolve(pathOutputDir, 'source-base-url.ts'), content);
}
18 changes: 12 additions & 6 deletions scripts/apidoc/fakerClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { analyzeSignature } from './signature';
import { selectApiSignature } from './typedoc';
import type { ModuleSummary } from './utils';

export function processFakerClass(project: ProjectReflection): ModuleSummary {
export async function processFakerClass(
project: ProjectReflection
): Promise<ModuleSummary> {
const fakerClass = project
.getChildrenByKind(ReflectionKind.Class)
.filter((clazz) => clazz.name === 'Faker')[0];
Expand All @@ -19,27 +21,31 @@ export function processFakerClass(project: ProjectReflection): ModuleSummary {
return processClass(fakerClass);
}

function processClass(fakerClass: DeclarationReflection): ModuleSummary {
async function processClass(
fakerClass: DeclarationReflection
): Promise<ModuleSummary> {
console.log(`Processing Faker class`);
const { comment, deprecated } = analyzeModule(fakerClass);
const methods: Method[] = [];

console.debug(`- constructor`);
methods.push(processConstructor(fakerClass));
methods.push(await processConstructor(fakerClass));

methods.push(...processModuleMethods(fakerClass, 'faker.'));
methods.push(...(await processModuleMethods(fakerClass, 'faker.')));

return writeApiDocsModule('Faker', 'faker', comment, deprecated, methods);
}

function processConstructor(fakerClass: DeclarationReflection): Method {
async function processConstructor(
fakerClass: DeclarationReflection
): Promise<Method> {
const constructor = fakerClass.getChildrenByKind(
ReflectionKind.Constructor
)[0];

const signature = selectApiSignature(constructor);

const method = analyzeSignature(signature, '', 'new Faker');
const method = await analyzeSignature(signature, '', 'new Faker');

return {
...method,
Expand Down
10 changes: 5 additions & 5 deletions scripts/apidoc/fakerUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ import { processMethods } from './moduleMethods';
import { selectApiSignature } from './typedoc';
import type { ModuleSummary } from './utils';

export function processFakerUtilities(
export async function processFakerUtilities(
project: ProjectReflection
): ModuleSummary {
): Promise<ModuleSummary> {
const fakerUtilities = project
.getChildrenByKind(ReflectionKind.Function)
.filter((method) => !method.flags.isPrivate);

return processUtilities(fakerUtilities);
}

function processUtilities(
async function processUtilities(
fakerUtilities: DeclarationReflection[]
): ModuleSummary {
): Promise<ModuleSummary> {
console.log(`Processing Faker Utilities`);
const comment = 'A list of all the utilities available in Faker.js.';

const methods: Method[] = processMethods(
const methods: Method[] = await processMethods(
Object.fromEntries(
fakerUtilities.map((method) => [method.name, selectApiSignature(method)])
)
Expand Down
6 changes: 3 additions & 3 deletions scripts/apidoc/format.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { Options } from 'prettier';
import { format } from 'prettier';
import prettierConfig from '../../.prettierrc.cjs';
import prettierConfig from '../../.prettierrc.js';

/**
* Formats markdown contents.
*
* @param text The text to format.
*/
export function formatMarkdown(text: string): string {
export async function formatMarkdown(text: string): Promise<string> {
return format(text, prettierMarkdown);
}

Expand All @@ -16,7 +16,7 @@ export function formatMarkdown(text: string): string {
*
* @param text The text to format.
*/
export function formatTypescript(text: string): string {
export async function formatTypescript(text: string): Promise<string> {
return format(text, prettierTypescript);
}

Expand Down
12 changes: 7 additions & 5 deletions scripts/apidoc/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ export async function generate(): Promise<void> {
// Useful for manually analyzing the content
await app.generateJson(project, pathOutputJson);

const pages = [
const pages = await Promise.all([
processFakerClass(project),
...processModules(project).sort((a, b) => a.text.localeCompare(b.text)),
...(await processModules(project)).sort((a, b) =>
a.text.localeCompare(b.text)
),
processFakerUtilities(project),
];
writeApiPagesIndex(pages.map(({ text, link }) => ({ text, link })));
]);
await writeApiPagesIndex(pages.map(({ text, link }) => ({ text, link })));
writeApiDiffIndex(
pages.reduce((data, { text, diff }) => ({ ...data, [text]: diff }), {})
);
writeApiSearchIndex(pages);

writeSourceBaseUrl(project);
await writeSourceBaseUrl(project);
}
25 changes: 16 additions & 9 deletions scripts/apidoc/moduleMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import { adjustUrls } from './utils';
* @param project The project used to extract the modules.
* @returns The generated pages.
*/
export function processModules(project: ProjectReflection): ModuleSummary[] {
return selectApiModules(project).map(processModule);
export async function processModules(
project: ProjectReflection
): Promise<ModuleSummary[]> {
return Promise.all(selectApiModules(project).map(processModule));
}

/**
Expand All @@ -33,12 +35,17 @@ export function processModules(project: ProjectReflection): ModuleSummary[] {
* @param module The module to process.
* @returns The generated pages.
*/
function processModule(module: DeclarationReflection): ModuleSummary {
async function processModule(
module: DeclarationReflection
): Promise<ModuleSummary> {
const moduleName = extractModuleName(module);
console.log(`Processing Module ${moduleName}`);
const moduleFieldName = extractModuleFieldName(module);
const { comment, deprecated } = analyzeModule(module);
const methods = processModuleMethods(module, `faker.${moduleFieldName}.`);
const methods = await processModuleMethods(
module,
`faker.${moduleFieldName}.`
);

return writeApiDocsModule(
moduleName,
Expand Down Expand Up @@ -72,10 +79,10 @@ export function analyzeModule(module: DeclarationReflection): {
* @param accessor The code used to access the methods within the module.
* @returns A list containing the documentation for the api methods in the given module.
*/
export function processModuleMethods(
export async function processModuleMethods(
module: DeclarationReflection,
accessor: string
): Method[] {
): Promise<Method[]> {
return processMethods(selectApiMethodSignatures(module), accessor);
}

Expand All @@ -86,15 +93,15 @@ export function processModuleMethods(
* @param accessor The code used to access the methods.
* @returns A list containing the documentation for the api methods.
*/
export function processMethods(
export async function processMethods(
signatures: Record<string, SignatureReflection>,
accessor: string = ''
): Method[] {
): Promise<Method[]> {
const methods: Method[] = [];

for (const [methodName, signature] of Object.entries(signatures)) {
console.debug(`- ${methodName}`);
methods.push(analyzeSignature(signature, accessor, methodName));
methods.push(await analyzeSignature(signature, accessor, methodName));
}

return methods;
Expand Down
Loading