本文整理匯總了TypeScript中prettier.check函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript check函數的具體用法?TypeScript check怎麽用?TypeScript check使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了check函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: minimatch
filesToCheck.forEach(filePath => {
const matchesPattern = minimatch(filePath, prettierPattern, {
matchBase: true,
})
if (!matchesPattern) return
const fileInfo = getFileInfo.sync(filePath)
if (fileInfo.ignored) return
if (!fileInfo.inferredParser) return
const source = readFileSync(filePath, 'utf8')
const config = resolveConfig.sync(filePath)
const options = { ...config, parser: fileInfo.inferredParser }
if (!check(source, options)) {
fail(`${filePath} is not formatted using Prettier.`)
prettierFailed = true
}
})
示例2: require
import * as prettier from 'prettier';
import { ExpressionStatement, CallExpression, Identifier } from 'babel-types';
import * as prettierStandalone from 'prettier/standalone';
import typescriptParser = require('prettier/parser-typescript');
import graphqlParser = require('prettier/parser-graphql');
import babylonParser = require('prettier/parser-babylon');
import htmlParser = require('prettier/parser-html');
import markdownParser = require('prettier/parser-markdown');
import postcssParser = require('prettier/parser-postcss');
import yamlParser = require('prettier/parser-yaml');
const formatted = prettier.format('foo ( );', { semi: false });
const isFormatted = prettier.check('foo ( );', { semi: false });
const result = prettier.formatWithCursor(' 1', { cursorOffset: 2 });
const customFormatted = prettier.format('lodash ( )', {
parser(text, { babylon }) {
const ast = babylon(text);
const statement = ast.program.body[0] as ExpressionStatement;
const expression = statement.expression as CallExpression;
const identifier = expression.callee as Identifier;
identifier.name = '_';
return ast;
},
});
prettier.resolveConfig('path/to/somewhere').then(options => {
if (options !== null) {
const formatted = prettier.format('hello world', options);
示例3: Error
import * as prettier from 'prettier';
import { ExpressionStatement, CallExpression, Identifier } from 'babel-types';
const formatted = prettier.format("foo ( );", { semi: false });
const isFormatted = prettier.check("foo ( );", { semi: false });
const result = prettier.formatWithCursor(" 1", { cursorOffset: 2 });
const customFormatted = prettier.format("lodash ( )", {
parser(text, { babylon }) {
const ast = babylon(text);
const statement = ast.program.body[0] as ExpressionStatement;
const expression = statement.expression as CallExpression;
const identifier = expression.callee as Identifier;
identifier.name = "_";
return ast;
}
});
prettier.resolveConfig('path/to/somewhere').then(options => {
if (options !== null) {
const formatted = prettier.format('hello world', options);
}
});
if (prettier.getFileInfo.sync('./tsconfig.json').inferredParser !== 'json') {
throw new Error('Bad parser');
}
prettier.getFileInfo('./tsconfig.json').then((result) => {