<commit_before>﻿namespace FilterLists.Services.Snapshot
{
    public static class RawRuleLinterExtensions
    {
        public static string LintRawRule(this string rule)
        {
            rule = rule?.TrimLeadingAndTrailingWhitespace();
            rule = rule?.DropIfEmpty();
            rule = rule?.DropIfComment();
            rule = rule?.DropIfTooLong();
            rule = rule?.DropIfContainsBackslashSingleQuote();
            rule = rule?.TrimSingleBackslashFromEnd();
            return rule;
        }

        private static string TrimLeadingAndTrailingWhitespace(this string rule)
        {
            char[] charsToTrim = {' ', '\t'};
            return rule.Trim(charsToTrim);
        }

        private static string DropIfEmpty(this string rule) => rule == "" ? null : rule;

        private static string DropIfComment(this string rule) =>
            rule.StartsWith(@"!") && !rule.StartsWith(@"!#") || rule.StartsWith(@"!##") ? null : rule;

        private static string DropIfTooLong(this string rule) => rule.Length > 8192 ? null : rule;

        private static string DropIfContainsBackslashSingleQuote(this string rule) =>
            rule.Contains(@"\'") ? null : rule;

        private static string TrimSingleBackslashFromEnd(this string rule) =>
            rule.EndsWith(@"\") && !rule.EndsWith(@"\\") ? rule.Remove(rule.Length - 1) : rule;
    }
}<commit_msg>tweak snapshot LintRawRule<commit_after>﻿using System;

namespace FilterLists.Services.Snapshot
{
    public static class RawRuleLinterExtensions
    {
        public static string LintRawRule(this string rule)
        {
            rule = rule.Trim();
            rule = rule.DropIfTooLong();
            rule = rule?.DropIfComment();
            rule = rule?.DropIfContainsBackslashSingleQuote();
            rule = rule?.TrimSingleBackslashFromEnd();
            rule = rule?.DropIfEmpty();
            return rule;
        }

        private static string DropIfTooLong(this string rule) =>
            rule.Length > 8192 ? null : rule;

        private static string DropIfComment(this string rule) =>
            rule.StartsWith(@"!", StringComparison.Ordinal) && !rule.StartsWith(@"!#", StringComparison.Ordinal) ||
            rule.StartsWith(@"!##", StringComparison.Ordinal)
                ? null
                : rule;

        private static string DropIfContainsBackslashSingleQuote(this string rule) =>
            rule.Contains(@"\'") ? null : rule;

        private static string TrimSingleBackslashFromEnd(this string rule) =>
            rule.EndsWith(@"\", StringComparison.Ordinal) && !rule.EndsWith(@"\\", StringComparison.Ordinal)
                ? rule.Remove(rule.Length - 1)
                : rule;

        private static string DropIfEmpty(this string rule) =>
            rule == string.Empty ? null : rule;
    }
}
{'fraction_non_alphanumeric': 0.11677805135420331, 'fraction_numerical': 0.0035174111853675696, 'mean_word_length': 2.3537735849056602, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '676282', 'n_tokens_mistral': 770, 'n_tokens_neox': 730, 'n_words': 173}