Completed
Pull Request — master (#1522)
by Abdeali
01:36
created

bears.natural_language.MarkdownBear   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %
Metric Value
dl 0
loc 48
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A config_file() 0 2 1
B run() 0 38 1
1
import json
2
3
from coalib.bearlib.abstractions.Lint import Lint
4
from coalib.bears.LocalBear import LocalBear
5
6
7
class MarkdownBear(Lint, LocalBear):
8
    executable = 'remark'
9
    diff_message = "The text does not comply to the set style."
10
    arguments = '-c {config_file}'
11
    gives_corrected = True
12
    use_stdin = True
13
14
    def config_file(self):
15
        return json.dumps(self.remark_configs).splitlines(keepends=True)
16
17
    def run(self, filename, file,
18
            markdown_bullets: str="-",
19
            markdown_use_closed_headings: bool=False,
20
            markdown_use_setext_headings: bool=False,
21
            markdown_emphasis: str="_",
22
            markdown_strong: str="*",
23
            markdown_encode_entities: bool=False,
24
            markdown_codefence: str="`",
25
            markdown_usefences: bool=False,
26
            markdown_list_indent: str="tab",
27
            markdown_loose_tables: bool=False,
28
            markdown_spaced_tables: bool=True,
29
            markdown_list_increment: bool=True,
30
            markdown_horizontal_rule: str='*',
31
            markdown_horizontal_rule_spaces: bool=False,
32
            markdown_horizontal_rule_repeat: int=3):
33
        """
34
        Raises issues against style violations on markdown files.
35
        """
36
        self.remark_configs = {
37
            "bullet": markdown_bullets,                        # Bool
38
            "closeAtx": markdown_use_closed_headings,          # Bool
39
            "setext": markdown_use_setext_headings,            # Bool
40
            "emphasis": markdown_emphasis,                     # char (_ or *)
41
            "strong": markdown_strong,                         # char (_ or *)
42
            "entities": markdown_encode_entities,              # Bool
43
            "fence": markdown_codefence,                       # char (~ or `)
44
            "fences": markdown_usefences,                      # Bool
45
            "listItemIndent": markdown_list_indent,            # int or "tab"
46
                                                               # or "mixed"
47
            "looseTable": markdown_loose_tables,               # Bool
48
            "spacedTable": markdown_spaced_tables,             # Bool
49
            "incrementListMarker": markdown_list_increment,    # Bool
50
            "rule": markdown_horizontal_rule,                  # - or * or _
51
            "ruleSpaces": markdown_horizontal_rule_spaces,     # Bool
52
            "ruleRepetition": markdown_horizontal_rule_repeat, # int
53
        }
54
        return self.lint(filename, file)
55