3

This is my first post (so if i've done something wrong please let me know), I've had a look through the forum and through the jshint documentation but haven't been able to find an answer so far.

I've found this post describing a similar problem Expected "{" and instead saw "return"

I am running the following code through jshint

if (!x) return;

which is returning the error "Expected '{' and instead saw 'return'"

From the other post I believe this is valid syntax but does anyone know how to configure jshint to ignore it? This is the gruntFile.js I am using

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    jshint: {
      files:['./src/*.js','!gruntFile.js'],
      options:{
          "curly": true,
          "eqnull": true,
          "eqeqeq": true,
          "undef": false,
          "esversion": 6,
          "globals":{
            "jQuery": true
           }
       }

    }
  });
  grunt.loadNpmTasks('grunt-contrib-jshint');
  // Default task(s).
  grunt.registerTask('default', ["jshint"]);

};

I'm sure it's something very simple but any help would be great.

Thanks

Community
  • 1
  • 1
user260652
  • 91
  • 1
  • 4
  • 2
    "From the other post I believe this is valid syntax" Sure it's valid syntax, but you don't use a linter to check your syntax. Linters are for detecting things that are *valid* code but nonetheless *bad* code because they tend to mask or otherwise invite runtime errors. Omitting curly braces is a perfect example of such code. – Jordan Running Apr 10 '17 at 21:34
  • Thanks Jordan. I'll keep that in mind. – user260652 Apr 10 '17 at 21:42

1 Answers1

8

The docs say that curly, which you set to true, controls this behaviour. Just set it to false to disable it.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
jcaron
  • 17,302
  • 6
  • 32
  • 46