question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

LESS mixin unexpected code formatting

See original GitHub issue

Description

This is moved over from https://github.com/microsoft/vscode/issues/146693

Using VSCode 1.66.0 and the new built-in LESS code formatting feature less.format.enable implemented by the JS Beautify library.

When using a LESS mixin that accepts CSS code rules as a parameter (this is used for media query mixins), the formatting when saved is a little unexpected. The formatting is consistent, but it is unusal.

Input & Expected Output

.example(@rules) {
    @rules();
}

.test {
    .example({
        color:red;
    });
}

Actual Output

.example(@rules) {
    @rules();
}

.test {
    .example( {
            color:red;
        }

    );
}

More Information

Similar issue reported a while back js-beautify issue 722

I’ve noticed that if you add the following to VSCode’s settings.json file, the results are slightly better:

"less.format.newlineBetweenRules": false

This gives you formatting like:

.example(@rules) {
    @rules();
}

.test {
    .example( {
            color:red;
        }
    );
}

I was asked to move the issue over here, so hope it’s in the right place now.

Environment

OS: macOS 12.3.1 VSCode 1.66.0 which bundles js-beautify

I have been trying to track down the version of js-beautify, but I cannot seem to find it within VSCode, so if anyone can advise how I can report this that would be great.

Settings

Defined by VSCode

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
mhnaeemcommented, Apr 7, 2022

@aeschli @bitwiseman I have added a PR for a possible solution to the spacing problems mentioned in this ticket and #722.

2reactions
aeschlicommented, Apr 5, 2022

VS Code 1.66.0 uses jsbeautify 1.14.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

LESS mixin unexpected code formatting · Issue #146693 · microsoft ...
When using a LESS mixin that accepts CSS code rules as a parameter (this is used for media query mixins), the formatting when...
Read more >
ParseError:Unrecognised input in less while creating custom ...
LESS throws an error and stop compiling if a variable or mixins is undefined. ... import required files s.a. variables.less and mixins.less.
Read more >
Mixins for Rem Font Sizing - CSS-Tricks
The rem font-size unit is similar to em, only instead of cascading it's always relative to the root (html) element (more information).
Read more >
Conditionals & Mixin Guards | Less | Tutorial 6 - YouTube
Giraffe Academy is rebranding! I've decided to re-focus the brand of this channel to highlight myself as a developer and teacher!
Read more >
Compiling Less | Less Web Development Essentials
With Less, you can produce CSS code that can be used to style your website. The process used to make CSS from Less...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found