<commit_before>import {sync as parse} from 'conventional-commits-parser';

export getConfiguration from './library/get-configuration';
export getMessages from './library/get-messages';
export getPreset from './library/get-preset';
export format from './library/format';

export default (message, options = {}) => {
	const {
		preset: {
			parserOpts: parserOptions
		},
		configuration: {
			rules,
			wildcards
		}
	} = options;

	const parsed = parse(message, parserOptions);

	// wildcard matches skip the linting
	const bails = Object.entries(wildcards || {})
		.filter(entry => {
			const [, pattern] = entry;
			return Array.isArray(pattern);
		})
		.filter(entry => {
			const [, pattern] = entry;
			const expression = new RegExp(...pattern);
			return parsed.header.match(expression);
		})
		.map(entry => entry[0]);

	if (bails.length > 0) {
		return {
			valid: true,
			wildcards: bails,
			rules: [],
			warnings: [],
			errors: []
		};
	}

	// validate against all rules
	const results = Object.entries(rules || {})
		.filter(entry => {
			const [, [level]] = entry;
			return level > 0;
		})
		.map(entry => {
			const [name, config] = entry;
			const [level, when, value] = config;

			// Level 0 rules are ignored
			if (level === 0) {
				return null;
			}

			const rule = require(`./rules/${name}`);
			const [valid, message] = rule(parsed, when, value);

			return {
				level,
				valid,
				name,
				message
			};
		})
		.filter(Boolean);

	const errors = results.filter(result =>
		result.level > 1 && !result.valid);

	const warnings = results.filter(result =>
		result.level < 2 && !result.valid);

	const valid = errors.length === 0;

	return {
		valid,
		errors,
		warnings
	};
};
<commit_msg>refactor: expose the entire commit message as raw to rules<commit_after>import {sync as parse} from 'conventional-commits-parser';
import {merge} from 'lodash';

export getConfiguration from './library/get-configuration';
export getMessages from './library/get-messages';
export getPreset from './library/get-preset';
export format from './library/format';

export default (message, options = {}) => {
	const {
		preset: {
			parserOpts: parserOptions
		},
		configuration: {
			rules,
			wildcards
		}
	} = options;

	const parsed = merge(
		{raw: message},
		parse(message, parserOptions)
	);

	// wildcard matches skip the linting
	const bails = Object.entries(wildcards || {})
		.filter(entry => {
			const [, pattern] = entry;
			return Array.isArray(pattern);
		})
		.filter(entry => {
			const [, pattern] = entry;
			const expression = new RegExp(...pattern);
			return parsed.header.match(expression);
		})
		.map(entry => entry[0]);

	if (bails.length > 0) {
		return {
			valid: true,
			wildcards: bails,
			rules: [],
			warnings: [],
			errors: []
		};
	}

	// validate against all rules
	const results = Object.entries(rules || {})
		.filter(entry => {
			const [, [level]] = entry;
			return level > 0;
		})
		.map(entry => {
			const [name, config] = entry;
			const [level, when, value] = config;

			// Level 0 rules are ignored
			if (level === 0) {
				return null;
			}

			const rule = require(`./rules/${name}`);
			const [valid, message] = rule(parsed, when, value);

			return {
				level,
				valid,
				name,
				message
			};
		})
		.filter(Boolean);

	const errors = results.filter(result =>
		result.level > 1 && !result.valid);

	const warnings = results.filter(result =>
		result.level < 2 && !result.valid);

	const valid = errors.length === 0;

	return {
		valid,
		errors,
		warnings
	};
};

{'fraction_non_alphanumeric': 0.15553677092138632, 'fraction_numerical': 0.004508312200619893, 'mean_word_length': 3.066437571592211, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '5346979', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1147, 'n_words': 304}