Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple fixes for class attribute conversions #509

Merged
merged 8 commits into from
Oct 11, 2024

Conversation

MrHaila
Copy link
Contributor

@MrHaila MrHaila commented Sep 8, 2024

Closes #508

This PR adds tests and fixes for previously untested variations of class literals in increasingly complex scenarios. Most of them output non-valid Pug code currently.

I fixed all the new test cases to output valid Pug code without regressions, so this is probably safe to merge. I don't have full confidence that there are no other (currently untested) bad combinations of the various options, but this is for sure better than before.

Examples of code that previously outputted invalid Pug but now work:

// Class literals at the end of attributes did not work.
div(attribute="value").foo
div(class="bar", attribute="value").foo
div(attribute="value", class="bar").foo.baz
div(
  attribute="value"
  class="bar"
).foo.baz
div.foo(attribute="value" class="bar").baz

// Class literals ending at : did not work
div(class="foo").bar: span Text
div: span.foo
div: span(class="foo")
div.foo: span.bar(class="baz").foo

// Class literals in an interpolated line did not work
div.foo(class="bar").baz: h1.foo(class="bar").baz Let's really #[span.foo(class="bar").baz get nasty]!

Copy link
Contributor

github-actions bot commented Sep 8, 2024

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 94.58% (🎯 90%)
⬆️ +0.06%
2638 / 2789
🟢 Statements 94.58% (🎯 90%)
⬆️ +0.06%
2638 / 2789
🟢 Functions 96.29% (🎯 90%)
🟰 ±0%
104 / 108
🟢 Branches 92.94% (🎯 90%)
⬇️ -0.07%
632 / 680
File Coverage
File Stmts % Branch % Funcs % Lines Uncovered Lines
Unchanged Files
src/doctype-shortcut-registry.ts 100% 100% 100% 100%
src/index.ts 93.18% 100% 71.42% 93.18% 78-80, 83-85
src/logger.ts 77.46% 90.9% 81.81% 77.46% 37-44, 46, 93-94, 153-157
src/printer.ts 94.05% 94.14% 100% 94.05% 330-331, 364-365, 507-509, 521-530, 535-548, 595-631, 646-647, 682-683, 739-743, 1071-1072, 1164-1165, 1190, 1202-1203, 1489-1490, 1532-1533, 1829-1835, 1873-1878
src/options/common.ts 100% 100% 100% 100%
src/options/constants.ts 100% 100% 100% 100%
src/options/converge.ts 100% 60% 100% 100%
src/options/index.ts 100% 100% 100% 100%
src/options/pug-attribute-separator.ts 90% 75% 100% 90% 51-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-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 95.69% 94.44% 100% 95.69% 78-79, 87-88
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.67% 86.11% 100% 89.67% 19-20, 25-26, 52-53, 251-252, 254-255, 259-262, 320-321
src/utils/script-mime-types.ts 87.5% 83.33% 100% 87.5% 42-43, 49-50
src/utils/svelte.ts 100% 100% 100% 100%
src/utils/vue.ts 100% 100% 100% 100%
Generated in workflow #53

@MrHaila MrHaila marked this pull request as ready for review September 17, 2024 19:31
@Shinigami92 Shinigami92 marked this pull request as draft September 25, 2024 18:49
@Shinigami92 Shinigami92 changed the title Draft: Multiple fixes for class attribute conversions Multiple fixes for class attribute conversions Sep 25, 2024
@MrHaila MrHaila marked this pull request as ready for review October 3, 2024 17:57
@MrHaila
Copy link
Contributor Author

MrHaila commented Oct 3, 2024

This PR is ready for review and would close #508 if deemed merge-worthy.

@Shinigami92 Shinigami92 added the type: enhancement Functionality that enhances existing features label Oct 9, 2024
@Shinigami92
Copy link
Member

Back from vacation, I'll have a look the next few days, because I need to ensure that everything is correct

@Shinigami92
Copy link
Member

Added 1-level indentation tests and made use of checkTokenType

I just saw that for some cases we have still a div leftover like with L17
But either this might get formatted by just a second run, or it can be fixed by a later MR (if it is even a problem)

@Shinigami92 Shinigami92 merged commit f0aa522 into prettier:main Oct 11, 2024
10 checks passed
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: pugClassNotation: 'attribute' outputs junk if class literals are after attributes
2 participants