<commit_before>from coalib.bears.LocalBear import LocalBear
from coalib.parsing.StringProcessing.Core import unescaped_search_for
from coalib.bearlib.languages.LanguageDefinition import LanguageDefinition
from coalib.results.SourceRange import SourceRange
from coalib.results.Result import Result, RESULT_SEVERITY
from coalib.results.AbsolutePosition import AbsolutePosition
from coalib.results.Diff import Diff

from bears.general.AnnotationBear import AnnotationBear
from bears.general.AnnotationBear import starts_within_ranges


class IndentationBear(LocalBear):

    def run(self,
            filename,
            file,
            dependency_results: dict,
            language: str,
            use_spaces: bool=True,
            tab_width: int=4,
            coalang_dir: str=None):
        """
        It is a generic indent bear, which looks for a start and end
        indent specifier, example: ``{ : }`` where "{" is the start indent
        specifier and "}" is the end indent specifier. If the end-specifier
        is not given, this bear looks for unindents within the code to correctly
        figure out indentation.

        It does not however support hanging indents or absolute indents of
        any sort, also indents based on keywords are not supported yet.
        for example:

            if(something)
            does not get indented

        undergoes no change.

        :param filename:
            Name of the file that needs to be checked.
        :param file:
            File that needs to be checked in the form of a list of strings.
        :param dependency_results:
            Results given by the AnnotationBear.
        :param language:
            Language to be used for indentation.
        :param use_spaces:
            Insert spaces instead of tabs for indentation.
        :param tab_width:
            No. of spaces to insert for indentation.
            Only Applicable if use_spaces is False.
        :param coalang_dir:
            Full path of external directory containing the coalang
            file for language.
        """
        lang_settings_dict = LanguageDefinition(
            language, coalang_dir=coalang_dir)
        annotation_dict = dependency_results[AnnotationBear.name][0].contents
        # sometimes can't convert strings with ':' to dict correctly
        if ':' in list(lang_settings_dict["indent_types"]):
            indent_types = dict(lang_settings_dict["indent_types"])
            indent_types[':'] = ''
        else:
            indent_types = dict(lang_settings_dict["indent_types"])
<commit_msg>IndentationBear: Explain that it is experimental<commit_after>from coalib.bears.LocalBear import LocalBear
from coalib.parsing.StringProcessing.Core import unescaped_search_for
from coalib.bearlib.languages.LanguageDefinition import LanguageDefinition
from coalib.results.SourceRange import SourceRange
from coalib.results.Result import Result, RESULT_SEVERITY
from coalib.results.AbsolutePosition import AbsolutePosition
from coalib.results.Diff import Diff

from bears.general.AnnotationBear import AnnotationBear
from bears.general.AnnotationBear import starts_within_ranges


class IndentationBear(LocalBear):

    def run(self,
            filename,
            file,
            dependency_results: dict,
            language: str,
            use_spaces: bool=True,
            tab_width: int=4,
            coalang_dir: str=None):
        """
        It is a generic indent bear, which looks for a start and end
        indent specifier, example: ``{ : }`` where "{" is the start indent
        specifier and "}" is the end indent specifier. If the end-specifier
        is not given, this bear looks for unindents within the code to correctly
        figure out indentation.

        It does not however support hanging indents or absolute indents of
        any sort, also indents based on keywords are not supported yet.
        for example:

            if(something)
            does not get indented

        undergoes no change.

        WARNING: The IndentationBear is experimental right now, you can report
        any issues found to https://github.com/coala-analyzer/coala-bears

        :param filename:
            Name of the file that needs to be checked.
        :param file:
            File that needs to be checked in the form of a list of strings.
        :param dependency_results:
            Results given by the AnnotationBear.
        :param language:
            Language to be used for indentation.
        :param use_spaces:
            Insert spaces instead of tabs for indentation.
        :param tab_width:
            No. of spaces to insert for indentation.
            Only Applicable if use_spaces is False.
        :param coalang_dir:
            Full path of external directory containing the coalang
            file for language.
        """
        lang_settings_dict = LanguageDefinition(
            language, coalang_dir=coalang_dir)
        annotation_dict = dependency_results[AnnotationBear.name][0].contents
        # sometimes can't convert strings with ':' to dict correctly
        if ':' in list(lang_settings_dict["indent_types"]):
            indent_types = dict(lang_settings_dict["indent_types"])
            indent_types[':'] = ''
        else:
            indent_types = dict(lang_settings_dict["indent_types"])

{'fraction_non_alphanumeric': 0.05796831314072693, 'fraction_numerical': 0.0007455731593662628, 'mean_word_length': 2.491216655823032, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '4531606', 'n_tokens_mistral': 1365, 'n_tokens_neox': 1328, 'n_words': 488}