Skip to content
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
31 changes: 31 additions & 0 deletions .changeset/trailing-newline-option.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
"@biomejs/biome": minor
---

Added the formatter option [`trailingNewline`](https://biomejs.dev/reference/configuration/#formattertrailingnewline).

When set to `false`, the formatter will remove the trailing newline at the end of formatted files. The default value is `true`, which preserves the current behavior of adding a trailing newline.

This option is available globally and for each language-specific formatter configuration:

```json
{
"formatter": {
"trailingNewline": false
},
"javascript": {
"formatter": {
"trailingNewline": true
}
}
}
```

The following CLI flags have been added. They accept `true` or `false` as value:
- `--formatter-trailing-newline`
- `--javascript-formatter-trailing-newline`
- `--json-formatter-trailing-newline`
- `--graphql-formatter-trailing-newline`
- `--css-formatter-trailing-newline`
- `--html-formatter-trailing-newline`

11 changes: 11 additions & 0 deletions .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"permissions": {
"allow": [
"Bash(cargo clippy:*)",
"Bash(cargo t:*)",
"Bash(cargo clean:*)"
],
"deny": [],
"ask": []
}
}
8 changes: 4 additions & 4 deletions crates/biome_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,16 +310,16 @@ pub enum BiomeCommand {
#[bpaf(external(json_parser_configuration), optional, hide_usage)]
json_parser: Option<JsonParserConfiguration>,

#[bpaf(external(css_parser_configuration), optional, hide_usage, hide)]
#[bpaf(external(css_parser_configuration), optional, hide_usage)]
css_parser: Option<CssParserConfiguration>,

#[bpaf(external(graphql_formatter_configuration), optional, hide_usage, hide)]
#[bpaf(external(graphql_formatter_configuration), optional, hide_usage)]
graphql_formatter: Option<GraphqlFormatterConfiguration>,

#[bpaf(external(css_formatter_configuration), optional, hide_usage, hide)]
#[bpaf(external(css_formatter_configuration), optional, hide_usage)]
css_formatter: Option<CssFormatterConfiguration>,

#[bpaf(external(html_formatter_configuration), optional, hide_usage, hide)]
#[bpaf(external(html_formatter_configuration), optional, hide_usage)]
html_formatter: Option<HtmlFormatterConfiguration>,

#[bpaf(external(vcs_configuration), optional, hide_usage)]
Expand Down
2 changes: 2 additions & 0 deletions crates/biome_cli/src/execute/migrate/prettier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ impl TryFrom<PrettierConfiguration> for biome_configuration::Configuration {
// editorconfig support is intentionally set to true, because prettier always reads the editorconfig file
// see: https://github.com/prettier/prettier/issues/15255
use_editorconfig: Some(true.into()),
trailing_newline: None,
};
result.formatter = Some(formatter);

Expand Down Expand Up @@ -278,6 +279,7 @@ impl TryFrom<PrettierConfiguration> for biome_configuration::Configuration {
jsx_quote_style: Some(jsx_quote_style),
attribute_position: Some(AttributePosition::default()),
operator_linebreak: None,
trailing_newline: None,
};
let js_config = biome_configuration::JsConfiguration {
formatter: Some(js_formatter),
Expand Down
1 change: 1 addition & 0 deletions crates/biome_cli/src/runner/impls/process_file/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ impl ProcessFile for FormatProcessFile {
execution: _,
skip_ignore_check,
} = payload;

let FileFeaturesResult {
features_supported: file_features,
} = workspace.file_features(SupportsFeatureParams {
Expand Down
47 changes: 47 additions & 0 deletions crates/biome_cli/tests/cases/editorconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,3 +698,50 @@ fn indent_size_can_set_to_tab() {
result,
));
}

#[test]
fn should_support_insert_final_newline() {
let fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

let editorconfig = Utf8Path::new(".editorconfig");
fs.insert(
editorconfig.into(),
r#"
[*]
insert_final_newline = false
"#,
);

let biomeconfig = Utf8Path::new("biome.json");
fs.insert(
biomeconfig.into(),
r#"{
"formatter": {
"useEditorconfig": true
}
}
"#,
);

let test_file = Utf8Path::new("test.js");
let contents = r#"function test() {
console.log("no newline")}"#;
fs.insert(test_file.into(), contents);

let (fs, result) = run_cli(
fs,
&mut console,
Args::from(["format", test_file.as_str()].as_slice()),
);

assert!(result.is_err(), "run_cli returned {result:?}");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"should_support_insert_final_newline",
fs,
console,
result,
));
}
Loading
Loading