This is a small check to avoid throwing objc exceptions.
In specific it will detect the usage of @throw statement and throw warning.
Details
- Reviewers
hokein benhamilton - Commits
- rG999458139555: add check to avoid throwing objc exception according to Google Objective-C guide
rCTE318366: add check to avoid throwing objc exception according to Google Objective-C guide
rL318366: add check to avoid throwing objc exception according to Google Objective-C guide
Diff Detail
- Build Status
Buildable 12189 Build 12189: arc lint + arc unit
Event Timeline
LGTM with a few nits, I'd like to see whether @benhamilton has comments before committing it.
docs/clang-tidy/checks/google-objc-avoid-throwing-exception.rst | ||
---|---|---|
4 | nit: remove the extra === | |
10 | Use the public link: http://google.github.io/styleguide/objcguide.html#avoid-throwing-exceptions | |
test/clang-tidy/google-objc-avoid-throwing-exception.m | ||
11 | nit: remove the empty line. |
clang-tidy/google/AvoidThrowingObjcExceptionCheck.cpp | ||
---|---|---|
22 | It looks like we also need to catch (no pun intended :) people who invoke the following class methods: +[NSException raise:format:] +[NSException raise:format:arguments:] We actually have a few places that use these: http://google3/googlemac/iPhone/Maps/SDK/Maps/GMSServices.mm?l=412&rcl=174266104 | |
30 | Suggested wording: "Pass in NSError ** instead of using @throw to indicate Objective-C errors" | |
clang-tidy/google/AvoidThrowingObjcExceptionCheck.h | ||
1 | Naming nit-pick: We are currently using ObjC, not Objc. | |
21–22 | Grammar nit: according to Google Objective-C Style Guide -> according to the Google Objective-C Style Guide | |
26 | Objc -> ObjC | |
docs/clang-tidy/checks/google-objc-avoid-throwing-exception.rst | ||
6–7 | How about: This check finds @throw usages in Objective-C files. For the same reasons as the Google C++ style guide, we prefer not throwing exceptions from Objective-C code. Instead, prefer passing in NSError ** and return BOOL to indicate success or failure. A counterexample: - (void)readFile { if ([self isError]) { @throw [NSException exceptionWithName:...]; } } Instead, returning an error via NSError ** is preferred: - (BOOL)readFileWithError:(NSError **)error { if ([self isError]) { *error = [NSError errorWithDomain:...]; return NO; } return YES; } | |
10 | +1 |
Looking good. Please rename the files correctly, or it will not build on Linux.
clang-tidy/google/AvoidThrowingObjcExceptionCheck.cpp | ||
---|---|---|
24 | Also need to match raise:format:arguments:. | |
clang-tidy/google/AvoidThrowingObjcExceptionCheck.h | ||
2 | Don't forget to rename the file to AvoidThrowingObjcExceptionCheck.h. | |
clang-tidy/google/CMakeLists.txt | ||
5 | Rename to AvoidThrowingObjCExceptionCheck.cpp | |
clang-tidy/google/GoogleTidyModule.cpp | ||
18 | I think you renamed the #include but not the file.. should test on Linux, it won't work with a case-sensitive file system ;) | |
docs/ReleaseNotes.rst | ||
63 | detect usage of @throw -> detect throwing exceptions | |
docs/clang-tidy/checks/google-objc-avoid-throwing-exception.rst | ||
7 | Can you include the link to the C++ style guide section here instead of at the end? http://google.github.io/styleguide/cppguide.html#Exceptions | |
7 | finds @throw usages -> finds uses of throwing exceptions |
File names look good now, thanks.
clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp | ||
---|---|---|
1 ↗ | (On Diff #123091) | Objc -> ObjC |
Naming nit-pick: We are currently using ObjC, not Objc.