Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 358939 - Correct range information for unused variable warning
Summary: Correct range information for unused variable warning
Status: RESOLVED FIXED
Alias: None
Product: Orion
Classification: ECD
Component: Client (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 0.3 RC1   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-26 13:31 EDT by John Arthorne CLA
Modified: 2011-10-11 15:40 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Arthorne CLA 2011-09-26 13:31:46 EDT
0.3 M2

I believe this is a known limitation from JSLint, but the unused variable warning range is wrong. It should underline the variable declaration rather than the surrounding function declaration.
Comment 1 Felipe Heidrich CLA 2011-09-26 13:42:11 EDT
JSLint does not provide that.

- We could write a bit of code to underline the name of function tha thas the problem (instead of te preceeding chars). (easy)

- We could writea lot o code trying to find the exactly place (harder).
Comment 2 John Arthorne CLA 2011-09-26 15:35:31 EDT
Underlining the function would be better. Currently it just looks floating squiggles not associated with anything. Actually, if we renamed the warning to "Function defines unused variable foo" then underlining the function name would at least be consistent with the description.
Comment 3 Mark Macdonald CLA 2011-09-27 18:24:02 EDT
Implemented John's suggestion from Comment 2:
http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=8e119732eb73624787dec641484eced08c3e47cb

Because JSLint doesn't give any more detail beyond line number and function name, my approach breaks down in some cases.
For example, this line is annotated correctly:
> var obj = { foo: function() { var unused1;  function bar() { var unused2; } } };
                   ^^^^^^^^                   ^^^^^^^^                    
But in this one, the name/linenumber combination is ambiguous so I end up annotating the first 'foo' for both unused variables:
> var obj = { foo: function() { var unused1;  function foo() { var unused2; } } };
                   ^^^^^^^^

This is not a big deal when editing normal code, but we will need a more robust parser to handle cases like these correctly.