Esempio n. 1
0
    def process_files(self, files):
        """
        Run code smell checks with reek
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = ['reek']
        if bundle_exists('reek'):
            command = ['bundle', 'exec', 'reek']
        command += ['--single-line','--no-color']
        command += files
        output = run_command(
            command,
            split=True,
            ignore_error=True,
            include_errors=False
        )

        if not output:
            log.debug('No reek errors found.')
            return False

        for line in output:
            """
            Reek -s outputs warnings with leading spaces
            """
            if isinstance(line, basestring) and line.startswith(' '):
                filename, line, error = self._parse_line(line)
                self.problems.add(filename, line, error)
Esempio n. 2
0
    def process_files(self, files):
        """
        Run code checks with puppet-lint
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = ['puppet-lint']
        if bundle_exists('puppet-lint'):
            command = ['bundle', 'exec', 'puppet-lint']
        command += ['--log-format',
                    '%{path}:%{linenumber}:%{KIND}:%{message}']
        command += files
        output = run_command(
            command,
            split=True,
            ignore_error=True,
            include_errors=False
        )

        if not output:
            log.debug('No puppet-lint errors found.')
            return False

        for line in output:
            filename, line, error = self._parse_line(line)
            self.problems.add(filename, line, error)
Esempio n. 3
0
    def process_files(self, files):
        """
        Run code checks with rubocop
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = ['rubocop']
        if bundle_exists('rubocop'):
            command = ['bundle', 'exec', 'rubocop']
        command += ['--format', 'emacs']
        if self.options.get('display_cop_names', '').lower() == 'true':
            command += ['--display-cop-names']
        command += files
        output = run_command(
            command,
            split=True,
            ignore_error=True,
            include_errors=False
        )

        if not output:
            log.debug('No rubocop errors found.')
            return False

        for line in output:
            filename, line, error = self._parse_line(line)
            self.problems.add(filename, line, error)
Esempio n. 4
0
    def process_files(self, files):
        command = ['foodcritic']
        if bundle_exists('foodcritic'):
            command = ['bundle', 'exec', 'foodcritic']
        # if no directory is set, assume the root
        path = os.path.join(self.base_path, self.options.get('path', ''))
        command += [path]
        output = run_command(command, split=True, ignore_error=False)

        if output[0] == '\n':
            log.debug('No foodcritic errors found.')
            return False

        for line in output:
            filename, line, error = self._parse_line(line)
            self.problems.add(filename, line, error)
Esempio n. 5
0
    def process_files(self, files):
        command = ['foodcritic']
        if bundle_exists('foodcritic'):
            command = ['bundle', 'exec', 'foodcritic']
        command.append('--no-progress')
        # if no directory is set, assume the root
        path = os.path.join(self.base_path, self.options.get('path', ''))
        command += [path]
        output = run_command(command, split=True, ignore_error=True)

        if output[0] == '\n':
            log.debug('No foodcritic errors found.')
            return False

        for line in output:
            filename, line, error = self._parse_line(line)
            self.problems.add(filename, line, error)
Esempio n. 6
0
    def process_files(self, files):
        """
        Run code checks with puppet-lint
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = ['puppet-lint']
        if bundle_exists('puppet-lint'):
            command = ['bundle', 'exec', 'puppet-lint']
        command += ['--log-format', '%{path}:%{linenumber}:%{KIND}:%{message}']
        command += files
        output = run_command(command,
                             split=True,
                             ignore_error=True,
                             include_errors=False)

        if not output:
            log.debug('No puppet-lint errors found.')
            return False

        for line in output:
            filename, line, error = self._parse_line(line)
            self.problems.add(filename, line, error)
