-
-
Notifications
You must be signed in to change notification settings - Fork 934
fix: --stdin-file-path with nested configuration
#8239
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
Open
cormacrelf
wants to merge
6
commits into
biomejs:main
Choose a base branch
from
cormacrelf:fix-stdin-nested-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f6a33be
Improve e2e test runner, can now run from workspace root and filter t…
cormacrelf d8314c2
Ignore e2e-tests from root biome.json
cormacrelf b9de5f1
Fix stdin path not being joined with workdir
cormacrelf 0565221
Add e2e-tests/stdin-nested-config
cormacrelf 46e8fc6
Warn when --stdin-file-path is an ignored path
cormacrelf 290e75a
Add a changeset
cormacrelf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| --- | ||
| "@biomejs/biome": patch | ||
| --- | ||
|
|
||
| Fixed [#8233](https://github.com/biomejs/biome/issues/8233), where Biome CLI in | ||
| stdin mode didn't work correctly when handling files in projects with nested | ||
| configurations. For example, with the following structure, | ||
| `--stdin-file-path=subdirectory/...` would not use the nested configuration in | ||
| `subdirectory/biome.json`: | ||
|
|
||
| ``` | ||
| ├── biome.json | ||
| └── subdirectory | ||
| ├── biome.json | ||
| └── lib.js | ||
| ``` | ||
|
|
||
| ```shell | ||
| biome format --write --stdin-file-path=subdirectory/lib.js < subdirectory/lib.js | ||
| ``` | ||
|
|
||
| Now, the nested configuration is correctly picked up and applied. | ||
|
|
||
| In addition, Biome now shows a warning if `--stdin-file-path` is provided but | ||
| that path is ignored and therefore not formatted or fixed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "root": false, | ||
| "root": true, | ||
| "files": { | ||
| "includes": ["**", "!file.js"] | ||
| }, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "root": false, | ||
| "root": true, | ||
| "files": { | ||
| "includes": ["**"] | ||
| }, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| let x = 5; | ||
|
|
||
| function indent() { | ||
| return x; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| let x = 5; | ||
|
|
||
| function indent() { | ||
| return x; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "root": true, | ||
| "vcs": { | ||
| "enabled": false | ||
| }, | ||
| "files": { | ||
| "ignoreUnknown": false, | ||
| // Include .js recursively, but not .ts | ||
| "includes": ["**/biome.jsonc", "**/*.js"] | ||
| }, | ||
| "formatter": { | ||
| "enabled": true, | ||
| "indentStyle": "space", | ||
| "indentWidth": 4 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| let x = 10; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "root": false, | ||
| "extends": "//", | ||
| "files": { | ||
| // This should be relative to the location of this config file, so we should not touch root/donotformat.ts | ||
| "includes": ["*.ts"] | ||
| }, | ||
| "formatter": { | ||
| "indentStyle": "space", | ||
| "indentWidth": 2 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| let y = 65; | ||
|
|
||
| function indent() { | ||
| return y; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| let y = 65; | ||
|
|
||
| function indent() { | ||
| return y; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| let y = 65; | ||
|
|
||
| function indent() { | ||
| return y; | ||
| } |
5 changes: 5 additions & 0 deletions
5
e2e-tests/stdin-nested-config/subdirectory/typed.ts.formatted
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| let y = 65; | ||
|
|
||
| function indent() { | ||
| return y; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| TEMP=$(mktemp) | ||
| trap 'rm -f $TEMP' EXIT | ||
|
|
||
| biome() { | ||
| cargo run --bin biome -- "$@" | ||
| } | ||
|
|
||
| STATUS=0 | ||
| diff_stdin_filepath() { | ||
| biome format --stdin-file-path="$1" < "$1" > "$TEMP" | ||
| if ! git diff --no-index "$1.formatted" "$TEMP"; then | ||
| STATUS=1 | ||
| fi | ||
| } | ||
|
|
||
| diff_stdin_filepath app.js | ||
| diff_stdin_filepath subdirectory/lib.js | ||
| diff_stdin_filepath subdirectory/typed.ts | ||
|
|
||
| biome format --stdin-file-path="donotformat.ts" < "donotformat.ts" > "$TEMP" | ||
| if ! git diff --no-index "donotformat.ts" "$TEMP"; then | ||
| STATUS=1 | ||
| fi | ||
|
|
||
| exit $STATUS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,35 @@ | ||
| #!/bin/sh | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Usage: | ||
| # ./test-all.sh | ||
| # ./test-all.sh stdin # to filter tests by name | ||
|
|
||
| set -eu | ||
|
|
||
| # Change to the script's directory | ||
| cd "$(dirname "$0")" | ||
|
|
||
| # Glob matcher | ||
| if [[ -z "${1:-}" ]]; then FILTER="*"; else FILTER="*$1*"; fi | ||
|
|
||
| redecho() { | ||
| echo -e "\033[1;31m$1\033[0m" | ||
| } | ||
|
|
||
| bail() { | ||
| redecho "Error: $1" | ||
| exit 1 | ||
| } | ||
|
|
||
| for x in *; do | ||
| if test -d "$x"; then | ||
| if [[ "$x" != $FILTER ]]; then | ||
| echo "Skipping $x" | ||
| continue | ||
| fi | ||
| echo "Testing $x..." | ||
| cd "$x" | ||
| sh test.sh | ||
| cd .. | ||
| pushd "$x" > /dev/null | ||
| bash test.sh || bail "Test failed: $x. To re-run: $0 $x" | ||
| popd > /dev/null | ||
| fi | ||
| done |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This operation might not be safe, because
stdin.as_pathmight be an absolute path. We should check it before running thejoinoperationThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost every path library I can think of, including camino, replaces the original path when you
.join(absolute).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well there may be an edge case where the working dir has a symlink in it somewhere and someone passes an absolute path that resolves to the same file ultimately, but does not appear to be inside any project. But I am not sure we care.