Is there a way I can make jslint work with curly braces on the next line of my javascript?

和自甴很熟 提交于 2019-12-23 15:41:52

问题


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?


回答1:


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.




回答2:


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..



来源:https://stackoverflow.com/questions/12633434/is-there-a-way-i-can-make-jslint-work-with-curly-braces-on-the-next-line-of-my-j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!