Skip to content

Commit

Permalink
Merge pull request #1575 from BlakeTnr/main
Browse files Browse the repository at this point in the history
task/1574 allow overriding prettier parser in config
  • Loading branch information
JoernBerkefeld authored Aug 19, 2024
2 parents c65095a + 1764bd5 commit c4a8dae
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 50 deletions.
2 changes: 1 addition & 1 deletion @types/lib/util/file.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

102 changes: 53 additions & 49 deletions lib/util/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,57 +260,61 @@ const File = {
// will throw an error falsely assuming bad syntax
return await this.beautify_beautyAmp(content, true);
}
// load the right prettier config relative to our file
switch (filetype) {
case 'htm':
case 'html': {
FileFs.prettierConfig.parser = 'html';
break;
}
case 'ssjs':
case 'js': {
FileFs.prettierConfig.parser = 'babel';
break;
}
case 'json': {
FileFs.prettierConfig.parser = 'json';
break;
}
case 'yaml':
case 'yml': {
FileFs.prettierConfig.parser = 'yaml';
break;
}
case 'ts': {
FileFs.prettierConfig.parser = 'babel-ts';
break;
}
case 'css': {
FileFs.prettierConfig.parser = 'css';
break;
}
case 'less': {
FileFs.prettierConfig.parser = 'less';
break;
}
case 'sass':
case 'scss': {
FileFs.prettierConfig.parser = 'scss';
break;
}
case 'md': {
FileFs.prettierConfig.parser = 'markdown';
break;
}
case 'sql': {
FileFs.prettierConfig.parser = 'sql';
FileFs.prettierConfig.plugins = ['prettier-plugin-sql'];
break;
}
default: {
FileFs.prettierConfig.parser = 'babel';

if (!FileFs.prettierConfig.parser) {
// load the right prettier config relative to our file
switch (filetype) {
case 'htm':
case 'html': {
FileFs.prettierConfig.parser = 'html';
break;
}
case 'ssjs':
case 'js': {
FileFs.prettierConfig.parser = 'babel';
break;
}
case 'json': {
FileFs.prettierConfig.parser = 'json';
break;
}
case 'yaml':
case 'yml': {
FileFs.prettierConfig.parser = 'yaml';
break;
}
case 'ts': {
FileFs.prettierConfig.parser = 'babel-ts';
break;
}
case 'css': {
FileFs.prettierConfig.parser = 'css';
break;
}
case 'less': {
FileFs.prettierConfig.parser = 'less';
break;
}
case 'sass':
case 'scss': {
FileFs.prettierConfig.parser = 'scss';
break;
}
case 'md': {
FileFs.prettierConfig.parser = 'markdown';
break;
}
case 'sql': {
FileFs.prettierConfig.parser = 'sql';
FileFs.prettierConfig.plugins = ['prettier-plugin-sql'];
break;
}
default: {
FileFs.prettierConfig.parser = 'babel';
}
}
}

formatted = await prettier.format(content, FileFs.prettierConfig);
} catch (ex) {
// save prettier errror into log file
Expand Down

0 comments on commit c4a8dae

Please sign in to comment.