clang-format-action icon indicating copy to clipboard operation
clang-format-action copied to clipboard

Add `-style file:<path>` option

Open mrousavy opened this issue 2 years ago • 7 comments

Hey! Thanks for your package.

I'm trying to use it in a project where my code is in a subdirectory:

- .github/
- README.md
- package/
    - cpp/.clang-format
    - cpp/...
    - package.json

I couldn't figure out how to properly configure the github action to use the .clang-format file in that directory. Here's my workflow:

jobs:
  lint:
    name: Check clang-format
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./package
    strategy:
      matrix:
        path:
          - 'cpp'
          - 'android/src/main/cpp'
          - 'ios'
    steps:
      - uses: actions/checkout@v2
      - name: Run clang-format style check
        uses: jidicula/[email protected]
        with:
          clang-format-version: '16'
          check-path: ${{ matrix.path }}
          fallback-style: file:./package/cpp/.clang-format

Any thoughts?

mrousavy avatar Sep 01 '23 15:09 mrousavy

This is the log output: image

mrousavy avatar Sep 01 '23 16:09 mrousavy

My project structure is

.github/
  workflows/
    format.yml
src/
.clang-format

But the action still uses llvm style as a basic one. I've tried to move .clang-format to src/, but this didnt help.

So I could figure out how to pass a path to .clang-format also.

Your comment was in 2023, maybe you found a solution @mrousavy?

skashtanoff avatar Jan 18 '24 09:01 skashtanoff

@jidicula

I guess it will be enougth to add a clang-format-file option, which will contain a path to a .clang-format. Then change this line

from

formatted="$(docker run -i -v "$(pwd)":"$(pwd)" -w "$(pwd)" --rm ghcr.io/jidicula/clang-format:"$CLANG_FORMAT_MAJOR_VERSION" --style=file --fallback-style="$FALLBACK_STYLE" "${filepath}")"

to smth like

formatted="$(docker run -i -v "$(pwd)":"$(pwd)" -w "$(pwd)" --rm ghcr.io/jidicula/clang-format:"$CLANG_FORMAT_MAJOR_VERSION" --style=file:$CLANG_FORMAT_FILE --fallback-style="$FALLBACK_STYLE" "${filepath}")"

It will be very helpful!

skashtanoff avatar Jan 18 '24 09:01 skashtanoff

I am using my fork: https://github.com/mrousavy/react-native-vision-camera/blob/50437b65682abda6a52b2363368b19aa8311772d/.github/workflows/validate-cpp.yml#L19-L36

Which simply removed the fallback style and replaced it with a custom style file: https://github.com/mrousavy/clang-format-action

I am not sure if I should create a PR for this here, since it basically removes the fallback style functionality. Idk why but those didn't work together very well in my experience.

mrousavy avatar Jan 18 '24 09:01 mrousavy

@mrousavy Thanks a lot, I'll check it ❤️

skashtanoff avatar Jan 18 '24 10:01 skashtanoff

I second this feature, would be really nice to have. We wanted to use this action, but ended up not using it because of missing style file option. We have monorepo with each dir having it's own .clang-format file.

picyg-intel avatar Jul 09 '24 09:07 picyg-intel

I am using my fork: https://github.com/mrousavy/react-native-vision-camera/blob/50437b65682abda6a52b2363368b19aa8311772d/.github/workflows/validate-cpp.yml#L19-L36

Which simply removed the fallback style and replaced it with a custom style file: https://github.com/mrousavy/clang-format-action

I am not sure if I should create a PR for this here, since it basically removes the fallback style functionality. Idk why but those didn't work together very well in my experience.

@mrousavy yes, definitely open a PR for this (idk why, but I hadn't seen your comment until now - sorry about that!). I'm not sure how useful fallback style even is.

jidicula avatar Jul 23 '24 01:07 jidicula