<commit_before>/*jshint node: true */
'use strict';

var path = require('path');
var clone = require('clone');
var dot = require('dot');
var Encoder = require('node-html-encoder').Encoder;
var encoder = new Encoder('entity');
var templates = require('./templates');
var buildManual = require('./build-manual');

var descriptionTmpl = '<tr><td><%=id%></td><td><%=description%></td><td><%=tags%></td></tr>\n',
	descriptionsTmpl = '<!DOCTYPE html>\n<html>\n<head></head>\n<body>\n<table>\n<thead><tr>' +
		'<th scope="col">Rule ID</th><th scope="col">Description</th><th scope="col">Tags</th></tr>' +
		'</thead>\n<tbody><%=descriptions%></tbody>\n</table>\n</body>\n</html>';

dot.templateSettings.strip = false;

function buildRules(grunt, options, callback) {

	options.getFiles = false;
	buildManual(grunt, options, function (result) {

		function parseMetaData(data) {
			var result = clone(data) || {};
			if (result.messages) {
				Object.keys(result.messages).forEach(function (key) {
					result.messages[key] = dot.template(result.messages[key]).toString();
				});
			}
			return result;
		}

		function createFailureSummaryObject(summaries) {
			var result = {};
			summaries.forEach(function (summary) {
				result[summary.type] = parseMetaData(summary.metadata);
			});
			return result;
		}<commit_msg>Used for summaries<commit_after>/*jshint node: true */
'use strict';

var path = require('path');
var clone = require('clone');
var dot = require('dot');
var Encoder = require('node-html-encoder').Encoder;
var encoder = new Encoder('entity');
var templates = require('./templates');
var buildManual = require('./build-manual');

var descriptionTmpl = '<tr><td><%=id%></td><td><%=description%></td><td><%=tags%></td></tr>\n',
	descriptionsTmpl = '<!DOCTYPE html>\n<html>\n<head></head>\n<body>\n<table>\n<thead><tr>' +
		'<th scope="col">Rule ID</th><th scope="col">Description</th><th scope="col">Tags</th></tr>' +
		'</thead>\n<tbody><%=descriptions%></tbody>\n</table>\n</body>\n</html>';

dot.templateSettings.strip = false;

function buildRules(grunt, options, callback) {

	options.getFiles = false;
	buildManual(grunt, options, function (result) {

		function parseMetaData(data) {
			var result = clone(data) || {};
			if (result.messages) {
				Object.keys(result.messages).forEach(function (key) {
					result.messages[key] = dot.template(result.messages[key]).toString();
				});
			}
			//TODO this is actually failureSummaries, property name should better reflect that
			if (result.failureMessage) {
				result.failureMessage = dot.template(result.failureMessage).toString();
			}
			return result;
		}

		function createFailureSummaryObject(summaries) {
			var result = {};
			summaries.forEach(function (summary) {
				result[summary.type] = parseMetaData(summary.metadata);
			});
			return result;
		}
{'fraction_non_alphanumeric': 0.1998587570621469, 'fraction_numerical': 0.0, 'mean_word_length': 4.96421052631579, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 69, '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': '4467357', 'n_tokens_mistral': 1003, 'n_tokens_neox': 896, 'n_words': 165}