Skip to content

prettierx 0.19.0

Latest
Compare
Choose a tag to compare
@brodybits brodybits released this 06 Jul 14:06
· 27 commits to dev since this release
prettierx-0.19.0
e96b04d

Changelog

prettierx 0.19.0

compare prettierx-0.18.3...prettierx-0.19.0

Include updates from Prettier 2.3.2

(with some prettierX language-js updates now based on Prettier 2.3.2)

with some updates including:

  • switch to pure CSS parser using PostCSS 8 (see below)
  • apply an optimization to reduce AST copying in HTML preprocessing - prettier/prettier#11108
  • update many dependencies
  • use @brodybits/remark-parse@8, with updated trim sub-dependency, as recommended by:
  • remove original author from package.json - with rationale:
    • The code base in both Prettier and prettierX has many authors.
    • Prettier has a number of committers and likely multiple owners, while prettierX has only one committer & owner at this point.
    • The primary authors should be in the copyright & license statements, while the all of actual code authors should be in the git commits.
    • The existing committer & owner of prettierX hence sees no point in keeping the original author entry.

prettierx 0.19.0 update(s) from Prettier next branch

[BREAKING] Add the pure css parser (prettier/prettier#7933, prettier/prettier#9092, prettier/prettier#9093 by @fisker)

(using PostCSS version 8)

Previously, when --parser=css was passed, Prettier tried to parse the content using postcss-scss and postcss-less. This caused confusion, and made syntax errors difficult to spot. Now --parser=css works only with the vanilla CSS syntax.

If you use parser="css" for your .less/.scss files, update it to the correct parser or remove the parser option to let Prettier auto-detect the parser by the file extension.

/* Input */
/* Less Syntax with `--parser=css` */
a {.bordered();}

/* Prettier stable */
/* Less Syntax with `--parser=css` */
a {
  .bordered();
}

/* Prettier main */
SyntaxError: (postcss) CssSyntaxError Unknown word (2:4)
  1 | /* Less Syntax with `--parser=css` */
> 2 | a {.bordered();}
/* Input */
/* Scss Syntax with `--parser=css` */
::before {content: #{$foo}}

/* Prettier stable */
/* Scss Syntax with `--parser=css` */
::before {
  content: #{$foo};
}

/* Prettier main */
SyntaxError: (postcss) CssSyntaxError Unknown word (2:22)
  1 | /* Scss Syntax with `--parser=css` */
> 2 | ::before {content: #{$foo}}

prettier 2.3.2

diff

Fix failure on dir with trailing slash (#11000 by @fisker)

$ ls
1.js  1.unknown

# Prettier 2.3.1
$ prettier . -l
1.js
$ prettier ./ -l
[error] No supported files were found in the directory: "./".

# Prettier 2.3.2
$ prettier ./ -l
1.js

Fix handling of parenthesis with Flow's {Optional}IndexedAccess (#11051 by @gkz)

Add parens when required.

// Input
type A = (T & S)['bar'];
type B = (T | S)['bar'];
type C = (?T)['bar'];
type D = (typeof x)['bar'];
type E = (string => void)['bar'];

// Prettier 2.3.1
type A = T & S["bar"];
type B = T | S["bar"];
type C = ?T["bar"];
type D = typeof x["bar"];
type E = (string) => void["bar"];

// Prettier 2.3.2
type A = (T & S)["bar"];
type B = (T | S)["bar"];
type C = (?T)["bar"];
type D = (typeof x)["bar"];
type E = ((string) => void)["bar"];

Print override modifiers for parameter property (#11074 by @sosukesuzuki)

// Input
class D extends B {
  constructor(override foo: string) {
    super();
  }
}

// Prettier 2.3.1
class D extends B {
  constructor(foo: string) {
    super();
  }
}

// Prettier 2.3.2
class D extends B {
  constructor(override foo: string) {
    super();
  }
}

prettier 2.3.1

diff

Support TypeScript 4.3 (#10945 by @sosukesuzuki)

override modifiers in class elements
class Foo extends  {
  override method() {}
}
static index signatures ([key: KeyType]: ValueType) in classes
class Foo {
  static [key: string]: Bar;
}
get / set in type declarations
interface Foo {
  set foo(value);
  get foo(): string;
}

Preserve attributes order for element node (#10958 by @dcyriller)

{{!-- Input --}}
<MyComponent
  {{! this is a comment for arg 1}}
  @arg1="hello"
  {{on "clik" this.modify}}
  @arg2="hello"
  {{! this is a comment for arg 3}}
  @arg3="hello"
  @arg4="hello"
  {{! this is a comment for arg 5}}
  @arg5="hello"
  ...arguments
/>
{{!-- Prettier stable --}}
<MyComponent
  @arg1="hello"
  @arg2="hello"
  @arg3="hello"
  @arg4="hello"
  @arg5="hello"
  ...arguments
  {{on "clik" this.modify}}
  {{! this is a comment for arg 1}}
  {{! this is a comment for arg 3}}
  {{! this is a comment for arg 5}}
/>
{{!-- Prettier main --}}
<MyComponent
  {{! this is a comment for arg 1}}
  @arg1="hello"
  {{on "clik" this.modify}}
  @arg2="hello"
  {{! this is a comment for arg 3}}
  @arg3="hello"
  @arg4="hello"
  {{! this is a comment for arg 5}}
  @arg5="hello"
  ...arguments
/>

Track cursor position properly when it’s at the end of the range to format (#10938 by @j-f1)

Previously, if the cursor was at the end of the range to format, it would simply be placed back at the end of the updated range.
Now, it will be repositioned if Prettier decides to add additional code to the end of the range (such as a semicolon).

// Input (<|> represents the cursor)
const someVariable = myOtherVariable<|>
// range to format:  ^^^^^^^^^^^^^^^

// Prettier stable
const someVariable = myOtherVariable;<|>
// range to format:  ^^^^^^^^^^^^^^^

// Prettier main
const someVariable = myOtherVariable<|>;
// range to format:  ^^^^^^^^^^^^^^^

Break the LHS of type alias that has complex type parameters (#10901 by @sosukesuzuki)

// Input
type FieldLayoutWith<
  T extends string,
  S extends unknown = { width: string }
> = {
  type: T;
  code: string;
  size: S;
};

// Prettier stable
type FieldLayoutWith<T extends string, S extends unknown = { width: string }> =
  {
    type: T;
    code: string;
    size: S;
  };

// Prettier main
type FieldLayoutWith<
  T extends string,
  S extends unknown = { width: string }
> = {
  type: T;
  code: string;
  size: S;
};

Break the LHS of assignments that has complex type parameters (#10916 by @sosukesuzuki)

// Input
const map: Map<
  Function,
  Map<string | void, { value: UnloadedDescriptor }>
> = new Map();

// Prettier stable
const map: Map<Function, Map<string | void, { value: UnloadedDescriptor }>> =
  new Map();

// Prettier main
const map: Map<
  Function,
  Map<string | void, { value: UnloadedDescriptor }>
> = new Map();

Fix incorrectly wrapped arrow functions with return types (#10940 by @thorn0)

// Input
longfunctionWithCall12("bla", foo, (thing: string): complex<type<something>> => {
  code();
});

// Prettier stable
longfunctionWithCall12("bla", foo, (thing: string): complex<
  type<something>
> => {
  code();
});

// Prettier main
longfunctionWithCall12(
  "bla",
  foo,
  (thing: string): complex<type<something>> => {
    code();
  }
);

Avoid breaking call expressions after assignments with complex type arguments (#10949 by @sosukesuzuki)

// Input
const foo = call<{
  prop1: string;
  prop2: string;
  prop3: string;
}>();

// Prettier stable
const foo =
  call<{
    prop1: string;
    prop2: string;
    prop3: string;
  }>();

// Prettier main
const foo = call<{
  prop1: string;
  prop2: string;
  prop3: string;
}>();

Fix order of override modifiers (#10961 by @sosukesuzuki)

// Input
class Foo extends Bar {
  abstract override foo: string;
}

// Prettier stable
class Foo extends Bar {
  abstract override foo: string;
}

// Prettier main
class Foo extends Bar {
  abstract override foo: string;
}

prettier 2.3.0

diff

🔗 Release Notes

prettier 2.2.1

diff

Fix formatting for AssignmentExpression with ClassExpression (#9741 by @sosukesuzuki)

// Input
module.exports = class A extends B {
  method() {
    console.log("foo");
  }
};

// Prettier 2.2.0
module.exports = class A extends (
  B
) {
  method() {
    console.log("foo");
  }
};

// Prettier 2.2.1
module.exports = class A extends B {
  method() {
    console.log("foo");
  }
};

prettier 2.2.0

diff

🔗 Release Notes

prettier 2.1.2

diff

Fix formatting for directives in fields (#9116 by @sosukesuzuki)

# Input
type Query {
  someQuery(id: ID!, someOtherData: String!): String! @deprecated @isAuthenticated
  versions: Versions!
}


# Prettier stable
type Query {
  someQuery(id: ID!, someOtherData: String!): String!
  @deprecated
  @isAuthenticated
  versions: Versions!
}

# Prettier master
type Query {
  someQuery(id: ID!, someOtherData: String!): String!
    @deprecated
    @isAuthenticated
  versions: Versions!
}

Fix line breaks for CSS in JS (#9136 by @sosukesuzuki)

// Input
styled.div`
  // prettier-ignore
  @media (aaaaaaaaaaaaa) {
	z-index: ${(props) => (props.isComplete ? '1' : '0')};
  }
`;
styled.div`
  ${props => getSize(props.$size.xs)}
  ${props => getSize(props.$size.sm, 'sm')}
  ${props => getSize(props.$size.md, 'md')}
`;

// Prettier stable
styled.div`
  // prettier-ignore
  @media (aaaaaaaaaaaaa) {
	z-index: ${(props) =>
    props.isComplete ? "1" : "0"};
  }
`;
styled.div`
  ${(props) => getSize(props.$size.xs)}
  ${(props) => getSize(props.$size.sm, "sm")}
  ${(props) =>
    getSize(props.$size.md, "md")}
`;

// Prettier master
styled.div`
  // prettier-ignore
  @media (aaaaaaaaaaaaa) {
        z-index: ${(props) => (props.isComplete ? "1" : "0")};
  }
`;
styled.div`
  ${(props) => getSize(props.$size.xs)}
  ${(props) => getSize(props.$size.sm, "sm")}
  ${(props) => getSize(props.$size.md, "md")}
`;

Fix comment printing in mapping and sequence (#9143, #9169 by @sosukesuzuki, @fisker, fix in yaml-unist-parser by @ikatyang)

# Input
- a
  # Should indent
- bb

---
- a: a
  b: b

  # Should print one empty line before
- another

# Prettier stable
- a
# Should indent
- bb

---
- a: a
  b: b


  # Should print one empty line before
- another

# Prettier master
- a
  # Should indent
- bb

---
- a: a
  b: b

  # Should print one empty line before
- another

prettier 2.1.1

diff

Fix format on html with frontMatter (#9043 by @fisker)

<!-- Input -->
---
layout: foo
---

Test <a
href="https://prettier.io">abc</a>.

<!-- Prettier stable -->
TypeError: Cannot read property 'end' of undefined
  ...

<!-- Prettier master -->
---
layout: foo
---

Test <a href="https://prettier.io">abc</a>.

Fix broken format for ...infer T (#9044 by @fisker)

// Input
type Tail<T extends any[]> = T extends [infer U, ...infer R] ? R : never;

// Prettier stable
type Tail<T extends any[]> = T extends [infer U, ...(infer R)] ? R : never;

// Prettier master
type Tail<T extends any[]> = T extends [infer U, ...infer R] ? R : never;

Fix format on style[lang="sass"] (#9051 by @fisker)

<!-- Input -->
<style lang="sass">
.hero
  @include background-centered
</style>

<!-- Prettier stable -->
<style lang="sass">
.hero @include background-centered;
</style>

<!-- Prettier master -->
<style lang="sass">
  .hero
    @include background-centered
</style>

Fix self-closing blocks and blocks with src attribute format (#9052, #9055 by @fisker)

<!-- Input -->
<custom lang="markdown" src="./foo.md"></custom>
<custom lang="markdown" src="./foo.md" />
<custom lang="markdown" />

<!-- Prettier stable -->
<custom lang="markdown" src="./foo.md">

</custom>
<custom lang="markdown" src="./foo.md"

/>
<custom lang="markdown"

/>

<!-- Prettier master -->
<custom lang="markdown" src="./foo.md"></custom>
<custom lang="markdown" src="./foo.md" />
<custom lang="markdown" />

prettier 2.1.0

diff

🔗 Release Notes