<commit_before>SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${SCRIPT_DIR}"

# Enforce line ending consistency in php files.
crlf_file=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --files-with-matches $'\r' {} \;)
if [[ ! -z "${crlf_file}" ]]; then
    echo "${crlf_file}" | perl -pe 's/(.*)/CRLF line terminators found in \1/'
    ((errors++))
fi

# Enforce indentation character consistency in php files.
tab_char=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --line-number -H --perl-regexp "\t" {} \;)
if [[ ! -z "${tab_char}" ]]; then
    echo -e "${tab_char}" | perl -pe 's/^(.*)$/Tab character found in \1/'
    ((errors++))
fi

# Enforce indentation consistency in php files.
find_invalid_indentation() {
    filename="${1}"
    script=$(cat <<'EOF'
    $file_name_color   = '35'; // 35 = Magenta.
    $separator_color   = '36'; // 36 = Cyan.
    $line_number_color = '32'; // 32 = Green.

    $filename = $argv['1'];
    $lines = explode("\n", file_get_contents($filename));
    $line_number = 0;
    foreach ($lines as $line) {
        $line_number += 1;
        $leading_space_count = strspn($line, ' ');
        $remainder = $leading_space_count % 4;
        if ($remainder !== 0) {
            $trimmed_line = ltrim($line);

            // Allow doc comments.
            if (substr($trimmed_line, 0, 1) === '*') {
                continue;
            }
            $add_count = 4 - $remainder;
            $remove_count = $remainder;
            echo 'Invalid indentation found in ' .
                "\033[" . $file_name_color   . 'm' . $filename    . "\033[0m" .
                "\033[" . $separator_color   . 'm' . ':'          . "\033[0m" .
                "\033[" . $line_number_color . 'm' . $line_number . "\033[0m" .
                ' (' . $leading_space_count . ':+' . $add_count . '/-' . $remove_count . ')' . "\n";
        }
    }
EOF<commit_msg>Allow method chaining indentation<commit_after>SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${SCRIPT_DIR}"

# Enforce line ending consistency in php files.
crlf_file=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --files-with-matches $'\r' {} \;)
if [[ ! -z "${crlf_file}" ]]; then
    echo "${crlf_file}" | perl -pe 's/(.*)/CRLF line terminators found in \1/'
    ((errors++))
fi

# Enforce indentation character consistency in php files.
tab_char=$(find .. -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --line-number -H --perl-regexp "\t" {} \;)
if [[ ! -z "${tab_char}" ]]; then
    echo -e "${tab_char}" | perl -pe 's/^(.*)$/Tab character found in \1/'
    ((errors++))
fi

# Enforce indentation consistency in php files.
find_invalid_indentation() {
    filename="${1}"
    script=$(cat <<'EOF'
    $file_name_color   = '35'; // 35 = Magenta.
    $separator_color   = '36'; // 36 = Cyan.
    $line_number_color = '32'; // 32 = Green.

    $filename = $argv['1'];
    $lines = explode("\n", file_get_contents($filename));
    $line_number = 0;
    foreach ($lines as $line) {
        $line_number += 1;
        $leading_space_count = strspn($line, ' ');
        $remainder = $leading_space_count % 4;
        if ($remainder !== 0) {
            $trimmed_line = ltrim($line);

            // Allow doc comments.
            if (substr($trimmed_line, 0, 1) === '*') {
                continue;
            }

            // Allow method chaining.
            if (substr($trimmed_line, 0, 2) === '->') {
                continue;
            }

            $add_count = 4 - $remainder;
            $remove_count = $remainder;
            echo 'Invalid indentation found in ' .
                "\033[" . $file_name_color   . 'm' . $filename    . "\033[0m" .
                "\033[" . $separator_color   . 'm' . ':'          . "\033[0m" .
                "\033[" . $line_number_color . 'm' . $line_number . "\033[0m" .
                ' (' . $leading_space_count . ':+' . $add_count . '/-' . $remove_count . ')' . "\n";
        }
    }
EOF
{'fraction_non_alphanumeric': 0.20156939676311916, 'fraction_numerical': 0.022560078469838155, 'mean_word_length': 2.0646130728775356, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 4, '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': '6063585', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1372, 'n_words': 330}