Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indentation of functions inside conditionals not passing jslint #298

Closed
fidian opened this issue Jun 19, 2013 · 5 comments
Closed

Indentation of functions inside conditionals not passing jslint #298

fidian opened this issue Jun 19, 2013 · 5 comments
Milestone

Comments

@fidian
Copy link

fidian commented Jun 19, 2013

When given this file it will pass jslint's tests.

'use strict';
if ([].some(function () {
        return false;
    })) {
    console.log('hello');
}

After beautifying with the -j option, the return false; and the next line both have one less indentation level, making jslint unhappy.

@evocateur
Copy link
Contributor

If you're using an inline iterator like that, I would argue that jslint is wrong. The function's closing brace doesn't line up with the opening brace's beginning column, for pity's sake.

All the "jslint-happy" arg does right now is put a space between the function keyword and the opening paren in anonymous functions. I don't think it should be modifying indentation behaviour like this.

(Coincidentally, jshint has no problem with the beautified output)

@fidian
Copy link
Author

fidian commented Jun 19, 2013

As it currently stands, either the documentation should change to say "--jslint-happy" only makes it sorta content and not truly happy, or else one should support the jslint quirks. I believe that discussion of jshint (a similar yet unrelated tool) is out of scope as the option I'm discussing is not "--jshint-or-jslint-happy". I mean no disrespect to jshint.

I suppose the topic about this being a bug in jslint might also be out of scope because I'd like for either the option to work or the documentation of the option to not be as misleading. Personally I don't like the above example formatted like this, which is what js-beautify does, and lean towards the indentation that jslint prefers.

'use strict';
if ([].some(function () {
    return false;
})) {
    console.log('hello');
}

@einars
Copy link
Contributor

einars commented Jun 19, 2013

  -j, --jslint-happy            Enable jslint-stricter mode

Stricter, so technically the description is fine.

I don't know if any of the active jsbeautifier's developers follow jslint's idea of beauty (it is too crazily hypercritical by default to me), but you're very welcome to submit a pull request that fixes things to jslint-happy mode to make it happier by default.

This will probably raise future issues "why is jslint-happy mode indenting my code so ugly? I just want spaces in empty functions", but that's a discussion for a day when that comes.

@bitwiseman
Copy link
Member

I need start out by saying this about the sample input code: ⁉️ ... 😱
Sorry. I'm okay now.

I think I made the conscious choice to not have the minimal indenting feature work inside conditionals for exactly the reason @einars mentions. Turning it on shouldn't be too hard.

@bitwiseman
Copy link
Member

Actually, it looks like the minimal indent does work inside conditionals and that's the problem. I need to make the indent from if/do/while parens be non-removable.

//input and expected output
'use strict';
if ([].some(function () {
        return false;
    })) {
    console.log('hello');
}

// actual output 
'use strict';
if ([].some(function () {
    return false;
})) {
    console.log('hello');
}

@bitwiseman bitwiseman modified the milestones: v1.6.0, v1.5.3 Sep 30, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants