Skip to content

Commit

Permalink
See #246. Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavin001 committed Mar 29, 2020
1 parent 6f9becd commit 7c01f5b
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 40 deletions.
110 changes: 75 additions & 35 deletions scripts/generate-docs/BeautifierDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,24 @@ export default class BeautifierDoc extends Doc {
) as any[];
}

private appendTroubleshootingSection(builder: MarkdownBuilder): MarkdownBuilder {
private appendTroubleshootingSection(
builder: MarkdownBuilder
): MarkdownBuilder {
if (this.executables.length === 0) {
return builder;
}
new ExecutableDoc(this.executables[0], this.beautifier, this.languages)
.appendTroubleshootingSection(builder);
new ExecutableDoc(
this.executables[0],
this.beautifier,
this.languages
).appendTroubleshootingSection(builder);
return builder;
}

private appendExecutableSection(executable: ExecutableDependencyDefinition, builder: MarkdownBuilder): MarkdownBuilder {
private appendExecutableSection(
executable: ExecutableDependencyDefinition,
builder: MarkdownBuilder
): MarkdownBuilder {
const { installationUrl, bugsUrl } = executable;
const dependency = executable;
const beautifierName: string = this.beautifier.name;
Expand Down Expand Up @@ -217,7 +225,9 @@ export default class BeautifierDoc extends Doc {
`A \`.unibeautifyrc.json\` file would look like the following:`
);
const hasOnly1Language = this.languages.length === 1;
const languageKey = hasOnly1Language ? this.languages[0].name : "LANGUAGE_NAME";
const languageKey = hasOnly1Language
? this.languages[0].name
: "LANGUAGE_NAME";

builder.code(
JSON.stringify(
Expand Down Expand Up @@ -251,12 +261,12 @@ export default class BeautifierDoc extends Doc {
builder.append(
`See ${MarkdownBuilder.createDocLink(
"beautifier options",
"options-for-beautifiers"
"options-for-beautifiers"
)} docs for more information.\n`
);
}

builder.append('Example advanced configuration:');
builder.append("Example advanced configuration:");
const beautifierOptions: any = this.beautifierOptionKeys.reduce(
(options, key) => ({
...options,
Expand Down Expand Up @@ -368,55 +378,85 @@ export default class BeautifierDoc extends Doc {
private appendFaqSection(builder: MarkdownBuilder): MarkdownBuilder {
builder.header("FAQ", 2);

builder.header(`How to use ${this.beautifierName} in Atom, VSCode, and other editors?`, 3);
builder.append(`See the ${MarkdownBuilder.createDocLink(
"editor integration",
"editors"
)} documentation for installation instructions for your editor of choice.`);
builder.header(
`How to use ${this.beautifierName} in Atom, VSCode, and other editors?`,
3
);
builder.append(
`See the ${MarkdownBuilder.createDocLink(
"editor integration",
"editors"
)} documentation for installation instructions for your editor of choice.`
);

if (this.canResolveConfig) {
builder.header(`How to use ${this.beautifierName} configuration file?`, 3);
builder.append(`You can override Unibeautify configuration and use ${this.beautifierName}'s own configuration file instead with \`prefer_beautifier_config\` beautifier option.`);
builder.header(
`How to use ${this.beautifierName} configuration file?`,
3
);
builder.append(
`You can override Unibeautify configuration and use ${
this.beautifierName
}'s own configuration file instead with \`prefer_beautifier_config\` beautifier option.`
);
builder.code(
JSON.stringify(
{
LANGUAGE_NAME: {
beautifiers: [this.beautifierName],
[this.beautifierName]: {
prefer_beautifier_config: `path/to/${this.beautifierName}/config/file`
beautifiers: [this.beautifierName],
[this.beautifierName]: {
prefer_beautifier_config: `path/to/${
this.beautifierName
}/config/file`,
},
},
},
},
null,
2
null,
2
),
"json"
);
builder.append(
`See ${MarkdownBuilder.createDocLink(
"beautifier options",
"options-for-beautifiers"
"options-for-beautifiers"
)} docs for more information.\n`
);
}

builder.header(`How to enable ${this.beautifierName} to format on save?`, 3);
builder.append(`See the ${MarkdownBuilder.createDocLink(
"editor integration",
"editors"
)} documentation for format on save instructions for your editor of choice.`);
builder.header(
`How to enable ${this.beautifierName} to format on save?`,
3
);
builder.append(
`See the ${MarkdownBuilder.createDocLink(
"editor integration",
"editors"
)} documentation for format on save instructions for your editor of choice.`
);

builder.header(`How to run ${this.beautifierName} on all files?`, 3);
builder.append(`You can run ${this.beautifierName} on all of your files for every commit with ${MarkdownBuilder.createLink(
'Unibeautify CI',
'https://github.com/apps/unibeautify-ci',
)}.`);
builder.append(
`You can run ${
this.beautifierName
} on all of your files for every commit with ${MarkdownBuilder.createLink(
"Unibeautify CI",
"https://github.com/apps/unibeautify-ci"
)}.`
);

builder.header(`Is there a ${this.beautifierName} sandbox or playground?`, 3);
builder.append(`You can quickly try ${this.beautifierName} online with ${MarkdownBuilder.createLink(
'Unibeautify Playground',
'https://playground.unibeautify.com/'
)}.`);
builder.header(
`Is there a ${this.beautifierName} sandbox or playground?`,
3
);
builder.append(
`You can quickly try ${
this.beautifierName
} online with ${MarkdownBuilder.createLink(
"Unibeautify Playground",
"https://playground.unibeautify.com/"
)}.`
);

return builder;
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate-docs/MarkdownBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ export default class MarkdownBuilder {
return `**${text}**`;
}
public static indent(text: string): string {
return text.replace(new RegExp("^(#+ .+)$","gm"),"#$1");
return text.replace(new RegExp("^(#+ .+)$", "gm"), "#$1");
}
}
5 changes: 1 addition & 4 deletions scripts/generate-docs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ async function main() {
writeDoc(optionsListDoc),
writeDoc(languagesListDoc),
writeDoc(contributingExamplesDoc),
updateSidebars({
languages: languageDocs,
beautifiers: beautifierDocs,
}),
updateSidebars({ languages: languageDocs, beautifiers: beautifierDocs }),
]).catch(error => {
console.error(error);
process.exit(1);
Expand Down

0 comments on commit 7c01f5b

Please sign in to comment.