Example #1
0
    def test_commented_out_code_line_numbers_with_for_statement(self):
        self.assertEqual([1, 2],
                         list(
                             eradicate.commented_out_code_line_numbers("""\
# for x in y:
#     oops = x.ham
""")))
Example #2
0
    def test_commented_out_code_line_numbers_with_with_statement(self):
        self.assertEqual([1, 2],
                         list(
                             eradicate.commented_out_code_line_numbers("""\
# with open('filename', 'w') as out_file:
#     json.dump(objects, out_file)
#
""")))
Example #3
0
    def test_commented_out_code_line_numbers(self):
        self.assertEqual([1, 3],
                         list(
                             eradicate.commented_out_code_line_numbers("""\
# print(5)
# This is a comment.
# x = 1

y = 1  # x = 3

# The below is another comment.
# 3 / 2 + 21
""")))
Example #4
0
    def test_commented_out_code_line_numbers(self):
        self.assertEqual(
            [1, 3],
            list(eradicate.commented_out_code_line_numbers(
                """\
# print(5)
# This is a comment.
# x = 1

y = 1  # x = 3

# The below is another comment.
# 3 / 2 + 21
""")))
Example #5
0
    def run(path, code=None, params=None, **meta):
        """Eradicate code checking.

        :return list: List of errors.
        """
        code = converter(code)
        line_numbers = commented_out_code_line_numbers(code)
        lines = code.split('\n')

        result = []
        for line_number in line_numbers:
            line = lines[line_number - 1]
            result.append(dict(
                lnum=line_number,
                offset=len(line) - len(line.rstrip()),
                # https://github.com/sobolevn/flake8-eradicate#output-example
                text=converter('E800 Found commented out code: ') + line,
                # https://github.com/sobolevn/flake8-eradicate#error-codes
                type='E800',
            ))
        return result
Example #6
0
    def execute(self, finder):  # pragma: PY2
        from eradicate import commented_out_code_line_numbers
        issues = []

        for filepath in finder.files(self.config['filters']):
            try:
                source = finder.read_file(filepath).decode('utf-8')
            except EnvironmentError as exc:
                issues.append(AccessIssue(exc, filepath))
                continue

            for line in commented_out_code_line_numbers(source):
                issues.append(
                    EradicateIssue(
                        'commented',
                        'Commented-out code',
                        filepath,
                        line,
                    ))

        return issues
Example #7
0
    def execute(self, finder):

        issues = []
        if CODE in self.config['disabled']:
            return issues

        for filepath in finder.files(self.config['filters']):
            try:
                source = finder.read_file(filepath)
            except EnvironmentError as exc:
                issues.append(AccessIssue(exc, filepath))
                continue

            for line in commented_out_code_line_numbers(source):
                issues.append(EradicateIssue(
                    CODE,
                    DESCRIPTION,
                    filepath,
                    line,
                ))

        return issues
Example #8
0
    def execute(self, finder):  # pragma: PY2
        from eradicate import commented_out_code_line_numbers  # noqa: no-name-in-module

        issues = []
        if CODE in self.config['disabled']:
            return issues

        for filepath in finder.files(self.config['filters']):
            try:
                source = finder.read_file(filepath).decode('utf-8')
            except EnvironmentError as exc:
                issues.append(AccessIssue(exc, filepath))
                continue

            for line in commented_out_code_line_numbers(source):
                issues.append(
                    EradicateIssue(
                        CODE,
                        DESCRIPTION,
                        filepath,
                        line,
                    ))

        return issues