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

Fix no space after unary minus when followed by opening parenthesis in LESS #14008

Merged
merged 1 commit into from Dec 29, 2022
Merged

Fix no space after unary minus when followed by opening parenthesis in LESS #14008

merged 1 commit into from Dec 29, 2022

Conversation

mvorisek
Copy link
Contributor

@mvorisek mvorisek commented Dec 17, 2022

Description

Fix #13998.

Less online compiler https://lesscss.org/less-preview/ can be used to verify, added space can change the meaning of the data.

The problem is solely with -, + is not supported by less before (.

Also solely for LESS/SCSS, as regular CSS supports calculations only inside calc() where space has no special meaning.

Checklist

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory).
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

@kachkaev kachkaev requested a review from fisker December 17, 2022 19:31
@mvorisek mvorisek changed the title Fix no space after unary operator when expression is in parentheses Fix no space after unary minus when expression is in parentheses Dec 17, 2022
@mvorisek mvorisek changed the title Fix no space after unary minus when expression is in parentheses Fix no space after unary minus when followed by opening parenthesis Dec 18, 2022
@mvorisek mvorisek changed the title Fix no space after unary minus when followed by opening parenthesis Fix no space after unary minus when followed by opening parenthesis in LESS Dec 18, 2022
@fisker
Copy link
Sponsor Member

fisker commented Dec 18, 2022

Can you add changelog for this?

@mvorisek
Copy link
Contributor Author

changelog entry added

Copy link
Sponsor Member

@fisker fisker left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

lubber-de pushed a commit to fomantic/Fomantic-UI that referenced this pull request Dec 21, 2022
Compared to Stylelint, Prettier is very simple tool and I am quite supprised Stylelint is deprecating the whitespace rules in favor of Prettier. For LESS it seems ok, for JS, we should never enable Prettier as formatting is part of a code and improves readability.

As Prettier is an opinionated formatter instead of an linter, we need to satisfy it everywhere without exceptions.

When I was crafting this PR, I found several Prettier issues and proposed changes to Prettier:

Fix semicolon duplicated at the end of LESS file prettier/prettier#14007
Fix no space after unary minus when followed by opening parenthesis in LESS prettier/prettier#14008
Do not change case of property name if inside a variable declaration in LESS prettier/prettier#14034
In this PR, these changes are contained and Prettier is patched before it is run. Once the changes are merged in prettier and stable release is made, they can be removed.

This PR fixes minor whitespaces unfixed/undetected in GH-2610.

And also asserts:

