Shawn Yu
Shawn Yu

Reputation: 43

How to make Clang-format ignore comments

/* xxx/xxx.c 
 * 
 * This file is part of xxx. 
 * 
 * xxx is free software: you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation, either version 3 of the License, or 
 * (at your option) any later version. 
 * 
 * xxx is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
 * GNU General Public License for more details. 
 * 
 * You should have received a copy of the GNU General Public License 
 * along with xxx. If not, see <https://www.gnu.org/licenses/>
 */ 

this comment is at the beginning of my code, but clang-format will trail space at the end of each line. how to make clang-format ignore comments?

Upvotes: 3

Views: 1818

Answers (1)

Wu Xiliang
Wu Xiliang

Reputation: 326

You can disable formatting on a piece of code using // clang-format off and then using // clang-format on to turn it on again.

// clang-format off

/* xxx/xxx.c 
 * 
 * This file is part of xxx. 
 * 
 * tripl is free software: you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation, either version 3 of the License, or 
 * (at your option) any later version. 
 * 
 * tripl is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
 * GNU General Public License for more details. 
 * 
 * You should have received a copy of the GNU General Public License 
 * along with xxx. If not, see <https://www.gnu.org/licenses/>
 */ 

// clang-format on

Upvotes: 4

Related Questions