Bug 140003 - [Cocoa] Enable the compiler to check format strings specified with UI_STRING and UI_STRING_KEY
Summary: [Cocoa] Enable the compiler to check format strings specified with UI_STRING ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: mitz
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-12-29 19:24 PST by mitz
Modified: 2014-12-30 12:43 PST (History)
2 users (show)

See Also:


Attachments
Add format_arg attributes to UI_STRING and UI_STRING_KEY (3.13 KB, patch)
2014-12-29 19:34 PST, mitz
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description mitz 2014-12-29 19:24:26 PST
Enable the compiler to emit a warning for something like [NSString stringWithFormat:UI_STRING("%d files", "label next to file upload button"), @"not an int"] based on %d not matching the NSString parameter.
Comment 1 mitz 2014-12-29 19:34:59 PST
Created attachment 243817 [details]
Add format_arg attributes to UI_STRING and UI_STRING_KEY
Comment 2 WebKit Commit Bot 2014-12-29 19:36:13 PST
Attachment 243817 [details] did not pass style-queue:


ERROR: Source/WebKit/mac/Misc/WebLocalizableStrings.h:47:  The parameter name "bundle" adds no information, so it should be removed.  [readability/parameter_name] [5]
ERROR: Source/WebKit/mac/Misc/WebLocalizableStrings.h:54:  The parameter name "bundle" adds no information, so it should be removed.  [readability/parameter_name] [5]
Total errors found: 2 in 2 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Darin Adler 2014-12-30 10:05:54 PST
Comment on attachment 243817 [details]
Add format_arg attributes to UI_STRING and UI_STRING_KEY

View in context: https://bugs.webkit.org/attachment.cgi?id=243817&action=review

> Source/WebKit/mac/ChangeLog:9
> +        that takes their "string" parameter as a "value" "parameter and has an attribute telling

Extra quote here?
Comment 4 Darin Adler 2014-12-30 10:09:07 PST
Comment on attachment 243817 [details]
Add format_arg attributes to UI_STRING and UI_STRING_KEY

View in context: https://bugs.webkit.org/attachment.cgi?id=243817&action=review

> Source/WebKit/mac/Misc/WebLocalizableStrings.h:52
> +static inline NS_FORMAT_ARGUMENT(3) NSString *WebLocalizedStringWithValue(WebLocalizableStringsBundle *bundle, const char* key, const char* value)
> +{
> +    return WebLocalizedString(bundle, key);
> +}

On reflection, I don’t think it’s good for WebLocalizedStringWithValue inlines to be inside extern "C"; I also don’t like the formatting with the #if right up against the functions, but blank lines between the two functions. I’d move WebLocalizedStringWithValue down below. And I’d even consider using a macro for the NS/CF_FORMAT_ARGUMENT so we don’t have to repeat the WebLocalizedStringWithValue function twice.
Comment 5 mitz 2014-12-30 10:13:09 PST
(In reply to comment #4)
> Comment on attachment 243817 [details]
> Add format_arg attributes to UI_STRING and UI_STRING_KEY
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=243817&action=review
> 
> > Source/WebKit/mac/Misc/WebLocalizableStrings.h:52
> > +static inline NS_FORMAT_ARGUMENT(3) NSString *WebLocalizedStringWithValue(WebLocalizableStringsBundle *bundle, const char* key, const char* value)
> > +{
> > +    return WebLocalizedString(bundle, key);
> > +}
> 
> On reflection, I don’t think it’s good for WebLocalizedStringWithValue
> inlines to be inside extern "C"; I also don’t like the formatting with the
> #if right up against the functions, but blank lines between the two
> functions. I’d move WebLocalizedStringWithValue down below.

OK.

> And I’d even
> consider using a macro for the NS/CF_FORMAT_ARGUMENT so we don’t have to
> repeat the WebLocalizedStringWithValue function twice.

Wouldn’t we still need to repeat at least the function signature because of the return types being different?
Comment 6 Darin Adler 2014-12-30 10:21:07 PST
(In reply to comment #5)
> > And I’d even
> > consider using a macro for the NS/CF_FORMAT_ARGUMENT so we don’t have to
> > repeat the WebLocalizedStringWithValue function twice.
> 
> Wouldn’t we still need to repeat at least the function signature because of
> the return types being different?

Might need a typedef too, yes.
Comment 7 mitz 2014-12-30 12:43:12 PST
Committed <http://trac.webkit.org/r177825>.