Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const options = {}
if (flags.parser) {
options.parser = flags.parser
}
if (hasStdin) {
const stdin = await getStdin()
options.filepath = '(stdin)'
if (flags['stdin-filepath']) {
Object.assign(
options,
prettierx.resolveConfig.sync(flags['stdin-filepath'], {
editorconfig: true
})
)
}
try {
if (flags.check) {
const valid = check(stdin, options)
if (!valid) {
console.log('(stdin)')
return 1
}
} else {
const output = format(stdin, options)
process.stdout.write(output)
}
function check (source, options) {
return prettierx.check(source, getOptions(options))
}
function format (source, options) {
return prettierx.format(source, getOptions(options))
}
for (const file of files) {
const start = Date.now()
const { filepath, changes } = file
const fullpath = path.join(root, filepath)
const input = fs.readFileSync(fullpath, 'utf8')
let ranges
if (config.lines && changes) {
ranges = getRanges(input, changes)
}
const fileOptions = Object.assign(
{},
prettierx.resolveConfig.sync(fullpath, {
editorconfig: true
}),
config.options,
{ filepath: fullpath }
)
const fileInfo = prettierx.getFileInfo.sync(fullpath, {})
if (!fileOptions.parser) {
fileOptions.parser = fileInfo.inferredParser
}
if (config.check) {
const formatted = checkWithRanges(input, ranges, fileOptions)
let report
file: filepath,
runtime: Date.now() - start,
formatted,
report,
check: config.check
})
}
}
module.exports = {
format,
check,
run,
getFileInfo,
formatWithCursor,
resolveConfig: prettierx.resolveConfig,
clearConfigCache: prettierx.clearConfigCache,
getSupportInfo: prettierx.getSupportInfo
}
runtime: Date.now() - start,
formatted,
report,
check: config.check
})
}
}
module.exports = {
format,
check,
run,
getFileInfo,
formatWithCursor,
resolveConfig: prettierx.resolveConfig,
clearConfigCache: prettierx.clearConfigCache,
getSupportInfo: prettierx.getSupportInfo
}
function formatWithCursor (source, options) {
return prettierx.formatWithCursor(source, getOptions(options))
}
function getFileInfo (filePath, options) {
return prettierx.getFileInfo(filePath, options)
}
formatted,
report,
check: config.check
})
}
}
module.exports = {
format,
check,
run,
getFileInfo,
formatWithCursor,
resolveConfig: prettierx.resolveConfig,
clearConfigCache: prettierx.clearConfigCache,
getSupportInfo: prettierx.getSupportInfo
}