Esempio n. 7
0
    def process_files(self, files):
        """
        Run code checks with brakeman
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = ['brakeman']
        if bundle_exists('brakeman'):
            command = ['bundle', 'exec', 'brakeman']
        command += ['--format', 'tabs']
        command += files
        output = run_command(
            command,
            split=True,
            ignore_error=True,
            include_errors=False
        )

        if not output:
            log.debug('No brakeman errors found.')
            return False

        for line in output:
            filename, line, error = self._parse_line(line)
            self.problems.add(filename, line, error)
Esempio n. 8
0
    def process_files(self, files):
        """
        Run code checks with rubocop
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = ['rubocop']
        if bundle_exists('rubocop'):
            command = ['bundle', 'exec', 'rubocop']
        command += ['--format', 'emacs']
        if self.options.get('display_cop_names', '').lower() == 'true':
            command += ['--display-cop-names']
        command += files
        output = run_command(command,
                             split=True,
                             ignore_error=True,
                             include_errors=False)

        if not output:
            log.debug('No rubocop errors found.')
            return False

        for line in output:
            filename, line, error = self._parse_line(line)
            self.problems.add(filename, line, error)
Esempio n. 9
0
 def check_dependencies(self):
     """
     See if foodcritic is on the PATH
     """
     return in_path('foodcritic') or bundle_exists('foodcritic')
Esempio n. 10
0
from __future__ import absolute_import
from os.path import abspath
from lintreview.review import Problems
from lintreview.review import Comment
from lintreview.utils import in_path, bundle_exists
from lintreview.tools.puppet import Puppet
from unittest import TestCase
from unittest import skipIf
from nose.tools import eq_
from operator import attrgetter

puppet_missing = not (in_path('puppet-lint') or bundle_exists('puppet-lint'))


class TestPuppet(TestCase):
    needs_puppet = skipIf(puppet_missing, 'Missing puppet-lint, cannot run')

    fixtures = [
        'tests/fixtures/puppet/no_errors.pp',
        'tests/fixtures/puppet/has_errors.pp',
    ]

    def setUp(self):
        self.problems = Problems()
        self.tool = Puppet(self.problems)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertTrue(self.tool.match_file('test.pp'))
        self.assertTrue(self.tool.match_file('dir/name/test.pp'))
Esempio n. 11
0
 def check_dependencies(self):
     """
     See if puppet-lint is on the PATH
     """
     return in_path('puppet-lint') or bundle_exists('puppet-lint')
Esempio n. 12
0
 def check_dependencies(self):
     """
     See if foodcritic is on the PATH
     """
     return in_path('foodcritic') or bundle_exists('foodcritic')
Esempio n. 13
0
from os.path import abspath
from lintreview.review import Problems
from lintreview.review import Comment
from lintreview.utils import in_path, bundle_exists
from lintreview.tools.puppet import Puppet
from unittest import TestCase
from unittest import skipIf
from nose.tools import eq_
from operator import attrgetter

puppet_missing = not(in_path('puppet-lint') or bundle_exists('puppet-lint'))


class TestPuppet(TestCase):
    needs_puppet = skipIf(puppet_missing, 'Missing puppet-lint, cannot run')

    fixtures = [
        'tests/fixtures/puppet/no_errors.pp',
        'tests/fixtures/puppet/has_errors.pp',
    ]

    def setUp(self):
        self.problems = Problems()
        self.tool = Puppet(self.problems)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertTrue(self.tool.match_file('test.pp'))
        self.assertTrue(self.tool.match_file('dir/name/test.pp'))
Esempio n. 14
0
from os.path import abspath
from lintreview.review import Problems
from lintreview.review import Comment
from lintreview.utils import in_path, bundle_exists
from lintreview.tools.rubocop import Rubocop
from unittest import TestCase
from unittest import skipIf
from nose.tools import eq_


rubocop_missing = not (in_path("rubocop") or bundle_exists("rubocop"))


