| Total Complexity | 7 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| 1 | from coalib.results.Result import Result, RESULT_SEVERITY |
||
| 5 | class KeywordBear(LocalBear): |
||
| 6 | def run(self, |
||
| 7 | filename, |
||
| 8 | file, |
||
| 9 | cs_keywords: list, |
||
| 10 | ci_keywords: list): |
||
| 11 | ''' |
||
| 12 | Checks the code files for given keywords. |
||
| 13 | |||
| 14 | :param cs_keywords: A list of keywords to search for (case sensitive). |
||
| 15 | Usual examples are TODO and FIXME. |
||
| 16 | :param ci_keywords: A list of keywords to search for (case |
||
| 17 | insensitive). |
||
| 18 | ''' |
||
| 19 | results = list() |
||
| 20 | |||
| 21 | for i in range(len(ci_keywords)): |
||
| 22 | ci_keywords[i] = ci_keywords[i].lower() |
||
| 23 | |||
| 24 | for line_number, line in enumerate(file): |
||
| 25 | for keyword in cs_keywords: |
||
| 26 | results += self.check_line_for_keyword(line, |
||
| 27 | filename, |
||
| 28 | line_number, |
||
| 29 | keyword) |
||
| 30 | |||
| 31 | for keyword in ci_keywords: |
||
| 32 | results += self.check_line_for_keyword(line.lower(), |
||
| 33 | filename, |
||
| 34 | line_number, |
||
| 35 | keyword) |
||
| 36 | |||
| 37 | return results |
||
| 38 | |||
| 39 | def check_line_for_keyword(self, line, filename, line_number, keyword): |
||
| 40 | pos = line.find(keyword) |
||
| 41 | if pos != -1: |
||
| 42 | return [Result.from_values( |
||
| 43 | origin=self, |
||
| 44 | message="The line contains the keyword `{}`." |
||
| 45 | .format(keyword), |
||
| 46 | file=filename, |
||
| 47 | line=line_number+1, |
||
| 48 | column=pos+1, |
||
| 49 | end_line=line_number+1, |
||
| 50 | end_column=pos+len(keyword)+1, |
||
| 51 | severity=RESULT_SEVERITY.INFO)] |
||
| 52 | |||
| 53 | return [] |
||
| 54 |