3

I changed my coding style from

function getParams(entity) {
    "use strict";
    var accountID = store.getItem('AccountID'),

    switch (entity) {
        case "Topic":

to

function getParams(entity) 
{

    "use strict";
    var accountID = store.getItem('AccountID'),

    switch (entity)
    {
        case "Topic":

Now I get any jslint errors such as:

Warning 6 JS Lint: Expected exactly one space between ')' and '{'. Warning 9 JS Lint: Expected 'var' at column 9, not column 5.

I checked through the options but cannot find any option to unselect relating to line position. Also if there is one then could I add it to the top of my file?

  • Not really the right place to post this question. SO relates to programming/development, not how to change preferences of software. – ahren Sep 28 '12 at 04:26

2 Answers2

5

In JavaScript is recommended to put opening braces on the same line for this reason:

function foo()
{
  return
  {
    a: 'foo'
  }
}

foo().a // error

This is more an advice than a solution but impossible to explain in a comment without new lines.

elclanrs
  • 92,861
  • 21
  • 134
  • 171
  • What causes this? I see the error, not sure I follow why it's there. – Shane Aug 15 '13 at 14:26
  • 2
    Automatic semi-colon insertion treats a newline after certain keywords as a statement terminator. `return` is one of these keywords. So `return27` is the same as `return;27;` instead of the more intuitive `return 27;`. This is a special case of ASI. In most other cases, ASI will continue a statement whenever possible, which causes even more weirdness, to be honest. – Keen Sep 09 '13 at 19:04
0

Try this, jSLint uses string javascript coding rules to check your javascript..

var store = {};
function getParams(entity) {
    "use strict";
    var accountID = store.getItem('AccountID');

    switch (entity) {
    case "Topic": 
        accountID = '0';
        break;
    }
}

For a function it expects just 1 space between the ) and { characters .. It is not an issue but it is a coding rule..

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
Sushanth --
  • 55,259
  • 9
  • 66
  • 105