Skip to content

Respect style tag type attribute when formatting - #670

Open
bminer wants to merge 2 commits into
prettier:mainfrom
bminer:fix/style-type-parser
Open

bminer wants to merge 2 commits into
prettier:mainfrom
bminer:fix/style-type-parser

Conversation

@bminer

@bminer bminer commented Sep 29, 2026

Copy link
Copy Markdown

Choose the parser for style blocks from the type attribute instead of always using css. scss and less types use their prettier parsers, and unsupported types such as sass are left unformatted instead of failing with a CssSyntaxError.

Closes #532

Choose the parser for `style` blocks from the `type` attribute instead of always
using `css`. `scss` and `less` types use their prettier parsers, and unsupported
types such as `sass` are left unformatted.

Closes prettier#532

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bminer
bminer requested a review from Shinigami92 as a code owner September 29, 2026 16:16
@Shinigami92 Shinigami92 added the type: enhancement Functionality that enhances existing features label Sep 29, 2026
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 93.76% (🎯 90%)
⬆️ +0.07%
1052 / 1122
🟢 Statements 93.64% (🎯 90%)
⬆️ +0.06%
1061 / 1133
🟢 Functions 97.95% (🎯 90%)
⬆️ +0.01%
144 / 147
🔴 Branches 88.25% (🎯 90%)
⬆️ +0.10%
691 / 783
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/printer.ts 94.02%
🟰 ±0%
89.15%
🟰 ±0%
100%
🟰 ±0%
94.23%
🟰 ±0%
338, 375, 525-527, 539-548, 553-564, 613-666, 705, 791-794, 1142, 1236, 1264, 1273, 1565, 1612, 1832, 1871, 2023-2028, 2068-2072
src/utils/style-mime-types.ts 100% 100% 100% 100%
Unchanged Files
src/doctype-shortcut-registry.ts 100% 100% 100% 100%
src/index.ts 86.66% 100% 71.42% 86.66% 79-85
src/logger.ts 82.14% 42.85% 91.66% 82.14% 37-44, 93, 153-155
src/prettier.d.ts 100% 100% 100% 100%
src/options/common.ts 100% 100% 100% 100%
src/options/constants.ts 100% 100% 100% 100%
src/options/converge.ts 100% 82.6% 100% 100%
src/options/index.ts 100% 100% 100% 100%
src/options/pug-attribute-separator.ts 75% 100% 100% 75% 52-54
src/options/pug-class-location.ts 100% 100% 100% 100%
src/options/pug-class-notation.ts 100% 100% 100% 100%
src/options/pug-closing-bracket-indent-depth.ts 100% 100% 100% 100%
src/options/pug-comment-preserve-spaces.ts 100% 100% 100% 100%
src/options/pug-explicit-div.ts 100% 100% 100% 100%
src/options/pug-framework.ts 100% 100% 100% 100%
src/options/pug-id-notation.ts 100% 100% 100% 100%
src/options/pug-preserve-attribute-brackets.ts 100% 100% 100% 100%
src/options/pug-preserve-whitespace.ts 100% 100% 100% 100%
src/options/pug-single-file-component-indentation.ts 100% 100% 100% 100%
src/options/pug-wrap-attributes.ts 100% 100% 100% 100%
src/options/types.ts 100% 100% 100% 100%
src/options/attribute-sorting/index.ts 100% 100% 100% 100%
src/options/attribute-sorting/utils.ts 96% 91.66% 100% 95.83% 82, 94
src/options/empty-attributes/index.ts 100% 100% 100% 100%
src/options/empty-attributes/types.ts 100% 100% 100% 100%
src/options/empty-attributes/utils.ts 100% 100% 100% 100%
src/utils/angular.ts 100% 100% 100% 100%
src/utils/common.ts 89.7% 86.76% 100% 88.88% 19, 27, 56, 258, 262, 269-272, 331
src/utils/script-mime-types.ts 86.66% 75% 100% 86.66% 42, 49
src/utils/svelte.ts 100% 100% 100% 100%
src/utils/vue.ts 100% 100% 100% 100%
Generated in workflow #1629 for commit 1939f93 by the Vitest Coverage Report Action

const typeRaw: string | boolean = typeAttrToken.val;
// If it's not a string, best not do anything
if (typeof typeRaw !== 'string') {
return;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (if-minor): line 35 and 42 are both uncovered, do you think we can add test cases for them?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be all set. Let me know what you think!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused myself, but the Coverage Report -> File Coverage -> src/utils/script-mime-types.ts now shows 42, 49 👀

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea. I think those lines have coverage. I'll investigate more tomorrow. Thanks!

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement Functionality that enhances existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: style tag with type="sass" is checked as CSS

2 participants