| OLD | NEW |
| 1 # -*- coding: utf-8; -*- | 1 # -*- coding: utf-8; -*- |
| 2 # | 2 # |
| 3 # Copyright (C) 2011 Google Inc. All rights reserved. | 3 # Copyright (C) 2011 Google Inc. All rights reserved. |
| 4 # Copyright (C) 2009 Torch Mobile Inc. | 4 # Copyright (C) 2009 Torch Mobile Inc. |
| 5 # Copyright (C) 2009 Apple Inc. All rights reserved. | 5 # Copyright (C) 2009 Apple Inc. All rights reserved. |
| 6 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) | 6 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) |
| 7 # | 7 # |
| 8 # Redistribution and use in source and binary forms, with or without | 8 # Redistribution and use in source and binary forms, with or without |
| 9 # modification, are permitted provided that the following conditions are | 9 # modification, are permitted provided that the following conditions are |
| 10 # met: | 10 # met: |
| (...skipping 2048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2059 'public:\n' | 2059 'public:\n' |
| 2060 ' enum Bar {\n' | 2060 ' enum Bar {\n' |
| 2061 ' Alpha,\n' | 2061 ' Alpha,\n' |
| 2062 ' Beta,\n' | 2062 ' Beta,\n' |
| 2063 '#if ENABLED_BETZ\n' | 2063 '#if ENABLED_BETZ\n' |
| 2064 ' Charlie,\n' | 2064 ' Charlie,\n' |
| 2065 '#endif\n' | 2065 '#endif\n' |
| 2066 ' };\n' | 2066 ' };\n' |
| 2067 '};', | 2067 '};', |
| 2068 '') | 2068 '') |
| 2069 self.assert_multi_line_lint( |
| 2070 'if (true) {\n' |
| 2071 ' myFunction(reallyLongParam1, reallyLongParam2,\n' |
| 2072 ' reallyLongParam3);\n' |
| 2073 '}\n', |
| 2074 'Weird number of spaces at line-start. Are you using a 4-space inde
nt? [whitespace/indent] [3]') |
| 2075 |
| 2076 self.assert_multi_line_lint( |
| 2077 'if (true) {\n' |
| 2078 ' myFunction(reallyLongParam1, reallyLongParam2,\n' |
| 2079 ' reallyLongParam3);\n' |
| 2080 '}\n', |
| 2081 'When wrapping a line, only indent 4 spaces. [whitespace/indent] [3
]') |
| 2082 |
| 2069 | 2083 |
| 2070 def test_not_alabel(self): | 2084 def test_not_alabel(self): |
| 2071 self.assert_lint('MyVeryLongNamespace::MyVeryLongClassName::', '') | 2085 self.assert_lint('MyVeryLongNamespace::MyVeryLongClassName::', '') |
| 2072 | 2086 |
| 2073 def test_tab(self): | 2087 def test_tab(self): |
| 2074 self.assert_lint('\tint a;', | 2088 self.assert_lint('\tint a;', |
| 2075 'Tab found; better to use spaces [whitespace/tab] [1]'
) | 2089 'Tab found; better to use spaces [whitespace/tab] [1]'
) |
| 2076 self.assert_lint('int a = 5;\t// set a to 5', | 2090 self.assert_lint('int a = 5;\t// set a to 5', |
| 2077 'Tab found; better to use spaces [whitespace/tab] [1]'
) | 2091 'Tab found; better to use spaces [whitespace/tab] [1]'
) |
| 2078 | 2092 |
| (...skipping 1921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4000 ' doSomethingElseAgain();\n' | 4014 ' doSomethingElseAgain();\n' |
| 4001 '}\n', | 4015 '}\n', |
| 4002 '') | 4016 '') |
| 4003 self.assert_multi_line_lint( | 4017 self.assert_multi_line_lint( |
| 4004 'if (condition)\n' | 4018 'if (condition)\n' |
| 4005 ' doSomething();\n' | 4019 ' doSomething();\n' |
| 4006 'else\n' | 4020 'else\n' |
| 4007 ' doSomethingElse();\n', | 4021 ' doSomethingElse();\n', |
| 4008 '') | 4022 '') |
| 4009 self.assert_multi_line_lint( | 4023 self.assert_multi_line_lint( |
| 4010 'if (condition)\n' | 4024 'if (condition) {\n' |
| 4011 ' doSomething();\n' | 4025 ' doSomething();\n' |
| 4012 'else {\n' | 4026 '} else {\n' |
| 4013 ' doSomethingElse();\n' | 4027 ' doSomethingElse();\n' |
| 4014 ' doSomethingElseAgain();\n' | 4028 ' doSomethingElseAgain();\n' |
| 4015 '}\n', | 4029 '}\n', |
| 4016 '') | 4030 '') |
| 4017 self.assert_multi_line_lint( | 4031 self.assert_multi_line_lint( |
| 4018 '#define TEST_ASSERT(expression) do { if (!(expression)) { TestsCont
roller::shared().testFailed(__FILE__, __LINE__, #expression); return; } } while
(0)\n', | 4032 '#define TEST_ASSERT(expression) do { if (!(expression)) { TestsCont
roller::shared().testFailed(__FILE__, __LINE__, #expression); return; } } while
(0)\n', |
| 4019 '') | 4033 '') |
| 4020 self.assert_multi_line_lint( | 4034 self.assert_multi_line_lint( |
| 4021 '#define TEST_ASSERT(expression) do { if ( !(expression)) { TestsCon
troller::shared().testFailed(__FILE__, __LINE__, #expression); return; } } while
(0)\n', | 4035 '#define TEST_ASSERT(expression) do { if ( !(expression)) { TestsCon
troller::shared().testFailed(__FILE__, __LINE__, #expression); return; } } while
(0)\n', |
| 4022 'Extra space after ( in if [whitespace/parens] [5]') | 4036 'Extra space after ( in if [whitespace/parens] [5]') |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4040 self.assert_multi_line_lint( | 4054 self.assert_multi_line_lint( |
| 4041 'if (condition) doSomething(); else doSomethingElse();\n', | 4055 'if (condition) doSomething(); else doSomethingElse();\n', |
| 4042 ['More than one command on the same line [whitespace/newline] [4]', | 4056 ['More than one command on the same line [whitespace/newline] [4]', |
| 4043 'Else clause should never be on same line as else (use 2 lines) [w
hitespace/newline] [4]', | 4057 'Else clause should never be on same line as else (use 2 lines) [w
hitespace/newline] [4]', |
| 4044 'More than one command on the same line in if [whitespace/parens]
[4]']) | 4058 'More than one command on the same line in if [whitespace/parens]
[4]']) |
| 4045 self.assert_multi_line_lint( | 4059 self.assert_multi_line_lint( |
| 4046 'if (condition) doSomething(); else {\n' | 4060 'if (condition) doSomething(); else {\n' |
| 4047 ' doSomethingElse();\n' | 4061 ' doSomethingElse();\n' |
| 4048 '}\n', | 4062 '}\n', |
| 4049 ['More than one command on the same line in if [whitespace/parens]
[4]', | 4063 ['More than one command on the same line in if [whitespace/parens]
[4]', |
| 4050 'One line control clauses should not use braces. [whitespace/brace
s] [4]']) | 4064 'If one part of an if-else statement uses curly braces, the other p
art must too. [whitespace/braces] [4]']) |
| 4051 self.assert_multi_line_lint( | |
| 4052 'if (condition)\n' | |
| 4053 ' doSomething();\n' | |
| 4054 'else {\n' | |
| 4055 ' doSomethingElse();\n' | |
| 4056 '}\n', | |
| 4057 'One line control clauses should not use braces. [whitespace/braces
] [4]') | |
| 4058 self.assert_multi_line_lint( | |
| 4059 'if (condition) {\n' | |
| 4060 ' doSomething1();\n' | |
| 4061 ' doSomething2();\n' | |
| 4062 '} else {\n' | |
| 4063 ' doSomethingElse();\n' | |
| 4064 '}\n', | |
| 4065 'One line control clauses should not use braces. [whitespace/braces
] [4]') | |
| 4066 self.assert_multi_line_lint( | 4065 self.assert_multi_line_lint( |
| 4067 'void func()\n' | 4066 'void func()\n' |
| 4068 '{\n' | 4067 '{\n' |
| 4069 ' while (condition) { }\n' | 4068 ' while (condition) { }\n' |
| 4070 ' return 0;\n' | 4069 ' return 0;\n' |
| 4071 '}\n', | 4070 '}\n', |
| 4072 '') | 4071 '') |
| 4073 self.assert_multi_line_lint( | 4072 self.assert_multi_line_lint( |
| 4074 'void func()\n' | 4073 'void func()\n' |
| 4075 '{\n' | 4074 '{\n' |
| 4076 ' for (i = 0; i < 42; i++) { foobar(); }\n' | 4075 ' for (i = 0; i < 42; i++) { foobar(); }\n' |
| 4077 ' return 0;\n' | 4076 ' return 0;\n' |
| 4078 '}\n', | 4077 '}\n', |
| 4079 'More than one command on the same line in for [whitespace/parens]
[4]') | 4078 'More than one command on the same line in for [whitespace/parens]
[4]') |
| 4080 | 4079 |
| 4081 # 3. An else if statement should be written as an if statement | 4080 # 3. An else if statement should be written as an if statement |
| 4082 # when the prior if concludes with a return statement. | 4081 # when the prior if concludes with a return statement. |
| 4083 self.assert_multi_line_lint( | 4082 self.assert_multi_line_lint( |
| 4084 'if (motivated) {\n' | 4083 'if (motivated) {\n' |
| 4085 ' if (liquid)\n' | 4084 ' if (liquid)\n' |
| 4086 ' return money;\n' | 4085 ' return money;\n' |
| 4087 '} else if (tired)\n' | 4086 '} else if (tired) {\n' |
| 4088 ' break;\n', | 4087 ' break;\n' |
| 4088 '}', |
| 4089 '') | 4089 '') |
| 4090 self.assert_multi_line_lint( | 4090 self.assert_multi_line_lint( |
| 4091 'if (condition)\n' | 4091 'if (condition)\n' |
| 4092 ' doSomething();\n' | 4092 ' doSomething();\n' |
| 4093 'else if (otherCondition)\n' | 4093 'else if (otherCondition)\n' |
| 4094 ' doSomethingElse();\n', | 4094 ' doSomethingElse();\n', |
| 4095 '') | 4095 '') |
| 4096 self.assert_multi_line_lint( | 4096 self.assert_multi_line_lint( |
| 4097 'if (condition)\n' | 4097 'if (condition)\n' |
| 4098 ' doSomething();\n' | 4098 ' doSomething();\n' |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4131 '}\n', | 4131 '}\n', |
| 4132 'An else if statement should be written as an if statement when the
' | 4132 'An else if statement should be written as an if statement when the
' |
| 4133 'prior "if" concludes with a return, break, continue or goto stateme
nt.' | 4133 'prior "if" concludes with a return, break, continue or goto stateme
nt.' |
| 4134 ' [readability/control_flow] [4]') | 4134 ' [readability/control_flow] [4]') |
| 4135 self.assert_multi_line_lint( | 4135 self.assert_multi_line_lint( |
| 4136 ' if (stupid) {\n' | 4136 ' if (stupid) {\n' |
| 4137 'infiniteLoop:\n' | 4137 'infiniteLoop:\n' |
| 4138 ' goto infiniteLoop;\n' | 4138 ' goto infiniteLoop;\n' |
| 4139 ' } else if (evil)\n' | 4139 ' } else if (evil)\n' |
| 4140 ' goto hell;\n', | 4140 ' goto hell;\n', |
| 4141 'An else if statement should be written as an if statement when the
' | 4141 ['If one part of an if-else statement uses curly braces, the other p
art must too. [whitespace/braces] [4]', |
| 4142 'prior "if" concludes with a return, break, continue or goto stateme
nt.' | 4142 'An else if statement should be written as an if statement when the
' |
| 4143 ' [readability/control_flow] [4]') | 4143 'prior "if" concludes with a return, break, continue or goto statem
ent.' |
| 4144 ' [readability/control_flow] [4]']) |
| 4144 self.assert_multi_line_lint( | 4145 self.assert_multi_line_lint( |
| 4145 'if (liquid)\n' | 4146 'if (liquid)\n' |
| 4146 '{\n' | 4147 '{\n' |
| 4147 ' prepare();\n' | 4148 ' prepare();\n' |
| 4148 ' return money;\n' | 4149 ' return money;\n' |
| 4149 '}\n' | 4150 '}\n' |
| 4150 'else if (greedy)\n' | 4151 'else if (greedy)\n' |
| 4151 ' keep();\n', | 4152 ' keep();\n', |
| 4152 ['This { should be at the end of the previous line [whitespace/brac
es] [4]', | 4153 ['If one part of an if-else statement uses curly braces, the other p
art must too. [whitespace/braces] [4]', |
| 4153 'An else should appear on the same line as the preceding } [whitesp
ace/newline] [4]', | 4154 'This { should be at the end of the previous line [whitespace/brac
es] [4]', |
| 4154 'An else if statement should be written as an if statement when the
' | 4155 'An else should appear on the same line as the preceding } [whites
pace/newline] [4]', |
| 4155 'prior "if" concludes with a return, break, continue or goto stateme
nt.' | 4156 'An else if statement should be written as an if statement when the
' |
| 4156 ' [readability/control_flow] [4]']) | 4157 'prior "if" concludes with a return, break, continue or goto statem
ent.' |
| 4158 ' [readability/control_flow] [4]']) |
| 4157 self.assert_multi_line_lint( | 4159 self.assert_multi_line_lint( |
| 4158 'if (gone)\n' | 4160 'if (gone)\n' |
| 4159 ' return;\n' | 4161 ' return;\n' |
| 4160 'else if (here)\n' | 4162 'else if (here)\n' |
| 4161 ' go();\n', | 4163 ' go();\n', |
| 4162 'An else if statement should be written as an if statement when the
' | 4164 'An else if statement should be written as an if statement when the
' |
| 4163 'prior "if" concludes with a return, break, continue or goto stateme
nt.' | 4165 'prior "if" concludes with a return, break, continue or goto stateme
nt.' |
| 4164 ' [readability/control_flow] [4]') | 4166 ' [readability/control_flow] [4]') |
| 4165 self.assert_multi_line_lint( | 4167 self.assert_multi_line_lint( |
| 4166 'if (gone)\n' | 4168 'if (gone)\n' |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4181 'An else statement can be removed when the prior "if" concludes ' | 4183 'An else statement can be removed when the prior "if" concludes ' |
| 4182 'with a return, break, continue or goto statement.' | 4184 'with a return, break, continue or goto statement.' |
| 4183 ' [readability/control_flow] [4]') | 4185 ' [readability/control_flow] [4]') |
| 4184 self.assert_multi_line_lint( | 4186 self.assert_multi_line_lint( |
| 4185 'if (tired)\n' | 4187 'if (tired)\n' |
| 4186 ' break;\n' | 4188 ' break;\n' |
| 4187 'else {\n' | 4189 'else {\n' |
| 4188 ' prepare();\n' | 4190 ' prepare();\n' |
| 4189 ' continue;\n' | 4191 ' continue;\n' |
| 4190 '}\n', | 4192 '}\n', |
| 4191 'An else statement can be removed when the prior "if" concludes ' | 4193 ['If one part of an if-else statement uses curly braces, the other p
art must too. [whitespace/braces] [4]', |
| 4192 'with a return, break, continue or goto statement.' | 4194 'An else statement can be removed when the prior "if" concludes ' |
| 4193 ' [readability/control_flow] [4]') | 4195 'with a return, break, continue or goto statement.' |
| 4196 ' [readability/control_flow] [4]']) |
| 4194 | 4197 |
| 4195 def test_braces(self): | 4198 def test_braces(self): |
| 4196 # 1. Function definitions: place each brace on its own line. | 4199 # 1. Function definitions: place each brace on its own line. |
| 4197 self.assert_multi_line_lint( | 4200 self.assert_multi_line_lint( |
| 4198 'int main()\n' | 4201 'int main()\n' |
| 4199 '{\n' | 4202 '{\n' |
| 4200 ' doSomething();\n' | 4203 ' doSomething();\n' |
| 4201 '}\n', | 4204 '}\n', |
| 4202 '') | 4205 '') |
| 4203 self.assert_multi_line_lint( | 4206 self.assert_multi_line_lint( |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4283 'case foo: return;\n' | 4286 'case foo: return;\n' |
| 4284 '}\n', | 4287 '}\n', |
| 4285 'This { should be at the end of the previous line [whitespace/brace
s] [4]') | 4288 'This { should be at the end of the previous line [whitespace/brace
s] [4]') |
| 4286 self.assert_multi_line_lint( | 4289 self.assert_multi_line_lint( |
| 4287 'else if (type)\n' | 4290 'else if (type)\n' |
| 4288 '{\n' | 4291 '{\n' |
| 4289 'case foo: return;\n' | 4292 'case foo: return;\n' |
| 4290 '}\n', | 4293 '}\n', |
| 4291 'This { should be at the end of the previous line [whitespace/brace
s] [4]') | 4294 'This { should be at the end of the previous line [whitespace/brace
s] [4]') |
| 4292 | 4295 |
| 4293 # 3. One-line control clauses should not use braces unless | 4296 # 3. Curly braces are not required for single-line conditionals and |
| 4294 # comments are included or a single statement spans multiple | 4297 # loop bodies, but are required for single-statement bodies that |
| 4295 # lines. | 4298 # span multiple lines. |
| 4296 self.assert_multi_line_lint( | 4299 |
| 4297 'if (true) {\n' | 4300 # |
| 4298 ' int foo;\n' | 4301 # Positive tests |
| 4299 '}\n', | 4302 # |
| 4300 'One line control clauses should not use braces. [whitespace/braces
] [4]') | 4303 self.assert_multi_line_lint( |
| 4304 'if (condition1)\n' |
| 4305 ' statement1();\n' |
| 4306 'else\n' |
| 4307 ' statement2();\n', |
| 4308 '') |
| 4309 |
| 4310 self.assert_multi_line_lint( |
| 4311 'if (condition1)\n' |
| 4312 ' statement1();\n' |
| 4313 'else if (condition2)\n' |
| 4314 ' statement2();\n', |
| 4315 '') |
| 4316 |
| 4317 self.assert_multi_line_lint( |
| 4318 'if (condition1)\n' |
| 4319 ' statement1();\n' |
| 4320 'else if (condition2)\n' |
| 4321 ' statement2();\n' |
| 4322 'else\n' |
| 4323 ' statement3();\n', |
| 4324 '') |
| 4325 |
| 4326 self.assert_multi_line_lint( |
| 4327 'for (; foo; bar)\n' |
| 4328 ' int foo;\n', |
| 4329 '') |
| 4301 | 4330 |
| 4302 self.assert_multi_line_lint( | 4331 self.assert_multi_line_lint( |
| 4303 'for (; foo; bar) {\n' | 4332 'for (; foo; bar) {\n' |
| 4304 ' int foo;\n' | 4333 ' int foo;\n' |
| 4305 '}\n', | 4334 '}\n', |
| 4306 'One line control clauses should not use braces. [whitespace/braces
] [4]') | 4335 '') |
| 4307 | 4336 |
| 4308 self.assert_multi_line_lint( | 4337 self.assert_multi_line_lint( |
| 4309 'foreach (foo, foos) {\n' | 4338 'foreach (foo, foos) {\n' |
| 4310 ' int bar;\n' | 4339 ' int bar;\n' |
| 4311 '}\n', | 4340 '}\n', |
| 4312 'One line control clauses should not use braces. [whitespace/braces
] [4]') | 4341 '') |
| 4342 |
| 4343 self.assert_multi_line_lint( |
| 4344 'foreach (foo, foos)\n' |
| 4345 ' int bar;\n', |
| 4346 '') |
| 4313 | 4347 |
| 4314 self.assert_multi_line_lint( | 4348 self.assert_multi_line_lint( |
| 4315 'while (true) {\n' | 4349 'while (true) {\n' |
| 4316 ' int foo;\n' | 4350 ' int foo;\n' |
| 4317 '}\n', | 4351 '}\n', |
| 4318 'One line control clauses should not use braces. [whitespace/braces
] [4]') | 4352 '') |
| 4319 | 4353 |
| 4320 self.assert_multi_line_lint( | 4354 self.assert_multi_line_lint( |
| 4321 'if (true)\n' | 4355 'while (true)\n' |
| 4356 ' int foo;\n', |
| 4357 '') |
| 4358 |
| 4359 self.assert_multi_line_lint( |
| 4360 'if (condition1) {\n' |
| 4361 ' statement1();\n' |
| 4362 '} else {\n' |
| 4363 ' statement2();\n' |
| 4364 '}\n', |
| 4365 '') |
| 4366 |
| 4367 self.assert_multi_line_lint( |
| 4368 'if (condition1) {\n' |
| 4369 ' statement1();\n' |
| 4370 '} else if (condition2) {\n' |
| 4371 ' statement2();\n' |
| 4372 '}\n', |
| 4373 '') |
| 4374 |
| 4375 self.assert_multi_line_lint( |
| 4376 'if (condition1) {\n' |
| 4377 ' statement1();\n' |
| 4378 '} else if (condition2) {\n' |
| 4379 ' statement2();\n' |
| 4380 '} else {\n' |
| 4381 ' statement3();\n' |
| 4382 '}\n', |
| 4383 '') |
| 4384 |
| 4385 self.assert_multi_line_lint( |
| 4386 'if (condition1) {\n' |
| 4387 ' statement1();\n' |
| 4388 ' statement1_2();\n' |
| 4389 '} else if (condition2) {\n' |
| 4390 ' statement2();\n' |
| 4391 ' statement2_2();\n' |
| 4392 '}\n', |
| 4393 '') |
| 4394 |
| 4395 self.assert_multi_line_lint( |
| 4396 'if (condition1) {\n' |
| 4397 ' statement1();\n' |
| 4398 ' statement1_2();\n' |
| 4399 '} else if (condition2) {\n' |
| 4400 ' statement2();\n' |
| 4401 ' statement2_2();\n' |
| 4402 '} else {\n' |
| 4403 ' statement3();\n' |
| 4404 ' statement3_2();\n' |
| 4405 '}\n', |
| 4406 '') |
| 4407 |
| 4408 # |
| 4409 # Negative tests |
| 4410 # |
| 4411 |
| 4412 self.assert_multi_line_lint( |
| 4413 'if (condition)\n' |
| 4414 ' doSomething(\n' |
| 4415 ' spanningMultipleLines);\n', |
| 4416 'A conditional or loop body must use braces if the statement is more
than one line long. [whitespace/braces] [4]') |
| 4417 |
| 4418 self.assert_multi_line_lint( |
| 4419 'if (condition)\n' |
| 4420 ' // Single-line comment\n' |
| 4421 ' doSomething();\n', |
| 4422 'A conditional or loop body must use braces if the statement is more
than one line long. [whitespace/braces] [4]') |
| 4423 |
| 4424 self.assert_multi_line_lint( |
| 4425 'if (condition1)\n' |
| 4426 ' statement1();\n' |
| 4427 'else if (condition2)\n' |
| 4428 ' // Single-line comment\n' |
| 4429 ' statement2();\n', |
| 4430 'A conditional or loop body must use braces if the statement is more
than one line long. [whitespace/braces] [4]') |
| 4431 |
| 4432 self.assert_multi_line_lint( |
| 4433 'if (condition1)\n' |
| 4434 ' statement1();\n' |
| 4435 'else if (condition2)\n' |
| 4436 ' statement2();\n' |
| 4437 'else\n' |
| 4438 ' // Single-line comment\n' |
| 4439 ' statement3();\n', |
| 4440 'A conditional or loop body must use braces if the statement is more
than one line long. [whitespace/braces] [4]') |
| 4441 |
| 4442 self.assert_multi_line_lint( |
| 4443 'for (; foo; bar)\n' |
| 4444 ' // Single-line comment\n' |
| 4445 ' int foo;\n', |
| 4446 'A conditional or loop body must use braces if the statement is more
than one line long. [whitespace/braces] [4]') |
| 4447 |
| 4448 self.assert_multi_line_lint( |
| 4449 'foreach (foo, foos)\n' |
| 4450 ' // Single-line comment\n' |
| 4451 ' int bar;\n', |
| 4452 'A conditional or loop body must use braces if the statement is more
than one line long. [whitespace/braces] [4]') |
| 4453 |
| 4454 self.assert_multi_line_lint( |
| 4455 'while (true)\n' |
| 4456 ' // Single-line comment\n' |
| 4322 ' int foo;\n' | 4457 ' int foo;\n' |
| 4458 '\n', |
| 4459 'A conditional or loop body must use braces if the statement is more
than one line long. [whitespace/braces] [4]') |
| 4460 |
| 4461 # 4. If one part of an if-else statement uses curly braces, the |
| 4462 # other part must too. |
| 4463 |
| 4464 self.assert_multi_line_lint( |
| 4465 'if (condition1) {\n' |
| 4466 ' doSomething1();\n' |
| 4467 ' doSomething1_2();\n' |
| 4468 '} else if (condition2)\n' |
| 4469 ' doSomething2();\n' |
| 4470 'else\n' |
| 4471 ' doSomething3();\n', |
| 4472 'If one part of an if-else statement uses curly braces, the other pa
rt must too. [whitespace/braces] [4]') |
| 4473 |
| 4474 self.assert_multi_line_lint( |
| 4475 'if (condition1)\n' |
| 4476 ' doSomething1();\n' |
| 4477 'else if (condition2) {\n' |
| 4478 ' doSomething2();\n' |
| 4479 ' doSomething2_2();\n' |
| 4480 '} else\n' |
| 4481 ' doSomething3();\n', |
| 4482 'If one part of an if-else statement uses curly braces, the other pa
rt must too. [whitespace/braces] [4]') |
| 4483 |
| 4484 self.assert_multi_line_lint( |
| 4485 'if (condition1) {\n' |
| 4486 ' doSomething1();\n' |
| 4487 '} else if (condition2) {\n' |
| 4488 ' doSomething2();\n' |
| 4489 ' doSomething2_2();\n' |
| 4490 '} else\n' |
| 4491 ' doSomething3();\n', |
| 4492 'If one part of an if-else statement uses curly braces, the other pa
rt must too. [whitespace/braces] [4]') |
| 4493 |
| 4494 self.assert_multi_line_lint( |
| 4495 'if (condition1)\n' |
| 4496 ' doSomething1();\n' |
| 4497 'else if (condition2)\n' |
| 4498 ' doSomething2();\n' |
| 4323 'else {\n' | 4499 'else {\n' |
| 4324 ' int foo;\n' | 4500 ' doSomething3();\n' |
| 4325 '}\n', | 4501 ' doSomething3_2();\n' |
| 4326 'One line control clauses should not use braces. [whitespace/braces
] [4]') | 4502 '}\n', |
| 4327 | 4503 'If one part of an if-else statement uses curly braces, the other pa
rt must too. [whitespace/braces] [4]') |
| 4328 self.assert_multi_line_lint( | 4504 |
| 4329 'if (true) {\n' | 4505 self.assert_multi_line_lint( |
| 4330 ' int foo;\n' | 4506 'if (condition1) {\n' |
| 4331 '} else\n' | 4507 ' doSomething1();\n' |
| 4332 ' int foo;\n', | 4508 ' doSomething1_2();\n' |
| 4333 'One line control clauses should not use braces. [whitespace/braces
] [4]') | 4509 '} else if (condition2)\n' |
| 4334 | 4510 ' doSomething2();\n' |
| 4335 self.assert_multi_line_lint( | 4511 'else {\n' |
| 4336 'if (true) {\n' | 4512 ' doSomething3();\n' |
| 4337 ' // Some comment\n' | 4513 ' doSomething3_2();\n' |
| 4338 ' int foo;\n' | 4514 '}\n', |
| 4339 '}\n', | 4515 'If one part of an if-else statement uses curly braces, the other pa
rt must too. [whitespace/braces] [4]') |
| 4340 '') | 4516 |
| 4341 | 4517 self.assert_multi_line_lint( |
| 4342 self.assert_multi_line_lint( | 4518 'if (condition1)\n' |
| 4343 'if (true) {\n' | 4519 ' doSomething1();\n' |
| 4344 ' myFunction(reallyLongParam1, reallyLongParam2,\n' | 4520 'else if (condition2) {\n' |
| 4345 ' reallyLongParam3);\n' | 4521 ' doSomething2();\n' |
| 4346 '}\n', | 4522 ' doSomething2_2();\n' |
| 4347 'Weird number of spaces at line-start. Are you using a 4-space inde
nt? [whitespace/indent] [3]') | 4523 '} else {\n' |
| 4348 | 4524 ' doSomething3();\n' |
| 4349 self.assert_multi_line_lint( | 4525 ' doSomething3_2();\n' |
| 4350 'if (true) {\n' | 4526 '}\n', |
| 4351 ' myFunction(reallyLongParam1, reallyLongParam2,\n' | 4527 'If one part of an if-else statement uses curly braces, the other pa
rt must too. [whitespace/braces] [4]') |
| 4352 ' reallyLongParam3);\n' | 4528 |
| 4353 '}\n', | 4529 |
| 4354 'When wrapping a line, only indent 4 spaces. [whitespace/indent] [3
]') | 4530 # 5. Control clauses without a body should use empty braces. |
| 4355 | |
| 4356 # 4. Control clauses without a body should use empty braces. | |
| 4357 self.assert_multi_line_lint( | 4531 self.assert_multi_line_lint( |
| 4358 'for ( ; current; current = current->next) { }\n', | 4532 'for ( ; current; current = current->next) { }\n', |
| 4359 '') | 4533 '') |
| 4360 self.assert_multi_line_lint( | 4534 self.assert_multi_line_lint( |
| 4361 'for ( ; current;\n' | 4535 'for ( ; current;\n' |
| 4362 ' current = current->next) { }\n', | 4536 ' current = current->next) { }\n', |
| 4363 'Weird number of spaces at line-start. Are you using a 4-space inde
nt? [whitespace/indent] [3]') | 4537 'Weird number of spaces at line-start. Are you using a 4-space inde
nt? [whitespace/indent] [3]') |
| 4364 self.assert_multi_line_lint( | 4538 self.assert_multi_line_lint( |
| 4365 'for ( ; current; current = current->next);\n', | 4539 'for ( ; current; current = current->next);\n', |
| 4366 'Semicolon defining empty statement for this loop. Use { } instead.
[whitespace/semicolon] [5]') | 4540 'Semicolon defining empty statement for this loop. Use { } instead.
[whitespace/semicolon] [5]') |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4964 def test_ne(self): | 5138 def test_ne(self): |
| 4965 """Test __ne__ inequality function.""" | 5139 """Test __ne__ inequality function.""" |
| 4966 checker1 = self._checker() | 5140 checker1 = self._checker() |
| 4967 checker2 = self._checker() | 5141 checker2 = self._checker() |
| 4968 | 5142 |
| 4969 # != calls __ne__. | 5143 # != calls __ne__. |
| 4970 # By default, __ne__ always returns true on different objects. | 5144 # By default, __ne__ always returns true on different objects. |
| 4971 # Thus, just check the distinguishing case to verify that the | 5145 # Thus, just check the distinguishing case to verify that the |
| 4972 # code defines __ne__. | 5146 # code defines __ne__. |
| 4973 self.assertFalse(checker1 != checker2) | 5147 self.assertFalse(checker1 != checker2) |
| OLD | NEW |