Strange Javascript validation in dreamweaver CC
Asked Answered
S

2

6

I've installed Dreamweaver CC 2015 and found out that I have MYRIAD errors in my working JavaScript files. Also I have MYRIAD errors in imported JavaScript libraries, including jQuery.

The most important "error" is this one in the beginning of every working function:

Missing "use strict" statement.

It worked quite well without "use strict" and I've never even seen this statement anywhere.

Another strange one is:

Extending prototype of native object: 'Array'.

Here is the code which provokes the warning:

Array.prototype.sortOn = function(key){
    this.sort(function(a, b){
        if(a[key] < b[key]){
            return -1;
        }else if(a[key] > b[key]){
            return 1;
        }
        return 0;
    });
};

So my options are:

  1. Ditch Dreamweaver and use another IDE (the worst, because it works perfectly fine for my purposes - I'm sole HTML/CSS/JS/PHP/MySQL developer in my project.
  2. Fix all errors like Dreamweaver wants, because it has a good point. Then please explain why? I'm OK with changing "==" to "===", adding "var" before variable declarations, not using "return" after "if" without curly braces, but that "use strict" thing bothers me.
  3. Tweak the JavaScript validation, so only critical errors are shown - the best option for me - but I don't know HOW to do it?

What's the best option to go with? Any help greatly appreciated.

Subheading answered 4/7, 2015 at 14:15 Comment(0)
S
11

Here's what I figured out.

The problem was that I was not aware of JSHint and JSLint solutions for validating javascript. JSHint is integrated into Dreamweaver CC and is easily configurable, provided you know what to do.

Normally JSHint has three ways to tweak it, but they don't work in the Dreamweaver environment.

What you should do is:

  • From the top menu select Edit -> Preferences (Dreamweaver -> Preferences on Mac)
  • Choose "Linting" from the side menu.
  • Select "JS" and click "Edit and save changes".
  • The file JS.jshintrc will be opened in Dreamweaver.
  • Edit the file like you normally would (see JSHint options) and save.

In my specific case I changed this:

"strict":false,
"undef":false,
"unused":false

...which means that I don't have to put "use strict" everywhere and may leave definitions and usage of variables in different files. YES, I don't use wrapper functions and use lots of globals. YES, I know it's bad, but refactoring this is not the highest priority in my schedule.

Of course I will change all three those options to "true" and refactor all my JS files to comply to standards when the time comes.

Subheading answered 5/7, 2015 at 8:1 Comment(3)
How to turn of validation for expected this === saw == thisHelico
Akash Kumar, just change "eqnull":false to "eqnull":trueSubheading
The === hinting is actually related to the eqeqeq setting.Malinin
S
0

Turning off the "undef" check is a sledge hammer, as JSHint will then ignore all variable and function name typos. You won't find the typo until run time, which is annoying and time wasting.

Rather than disabling the "undef" messages completely, I've been using JSHint Inline Directives near the top of my .js files. For example:

/* globals myGlobalVar, myGlobalFunction */
var myLocalVar = myGlobalVar;
myGlobalFunction();

With the globals directive in the file, JSHint will not mark myGlobalVar or myGlobalFunction() as undefined errors. Using "globals" inline directives has the added benefit of documenting the dependencies between your .js files.

Read about JSHint inline directives here:

http://jshint.com/docs/#inline-configuration

Schappe answered 11/2, 2016 at 21:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.