Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jshint "use strict" issue [duplicate]

Tags:

Here's my file: app/scripts/controllers/main.js

"use strict";  angular.module('appApp')   .controller('MainCtrl', ['$scope', function ($scope) {     $scope.awesomeThings = [       'HTML5 Boilerplate',       'AngularJS',       'Karma'     ];   }]); 

My Gruntfile.coffee has:

jshint:     options:         globals:             require: false             module: false             console: false             __dirname: false             process: false             exports: false      server:         options:             node: true         src: ["server/**/*.js"]      app:         options:             globals:                 angular: true                 strict: true          src: ["app/scripts/**/*.js"] 

When I run grunt, I get:

Linting app/scripts/controllers/main.js ...ERROR [L1:C1] W097: Use the function form of "use strict". "use strict"; 
like image 645
Shamoon Avatar asked Nov 11 '13 15:11

Shamoon


Video Answer


1 Answers

The issue is that if you don't use the function form it applies to everything, and not just your code. The solution to that is to scope use strict inside functions you control.

Refer to this question: JSLint is suddenly reporting: Use the function form of “use strict”.

Rather than doing

"use strict";  angular.module('appApp')   .controller('MainCtrl', ['$scope', function ($scope) {     $scope.awesomeThings = [       'HTML5 Boilerplate',       'AngularJS',       'Karma'     ];   }]); 

You should be doing

angular.module('appApp')   .controller('MainCtrl', ['$scope', function ($scope) {     "use strict";      $scope.awesomeThings = [       'HTML5 Boilerplate',       'AngularJS',       'Karma'     ];   }]); 

It's either that or wrapping your code in a self-executing closure, like below.

(function(){     "use strict";      // your stuff })(); 
like image 191
bevacqua Avatar answered Sep 28 '22 00:09

bevacqua