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

added yaml configuration which refers to add break before comments fo… #698

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ prettierx <options> <file(s)>
- `--no-object-curly-spacing` (`objectCurlySpacing: false`): Disable spaces between object curly braces (similar to the corresponding eslint option).
- `--no-graphql-curly-spacing` (`graphqlCurlySpacing: false`): Disable spaces between curly braces for GraphQL.
- `--no-yaml-bracket-spacing` (`yamlBracketSpacing: false`): Disable spaces between brackets / curly braces for YAML.
- `--no-yaml-break-before-comment` (`yamlBreakBeforeComment: false`): Put or remove line break before comment section.
- `--no-type-curly-spacing` (`typeCurlySpacing: false`): Disable spaces between type curly braces.

(See [`docs/options.md`](docs/options.md) for more information.)
Expand Down
8 changes: 8 additions & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,14 @@ Put or disable spaces between brackets / curly braces for YAML.
| ------- | --------------------------- | ---------------------------- |
| `true` | `--no-yaml-bracket-spacing` | `yamlBracketSpacing: <bool>` |

## YAML line break before comment

Put or remove line breaked before comment section for YAML.

| Default | CLI Override | API Override |
| ------- | --------------------------- | ---------------------------- |
| `false` | `--no-yaml-break-before-comment` | `yamlBreakBeforeComment: <bool>` |

## Type curly spacing

Put or disable spaces between type curly braces.
Expand Down
8 changes: 8 additions & 0 deletions src/language-yaml/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,12 @@ module.exports = {
oppositeDescription:
"Do not put spaces between brackets / curly braces for YAML.",
},
yamlBreakBeforeComment: {
category: "Other",
type: "boolean",
default: false,
description: "Put or remove line breaked before comment section for YAML.",
oppositeDescription:
"Do not put line break before comment section for YAML.",
},
};
3 changes: 2 additions & 1 deletion src/language-yaml/printer-yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const {
} = require("./print/flow-mapping-sequence");
const printMappingItem = require("./print/mapping-item");
const printBlock = require("./print/block");
const { yamlBreakBeforeComment } = require("./options");

function genericPrint(path, options, print) {
const node = path.getValue();
Expand Down Expand Up @@ -91,7 +92,7 @@ function genericPrint(path, options, print) {

if (hasMiddleComments(node)) {
parts.push([
node.middleComments.length === 1 ? "" : hardline,
node.middleComments.length === 1 && !yamlBreakBeforeComment ? "" : hardline,
join(hardline, path.map(print, "middleComments")),
hardline,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ proseWrap: "always"
123

=====================================output=====================================
!!str #comment
!!str
#comment
>
123

Expand All @@ -242,7 +243,8 @@ printWidth: 80
123

=====================================output=====================================
!!str #comment
!!str
#comment
>
123

Expand Down
Loading