From f85696333a7e80e30a7f05770379ef0b62f9e52a Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Wed, 29 Jan 2025 22:06:14 -0500 Subject: [PATCH 1/4] don't err on non-const reference by default --- cpplint.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cpplint.py b/cpplint.py index 79a16f25..a4b4676d 100755 --- a/cpplint.py +++ b/cpplint.py @@ -414,6 +414,7 @@ _DEFAULT_FILTERS = [ '-build/include_alpha', '-readability/fn_size', + '-runtime/references', ] # The default list of categories suppressed for C (not C++) files. From 404f56e5255216e20f7b5e1b027940b64a91eb0e Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Fri, 7 Mar 2025 19:26:28 -0500 Subject: [PATCH 2/4] fix tests --- samples/codelite-sample/simple.def | 12 +----------- samples/silly-sample/cfg.def | 7 +------ samples/silly-sample/filters.def | 9 ++------- samples/silly-sample/includeorder_cfirst.def | 7 +------ samples/silly-sample/sed.def | 5 ----- samples/silly-sample/simple.def | 7 +------ 6 files changed, 6 insertions(+), 41 deletions(-) diff --git a/samples/codelite-sample/simple.def b/samples/codelite-sample/simple.def index 012d3bc9..069767f0 100644 --- a/samples/codelite-sample/simple.def +++ b/samples/codelite-sample/simple.def @@ -3,7 +3,7 @@ src/* 4 Done processing src/pptable.cpp Done processing src/pptable.h -Total errors found: 685 +Total errors found: 675 src/pptable.cpp:0: No copyright message found. You should have a line: "Copyright [year] " [legal/copyright] [5] src/pptable.cpp:1: Include the directory when naming header files [build/include_subdir] [4] @@ -496,7 +496,6 @@ src/pptable.cpp:534: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.cpp:538: { should almost always be at the end of the previous line [whitespace/braces] [4] src/pptable.cpp:539: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.cpp:542: Lines should be <= 80 characters long [whitespace/line_length] [2] -src/pptable.cpp:542: Is this a non-const reference? If so, make const or use a pointer: wxString &outStr [runtime/references] [2] src/pptable.cpp:543: { should almost always be at the end of the previous line [whitespace/braces] [4] src/pptable.cpp:544: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.cpp:545: Tab found; better to use spaces [whitespace/tab] [1] @@ -534,7 +533,6 @@ src/pptable.cpp:578: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.cpp:579: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.cpp:582: Static/global string variables are not permitted. [runtime/string] [4] src/pptable.cpp:584: Lines should be <= 80 characters long [whitespace/line_length] [2] -src/pptable.cpp:584: Is this a non-const reference? If so, make const or use a pointer: std::string& outStr [runtime/references] [2] src/pptable.cpp:585: { should almost always be at the end of the previous line [whitespace/braces] [4] src/pptable.cpp:586: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.cpp:587: Tab found; better to use spaces [whitespace/tab] [1] @@ -621,9 +619,7 @@ src/pptable.h:30: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.h:31: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.h:32: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.h:49: Lines should be <= 80 characters long [whitespace/line_length] [2] -src/pptable.h:49: Is this a non-const reference? If so, make const or use a pointer: wxString &output [runtime/references] [2] src/pptable.h:63: Lines should be <= 80 characters long [whitespace/line_length] [2] -src/pptable.h:63: Is this a non-const reference? If so, make const or use a pointer: std::string& outStr [runtime/references] [2] src/pptable.h:69: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.h:70: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.h:71: Tab found; better to use spaces [whitespace/tab] [1] @@ -646,15 +642,10 @@ src/pptable.h:88: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.h:89: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.h:90: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.h:91: Tab found; better to use spaces [whitespace/tab] [1] -src/pptable.h:91: Is this a non-const reference? If so, make const or use a pointer: wxFFile &fp [runtime/references] [2] src/pptable.h:92: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.h:92: Lines should be <= 80 characters long [whitespace/line_length] [2] -src/pptable.h:92: Is this a non-const reference? If so, make const or use a pointer: wxString& initList [runtime/references] [2] -src/pptable.h:92: Is this a non-const reference? If so, make const or use a pointer: wxArrayString &initListArr [runtime/references] [2] src/pptable.h:93: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.h:93: Lines should be <= 80 characters long [whitespace/line_length] [2] -src/pptable.h:93: Is this a non-const reference? If so, make const or use a pointer: std::string& initList [runtime/references] [2] -src/pptable.h:93: Is this a non-const reference? If so, make const or use a pointer: std::vector &initListArr [runtime/references] [2] src/pptable.h:94: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.h:95: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.h:96: Tab found; better to use spaces [whitespace/tab] [1] @@ -676,7 +667,6 @@ src/pptable.h:115: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.h:115: Extra space before ( in function call [whitespace/parens] [4] src/pptable.h:116: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.h:117: Tab found; better to use spaces [whitespace/tab] [1] -src/pptable.h:117: Is this a non-const reference? If so, make const or use a pointer: wxFFile &fp [runtime/references] [2] src/pptable.h:118: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.h:119: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.h:120: Tab found; better to use spaces [whitespace/tab] [1] diff --git a/samples/silly-sample/cfg.def b/samples/silly-sample/cfg.def index 9e3b03ee..b0e424df 100644 --- a/samples/silly-sample/cfg.def +++ b/samples/silly-sample/cfg.def @@ -3,22 +3,17 @@ 4 Done processing src/sillycode.cpp Done processing src/sillycode.w -Total errors found: 26 +Total errors found: 21 src/sillycode.cpp:0: No copyright message found. You should have a line: "Copyright [year] " [legal/copyright] [5] src/sillycode.cpp:2: is an unapproved C++11 header. [build/c++11] [5] src/sillycode.cpp:3: Found C system header after other header. Should be: sillycode.h, c system, c++ system, other. [build/include_order] [4] src/sillycode.cpp:4: Found C system header after other header. Should be: sillycode.h, c system, c++ system, other. [build/include_order] [4] -src/sillycode.cpp:14: Is this a non-const reference? If so, make const or use a pointer: vector& v [runtime/references] [2] src/sillycode.cpp:40: If/else bodies with multiple statements require braces [readability/braces] [4] src/sillycode.cpp:66: Single-parameter constructors should be marked explicit. [runtime/explicit] [4] src/sillycode.cpp:76: Single-parameter constructors should be marked explicit. [runtime/explicit] [4] src/sillycode.cpp:85: Constructors callable with one argument should be marked explicit. [runtime/explicit] [4] src/sillycode.cpp:86: Lines should be <= 80 characters long [whitespace/line_length] [2] -src/sillycode.cpp:118: Is this a non-const reference? If so, make const or use a pointer: N::X& a [runtime/references] [2] -src/sillycode.cpp:118: Is this a non-const reference? If so, make const or use a pointer: N::X& b [runtime/references] [2] -src/sillycode.cpp:123: Is this a non-const reference? If so, make const or use a pointer: N::X& a [runtime/references] [2] -src/sillycode.cpp:123: Is this a non-const reference? If so, make const or use a pointer: N::X& b [runtime/references] [2] src/sillycode.cpp:171: Do not use variable-length arrays. Use an appropriately named ('k' followed by CamelCase) compile-time constant for the size. [runtime/arrays] [1] src/sillycode.cpp:178: Static/global string variables are not permitted. [runtime/string] [4] src/sillycode.cpp:199: If an else has a brace on one side, it should have it on both [readability/braces] [5] diff --git a/samples/silly-sample/filters.def b/samples/silly-sample/filters.def index fcdfbaa8..e0fac32e 100644 --- a/samples/silly-sample/filters.def +++ b/samples/silly-sample/filters.def @@ -5,8 +5,8 @@ Done processing src/sillycode.cpp Category 'build' errors found: 5 Category 'legal' errors found: 1 Category 'readability' errors found: 4 -Category 'runtime' errors found: 12 -Total errors found: 22 +Category 'runtime' errors found: 7 +Total errors found: 17 src/sillycode.cpp:0: No copyright message found. You should have a line: "Copyright [year] " [legal/copyright] [5] src/sillycode.cpp:1: Include the directory when naming header files [build/include_subdir] [4] @@ -14,15 +14,10 @@ src/sillycode.cpp:2: is an unapproved C++11 header. [build/c++11] [5] src/sillycode.cpp:3: Found C system header after other header. Should be: sillycode.h, c system, c++ system, other. [build/include_order] [4] src/sillycode.cpp:4: Found C system header after other header. Should be: sillycode.h, c system, c++ system, other. [build/include_order] [4] src/sillycode.cpp:5: Do not use namespace using-directives. Use using-declarations instead. [build/namespaces] [5] -src/sillycode.cpp:14: Is this a non-const reference? If so, make const or use a pointer: vector& v [runtime/references] [2] src/sillycode.cpp:40: If/else bodies with multiple statements require braces [readability/braces] [4] src/sillycode.cpp:66: Single-parameter constructors should be marked explicit. [runtime/explicit] [4] src/sillycode.cpp:76: Single-parameter constructors should be marked explicit. [runtime/explicit] [4] src/sillycode.cpp:85: Constructors callable with one argument should be marked explicit. [runtime/explicit] [4] -src/sillycode.cpp:118: Is this a non-const reference? If so, make const or use a pointer: N::X& a [runtime/references] [2] -src/sillycode.cpp:118: Is this a non-const reference? If so, make const or use a pointer: N::X& b [runtime/references] [2] -src/sillycode.cpp:123: Is this a non-const reference? If so, make const or use a pointer: N::X& a [runtime/references] [2] -src/sillycode.cpp:123: Is this a non-const reference? If so, make const or use a pointer: N::X& b [runtime/references] [2] src/sillycode.cpp:171: Do not use variable-length arrays. Use an appropriately named ('k' followed by CamelCase) compile-time constant for the size. [runtime/arrays] [1] src/sillycode.cpp:178: Static/global string variables are not permitted. [runtime/string] [4] src/sillycode.cpp:199: If an else has a brace on one side, it should have it on both [readability/braces] [5] diff --git a/samples/silly-sample/includeorder_cfirst.def b/samples/silly-sample/includeorder_cfirst.def index 84a3af5d..a3b30a48 100644 --- a/samples/silly-sample/includeorder_cfirst.def +++ b/samples/silly-sample/includeorder_cfirst.def @@ -2,7 +2,7 @@ 1 3 Done processing src/sillycode.cpp -Total errors found: 123 +Total errors found: 118 src/sillycode.cpp:0: No copyright message found. You should have a line: "Copyright [year] " [legal/copyright] [5] src/sillycode.cpp:1: Include the directory when naming header files [build/include_subdir] [4] @@ -13,7 +13,6 @@ src/sillycode.cpp:3: Found other system header after other header. Should be: s src/sillycode.cpp:4: Found other system header after other header. Should be: sillycode.h, c system, c++ system, other. [build/include_order] [4] src/sillycode.cpp:5: Do not use namespace using-directives. Use using-declarations instead. [build/namespaces] [5] src/sillycode.cpp:8: public: should be indented +1 space inside class Date [whitespace/indent] [3] -src/sillycode.cpp:14: Is this a non-const reference? If so, make const or use a pointer: vector& v [runtime/references] [2] src/sillycode.cpp:15: { should almost always be at the end of the previous line [whitespace/braces] [4] src/sillycode.cpp:39: { should almost always be at the end of the previous line [whitespace/braces] [4] src/sillycode.cpp:40: Tab found; better to use spaces [whitespace/tab] [1] @@ -43,15 +42,11 @@ src/sillycode.cpp:110: Tab found; better to use spaces [whitespace/tab] [1] src/sillycode.cpp:111: Tab found; better to use spaces [whitespace/tab] [1] src/sillycode.cpp:111: At least two spaces is best between code and comments [whitespace/comments] [2] src/sillycode.cpp:113: public: should be indented +1 space inside class Vector2 [whitespace/indent] [3] -src/sillycode.cpp:118: Is this a non-const reference? If so, make const or use a pointer: N::X& a [runtime/references] [2] -src/sillycode.cpp:118: Is this a non-const reference? If so, make const or use a pointer: N::X& b [runtime/references] [2] src/sillycode.cpp:119: { should almost always be at the end of the previous line [whitespace/braces] [4] src/sillycode.cpp:120: Tab found; better to use spaces [whitespace/tab] [1] src/sillycode.cpp:120: Missing space after , [whitespace/comma] [3] src/sillycode.cpp:122: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] src/sillycode.cpp:122: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] -src/sillycode.cpp:123: Is this a non-const reference? If so, make const or use a pointer: N::X& a [runtime/references] [2] -src/sillycode.cpp:123: Is this a non-const reference? If so, make const or use a pointer: N::X& b [runtime/references] [2] src/sillycode.cpp:124: { should almost always be at the end of the previous line [whitespace/braces] [4] src/sillycode.cpp:125: Tab found; better to use spaces [whitespace/tab] [1] src/sillycode.cpp:125: At least two spaces is best between code and comments [whitespace/comments] [2] diff --git a/samples/silly-sample/sed.def b/samples/silly-sample/sed.def index e4a40cce..b3778eeb 100644 --- a/samples/silly-sample/sed.def +++ b/samples/silly-sample/sed.def @@ -17,7 +17,6 @@ sed -i '249s/\([^ ]\){/\1 {/' src/sillycode.cpp # Missing space before { [white # src/sillycode.cpp:4: "Found C system header after other header. Should be: sillycode.h, c system, c++ system, other." [build/include_order] [4] # src/sillycode.cpp:5: "Do not use namespace using-directives. Use using-declarations instead." [build/namespaces] [5] # src/sillycode.cpp:8: "public: should be indented +1 space inside class Date" [whitespace/indent] [3] -# src/sillycode.cpp:14: "Is this a non-const reference? If so, make const or use a pointer: vector& v" [runtime/references] [2] # src/sillycode.cpp:15: "{ should almost always be at the end of the previous line" [whitespace/braces] [4] # src/sillycode.cpp:39: "{ should almost always be at the end of the previous line" [whitespace/braces] [4] # src/sillycode.cpp:40: "Tab found; better to use spaces" [whitespace/tab] [1] @@ -47,13 +46,9 @@ sed -i '249s/\([^ ]\){/\1 {/' src/sillycode.cpp # Missing space before { [white # src/sillycode.cpp:111: "Tab found; better to use spaces" [whitespace/tab] [1] # src/sillycode.cpp:111: "At least two spaces is best between code and comments" [whitespace/comments] [2] # src/sillycode.cpp:113: "public: should be indented +1 space inside class Vector2" [whitespace/indent] [3] -# src/sillycode.cpp:118: "Is this a non-const reference? If so, make const or use a pointer: N::X& a" [runtime/references] [2] -# src/sillycode.cpp:118: "Is this a non-const reference? If so, make const or use a pointer: N::X& b" [runtime/references] [2] # src/sillycode.cpp:119: "{ should almost always be at the end of the previous line" [whitespace/braces] [4] # src/sillycode.cpp:120: "Tab found; better to use spaces" [whitespace/tab] [1] # src/sillycode.cpp:122: "Weird number of spaces at line-start. Are you using a 2-space indent?" [whitespace/indent] [3] -# src/sillycode.cpp:123: "Is this a non-const reference? If so, make const or use a pointer: N::X& a" [runtime/references] [2] -# src/sillycode.cpp:123: "Is this a non-const reference? If so, make const or use a pointer: N::X& b" [runtime/references] [2] # src/sillycode.cpp:124: "{ should almost always be at the end of the previous line" [whitespace/braces] [4] # src/sillycode.cpp:125: "Tab found; better to use spaces" [whitespace/tab] [1] # src/sillycode.cpp:125: "At least two spaces is best between code and comments" [whitespace/comments] [2] diff --git a/samples/silly-sample/simple.def b/samples/silly-sample/simple.def index e9a3feeb..7bc1dc61 100644 --- a/samples/silly-sample/simple.def +++ b/samples/silly-sample/simple.def @@ -3,7 +3,7 @@ src/* 4 Done processing src/sillycode.cpp Done processing src/sillycode.w -Total errors found: 126 +Total errors found: 121 src/sillycode.cpp:0: No copyright message found. You should have a line: "Copyright [year] " [legal/copyright] [5] src/sillycode.cpp:1: Include the directory when naming header files [build/include_subdir] [4] @@ -14,7 +14,6 @@ src/sillycode.cpp:3: Found C system header after other header. Should be: silly src/sillycode.cpp:4: Found C system header after other header. Should be: sillycode.h, c system, c++ system, other. [build/include_order] [4] src/sillycode.cpp:5: Do not use namespace using-directives. Use using-declarations instead. [build/namespaces] [5] src/sillycode.cpp:8: public: should be indented +1 space inside class Date [whitespace/indent] [3] -src/sillycode.cpp:14: Is this a non-const reference? If so, make const or use a pointer: vector& v [runtime/references] [2] src/sillycode.cpp:15: { should almost always be at the end of the previous line [whitespace/braces] [4] src/sillycode.cpp:39: { should almost always be at the end of the previous line [whitespace/braces] [4] src/sillycode.cpp:40: Tab found; better to use spaces [whitespace/tab] [1] @@ -44,15 +43,11 @@ src/sillycode.cpp:110: Tab found; better to use spaces [whitespace/tab] [1] src/sillycode.cpp:111: Tab found; better to use spaces [whitespace/tab] [1] src/sillycode.cpp:111: At least two spaces is best between code and comments [whitespace/comments] [2] src/sillycode.cpp:113: public: should be indented +1 space inside class Vector2 [whitespace/indent] [3] -src/sillycode.cpp:118: Is this a non-const reference? If so, make const or use a pointer: N::X& a [runtime/references] [2] -src/sillycode.cpp:118: Is this a non-const reference? If so, make const or use a pointer: N::X& b [runtime/references] [2] src/sillycode.cpp:119: { should almost always be at the end of the previous line [whitespace/braces] [4] src/sillycode.cpp:120: Tab found; better to use spaces [whitespace/tab] [1] src/sillycode.cpp:120: Missing space after , [whitespace/comma] [3] src/sillycode.cpp:122: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3] src/sillycode.cpp:122: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] -src/sillycode.cpp:123: Is this a non-const reference? If so, make const or use a pointer: N::X& a [runtime/references] [2] -src/sillycode.cpp:123: Is this a non-const reference? If so, make const or use a pointer: N::X& b [runtime/references] [2] src/sillycode.cpp:124: { should almost always be at the end of the previous line [whitespace/braces] [4] src/sillycode.cpp:125: Tab found; better to use spaces [whitespace/tab] [1] src/sillycode.cpp:125: At least two spaces is best between code and comments [whitespace/comments] [2] From 7654e19c35eac7341d5243d11d4b4bf276948c7c Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Fri, 7 Mar 2025 20:08:13 -0500 Subject: [PATCH 3/4] Update CHANGELOG.rst --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 50db299e..ad27c2e7 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,6 +9,7 @@ Yet another overdue... hotfix. Sorry this took so long. * The false positive for indented function parameters in namespaces was eradicated. * build/include-what-you-use now recognizes c-style headers, such as for symbols from . (https://github.com/cpplint/cpplint/pull/306) +* The warning on non-const references (runtime/references) is now disabled by default pursuant to the May 2020 Google style guide update. (https://github.com/cpplint/cpplint/pull/305) 2.0 (2024-10-06) ================ From 142486fabe810afed0b4ef56b8604f5bb1b4854e Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Mon, 17 Mar 2025 00:51:16 +0000 Subject: [PATCH 4/4] quotability --- cpplint.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cpplint.py b/cpplint.py index c09e5974..61b11da6 100755 --- a/cpplint.py +++ b/cpplint.py @@ -407,9 +407,9 @@ # off by default (i.e., categories that must be enabled by the --filter= flags). # All entries here should start with a '-' or '+', as in the --filter= flag. _DEFAULT_FILTERS = [ - '-build/include_alpha', - '-readability/fn_size', - '-runtime/references', + "-build/include_alpha", + "-readability/fn_size", + "-runtime/references", ] # The default list of categories suppressed for C (not C++) files.