0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-06-22 07:08:40 +00:00

add formatting options plus single delcaration rule encapsulating

This commit is contained in:
Víctor Losada Hernández
2026-06-02 15:40:40 +02:00
parent 6bbc36501d
commit 1558a14a91
2 changed files with 16 additions and 44 deletions
@@ -12,10 +12,23 @@ export async function formatCSS(view) {
const selection = view.state.doc.sliceString(from, to);
const code = empty ? fullDoc : selection;
const formatted = await prettier.format(code, {
parser : 'css',
plugins : [postcssPlugin]
let formatted = await prettier.format(code, {
parser: 'css',
plugins: [postcssPlugin],
// formatting options
tabWidth: 2,
useTabs: false,
printWidth: 100,
singleQuote: false,
trailingComma: 'all',
bracketSpacing: true,
endOfLine: 'lf'
});
formatted = formatted.replace(
/([^{]+)\{\s*\n\s*([^;\n]+:[^;\n]+;)\s*\n\s*\}/g,
(_, selector, decl)=>`${selector.trim()} { ${decl.trim()} }`
);
if(formatted === code) return true;
const dom = view.dom;