<commit_before>"use strict";


// Hooks for each node.type that should be processed individually
// ---
// using an object to store each transform method to avoid a long switch
// statement, will be more organized in the long run and also allow
// monkey-patching/spies/mock/stub.


// ---


var _ast = require('./util/ast');
var _tk = require('./util/token');
var _ws = require('./util/whiteSpace');
var _br = require('./util/lineBreak');
var _indent = require('./util/indent');
var _brws = require('./util/insert');


// ---


exports.FunctionDeclaration = function(node){
    _tk.removeEmptyInBetween(node.id.startToken, _tk.findNext(node.id.startToken, '{'));

    _ws.afterIfNeeded(node.id.startToken, 'FunctionName');
    exports.Params(node.params);

    _brws.aroundIfNeeded(node.body.startToken, 'FunctionDeclarationOpeningBrace');
    _brws.aroundIfNeeded(node.body.endToken, 'FunctionDeclarationClosingBrace');

    _indent.ifNeeded(node.body.startToken, node.indentLevel);
    _indent.ifNeeded(node.body.endToken, node.indentLevel);
};


exports.Params = function(params){
    if (params.length) {
        _ws.beforeIfNeeded(params[0].startToken, 'ParameterList');
        params.forEach(function(param){
            if (param.startToken.next.value === ',') {
                _ws.aroundIfNeeded(param.startToken.next, 'ParameterComma');
            }
        });
        _ws.afterIfNeeded(params[params.length - 1].endToken, 'ParameterList');
    }
};


exports.FunctionExpression = function(node){
    _tk.removeEmptyInBetween(_tk.findPrev(node.body.startToken, ')'),
                            node.body.startToken);

    if (_tk.findNextNonEmpty(node.body.startToken).value === '}') {
        // noop
        _tk.removeEmptyInBetween(node.startToken, node.endToken);
    } else {
        if (node.id) {
            _ws.afterIfNeeded(node.id.startToken, 'FunctionName');
        }
        exports.Params(node.params);

        _ws.aroundIfNeeded( node.body.startToken, 'FunctionExpressionOpeningBrace' );
        if (node.parent.type !== 'CallExpression') {
            _ws.aroundIfNeeded( node.endToken, 'FunctionExpressionClosingBrace' );
        } else {
            _ws.beforeIfNeeded( node.endToken, 'FunctionExpressionClosingBrace' );
        }

        _br.aroundIfNeeded( node.body.startToken, 'FunctionExpressionOpeningBrace' );
        _br.aroundIfNeeded( node.endToken, 'FunctionExpressionClosingBrace' );
        _indent.ifNeeded(node.body.endToken, node.closingIndentLevel);
    }
};



exports.BinaryExpression = function(node){
    _tk.removeInBetween(node.startToken, node.endToken, 'LineBreak');
    var operator = _tk.findNext(node.left.endToken, node.operator);
    _ws.aroundIfNeeded(operator, 'BinaryExpressionOperator');
    addSpaceInsideExpressionParentheses(node);
};


<commit_msg>remove indent inside binary expressions<commit_after>"use strict";


// Hooks for each node.type that should be processed individually
// ---
// using an object to store each transform method to avoid a long switch
// statement, will be more organized in the long run and also allow
// monkey-patching/spies/mock/stub.


// ---


var _ast = require('./util/ast');
var _tk = require('./util/token');
var _ws = require('./util/whiteSpace');
var _br = require('./util/lineBreak');
var _indent = require('./util/indent');
var _brws = require('./util/insert');


// ---


exports.FunctionDeclaration = function(node){
    _tk.removeEmptyInBetween(node.id.startToken, _tk.findNext(node.id.startToken, '{'));

    _ws.afterIfNeeded(node.id.startToken, 'FunctionName');
    exports.Params(node.params);

    _brws.aroundIfNeeded(node.body.startToken, 'FunctionDeclarationOpeningBrace');
    _brws.aroundIfNeeded(node.body.endToken, 'FunctionDeclarationClosingBrace');

    _indent.ifNeeded(node.body.startToken, node.indentLevel);
    _indent.ifNeeded(node.body.endToken, node.indentLevel);
};


exports.Params = function(params){
    if (params.length) {
        _ws.beforeIfNeeded(params[0].startToken, 'ParameterList');
        params.forEach(function(param){
            if (param.startToken.next.value === ',') {
                _ws.aroundIfNeeded(param.startToken.next, 'ParameterComma');
            }
        });
        _ws.afterIfNeeded(params[params.length - 1].endToken, 'ParameterList');
    }
};


exports.FunctionExpression = function(node){
    _tk.removeEmptyInBetween(_tk.findPrev(node.body.startToken, ')'),
                            node.body.startToken);

    if (_tk.findNextNonEmpty(node.body.startToken).value === '}') {
        // noop
        _tk.removeEmptyInBetween(node.startToken, node.endToken);
    } else {
        if (node.id) {
            _ws.afterIfNeeded(node.id.startToken, 'FunctionName');
        }
        exports.Params(node.params);

        _ws.aroundIfNeeded( node.body.startToken, 'FunctionExpressionOpeningBrace' );
        if (node.parent.type !== 'CallExpression') {
            _ws.aroundIfNeeded( node.endToken, 'FunctionExpressionClosingBrace' );
        } else {
            _ws.beforeIfNeeded( node.endToken, 'FunctionExpressionClosingBrace' );
        }

        _br.aroundIfNeeded( node.body.startToken, 'FunctionExpressionOpeningBrace' );
        _br.aroundIfNeeded( node.endToken, 'FunctionExpressionClosingBrace' );
        _indent.ifNeeded(node.body.endToken, node.closingIndentLevel);
    }
};



exports.BinaryExpression = function(node){
    _tk.removeInBetween(node.startToken, node.endToken, ['LineBreak', 'Indent']);
    var operator = _tk.findNext(node.left.endToken, node.operator);
    _ws.aroundIfNeeded(operator, 'BinaryExpressionOperator');
    addSpaceInsideExpressionParentheses(node);
};



{'fraction_non_alphanumeric': 0.13921154523055262, 'fraction_numerical': 0.0007039774727208729, 'mean_word_length': 3.3648233486943164, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '561322', 'n_tokens_mistral': 1761, 'n_tokens_neox': 1709, 'n_words': 269}