linter thinks that variable is unused even though it's used in both sides of an if statement

50 views
Skip to first unread message

John Munro

unread,
Jul 12, 2013, 11:12:08 AM7/12/13
to closure-lin...@googlegroups.com
Line 406, E:0133: Unused local variable: contentType.
 
    var /** @type {string} */ contentType = '';

    if (file instanceof File) {
        contentType = file.type;
    } else {
        contentType = 'text/plain';
    }

Tyler Breisacher

unread,
Jul 12, 2013, 2:01:42 PM7/12/13
to closure-lin...@googlegroups.com
It's not typical to put the @type annotation there. Try this:

/** @type {string} */
var contentType = '';



--
You received this message because you are subscribed to the Google Groups "Closure Linter Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to closure-linter-di...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

John Munro

unread,
Jul 15, 2013, 9:31:42 AM7/15/13
to closure-lin...@googlegroups.com
That didn't fix it


On Friday, July 12, 2013 2:01:42 PM UTC-4, Tyler Breisacher wrote:
It's not typical to put the @type annotation there. Try this:

/** @type {string} */
var contentType = '';
On Fri, Jul 12, 2013 at 8:12 AM, John Munro <ghos...@gmail.com> wrote:
Line 406, E:0133: Unused local variable: contentType.
 
    var /** @type {string} */ contentType = '';

    if (file instanceof File) {
        contentType = file.type;
    } else {
        contentType = 'text/plain';
    }

--
You received this message because you are subscribed to the Google Groups "Closure Linter Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to closure-linter-discuss+unsub...@googlegroups.com.

John Munro

unread,
Aug 16, 2013, 1:56:32 PM8/16/13
to closure-lin...@googlegroups.com
Actually this isn't a bug - I was writing to the variable but never actually using it anywhere so the Linter was right - it was unused

Tyler Breisacher

unread,
Aug 19, 2013, 3:25:57 PM8/19/13
to closure-lin...@googlegroups.com
Don't you love when tools help you out? :)

Although, perhaps the message should say "is never read" instead of "unused". Maybe it would be slightly clearer that way.


--
You received this message because you are subscribed to the Google Groups "Closure Linter Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to closure-linter-di...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages