コード例 #1
0
ファイル: validator.py プロジェクト: gafetinov/pep8_validator
 def check_error0903(self, line):
     if (line.startswith('def') or line.startswith('class'))\
             and self.line_number > 2:
         if not (self.previous_lines[-1].isspace()
                 and self.previous_lines[-2].isspace()):
             self.errors_found.append(Error((self.line_number, 1), 'E0903'))
         elif self.line_number > 3 and self.previous_lines[-3].isspace():
             self.errors_found.append(Error((self.line_number, 1), 'E0903'))
コード例 #2
0
ファイル: validator.py プロジェクト: gafetinov/pep8_validator
 def check_error0906(self, line):
     if (re.match('\S', line.lstrip()) and self.line_number > 2
             and self.previous_lines[-1].isspace()
             and self.previous_lines[-2].isspace()):
         if re.match('\s', line):
             self.errors_found.append(Error((self.line_number, 1), 'E0906'))
         elif self.line_number > 3 and self.previous_lines[-3].isspace():
             self.errors_found.append(Error((self.line_number, 1), 'E0906'))
コード例 #3
0
ファイル: validator.py プロジェクト: gafetinov/pep8_validator
 def check_error0202(self, line):
     words = line.split()
     if words and words[0] == 'def':
         if len(words) == 1:
             self.errors_found.append(
                 Error((self.line_number, line.find(words[0]) + len('def')),
                       'E0202'))
         if not words[1].islower():
             self.errors_found.append(
                 Error((self.line_number, line.find(words[1])), 'E0202'))
コード例 #4
0
ファイル: validator.py プロジェクト: gafetinov/pep8_validator
 def check_error0201(self, line):
     words = line.split()
     if words and words[0] == 'class':
         if len(words) == 1:
             self.errors_found.append(
                 Error(
                     (self.line_number, line.find(words[0]) + len('class')),
                     'E0201'))
         elif not is_cap_word(words[1]):
             self.errors_found.append(
                 Error((self.line_number, line.find(words[1])), 'E0201'))
コード例 #5
0
ファイル: validator.py プロジェクト: gafetinov/pep8_validator
 def check_error0902(self, line):
     if line.startswith('class') and \
             len(self.previous_lines) >= self.line_number:
         if self.previous_lines[self.line_number - 1] != ' ' and \
                 self.previous_lines[self.line_number - 2] != ' ' and \
                 self.previous_lines[self.line_number - 3] == ' ':
             self.errors_found.append(
                 Error((self.line_number, line.find('class')), 'E0902'))
コード例 #6
0
ファイル: validator.py プロジェクト: gafetinov/pep8_validator
 def check_error0301(self, line):
     words = line.split()
     if words and words[0] == 'import':
         if len(words) > 2:
             if words[2] != 'as':
                 self.errors_found.append(
                     Error((self.line_number, line.find(words[2])),
                           'E0301'))
コード例 #7
0
ファイル: validator.py プロジェクト: gafetinov/pep8_validator
 def check_error0705(self, line):
     # Unexpected spaces around keyword / parameter equals
     indexes = self.get_all_occurrences('=', line)
     for index in indexes:
         if not self.is_in_quotes(line, index) and \
                 self.is_for_parameter(line, index) and\
                 line[index-1] != '=' and line[index-1] != '!' and\
                 line[index+1] != '=':
             if line[index - 1] == ' ':
                 i = 2
                 while line[index - i] == ' ':
                     i += 1
                 self.errors_found.append(
                     Error((self.line_number, index - i + 2), 'E0705'))
             if line[index + 1] == ' ':
                 i = 2
                 while line[index + i] == ' ':
                     i += 1
                 self.errors_found.append(
                     Error((self.line_number, index + i), 'E0705'))
コード例 #8
0
ファイル: validator.py プロジェクト: gafetinov/pep8_validator
 def check_error0501(self, line):
     for boolean in BOOL_TYPES:
         line_without_spaces = line.replace(' ', '')
         i = line_without_spaces.find(boolean)
         operators = ('==', '!=', 'is', 'isnot')
         if i != -1:
             for operator in operators:
                 if line_without_spaces[i - 2:i] == operator or \
                         line_without_spaces[i - 5:i] == operator:
                     self.errors_found.append(
                         Error((self.line_number, i), 'E0501'))
コード例 #9
0
ファイル: validator.py プロジェクト: gafetinov/pep8_validator
 def check_error0904(self, line):
     if (line.lstrip().startswith('def') and self.line_number > 2
             and not self.previous_lines[-1].lstrip().startswith('class')
             and not self.previous_lines[-1].lstrip().startswith('def')
             and not self.previous_lines[-1].lstrip().startswith('#')
             and re.match('\s', line)):
         if not self.previous_lines[-1].isspace() or\
                 self.previous_lines[-2].isspace():
             self.errors_found.append(
                 Error((self.line_number, str.find('def', line) + 1),
                       'E0904'))
コード例 #10
0
ファイル: validator.py プロジェクト: gafetinov/pep8_validator
 def check_error0704(self, line):
     words = line.split()
     previous_word = ''
     symbol_index = len(line) - len(line.lstrip())
     for i in range(len(words)):
         if words[i][0] in PUNCTUATION_MARKS and \
                 len(previous_word) > 0 and previous_word[-1] != ',' and \
                 previous_word not in BIN_OPERATORS:
             self.errors_found.append(
                 Error((self.line_number, symbol_index + len(words[i]) + 1),
                       'E0704'))
         previous_word = words[i]
コード例 #11
0
ファイル: validator.py プロジェクト: gafetinov/pep8_validator
 def check_error0707(self, line):
     line = line.lstrip()
     for operator in BIN_OPERATORS:
         indexes = self.get_all_occurrences(operator, line)
         for index in indexes:
             if line[index - 1] not in ARITHMETIC_OPERATORS and \
                     not self.is_in_quotes(line, index):
                 if line[index - 1] == ' ':
                     if line[index - 2] == ' ':
                         i = 2
                         while line[index - i] == ' ':
                             i += 1
                         self.errors_found.append(
                             Error((self.line_number, i), 'E0707'))
                 if line[index + len(operator)] == ' ':
                     if line[index + len(operator) + 1] == ' ':
                         i = len(operator) + 1
                         while line[index + 1] == ' ':
                             i += 1
                         self.errors_found.append(
                             Error((self.line_number, index + i), 'E0707'))
コード例 #12
0
ファイル: validator.py プロジェクト: gafetinov/pep8_validator
 def check_error0701(self, line):
     words = line.split()
     next_word = ''
     symbol_index = len(line) - len(line.lstrip())
     for i in range(len(words)):
         if i + 1 < len(words):
             next_word = words[i + 1]
         if words[i][-1] in OPENED_BRACKETS and \
                 i + 1 < len(words) and next_word not in BIN_OPERATORS:
             self.errors_found.append(
                 Error((self.line_number, symbol_index + len(words[i]) + 1),
                       'E0701'))
         symbol_index += len(words[i]) + 1
コード例 #13
0
ファイル: validator.py プロジェクト: gafetinov/pep8_validator
 def check_error0302(self, line):
     i = line.find(' lambda ')
     if i == -1:
         for mark in PUNCTUATION_MARKS:
             i = line.find(mark)
             if mark == ',':
                 i = -1
             if i != -1:
                 if not self.is_in_quotes(line, i) and \
                         not self.is_in_quadratic_bracket(line, i) and \
                         i + 1 < len(line.rstrip()) \
                         and not self.is_in_bracket(line, i):
                     self.errors_found.append(
                         Error((self.line_number, i), 'E0302'))
コード例 #14
0
ファイル: validator.py プロジェクト: gafetinov/pep8_validator
 def check_error0706(self, line):
     for operator in BIN_OPERATORS2:
         indexes = self.get_all_occurrences(operator, line)
         for index in indexes:
             if line[index] and not line[index - 1].isalpha() and \
                     not line[index + len(operator)].isalpha() and \
                     line[index - 1] not in ARITHMETIC_OPERATORS and \
                     not self.is_in_quotes(line, index):
                 if (line[index - 1] == ')' or line[index - 1] == '(')\
                         and line[index:index+3] != 'not':
                     self.errors_found.append(
                         Error((self.line_number, index - 1), 'E0706'))
                 if line[index + len(operator)] == ')' or \
                         line[index + len(operator)] == ')':
                     self.errors_found.append(
                         Error((self.line_number, index + len(operator)),
                               'E0706'))
     for operator in BIN_OPERATORS1:
         indexes = self.get_all_occurrences(operator, line)
         for index in indexes:
             if line[index - 1] not in ARITHMETIC_OPERATORS and \
                     line[index - 1] != '!' and \
                     line[index - 1] != '>' and \
                     line[index - 1] != '<' and \
                     line[index - 1] != '=' and \
                     line[index + 1] != '=' and \
                     not self.is_in_quotes(line, index) and \
                     not self.is_for_parameter(line, index) and \
                     len(self.bracket_stack) > 0:
                 if line[index - 1] != ' ':
                     self.errors_found.append(
                         Error((self.line_number, index - 1), 'E0706'))
                 if line[index + len(operator)] != ' ':
                     self.errors_found.append(
                         Error(
                             (self.line_number, index + len(operator) + 1),
                             'E0706'))
