4

When I try to save the following code in sublime text,

'use strict';
 /*global angular,_*/

 var app = angular.module("myApp", []);
 app.controller("myCtrl", function ($scope) {
   $scope.firstName = "John";
   $scope.lastName = "Doe";
 });

I am getting the following jslint error :

 #1 Unexpected expression 'use strict' in statement position.
    'use strict'; // Line 1, Pos 1
 #2 Place the '/*global*/' directive before the first statement.
    /*global angular,_*/ // Line 2, Pos 1
 #3 Undeclared 'angular'.
    var app = angular.module("myApp", []); // Line 4, Pos 11
 #4 Expected 'use strict' before '$scope'.
    $scope.firstName = "John"; // Line 6, Pos 3
 #5 Expected '$scope' at column 5, not column 3.
    $scope.lastName = "Doe"; // Line 7, Pos 3
TheSharpieOne
  • 25,646
  • 9
  • 66
  • 78
Ayan
  • 8,192
  • 4
  • 46
  • 51
  • I already checked that link @TheSharpieOne . It doesn't serve my purpose. – Ayan Dec 27 '16 at 18:01
  • So.. the part of the answer which says "According to [the documentation](http://jslint.com/help.html), the browser option for JSLint automatically disables use of "use strict"; at the global level. As far as I'm aware, there's no way to turn it back on." didn't help you realize that you cannot put `'use strict';` there and that putting it there is the issue? – TheSharpieOne Dec 27 '16 at 18:05
  • If 'use strict' is not used,then jslint error persists saying "Expected 'use strict' before '$scope' " – Ayan Dec 27 '16 at 18:25

1 Answers1

3

You cannot use 'use strict'; there in a global way with jslint. See https://stackoverflow.com/a/35297691/1873485

With that in mind, you need to remove it from the global scope and add it in your function scope or wrap everything in an IFEE

 /*global angular,_*/
 var app = angular.module("myApp", []);
 app.controller("myCtrl", function ($scope) {
  'use strict';
   $scope.firstName = "John";
   $scope.lastName = "Doe";
 });

or wrap it:

/*global angular,_*/
(function(){
  'use strict';
   var app = angular.module("myApp", []);
   app.controller("myCtrl", function ($scope) {
     $scope.firstName = "John";
     $scope.lastName = "Doe";
   });
})();
Community
  • 1
  • 1
TheSharpieOne
  • 25,646
  • 9
  • 66
  • 78
  • 1
    Yes, but no. JSLint treats wrapping with the error message: "Don't wrap function literals in parens." – schlenger Aug 31 '17 at 16:33