Chromium Code Reviews| Index: PRESUBMIT.py |
| =================================================================== |
| --- PRESUBMIT.py (revision 157289) |
| +++ PRESUBMIT.py (working copy) |
| @@ -377,6 +377,24 @@ |
| return [] |
| +def _CheckNoTrinaryTrueFalse(input_api, output_api): |
| + """Checks to make sure we don't introduce use of foo ? true : false.""" |
| + problems = [] |
| + for f in input_api.AffectedFiles(): |
| + if not f.LocalPath().endswith(('.cc', '.h')): |
|
M-A Ruel
2012/09/18 10:20:40
.mm, .m, .inl
Lei Zhang
2012/09/18 18:45:18
Done.
|
| + continue |
| + |
| + for line_num, line in f.ChangedContents(): |
| + if '? true : false' in line or '? false : true' in line: |
|
M-A Ruel
2012/09/18 10:20:40
I'd use a regexp so whitespaces are ignored. e.g.
Lei Zhang
2012/09/18 18:45:18
Done.
|
| + problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
| + |
| + if not problems: |
| + return [] |
| + return [output_api.PresubmitPromptWarning( |
| + 'Please consider avoiding the "? true : false" pattern if possible.\n' + |
| + '\n'.join(problems))] |
| + |
| + |
| def _CheckUnwantedDependencies(input_api, output_api): |
| """Runs checkdeps on #include statements added in this |
| change. Breaking - rules is an error, breaking ! rules is a |
| @@ -466,6 +484,7 @@ |
| results.extend(_CheckNoDEPSGIT(input_api, output_api)) |
| results.extend(_CheckNoBannedFunctions(input_api, output_api)) |
| results.extend(_CheckNoPragmaOnce(input_api, output_api)) |
| + results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api)) |
| results.extend(_CheckUnwantedDependencies(input_api, output_api)) |
| results.extend(_CheckFilePermissions(input_api, output_api)) |
| return results |