Javascript Delinting -- Problem: Stopping on loop line.

For technical support for all editions of CSS HTML Validator. Includes bug reports.
Post Reply
JoshuaTausz
Rank 0 - Newcomer
Rank 0 - Newcomer
Posts: 5
Joined: Fri Mar 07, 2014 1:10 pm

Javascript Delinting -- Problem: Stopping on loop line.

Post by JoshuaTausz » Fri Mar 07, 2014 1:24 pm

Hello there.

I am currently assessing this product for use by my company, on a webservice project. When it comes to the HTML and CSS, I am thus far quite pleased.

However, when it comes to the javascript delinter, I have encountered a one major problem. When attempting to delint one of our more complex pieces of Javascript, the checking process shuts down approximately 30% of the way through.

The line in question is of the following format

Code: Select all

for (var i=0; i < object.collection.length; i++) {
Where the object in question belongs to an external file, and is passed in to this file, as a part of the function declaration.

To further help you diagnose the problem, I'll let you know that we are using require.js, and that the function I am defining this code inside of is a part of a require module.

require.js seems to cause the delinter further problems, in that it reports both require, and jQuerry's $ symbol as "used before it was defined".

If you can give me a work around (possibly setting changes) for this problem, it would be appreciated.

Note that I am not authorized to give you the actual code in question.

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3412
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Javascript Delinting -- Problem: Stopping on loop line.

Post by Albert Wiersch » Fri Mar 07, 2014 6:16 pm

Hello,

Is it possible to create a small sample JavaScript file that reproduces the problem?

Also, can you copy and paste the exact message text? An easy way to do this is to right-click in the Results Window and choose Copy Messages to Clipboard->In Text Format.

I assume you are using JSLint (the default JavaScript linter in CSE HTML Validator). There is some documentation for it here (which may help):
http://www.jslint.com/lint.html

Also please note that JSLint is rather strict... some people like this and some don't. :)
Image
Albert Wiersch

JoshuaTausz
Rank 0 - Newcomer
Rank 0 - Newcomer
Posts: 5
Joined: Fri Mar 07, 2014 1:10 pm

Re: Javascript Delinting -- Problem: Stopping on loop line.

Post by JoshuaTausz » Mon Mar 10, 2014 12:36 pm

Yes, I've been using JSLint, as is default. I generally like strict validators, as if I decide something is not a problem (or just not presently high priority compared to other errors), I can ignore it and move on to other issues that wouldn't be reported by a less-strict delinter.
When they stop checking part way through a file, though, I can't.

I've created a code-snippet that replicates the problem. require.js no longer seems to be the problem, but rather a style of loop declaration.

Code: Select all

var jungle = function () {
    "use strict";
    var j = 0;
    for (var i = 0; i < 10; i++) {
        j += i;
    }
};
The exact JSLint message on this 4 line file is: "Error in line 4 at character 10: [JSLint] Problem: Stopping. (44% scanned)."

If I move the declaration of i to the same declaration statement as j, the error changes.

It becomes "Error in line 4 at character 26: [JSLint] Problem: Unexpected '++'."

Thank you for your assistance.

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3412
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Javascript Delinting -- Problem: Stopping on loop line.

Post by Albert Wiersch » Mon Mar 10, 2014 2:02 pm

Hello,

You're very welcome!

This works:

Code: Select all

var jungle = function () {
    "use strict";
    var j = 0, i;
    for (i = 0; i < 10; i++) {
        j += i;
    }
};
To allow "++" and "--", goto Options->Validator Engine Options->Options and the JSLint page. In the general arguments, add this: plusplus:true

For example, change it to:

Code: Select all

"/options:{browser:true,devel:true,fragment:true,indent:4,maxerr:30,on:true,plusplus:true,white:true}"
When I use the above, JSLint is happy.
Image
Albert Wiersch

JoshuaTausz
Rank 0 - Newcomer
Rank 0 - Newcomer
Posts: 5
Joined: Fri Mar 07, 2014 1:10 pm

Re: Javascript Delinting -- Problem: Stopping on loop line.

Post by JoshuaTausz » Mon Mar 10, 2014 4:23 pm

Thank you for the instruction on the option to enable increment and decrements.

What about the delinter ceasing operation on the loop with the variable being declared as a part of the loop? Even if you would label this as an error, the parser should be robust enough to continue processing.

I've tried switching JSLint to JavaScript Lint in order to see if this alternate checker fails on loops as well, but the system still seems to be delinting using JSLint, and the help file isn't much help in this case.

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3412
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Javascript Delinting -- Problem: Stopping on loop line.

Post by Albert Wiersch » Mon Mar 10, 2014 5:02 pm

Hello,

I am not sure why JSLint stops. I agree it should continue but I didn't write it. :D

It's possible that JSLint considers this such a serious issue that it is designed to stop (it is quite picky).

This page might help you decide what options you want:
http://www.jslint.com/

You can paste your script there and check it only and test out different JSLint options.

If you go to the 'JavaScript Lint' page and check the 'Enable JavaScript lint messages' option, then it should run that checker as well for JavaScript files. I tried it and it worked. One of the comment messages was "[JavaScript Lint] 0 error(s), 0 warning(s)". Please make sure you have comments enabled and are not doing an 'Errors only' or 'Errors and warnings only' validation, in which case that comment message would not show up.... or you could change 'var' to 'vaar' and force an error and see if JavaScript Lint is running, in which case you should see an error message from it.

If you still can't get it to work, then please provide me with more details about your settings.

Thanks.
Image
Albert Wiersch

JoshuaTausz
Rank 0 - Newcomer
Rank 0 - Newcomer
Posts: 5
Joined: Fri Mar 07, 2014 1:10 pm

Re: Javascript Delinting -- Problem: Stopping on loop line.

Post by JoshuaTausz » Tue Mar 11, 2014 1:17 pm

I was able to get the ++ messages to go away as per your suggestion. I was also able to verify that moving the var statement outside of the loop removed the issues.

As I understand it, Javascript uses either global or function scope variables, so changing the placement of the var statement wouldn't affect scope. I'm not sure whether our coding group would adjust coding style, or stop using the JSLint entirely.

I was able to turn on Javascript Lint messages instead of JSLint, as well as turning them both on together by clicking the "enable" box for each on their respective option pages.

I think that pointing this out with the in-org setup / use wiki pages would be sufficient.

I'll talk with the JSLint people further about their parsing halt.

Thank you for your assistance.

Though I do have one other question. Are the configuration options saved in some number of central files, so that we can just change the default configuration to be dropped once, then drop the file into our default configuration for new users of the tool?

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3412
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Javascript Delinting -- Problem: Stopping on loop line.

Post by Albert Wiersch » Tue Mar 11, 2014 3:39 pm

JoshuaTausz wrote:Thank you for your assistance.
Sure! You're very welcome.
JoshuaTausz wrote:Though I do have one other question. Are the configuration options saved in some number of central files, so that we can just change the default configuration to be dropped once, then drop the file into our default configuration for new users of the tool?
Most options are stored in the registry. For example, the JSLint options are stored in "GeneralArguments" in the key "HKEY_CURRENT_USER\Software\AI Internet Solutions\CSE HTML Validator v4\Validator DLL\JSLint".

Perhaps you have a tool that could make that registry entry upon installation? You might also make a reg file to execute after installing CSE HTML Validator to make some registry entries for the defaults you'd like to override.

You could also add equivalent registry entries under "HKEY_USERS\.DEFAULT\Software\AI Internet Solutions\CSE HTML Validator v4" which should let you apply your own defaults to any user on the system.

Finally there is "cseoptions.ini" that you could potentially use if you want to run the program as though it were in portable mode. This would save all the options in ini files and you could include a default ini file for your users to use that includes the settings you'd like. More about portable mode is here:
Running a portable version of CSE HTML Validator

I hope one or more of these options will be sufficient for you.

Thanks!
Image
Albert Wiersch

JoshuaTausz
Rank 0 - Newcomer
Rank 0 - Newcomer
Posts: 5
Joined: Fri Mar 07, 2014 1:10 pm

Re: Javascript Delinting -- Problem: Stopping on loop line.

Post by JoshuaTausz » Tue Mar 11, 2014 5:34 pm

Running it like it was portable, but in place on the machine might be doable, if the number of options we need to change from default grows large enough.

Can you activate portable mode off of an internal hard-drive after creating said ini-file, or must it run off of a USB drive? Would this have any performance impact when compared to using the registry? I'd rather not pursue an option that could lead to noticeable lag for the other users.

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3412
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Javascript Delinting -- Problem: Stopping on loop line.

Post by Albert Wiersch » Tue Mar 11, 2014 5:41 pm

All you should have to do is create the cseoptions.ini file in the proper place, so no USB drive is required. You could just create the file in the folder where you installed CSE HTML Validator and it should see it and activate portable mode, regardless of whether it's an internal drive or USB drive.

However, please note that the free trial version does not support portable mode.
Image
Albert Wiersch

Post Reply