<commit_before>/*globals exports, require */

'use strict';

var check, syntaxDefinitions, safeName, syntaxes, report, clearDependencies;

exports.analyse = analyse;

check = require('check-types');
safeName = require('./safeName');
syntaxDefinitions = require('./syntax');

function analyse (ast, options) {
    // TODO: Asynchronize.

    var settings;

    check.verifyObject(ast, 'Invalid syntax tree');

    if (check.isObject(options)) {
        settings = options;
    } else {
        settings = getDefaultSettings();
    }

    syntaxes = syntaxDefinitions.get(settings);
    report = createReport(ast.loc);
    clearDependencies = true;

    processTree(ast.body.statements || ast.body, undefined, undefined);

    calculateMetrics(settings);

    return report;
}

function getDefaultSettings () {
    return {
        logicalor: true,
        switchcase: true,
        forin: false,
        trycatch: false,
        newmi: false
    };
}

function createReport (lines) {
    return {
        aggregate: createFunctionReport(undefined, lines, 0),
        functions: [],
        dependencies: []
    };
}

function createFunctionReport (name, lines, params) {
    var result = {
        name: name,
        complexity: {
            sloc: {
                logical: 0
            },
            cyclomatic: 1,
            halstead: createInitialHalsteadState(),
            params: params
        }
    };

    if (check.isObject(lines)) {
        result.line = lines.start.line;
        result.complexity.sloc.physical: lines.end.line - lines.start.line + 1;
    }

    return result;
}

function createInitialHalsteadState () {
    return {
        operators: createInitialHalsteadItemState(),
        operands: createInitialHalsteadItemState()
    };
}

function createInitialHalsteadItemState () {
    return {
        distinct: 0,
        total: 0,
        identifiers: []
    };
}

function processTree (tree, assignedName, currentReport) {
    check.verifyArray(tree, 'Invalid syntax tree');

    tree.forEach(function (node) {
        processNode(node, assignedName, currentReport);
    });
}

function processNode (node, assignedName, currentReport) {
    var syntax;
<commit_msg>Fix dumb error.<commit_after>/*globals exports, require */

'use strict';

var check, syntaxDefinitions, safeName, syntaxes, report, clearDependencies;

exports.analyse = analyse;

check = require('check-types');
safeName = require('./safeName');
syntaxDefinitions = require('./syntax');

function analyse (ast, options) {
    // TODO: Asynchronize.

    var settings;

    check.verifyObject(ast, 'Invalid syntax tree');

    if (check.isObject(options)) {
        settings = options;
    } else {
        settings = getDefaultSettings();
    }

    syntaxes = syntaxDefinitions.get(settings);
    report = createReport(ast.loc);
    clearDependencies = true;

    processTree(ast.body.statements || ast.body, undefined, undefined);

    calculateMetrics(settings);

    return report;
}

function getDefaultSettings () {
    return {
        logicalor: true,
        switchcase: true,
        forin: false,
        trycatch: false,
        newmi: false
    };
}

function createReport (lines) {
    return {
        aggregate: createFunctionReport(undefined, lines, 0),
        functions: [],
        dependencies: []
    };
}

function createFunctionReport (name, lines, params) {
    var result = {
        name: name,
        complexity: {
            sloc: {
                logical: 0
            },
            cyclomatic: 1,
            halstead: createInitialHalsteadState(),
            params: params
        }
    };

    if (check.isObject(lines)) {
        result.line = lines.start.line;
        result.complexity.sloc.physical = lines.end.line - lines.start.line + 1;
    }

    return result;
}

function createInitialHalsteadState () {
    return {
        operators: createInitialHalsteadItemState(),
        operands: createInitialHalsteadItemState()
    };
}

function createInitialHalsteadItemState () {
    return {
        distinct: 0,
        total: 0,
        identifiers: []
    };
}

function processTree (tree, assignedName, currentReport) {
    check.verifyArray(tree, 'Invalid syntax tree');

    tree.forEach(function (node) {
        processNode(node, assignedName, currentReport);
    });
}

function processNode (node, assignedName, currentReport) {
    var syntax;

{'fraction_non_alphanumeric': 0.11292887980004544, 'fraction_numerical': 0.0027266530334014998, 'mean_word_length': 2.5759545085296507, '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': '1145421', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1210, 'n_words': 282}