clang-format 3.9 でファイルやディレクトリを無視する方法 質問する

clang-format 3.9 でファイルやディレクトリを無視する方法 質問する

現在、私は travis ci を使用して、github に届いたパッチをチェックしており、変更をスキャンするときにディレクトリまたはファイル全体を無視するために clang-format 3.9 (travis ci は現在、最新として ubuntu 14.04 のみをサポートしているため) で方法があるかどうかを調べようとしています。

私の .travis.yml ファイル:

language: c++
sudo: required
dist: trusty
install:
- sudo apt-get update
- sudo apt-get install clang-format-3.9 python3
- ./travisci/check_patch.py

私の travisci/check_patch.py​​ ファイル:

#!/usr/bin/env python3

from subprocess import Popen, PIPE, STDOUT

# Run clang to check if code changes cause a diff output and return 1 if so.
cmd = "git show origin/master..@ | clang-format-diff-3.9 -p 1 -style=file"
diff = Popen(cmd, stdout=PIPE, shell=True).communicate()[0]
if diff:
    print("Code formatting is not according to style guidelines. Read https://github.com/intel/IA-Hardware-Composer/wiki/Contributions#coding_style")
    exit(1)

exit(0)

ベストアンサー1

個人ファイル番号、 しかしディレクトリ、はい

言われるようにここ.clang-formatフォーマットしないファイルが含まれているフォルダー内に新しい -file を置くことができます。

例: 次のようなヘッダーのみのライブラリを含むプロジェクトがあります。cppzmqそして私はただ私のライブラリを更新するときに、差分を小さく保つためにソース ファイルをフォーマットする必要があります。そのため、次のようなレイアウトを作成します。

project/
├ include/
│ ├ 3rdparty/
│ │ ├ .clang-format   (1)
│ │ └ zmq.hpp
│ └ my_app.hpp
├ src/
│ └ my_app.cpp
└ .clang-format       (2)

どこ初め .clang-format保持:

{
    "DisableFormat": true,
    "SortIncludes": "Never"  // with clang-format version < 13 use `false` here.
}

( DisableFormatinclude-sorting を無効にしないようですので、明示的に指定する必要があります。)

2番 .clang-format通常の clang 形式の設定を保持します。

グローバル/プロジェクトレベルのclang-formatのstyle設定が次のように設定されていることを確認してください。File


編集: clang-format が 2 行目の値が無効であると報告する場合は、末尾にコンマを追加します。

{
    "DisableFormat": true,
    "SortIncludes": "Never",
}

または、JSON の代わりに YAML 構文を使用します。

DisableFormat: true
SortIncludes: Never

おすすめ記事