Skip to content

🐛 CLI setting --staged checks unstaged changes #3608

Closed as not planned
Closed as not planned

Description

@hrasekj

Environment information

CLI:
  Version:                      1.8.3
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           linux

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-color"
  JS_RUNTIME_VERSION:           "v20.12.2"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         unset

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           false
  Linter disabled:              false
  Organize imports disabled:    false
  VCS disabled:                 true

Workspace:
  Open Documents:               0

What happened?

Hello,

i have pre-commit hook in git which looks like this:

./node_modules/.bin/biome check --staged --no-errors-on-unmatched

The issue is that Biome checks staged files, but i have unstaged changes, that may cause linter error.

For now i ended up with this workaround:

# get staged file names
stage_files=$(git diff --cached --name-only)

err_output=""
# check each staged file via biome check
# @see https://biomejs.dev/reference/cli/
for file in $stage_files; do
    file_content=$(git show ":$file")
    err_output="$err_output"`echo "$file_content" | ./node_modules/.bin/biome lint --no-errors-on-unmatched --stdin-file-path="$file" 2>&1 > /dev/null`
done

if [ -n "$err_output" ]; then
    echo "$err_output"
    exit 1
fi

Expected result

Would be nice, that biome could have options like --staged-files and --staged-changes.

Code of Conduct

  • I agree to follow Biome's Code of Conduct

Activity

  1. ematipico commented on Aug 7, 2024

    @ematipico
    Member

    Can you provide a reproduction, or at least some steps to reproduce it locally?

  2. hrasekj commented on Aug 9, 2024

    @hrasekj
    Author

    Yes,

    • make some changes in file, that are ok with linter
    • git stage that file
    • make some changes in the same file, that you know will have lint error
    • now call biome lint --staged
    • You should obtain linter error on unstaged changes
  3. ematipico commented on Aug 14, 2024

    @ematipico
    Member

    @hrasekj this is the expected behaviour, because the VCS integration isn't enabled by default. Please refer to this page https://biomejs.dev/guides/integrate-in-vcs/

  4. hrasekj commented on Aug 14, 2024

    @hrasekj
    Author

    @ematipico I've also tested this behavior with VCS enabled, the result was the same.

    Ok, then i made gist for my pre-commit hook. Maybe it helps to someone with the same issue.
    https://gist.github.com/hrasekj/ec6eb27491643306aed3e04efbd1fda6

  5. ematipico commented on Aug 14, 2024

    @ematipico
    Member

    @ematipico I've also tested this behavior with VCS enabled, the result was the same.

    Sorry, that wasn't stated in your instructions. Please create a reproduction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    S-Needs reproStatus: needs a reproduction

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions