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 ( c62466...91ade9 )
by thatsIch
59s
created

SkinSectionAutoCompleter   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 71
Duplicated Lines 52.11 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 37
loc 71
rs 10
wmc 14

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __get_completions() 0 10 2
A __get_compiled_key_completions() 0 14 3
F get_key_context_completion() 37 37 9

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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...
Configuration introduced by
The import yaml could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
2
3
import sublime
0 ignored issues
show
Configuration introduced by
The import sublime could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
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")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (83/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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
    # only show our completion list because nothing else makes sense in this context
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (84/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
39
    flags = sublime.INHIBIT_EXPLICIT_COMPLETIONS | sublime.INHIBIT_WORD_COMPLETIONS
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (83/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
40
41
    all_completions = None
42
    all_key_completions = None
43
44 View Code Duplication
    def get_key_context_completion(self, prefix, line_content, sections):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
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
        # if section.casefold() != "Metadata".casefold():
46
        #     return None
47
48
        # use lazy initialization because else the API is not available yet
49
        if not self.all_completions:
50
            self.all_completions = self.__get_completions()
51
            self.all_key_completions = self.__get_compiled_key_completions(self.all_completions)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (96/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
52
53
        # filter by already existing keys
54
        completions = []
55
56
        for completion in self.all_key_completions:
57
            # trigger is not used here
58
            _, content = completion
59
60
            contained = 0
61
            # value not used here
62
            for section in sections:
63
                if section.casefold() == content.casefold():
64
                    contained = 1
65
                    break
66
67
            if contained == 0:
68
                completions.append(completion)
69
70
        # no results, means all keys are used up
71
        if not completions:
72
            return None
73
74
        # only show sorted by distance if something was already typed because distance to empty string makes no sense
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (117/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
75
        if line_content != "":
76
            # sort by levenshtein distance
77
            sorted_completions = sorted(completions, key=lambda completion: levenshtein(completion[1], prefix))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (111/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
78
            return sorted_completions, self.flags
79
        else:
80
            return completions, self.flags
81