PHP port of the LESS fails to compile colors.less #1832
feat(lint): add stylelint overrides and variation files #2593 (comment)
Prettier has no built in support to dump the diff - prettier/prettier#6885 - so we dump it in the CI using git.
@fisker fisker merged commit 4551fe6 into prettier:main Dec 29, 2022
@mvorisek mvorisek deleted the fix_unary_space branch December 29, 2022 08:36
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Jan 11, 2023
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [prettier](https://prettier.io) ([source](https://github.com/prettier/prettier)) | devDependencies | patch | [`2.8.1` -> `2.8.2`](https://renovatebot.com/diffs/npm/prettier/2.8.1/2.8.2) |

---

### Release Notes

<details>
<summary>prettier/prettier</summary>

### [`v2.8.2`](https://github.com/prettier/prettier/blob/HEAD/CHANGELOG.md#&#8203;282)

[Compare Source](prettier/prettier@2.8.1...2.8.2)

[diff](prettier/prettier@2.8.1...2.8.2)

##### Don't lowercase link references ([#&#8203;13155](prettier/prettier#13155) by [@&#8203;DerekNonGeneric](https://github.com/DerekNonGeneric) & [@&#8203;fisker](https://github.com/fisker))

<!-- prettier-ignore -->

```markdown
<!-- Input -->
We now don't strictly follow the release notes format suggested by [Keep a Changelog].

[Keep a Changelog]: https://example.com/

<!-- Prettier 2.8.1 -->
We now don't strictly follow the release notes format suggested by [Keep a Changelog].

[keep a changelog]: https://example.com/
<!--
^^^^^^^^^^^^^^^^^^ lowercased
-->

<!-- Prettier 2.8.2 -->
<Same as input>
```

##### Preserve self-closing tags ([#&#8203;13691](prettier/prettier#13691) by [@&#8203;dcyriller](https://github.com/dcyriller))

<!-- prettier-ignore -->

```hbs
{{! Input }}
<div />
<div></div>
<custom-component />
<custom-component></custom-component>
<i />
<i></i>
<Component />
<Component></Component>

{{! Prettier 2.8.1 }}
<div></div>
<div></div>
<custom-component></custom-component>
<custom-component></custom-component>
<i></i>
<i></i>
<Component />
<Component />

{{! Prettier 2.8.2 }}
<div />
<div></div>
<custom-component />
<custom-component></custom-component>
<i />
<i></i>
<Component />
<Component />
```

##### Allow custom "else if"-like blocks with block params ([#&#8203;13930](prettier/prettier#13930) by [@&#8203;jamescdavis](https://github.com/jamescdavis))

[#&#8203;13507](prettier/prettier#13507) added support for custom block keywords used with `else`, but failed to allow block params. This updates printer-glimmer to allow block params with custom "else if"-like blocks.

<!-- prettier-ignore -->

```hbs
{{! Input }}
{{#when isAtWork as |work|}}
  Ship that
  {{work}}!
{{else when isReading as |book|}}
  You can finish
  {{book}}
  eventually...
{{else}}
  Go to bed!
{{/when}}

{{! Prettier 2.8.1 }}
{{#when isAtWork as |work|}}
  Ship that
  {{work}}!
{{else when isReading}}
  You can finish
  {{book}}
  eventually...
{{else}}
  Go to bed!
{{/when}}

{{! Prettier 2.8.2 }}
{{#when isAtWork as |work|}}
  Ship that
  {{work}}!
{{else when isReading as |book|}}
  You can finish
  {{book}}
  eventually...
{{else}}
  Go to bed!
{{/when}}
```

##### Preserve empty lines between nested SCSS maps ([#&#8203;13931](prettier/prettier#13931) by [@&#8203;jneander](https://github.com/jneander))

<!-- prettier-ignore -->

```scss
/* Input */
$map: (
  'one': (
     'key': 'value',
  ),

  'two': (
     'key': 'value',
  ),
)

/* Prettier 2.8.1 */
$map: (
  'one': (
     'key': 'value',
  ),
  'two': (
     'key': 'value',
  ),
)

/* Prettier 2.8.2 */
$map: (
  'one': (
     'key': 'value',
  ),

  'two': (
     'key': 'value',
  ),
)
```

##### Fix missing parentheses when an expression statement starts with `let[` ([#&#8203;14000](prettier/prettier#14000), [#&#8203;14044](prettier/prettier#14044) by [@&#8203;fisker](https://github.com/fisker), [@&#8203;thorn0](https://github.com/thorn0))

<!-- prettier-ignore -->

```jsx
// Input
(let[0] = 2);

// Prettier 2.8.1
let[0] = 2;

// Prettier 2.8.1 (second format)
SyntaxError: Unexpected token (1:5)
> 1 | let[0] = 2;
    |     ^
  2 |

// Prettier 2.8.2
(let)[0] = 2;
```

##### Fix semicolon duplicated at the end of LESS file ([#&#8203;14007](prettier/prettier#14007) by [@&#8203;mvorisek](https://github.com/mvorisek))

<!-- prettier-ignore -->

```less
// Input
@&#8203;variable: {
  field: something;
};

// Prettier 2.8.1
@&#8203;variable: {
  field: something;
}; ;

// Prettier 2.8.2
@&#8203;variable: {
  field: something;
};
```

##### Fix no space after unary minus when followed by opening parenthesis in LESS ([#&#8203;14008](prettier/prettier#14008) by [@&#8203;mvorisek](https://github.com/mvorisek))

<!-- prettier-ignore -->

```less
// Input
.unary_minus_single {
  margin: -(@&#8203;a);
}

.unary_minus_multi {
  margin: 0 -(@&#8203;a);
}

.binary_minus {
  margin: 0 - (@&#8203;a);
}

// Prettier 2.8.1
.unary_minus_single {
  margin: - (@&#8203;a);
}

.unary_minus_multi {
  margin: 0 - (@&#8203;a);
}

.binary_minus {
  margin: 0 - (@&#8203;a);
}

// Prettier 2.8.2
.unary_minus_single {
  margin: -(@&#8203;a);
}

.unary_minus_multi {
  margin: 0 -(@&#8203;a);
}

.binary_minus {
  margin: 0 - (@&#8203;a);
}
```

##### Do not change case of property name if inside a variable declaration in LESS ([#&#8203;14034](prettier/prettier#14034) by [@&#8203;mvorisek](https://github.com/mvorisek))

<!-- prettier-ignore -->

```less
// Input
@&#8203;var: {
  preserveCase: 0;
};

// Prettier 2.8.1
@&#8203;var: {
  preservecase: 0;
};

// Prettier 2.8.2
@&#8203;var: {
  preserveCase: 0;
};
```

##### Fix formatting for auto-accessors with comments ([#&#8203;14038](prettier/prettier#14038) by [@&#8203;fisker](https://github.com/fisker))

<!-- prettier-ignore -->

```jsx
// Input
class A {
  @&#8203;dec()
  // comment
  accessor b;
}

// Prettier 2.8.1
class A {
  @&#8203;dec()
  accessor // comment
  b;
}

// Prettier 2.8.1 (second format)
class A {
  @&#8203;dec()
  accessor; // comment
  b;
}

// Prettier 2.8.2
class A {
  @&#8203;dec()
  // comment
  accessor b;
}
```

##### Add parentheses for TSTypeQuery to improve readability ([#&#8203;14042](prettier/prettier#14042) by [@&#8203;onishi-kohei](https://github.com/onishi-kohei))

<!-- prettier-ignore -->

```tsx
// Input
a as (typeof node.children)[number]
a as (typeof node.children)[]
a as ((typeof node.children)[number])[]

// Prettier 2.8.1
a as typeof node.children[number];
a as typeof node.children[];
a as typeof node.children[number][];

// Prettier 2.8.2
a as (typeof node.children)[number];
a as (typeof node.children)[];
a as (typeof node.children)[number][];
```

##### Fix displacing of comments in default switch case ([#&#8203;14047](prettier/prettier#14047) by [@&#8203;thorn0](https://github.com/thorn0))

It was a regression in Prettier 2.6.0.

<!-- prettier-ignore -->

```jsx
// Input
switch (state) {
  default:
    result = state; // no change
    break;
}

// Prettier 2.8.1
switch (state) {
  default: // no change
    result = state;
    break;
}

// Prettier 2.8.2
switch (state) {
  default:
    result = state; // no change
    break;
}
```

##### Support type annotations on auto accessors via `babel-ts` ([#&#8203;14049](prettier/prettier#14049) by [@&#8203;sosukesuzuki](https://github.com/sosukesuzuki))

[The bug that `@babel/parser` cannot parse auto accessors with type annotations](babel/babel#15205) has been fixed. So we now support it via `babel-ts` parser.

<!-- prettier-ignore -->

```tsx
class Foo {
  accessor prop: number;
}
```

##### Fix formatting of empty type parameters ([#&#8203;14073](prettier/prettier#14073) by [@&#8203;fisker](https://github.com/fisker))

<!-- prettier-ignore -->

```jsx
// Input
const foo: bar</* comment */> = () => baz;

// Prettier 2.8.1
Error: Comment "comment" was not printed. Please report this error!

// Prettier 2.8.2
const foo: bar</* comment */> = () => baz;
```

##### Add parentheses to head of `ExpressionStatement` instead of the whole statement ([#&#8203;14077](prettier/prettier#14077) by [@&#8203;fisker](https://github.com/fisker))

<!-- prettier-ignore -->

```jsx
// Input
({}).toString.call(foo) === "[object Array]"
  ? foo.forEach(iterateArray)
  : iterateObject(foo);

// Prettier 2.8.1
({}.toString.call(foo) === "[object Array]"
  ? foo.forEach(iterateArray)
  : iterateObject(foo));

// Prettier 2.8.2
({}).toString.call(foo.forEach) === "[object Array]"
  ? foo.forEach(iterateArray)
  : iterateObject(foo);
```

##### Fix comments after directive ([#&#8203;14081](prettier/prettier#14081) by [@&#8203;fisker](https://github.com/fisker))

<!-- prettier-ignore -->

```jsx
// Input
"use strict" /* comment */;

// Prettier 2.8.1 (with other js parsers except `babel`)
Error: Comment "comment" was not printed. Please report this error!

// Prettier 2.8.2
<Same as input>
```

##### Fix formatting for comments inside JSX attribute ([#&#8203;14082](prettier/prettier#14082) with by [@&#8203;fisker](https://github.com/fisker))

<!-- prettier-ignore -->

```jsx
// Input
function MyFunctionComponent() {
  <button label=/*old*/"new">button</button>
}

// Prettier 2.8.1
Error: Comment "old" was not printed. Please report this error!

// Prettier 2.8.2
function MyFunctionComponent() {
  <button label=/*old*/ "new">button</button>;
}
```

##### Quote numeric keys for json-stringify parser ([#&#8203;14083](prettier/prettier#14083) by [@&#8203;fisker](https://github.com/fisker))

<!-- prettier-ignore -->

```jsx
// Input
{0: 'value'}

// Prettier 2.8.1
{
  0: "value"
}

// Prettier 2.8.2
{
  "0": "value"
}
```

##### Fix removing commas from function arguments in maps ([#&#8203;14089](prettier/prettier#14089) by [@&#8203;sosukesuzuki](https://github.com/sosukesuzuki))

<!-- prettier-ignore -->

```scss
/* Input */
$foo: map-fn(
  (
    "#{prop}": inner-fn($first, $second),
  )
);

/* Prettier 2.8.1 */
$foo: map-fn(("#{prop}": inner-fn($first $second)));

/* Prettier 2.8.2 */
$foo: map-fn(
  (
    "#{prop}": inner-fn($first, $second),
  )
);

```

##### Do not insert space in LESS property access ([#&#8203;14103](prettier/prettier#14103) by [@&#8203;fisker](https://github.com/fisker))

<!-- prettier-ignore -->

```less
// Input
a {
  color: @&#8203;colors[@&#8203;white];
}

// Prettier 2.8.1
a {
  color: @&#8203;colors[ @&#8203;white];
}

// Prettier 2.8.2
<Same as input>
```

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC45MC4wIiwidXBkYXRlZEluVmVyIjoiMzQuOTcuNSJ9-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1708
Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
medikoo pushed a commit to medikoo/prettier-elastic that referenced this pull request Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unary minus must not be followed by a space in LESS
3 participants