Skip to content

Instantly share code, notes, and snippets.

@pansila
Last active August 28, 2018 04:00
Show Gist options
  • Select an option

  • Save pansila/8fcd90aa66ce763b9d63a5bbda485d04 to your computer and use it in GitHub Desktop.

Select an option

Save pansila/8fcd90aa66ce763b9d63a5bbda485d04 to your computer and use it in GitHub Desktop.
Patch of cpplint to filter whitespace/braces for opening brace of C function
diff --git a/cpplint.py b/cpplint.py
index 95c0c32..fc8f6ba 100755
--- a/cpplint.py
+++ b/cpplint.py
@@ -3897,6 +3897,8 @@ def CheckBraces(filename, clean_lines, linenum, error):
# within the 80 character limit of the preceding line.
prevline = GetPreviousNonBlankLine(clean_lines, linenum)[0]
if (not Search(r'[,;:}{(]\s*$', prevline) and
+ # test a C function definition
+ not Search(r'(void\s*|\(\s*|\w+(\s+\**\w+)+(,\s*\w+(\s+\**\w+)+)*\s*)\)', prevline) and
not Match(r'\s*#', prevline) and
not (GetLineWidth(prevline) > _line_length - 2 and '[]' in prevline)):
error(filename, linenum, 'whitespace/braces', 4,
@pansila
Copy link
Copy Markdown
Author

pansila commented Aug 16, 2018

Test cases:

int foo()
{
int foo(void)
{
int foo(junk)  // warning for if/switch/while/...
{
int foo(int a)
{
int foo(int *a)
{
int foo(int *a, int b)
{
int foo(struct ssss *a, int b)
{
int foo(struct ssss *a,int b)
{
int foo(struct  ssss  *a,  int  b )
{
int foo(struct ssss *a,
		int b)
{

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