Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange Javascript validation in dreamweaver CC

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.

like image 465
Megan Caithlyn Avatar asked Jul 04 '15 14:07

Megan Caithlyn


1 Answers

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.

like image 182
Megan Caithlyn Avatar answered Nov 17 '22 10:11

Megan Caithlyn