class TestRubocop(TestCase):
    needs_rubocop = skipIf(rubocop_missing, "Missing rubocop, cannot run")

    fixtures = ["tests/fixtures/rubocop/no_errors.rb", "tests/fixtures/rubocop/has_errors.rb"]

    def setUp(self):
        self.problems = Problems()
        self.tool = Rubocop(self.problems)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file("test.py"))
        self.assertFalse(self.tool.match_file("dir/name/test.py"))
        self.assertTrue(self.tool.match_file("test.rb"))
        self.assertTrue(self.tool.match_file("dir/name/test.rb"))

    @needs_rubocop
    def test_process_files__one_file_pass(self):
        self.tool.process_files([self.fixtures[0]])
Esempio n. 15
0
 def check_dependencies(self):
     """
     See if rubocop is on the PATH
     """
     return in_path('rubocop') or bundle_exists('rubocop')
Esempio n. 16
0
 def check_dependencies(self):
     """
     See if puppet-lint is on the PATH
     """
     return in_path('puppet-lint') or bundle_exists('puppet-lint')
Esempio n. 17
0
from __future__ import absolute_import
from lintreview.review import Comment
from lintreview.review import Problems
from lintreview.tools.foodcritic import Foodcritic
from lintreview.utils import in_path, bundle_exists
from unittest import TestCase, skipIf
from nose.tools import eq_


critic_missing = not(in_path('foodcritic') or bundle_exists('foodcritic'))


class TestFoodcritic(TestCase):
    needs_critic = skipIf(critic_missing, 'Missing foodcritic, cannot run')

    fixtures = [
        'tests/fixtures/foodcritic/noerrors',
        'tests/fixtures/foodcritic/errors',
    ]

    def setUp(self):
        self.problems = Problems()

    @needs_critic
    def test_process_cookbook_pass(self):
        self.tool = Foodcritic(self.problems, None, self.fixtures[0])
        self.tool.process_files(None)
        eq_([], self.problems.all())

    @needs_critic
    def test_process_cookbook_fail(self):
Esempio n. 18
0
 def check_dependencies(self):
     """
     See if brakeman is on the PATH
     """
     return in_path('brakeman') or bundle_exists('brakeman')
Esempio n. 19
0
 def check_dependencies(self):
     """
     See if reek is on the PATH
     """
     return in_path('reek') or bundle_exists('reek')
Esempio n. 20
0
from os.path import abspath
from lintreview.review import Problems
from lintreview.review import Comment
from lintreview.utils import in_path, bundle_exists
from lintreview.tools.rubocop import Rubocop
from unittest import TestCase
from unittest import skipIf
from nose.tools import eq_

rubocop_missing = not (in_path('rubocop') or bundle_exists('rubocop'))


class TestRubocop(TestCase):
    needs_rubocop = skipIf(rubocop_missing, 'Missing rubocop, cannot run')

    fixtures = [
        'tests/fixtures/rubocop/no_errors.rb',
        'tests/fixtures/rubocop/has_errors.rb',
    ]

    def setUp(self):
        self.problems = Problems()
        self.tool = Rubocop(self.problems)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertTrue(self.tool.match_file('test.rb'))
        self.assertTrue(self.tool.match_file('dir/name/test.rb'))

    @needs_rubocop
Esempio n. 21
0
from os.path import abspath
from lintreview.review import Problems
from lintreview.review import Comment
from lintreview.utils import in_path, bundle_exists
from lintreview.tools.rubocop import Rubocop
from unittest import TestCase
from unittest import skipIf
from nose.tools import eq_


rubocop_missing = not(in_path('rubocop') or bundle_exists('rubocop'))


class TestRubocop(TestCase):
    needs_rubocop = skipIf(rubocop_missing, 'Missing rubocop, cannot run')

    fixtures = [
        'tests/fixtures/rubocop/no_errors.rb',
        'tests/fixtures/rubocop/has_errors.rb',
    ]

    def setUp(self):
        self.problems = Problems()
        self.tool = Rubocop(self.problems)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertTrue(self.tool.match_file('test.rb'))
        self.assertTrue(self.tool.match_file('dir/name/test.rb'))