prettier#BuiltInParserName TypeScript Examples
The following examples show how to use
prettier#BuiltInParserName.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: descriptionFormatter.ts From prettier-plugin-jsdoc with MIT License | 6 votes |
parserSynonyms = (lang: string): BuiltInParserName[] => {
switch (lang) {
case "js":
case "javascript":
case "jsx":
return ["babel", "babel-flow", "vue"];
case "ts":
case "typescript":
case "tsx":
return ["typescript", "babel-ts", "angular"];
case "json":
case "css":
return ["css"];
case "less":
return ["less"];
case "scss":
return ["scss"];
case "html":
return ["html"];
case "yaml":
return ["yaml"];
default:
return ["babel"];
}
}
Example #2
Source File: prettier.ts From mercurius-typescript with MIT License | 6 votes |
export async function formatPrettier(str: string, parser: BuiltInParserName) {
const { format, resolveConfig } = await import('prettier')
const prettierConfig = Object.assign({}, await resolveConfig(process.cwd()))
return format(str, {
parser,
...prettierConfig,
})
}
Example #3
Source File: prettify.ts From genql with MIT License | 6 votes |
prettify = (code: string, parser?: BuiltInParserName): string => {
// return code
return prettier.format(code, {
parser,
plugins: [parserGraphql, parserTS],
semi: false,
singleQuote: true,
trailingComma: 'all',
printWidth: 80,
})
}
Example #4
Source File: RenderContext.ts From genql with MIT License | 6 votes |
toCode(parser?: BuiltInParserName, pretty = false) {
const blocks = [...this.codeBlocks]
if (parser && (parser === 'typescript' || parser === 'babel')) {
const importBlock = this.getImportBlock()
if (importBlock) blocks.unshift(importBlock)
}
if (parser && pretty) {
return prettify(blocks.join('\n\n'), parser)
}
if (parser) {
return blocks.join('\n\n')
}
return blocks.join('')
}
Example #5
Source File: render.ts From genql with MIT License | 6 votes |
schemaRenderTest = async (
schemaGql: string,
renderer: SchemaRenderer,
parser?: BuiltInParserName,
) => {
const schema = await toClientSchema(schemaGql)
const ctx = new RenderContext(schema)
renderer(schema, ctx)
return ctx.toCode(parser, true)
}
Example #6
Source File: render.ts From genql with MIT License | 6 votes |
typeRenderTest = async (
schemaGql: string,
renderer: TypeRenderer,
typeNames: string[],
parser?: BuiltInParserName,
) => {
const schema = await toClientSchema(schemaGql)
const ctx = new RenderContext(schema)
typeNames.forEach((typeName) => {
const type = schema.getType(typeName)
if (!type) {
throw new Error(`type ${typeName} is not defined in the schema`)
}
renderer(type, ctx)
})
return ctx.toCode(parser, true)
}