GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( a80d0d...29a21c )
by thatsIch
01:00
created

get_key_context_completion()   A

Complexity

Conditions 4

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
c 2
b 0
f 0
dl 0
loc 18
rs 9.2
1
import yaml
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
3
import sublime
4
5
from .. import logger
0 ignored issues
show
Bug introduced by
The name logger does not seem to exist in module completion.
Loading history...
6
from .levenshtein import levenshtein
7
from .yaml_content_reader import YamlContentReader
8
9
10
class SkinSectionAutoCompleter(YamlContentReader):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
11
12
    def __get_completions(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
13
        try:
14
            section_content = self._get_yaml_content("completion/", "section.yaml")
15
            section = yaml.load(section_content)
16
17
            return section
18
19
        except yaml.YAMLError as error:
20
            logger.error(__file__, "__get_completions(self)", error)
21
            return []
22
23
    def __get_compiled_key_completions(self, options):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
24
        keys = []
25
        for option in options:
26
            title = option['title'] + "\t" + option['hint']
27
28
            if 'value' in option:
29
                result = option['value']
30
            else:
31
                result = option['title']
32
33
            pair = (title, result)
34
            keys.append(pair)
35
36
        return keys
37
38
    def __lazy_initialize_completions(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
39
        # use lazy initialization because else the API is not available yet
40
        if not self.all_completions:
41
            self.all_completions = self.__get_completions()
42
            self.all_key_completions = self.__get_compiled_key_completions(self.all_completions)
43
44
    def __filter_completions_by_already_defined_sections(self, sections):
0 ignored issues
show
Coding Style Naming introduced by
The name __filter_completions_by_already_defined_sections does not conform to the method naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
45
        # filter by already existing keys
46
        completions = []
47
48
        for completion in self.all_key_completions:
49
            # trigger is not used here
50
            _, content = completion
51
52
            contained = 0
53
            # value not used here
54
            for section in sections:
55
                if section.casefold() == content.casefold():
56
                    contained = 1
57
                    break
58
59
            if contained == 0:
60
                completions.append(completion)
61
62
        return completions
63
64
    # only show our completion list because nothing else makes sense in this context
65
    flags = sublime.INHIBIT_EXPLICIT_COMPLETIONS | sublime.INHIBIT_WORD_COMPLETIONS
66
67
    all_completions = None
68
    all_key_completions = None
69
70
    def get_key_context_completion(self, prefix, line_content, sections):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
71
        # if section.casefold() != "Metadata".casefold():
72
        #     return None
73
74
        self.__lazy_initialize_completions()
75
        completions = self.__filter_completions_by_already_defined_sections(sections)
76
77
        # no results, means all keys are used up
78
        if not completions:
79
            return None
80
81
        # only show sorted by distance if something was already typed because distance to empty string makes no sense
82
        if line_content != "":
83
            # sort by levenshtein distance
84
            sorted_completions = sorted(completions, key=lambda completion: levenshtein(completion[1], prefix))
85
            return sorted_completions, self.flags
86
        else:
87
            return completions, self.flags
88