Bug 255020 - "Duplicate local variable" error not applicable to JavaScript
Summary: "Duplicate local variable" error not applicable to JavaScript
Status: VERIFIED FIXED
Alias: None
Product: JSDT
Classification: WebTools
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.0.4   Edit
Assignee: Chris Jaun CLA
QA Contact: Phil Berkland CLA
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2008-11-12 07:29 EST by Viktor Pracht CLA
Modified: 2010-03-03 11:12 EST (History)
1 user (show)

See Also:
cmjaun: review? (berkland)


Attachments
Adds an option to the preference page to decide how to display a duplicate local variables problem. (14.14 KB, patch)
2008-11-19 13:42 EST, Chris Jaun CLA
thatnitind: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Viktor Pracht CLA 2008-11-12 07:29:30 EST
Build ID: M20080911-1700

Steps To Reproduce:
1. Create a new JavaScript project with a single JS file.
2. Enter "var x, x;" into the file (without quotes).
3. Get "Duplicate local variable x" errors about perfectly valid JavaScript.


More information:
Unlike Java, JavaScript does allow a variable to be declared multiple times. The real-world use case is multiple "for (var i..." loops in a function. Replacing them with a simple "for (i..." and a separate "var i" makes the code much less readable because of the hunt-the-declaration game one would have to play then.
Comment 1 Chris Jaun CLA 2008-11-17 18:01:24 EST
I would propose adding a new option to the Validator preferences(under Potential Programming Problems) to allow the users to specify how they want this situation handled.

We can default this option to warning or ignore. It is valid javascript, but I could see someone unintentionally duplicating variables and they may want to be notified of that.
Comment 2 Viktor Pracht CLA 2008-11-18 06:03:34 EST
An option would work, too.
Comment 3 Chris Jaun CLA 2008-11-19 13:42:23 EST
Created attachment 118297 [details]
Adds an option to the preference page to decide how to display a duplicate local variables problem.
Comment 4 Phil Berkland CLA 2008-11-21 16:32:28 EST
Checked in patch
Comment 5 Chris Jaun CLA 2008-12-17 16:56:48 EST
Verified in 20081215095735