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

Add -style file:<path> option #156

Open
mrousavy opened this issue Sep 1, 2023 · 7 comments · May be fixed by #211
Open

Add -style file:<path> option #156

mrousavy opened this issue Sep 1, 2023 · 7 comments · May be fixed by #211

Comments

@mrousavy
Copy link

mrousavy commented Sep 1, 2023

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
Copy link
Author

mrousavy commented Sep 1, 2023

This is the log output:
image

@skashtanoff
Copy link

skashtanoff commented Jan 18, 2024

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
Copy link

@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!

@mrousavy
Copy link
Author

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.

@skashtanoff
Copy link

skashtanoff commented Jan 18, 2024

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

@picyg-intel
Copy link

picyg-intel commented Jul 9, 2024

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.

@jidicula
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants