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

Unary and Binary Operators combined with Functions produce incorrect indentation #445

Open
Faleij opened this issue Jun 5, 2016 · 1 comment
Labels
Milestone

Comments

@Faleij
Copy link

Faleij commented Jun 5, 2016

Thanks for fixing #443, however I have found some more indentation problems with Unary and Binary operators combined with Functions. Return statement is irrelevant in all cases, could as well be an variable assignment.

'use strict';

// Unary Operators produce incorrect indentation with functions (return statement is irrelevant)
function aFn() {
    return [].reduce((p, c) => {
            return p + c;
        }, 0) / 1;
}

function aFn() {
    return 1 + (function() {
            return arguments;
        })();
}

function aFn() {
    return typeof function() {
            return arguments;
        } === 'function';
}

function aFn() {
    const b = [].reduce((p, c) => {
            return p + c;
        }, 0) / 1;
    return b;
}

// Binary Operators |, &&, instanceof and in, (possibly more?) produce incorrect indentation combined with functions  (return statement is irrelevant)
function aFn() {
    return 1 | (function() {
            return arguments;
        })();
}

function aFn(a) {
    return (function() {
            return arguments;
        })() && (function() {
            return arguments;
        })(); // same results if functions are not wrapped
}

function aFn(a) {
    return [function() {
            return;
        }] instanceof Array;
}

function aFn(a) {
    const b = [function() {
            return;
        }] instanceof Array;
    return b;
}

function aFn(a) {
    return a in [function() {
            return;
        }];
}

function aFn(a) {
    return function() {
            return;
        } instanceof Function;
}

aFn();
$ esformatter test.js > test_out.js
$ eslint test_out.js

D:\github\test\test.js
   6:13  error  Expected indentation of 8 space characters but found 12  indent
   7:9   error  Expected indentation of 4 space characters but found 8   indent
  12:13  error  Expected indentation of 8 space characters but found 12  indent
  13:9   error  Expected indentation of 4 space characters but found 8   indent
  18:13  error  Expected indentation of 8 space characters but found 12  indent
  19:9   error  Expected indentation of 4 space characters but found 8   indent
  24:13  error  Expected indentation of 8 space characters but found 12  indent
  25:9   error  Expected indentation of 4 space characters but found 8   indent
  38:13  error  Expected indentation of 8 space characters but found 12  indent
  39:9   error  Expected indentation of 4 space characters but found 8   indent
  46:13  error  Expected indentation of 8 space characters but found 12  indent
  47:9   error  Expected indentation of 4 space characters but found 8   indent
  52:13  error  Expected indentation of 8 space characters but found 12  indent
  53:9   error  Expected indentation of 4 space characters but found 8   indent
  60:13  error  Expected indentation of 8 space characters but found 12  indent
  61:9   error  Expected indentation of 4 space characters but found 8   indent
  66:13  error  Expected indentation of 8 space characters but found 12  indent
  67:9   error  Expected indentation of 4 space characters but found 8   indent
  73:13  error  Expected indentation of 8 space characters but found 12  indent
  74:9   error  Expected indentation of 4 space characters but found 8   indent
  79:13  error  Expected indentation of 8 space characters but found 12  indent
  80:9   error  Expected indentation of 4 space characters but found 8   indent

✖ 22 problems (22 errors, 0 warnings)

esformatter v0.9.5

@millermedeiros
Copy link
Owner

millermedeiros commented Jun 5, 2016

@Faleij thanks a lot for the bug reports! please keep them coming!

it is a conflict with the ReturnStatement indentation, similar to what happened on #443 - will probably need to improve logic to actually check if nodes at left/right of the operator will add indentation or not (for BinaryExpression, UnaryExpression and LogicalExpression)

maybe we can abstract the logic somehow, so we don't need to implement it also for AssignmentExpression, VariableDeclaration and ObjectExpression... - I wish the whole indentation logic was simpler...

@millermedeiros millermedeiros modified the milestone: v0.11.0 Oct 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants