def _check_new_line_after_assign(self, oToi): if self.new_line_after_assign == 'ignore': return iLine, lTokens = utils.get_toi_parameters(oToi) iNextToken = utils.find_next_non_whitespace_token(1, lTokens) iNumCarriageReturns = utils.count_carriage_returns(lTokens[:iNextToken]) if iNumCarriageReturns == 0: if self.new_line_after_assign == 'yes': sSolution = 'Add return after assignment.' oViolation = _create_violation(oToi, iLine, 1, 1, 'new_line_after_assign', 'insert', sSolution) self.add_violation(oViolation) else: if self.new_line_after_assign == 'no': sSolution = 'Move code after assignment to the same line as assignment.' oViolation = _create_violation(oToi, iLine, 0, iNextToken, 'new_line_after_assign', 'remove', sSolution) self.add_violation(oViolation)
def _check_open_paren_new_line(self, oToi): if self.open_paren_new_line == 'ignore': return iLine, lTokens = utils.get_toi_parameters(oToi) bSearch = False bAssignmentFound = False bOthersClause = False iToken = _find_assignment_operator(lTokens) + 1 iStopIndex = len(lTokens) bFirstParenFound = False while iToken < iStopIndex: if bFirstParenFound: iToken, bOthersClause = _classify_others(iToken, lTokens) if bOthersClause: iToken += 1 continue iToken, bAssignmentFound = _classify_assignment(iToken, lTokens) if bAssignmentFound: iToken += 1 continue oToken = lTokens[iToken] if isinstance(oToken, parser.open_parenthesis): bFirstParenFound = True if utils.is_token_at_end_of_line(iToken, lTokens): if self.open_paren_new_line == 'no': iEnd = utils.find_next_non_whitespace_token( iToken + 1, lTokens) iErrorLine = rule_utils.number_of_carriage_returns( lTokens[:iToken]) + iLine sSolution = 'Remove carriage return after open parenthesis.' oViolation = _create_violation(oToi, iErrorLine, iToken, iEnd, 'open_paren_new_line', 'remove', sSolution) self.add_violation(oViolation) else: if self.open_paren_new_line == 'yes': sSolution = 'Add carriage return after open parenthesis.' iErrorLine = rule_utils.number_of_carriage_returns( lTokens[:iToken]) + iLine oViolation = _create_violation(oToi, iErrorLine, iToken, iToken, 'open_paren_new_line', 'insert', sSolution) self.add_violation(oViolation) bOthersClause = False iToken += 1 return None
def _starts_with_paren(lTokens): iToken = utils.find_next_non_whitespace_token(1, lTokens) try: if isinstance(lTokens[iToken], parser.open_parenthesis): return True except IndexError: if isinstance(lTokens[0], parser.open_parenthesis): return True return False