コード例 #15
0
ファイル: validator.py プロジェクト: gafetinov/pep8_validator
 def check_error0702(self, line):
     words = line.split()
     previous_word = ''
     symbol_index = len(line) - len(line.lstrip())
     for i in range(len(words)):
         index = line.find(words[i])
         if words[i][0] == OPENED_BRACKETS and \
                 not self.is_in_quotes(line, index) and \
                 len(previous_word) > 0 and previous_word[-1] != ',' and \
                 previous_word not in BIN_OPERATORS:
             self.errors_found.append(
                 Error((self.line_number, symbol_index + len(words[i]) + 1),
                       'E0702'))
         previous_word = words[i]
         symbol_index += len(words[i]) + 1
コード例 #16
0
ファイル: validator.py プロジェクト: gafetinov/pep8_validator
 def check_error0102(self, line):
     if self.bracket_stack:
         spaces = self.get_space_count(line)
         sub = line.lstrip()
         if sub[0] in QUOTES:
             spaces -= 1
         index = -1
         if self.bracket_stack[-1] != spaces - 1:
             if spaces-1 == line[:re.search('\S', line).start()]\
                     .count(' ')+4:
                 self.errors_found.append(
                     Error((self.line_number, spaces), 'E0102'))
     for i in range(len(line)):
         symbol = line[i]
         if symbol in OPENED_BRACKETS and not self.is_in_quotes(line, i):
             self.bracket_stack.append(i)
         elif symbol in CLOSED_BRACKETS and \
                 not self.is_in_quotes(line, i):
             self.bracket_stack.pop()
コード例 #17
0
ファイル: validator.py プロジェクト: gafetinov/pep8_validator
 def check_error0101(self, line):
     if not is_space_count_multiple_four(line) and \
             len(self.bracket_stack) == 0:
         self.errors_found.append(Error((self.line_number, 1), 'E0101'))
コード例 #18
0
ファイル: validator.py プロジェクト: gafetinov/pep8_validator
 def check_error0905(self):
     if self.is_file and self.previous_lines[-1] == '\n' and \
             self.previous_lines[-2][-1] == '\n':
         self.errors_found.append(Error((self.line_number, 1), 'E0905'))
コード例 #19
0
ファイル: validator.py プロジェクト: gafetinov/pep8_validator
 def check_error0203(self, line):
     words = line.split()
     if words and words[0] == 'import':
         if not words[1].islower():
             self.errors_found.append(
                 Error((self.line_number, line.find(words[1])), 'E0203'))
コード例 #20
0
ファイル: validator.py プロジェクト: gafetinov/pep8_validator
 def check_error0401(self, line):
     line = line.lstrip()
     i = line.find('#')
     if i != -1:
         if line[i + 1] != ' ' and not self.is_in_quotes(line, i):
             self.errors_found.append(Error((self.line_number, i), 'E0401'))
コード例 #21
0
ファイル: validator.py プロジェクト: gafetinov/pep8_validator
 def check_error0601(self, line):
     if len(line) > 79:
         self.errors_found.append(Error((self.line_number, 79), 'E0601'))
コード例 #22
0
ファイル: validator.py プロジェクト: gafetinov/pep8_validator
 def check_error0901(self):
     if self.is_file and self.previous_lines[-1][-1] != '\n':
         self.errors_found.append(Error((self.line_number, 0), 'E0901'))
コード例 #23
0
ファイル: validator.py プロジェクト: gafetinov/pep8_validator
 def check_error0801(self, line):
     indexes = self.get_all_occurrences(' lambda ', line)
     for i in indexes:
         if not self.is_in_quotes(line, i):
             self.errors_found.append(Error((self.line_number, i), 'E0801'))