node-jscs icon indicating copy to clipboard operation
node-jscs copied to clipboard

validateIndentation with chained methods and callbacks

Open sorccu opened this issue 12 years ago • 16 comments

Is there a way to make the following snippet validate using the current ruleset? On both lines with function on them, I get "Expected indentation of 0 characters". It also seems to reset the indent counter of the function body, requiring it to be on level one.

fs.createReadStream('..')
  .on('bar', function() { // validateIndentation wants 0 indent here
    hello()               // and this to be on level 1 (2 spaces)
  })                      // 0
  .on('baz', function() { // 0
  })                      // 0

sorccu avatar Jan 22 '14 02:01 sorccu

Which version are you using?

mdevils avatar Jan 22 '14 08:01 mdevils

1.2.4, the latest version on NPM.

sorccu avatar Jan 22 '14 08:01 sorccu

This is not related to the functions.

I have a similar problem with

Log
    .find({
        level: 1
    })
    .filter('some')

Output is

Expected indentation of 4 characters at test.js :
     1 |Log
     2 |    .find({
     3 |        level: 1
------------^
     4 |    })
     5 |    .filter('some')

Expected indentation of 0 characters at test.js :
     2 |    .find({
     3 |        level: 1
     4 |    })
--------^
     5 |    .filter('some')
     6 |

and validateIndention: 4 on v1.2.4.

Surely,

Log
    .find({
    level: 1
})
    .filter('some')

does not look right.

janraasch avatar Jan 22 '14 09:01 janraasch

I'll be permafixing remaining indentation issues today. I have a strategy to solve this.

mikesherov avatar Jan 22 '14 12:01 mikesherov

Any news on this?

XhmikosR avatar Feb 19 '14 12:02 XhmikosR

We have a lot of issues to attend to, but it's on our radar, any help would be appreciated

markelog avatar Feb 19 '14 12:02 markelog

It's currently the only issue I'm having with JSCS and prevents us from switching to it in Bootstrap. As soon as this is fixed, I will make the switch.

XhmikosR avatar Feb 19 '14 12:02 XhmikosR

Have you tried latest master? This should be fixed... If not, I'll tackle it today. @xhmikosR, let me know.

If latest master fixes it, I'll cut a release.

mikesherov avatar Feb 19 '14 13:02 mikesherov

@mikesherov: I just tried the latest master; we use jscs via grunt-jscs-checker btw.

I replaced grunt-jscs-checker jscs with the latest master and it seems I keep getting the warnings.

Example output:

   231 |
   232 |    $target
Expected indentation of 12 characters at js/modal.js :
   230 |    if ($this.is('a')) e.preventDefault()
   231 |
   232 |    $target
--------------------^
   233 |      .modal(option, this)
   234 |      .one('hide', function () {
Expected indentation of 10 characters at js/modal.js :
   235 |        $this.is(':visible') && $this.focus()
   236 |      })
   237 |  })
------------------^
   238 |
   239 |  $(document)
Expected indentation of 12 characters at js/modal.js :
   237 |  })
   238 |
   239 |  $(document)
--------------------^
   240 |    .on('show.bs.modal', '.modal', function () { $(document.body).addClass('modal-open') })
   241 |    .on('hidden.bs.modal', '.modal', function () { $(document.body).removeClass('modal-open') })
Expected indentation of 10 characters at js/modal.js :
   241 |    .on('hidden.bs.modal', '.modal', function () { $(document.body).removeClass('modal-open') })
   242 |
   243 |}(jQuery);
------------------^
   244 |
>> 181 code style errors found!
Warning: Task "jscs:src" failed. Use --force to continue.

Aborted due to warnings.

C:\Users\xmr\Desktop\bootstrap>

js/modal.js line 239

  $(document)
    .on('show.bs.modal', '.modal', function () { $(document.body).addClass('modal-open') })
    .on('hidden.bs.modal', '.modal', function () { $(document.body).removeClass('modal-open') })

XhmikosR avatar Feb 19 '14 13:02 XhmikosR

Fix incoming. Thanks for the report and your patience.

mikesherov avatar Feb 19 '14 14:02 mikesherov

No problem, thanks for your work!

XhmikosR avatar Feb 19 '14 14:02 XhmikosR

@XhmikosR can you test against master again please? Just want to verify this fix is complete.

mikesherov avatar Feb 19 '14 14:02 mikesherov

Unfortunately, It still fails :/

https://gist.github.com/XhmikosR/9edffc9de843289c716c

XhmikosR avatar Feb 19 '14 14:02 XhmikosR

I just pushed my WIP branch here https://github.com/twbs/bootstrap/compare/jscs

Doing npm install && grunt jscs you should be able to reproduce the warnings better.

XhmikosR avatar Feb 19 '14 15:02 XhmikosR

It's not chained methods and callbacks that's the problem. It's the semicolon-less, brace-less conditionals. Fix ready!

mikesherov avatar Feb 25 '14 15:02 mikesherov

Hey, had the same problem.

fixed by writing the object in one line.

FROM: var session = { from : new Date(0), to : new Date(0), name : results.data[i].name };

TO: var session = {from:new Date(0),to:new Date(0),name:results.data[i].name};

YanBlochSergata avatar Oct 29 '14 12:10 YanBlochSergata