Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function parseSyntax(resolve, file, data, onSuccess, inst = undefined) {
if (typeof inst === 'undefined') {
if (typeof henri === 'undefined') {
throw new Error('henri is not defined...');
}
inst = henri;
}
try {
const fileInfo = await prettier.getFileInfo(file);
if (fileInfo) {
prettier.format(data.toString(), { parser: fileInfo.inferredParser });
}
inst.status.set('locked', false);
typeof onSuccess === 'function' && onSuccess();
return resolve(true);
} catch (error) {
const { line, column } = _.has(error, 'loc.start')
? error.loc.start
: { column: 0, line: 0 };
inst.pen.error('server', `while parsing ${file}:${line}:${column}`);
// eslint-disable-line no-console
toInferRubyParser(filename) {
const filepath = path.join(__dirname, filename);
const plugin = path.join(__dirname, "..", "..", "src", "ruby");
return prettier
.getFileInfo(filepath, { plugins: [plugin] })
.then(({ inferredParser }) => ({
pass: inferredParser === "ruby",
message: () => `
Expected prettier to infer the ruby parser for ${filename},
but got ${inferredParser} instead
`
}));
}
});
files.forEach(file => {
Promise.all([
prettier.resolveConfig(file, {
config: prettierConfigPath,
}),
prettier.getFileInfo(file),
])
.then(resolves => {
const [options, fileInfo] = resolves;
if (fileInfo.ignored) {
return;
}
const input = fs.readFileSync(file, 'utf8');
const withParserOptions = {
...options,
parser: fileInfo.inferredParser,
};
const isPrettier = prettier.check(input, withParserOptions);
if (!isPrettier) {
console.log(
`\x1b[31m ${file} is no prettier, please use npm run prettier and git add !\x1b[0m`
);
export async function getFilePathsToFormat() {
const paths = [];
for (const path of getModifiedFilePaths()) {
if (!FORMATTED_EXTENSIONS_REGEX.test(path)) continue;
const info = await prettier.getFileInfo(`${getWorkspacePath()}/${path}`, { ignorePath: getPrettierignorePath() });
if (info.ignored) continue;
paths.push(path);
}
return paths;
}
files.forEach(file => {
Promise.all([
prettier.resolveConfig(file, {
config: prettierConfigPath,
}),
prettier.getFileInfo(file),
])
.then(resolves => {
const [options, fileInfo] = resolves;
if (fileInfo.ignored) {
return;
}
const input = fs.readFileSync(file, 'utf8');
const withParserOptions = {
...options,
parser: fileInfo.inferredParser,
};
const output = prettier.format(input, withParserOptions);
if (output !== input) {
fs.writeFileSync(file, output, 'utf8');
console.log(chalk.green(`${file} is prettier`));
}
files.forEach(file => {
Promise.all([
prettier.resolveConfig(file, {
config: prettierConfigPath,
}),
prettier.getFileInfo(file),
])
.then(resolves => {
const [options, fileInfo] = resolves;
if (fileInfo.ignored) {
return;
}
const input = fs.readFileSync(file, 'utf8');
const withParserOptions = {
...options,
parser: fileInfo.inferredParser,
};
const output = prettier.format(input, withParserOptions);
if (output !== input) {
fs.writeFileSync(file, output, 'utf8');
console.log(chalk.green(`${file} is prettier`));
}
const checkFileWithPrettierConfig = filePath =>
prettier
.getFileInfo(filePath, { ignorePath: '.prettierignore' })
.then(({ ignored, inferredParser }) => {
if (ignored || !inferredParser) {
ignoredCount += 1;
return;
}
return prettier.resolveConfig(filePath).then(fileOptions => {
const options = { ...fileOptions, parser: inferredParser };
return checkFileWithOptions(filePath, options);
});
});