Exemplo n.º 1
0
    def process_files(self, files):
        """
        Run code checks with ESLint.
        """
        log.debug('Processing %s files with %s', files, self.name)
        cmd = self.name
        if npm_exists('eslint'):
            cmd = os.path.join(os.getcwd(), 'node_modules', '.bin', 'eslint')
        command = [cmd, '--format', 'checkstyle']

        # Add config file or default to recommended linters
        if self.options.get('config'):
            command += ['--config', self.apply_base(self.options['config'])]

        command += files
        output = run_command(command, ignore_error=True)

        if output.startswith('Cannot read config file'):
            msg = u'Your eslint config file is missing or invalid. ' \
                   u'Please ensure that `{}` exists and is valid.'
            msg = msg.format(self.options['config'])
            return self.problems.add(IssueComment(msg))

        filename_converter = functools.partial(self._relativize_filename,
                                               files)
        self._process_checkstyle(output, filename_converter)
Exemplo n.º 2
0
    def process_files(self, files):
        """
        Run code checks with ESLint.
        """
        log.debug('Processing %s files with %s', files, self.name)
        cmd = self.name
        if npm_exists('eslint'):
            cmd = os.path.join(os.getcwd(), 'node_modules', '.bin', 'eslint')
        command = [cmd, '--format', 'checkstyle']

        # Add config file or default to recommended linters
        if self.options.get('config'):
            command += ['--config', self.apply_base(self.options['config'])]

        command += files
        output = run_command(
            command,
            ignore_error=True)

        if output.startswith('Cannot read config file'):
            msg = u'Your eslint config file is missing or invalid. ' \
                   u'Please ensure that `{}` exists and is valid.'
            msg = msg.format(self.options['config'])
            return self.problems.add(IssueComment(msg))

        filename_converter = functools.partial(
            self._relativize_filename,
            files)
        self._process_checkstyle(output, filename_converter)
Exemplo n.º 3
0
 def create_command(self, files):
     cmd = 'gjslint'
     if npm_exists('gjslint'):
         cmd = os.path.join(os.getcwd(), 'node_modules', '.bin', 'gjslint')
     command = [cmd, '--strict']
     command += files
     return command
Exemplo n.º 4
0
 def process_files(self, files):
     """
     Run code checks with sass-lint.
     Only a single process is made for all files
     to save resources.
     """
     log.debug('Processing %s files with %s', files, self.name)
     cmd = 'sass-lint'
     if npm_exists('sass-lint'):
         cmd = os.path.join(
             os.getcwd(),
             'node_modules',
             '.bin',
             'sass-lint')
     command = [cmd, '-f', 'checkstyle', '-v']
     command += files
     if self.options.get('ignore'):
         command += ['--ignore ', self.options.get('ignore')]
     if self.options.get('config'):
         command += ['--config', self.apply_base(self.options['config'])]
     output = run_command(
         command,
         ignore_error=True)
     filename_converter = functools.partial(
         self._relativize_filename,
         files)
     self._process_checkstyle(output, filename_converter)
Exemplo n.º 5
0
 def create_command(self, files):
     cmd = 'jshint'
     if npm_exists('jshint'):
         cmd = os.path.join(os.getcwd(), 'node_modules', '.bin', 'jshint')
     command = [cmd, '--checkstyle-reporter']
     # Add config file if its present
     if self.options.get('config'):
         command += ['--config', self.apply_base(self.options['config'])]
     command += files
     return command
Exemplo n.º 6
0
 def create_command(self, files):
     cmd = 'jshint'
     if npm_exists('jshint'):
         cmd = os.path.join(os.getcwd(), 'node_modules', '.bin', 'jshint')
     command = [cmd, '--checkstyle-reporter']
     # Add config file if its present
     if self.options.get('config'):
         command += ['--config', self.apply_base(self.options['config'])]
     command += files
     return command
Exemplo n.º 7
0
    def process_files(self, files):
        """
        Run code checks with XO.
        """
        log.debug('Processing %s files with %s', files, self.name)
        cmd = self.name
        if npm_exists('xo'):
            cmd = os.path.join(os.getcwd(), 'node_modules', '.bin', 'xo')
        command = [cmd, '--reporter', 'checkstyle']

        command += files
        output = run_command(command, ignore_error=True)
        self._process_output(output, files)
Exemplo n.º 8
0
    def process_files(self, files):
        """
        Run code checks with XO.
        """
        log.debug('Processing %s files with %s', files, self.name)
        cmd = self.name
        if npm_exists('xo'):
            cmd = os.path.join(os.getcwd(), 'node_modules', '.bin', 'xo')
        command = [cmd, '--reporter', 'checkstyle']

        command += files
        output = run_command(command, ignore_error=True)
        self._process_output(output, files)
Exemplo n.º 9
0
 def process_files(self, files):
     """
     Run code checks with ESLint.
     """
     log.debug('Processing %s files with %s', files, self.name)
     cmd = self.name
     if npm_exists('eslint'):
         cmd = os.path.join(os.getcwd(), 'node_modules', '.bin', 'eslint')
     command = [cmd, '--format', 'checkstyle']
     # Add config file if it's present
     if self.options.get('config'):
         command += ['--config', self.apply_base(self.options['config'])]
     command += files
     output = run_command(command, ignore_error=True)
     self._process_checkstyle(output)
Exemplo n.º 10
0
    def process_files(self, files):
        """
        Run code checks with standard.
        """
        log.debug('Processing %s files with %s', files, self.name)
        cmd = self.name
        if npm_exists('standard'):
            cmd = os.path.join(os.getcwd(), 'node_modules', '.bin', 'standard')

        filename_converter = functools.partial(self._relativize_filename,
                                               files)

        command = [cmd] + list(files)
        output = run_command(command, split=True, ignore_error=True)

        output = filter(lambda line: not line.startswith('standard'), output)
        process_quickfix(self.problems, output, filename_converter)
Exemplo n.º 11
0
    def process_files(self, files):
        """
        Run code checks with csslint.
        Only a single process is made for all files
        to save resources.
        """
        log.debug('Processing %s files with %s', files, self.name)
        cmd = 'csslint'
        if npm_exists('csslint'):
            cmd = os.path.join(os.getcwd(), 'node_modules', '.bin', 'csslint')
        command = [cmd, '--format=checkstyle-xml']

        if self.options.get('ignore'):
            command += ['--ignore=' + self.options.get('ignore')]
        command += files
        output = run_command(command, ignore_error=True)
        self._process_checkstyle(output)
Exemplo n.º 12
0
 def process_files(self, files):
     """
     Run code checks with ESLint.
     """
     log.debug('Processing %s files with %s', files, self.name)
     cmd = self.name
     if npm_exists('eslint'):
         cmd = os.path.join(os.getcwd(), 'node_modules', '.bin', 'eslint')
     command = [cmd, '--format', 'checkstyle']
     # Add config file if it's present
     if self.options.get('config'):
         command += ['--config', self.apply_base(self.options['config'])]
     command += files
     output = run_command(
         command,
         ignore_error=True)
     self._process_checkstyle(output)
Exemplo n.º 13
0
    def process_files(self, files):
        """
        Run code checks with csslint.
        Only a single process is made for all files
        to save resources.
        """
        log.debug('Processing %s files with %s', files, self.name)
        cmd = 'csslint'
        if npm_exists('csslint'):
            cmd = os.path.join(os.getcwd(), 'node_modules', '.bin', 'csslint')
        command = [cmd, '--format=checkstyle-xml']

        if self.options.get('ignore'):
            command += ['--ignore=' + self.options.get('ignore')]
        command += files
        output = run_command(
            command,
            ignore_error=True)
        self._process_checkstyle(output)
Exemplo n.º 14
0
    def process_files(self, files):
        """
        Run code checks with standard.
        """
        log.debug('Processing %s files with %s', files, self.name)
        cmd = self.name
        if npm_exists('standard'):
            cmd = os.path.join(os.getcwd(), 'node_modules', '.bin', 'standard')

        filename_converter = functools.partial(
            self._relativize_filename,
            files)

        command = [cmd] + list(files)
        output = run_command(
            command,
            split=True,
            ignore_error=True)

        output = [line for line in output if not line.startswith('standard')]
        process_quickfix(self.problems, output, filename_converter)
Exemplo n.º 15
0
 def check_dependencies(self):
     """
     See if jscs is on the system path.
     """
     return in_path('jscs') or npm_exists('jscs')
Exemplo n.º 16
0
 def check_dependencies(self):
     """
     See if XO is on the system path.
     """
     return in_path('xo') or npm_exists('xo')
Exemplo n.º 17
0
 def check_dependencies(self):
     """
     See if standard is on the system path.
     """
     return in_path('standard') or npm_exists('standard')
Exemplo n.º 18
0
 def check_dependencies(self):
     """
     See if ESLint is on the system path.
     """
     return in_path('eslint') or npm_exists('eslint')
Exemplo n.º 19
0
from __future__ import absolute_import
from lintreview.review import Problems
from lintreview.review import Comment
from lintreview.tools.jscs import Jscs
from lintreview.utils import in_path
from lintreview.utils import npm_exists
from unittest import TestCase
from unittest import skipIf
from nose.tools import eq_

jscs_missing = not(in_path('jscs') or npm_exists('jscs'))


class TestJscs(TestCase):

    needs_jscs = skipIf(jscs_missing, 'Needs jscs to run')

    fixtures = [
        'tests/fixtures/jscs/no_errors.js',
        'tests/fixtures/jscs/has_errors.js',
    ]

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

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('test.js'))
Exemplo n.º 20
0
from __future__ import absolute_import
from unittest import TestCase
from unittest import skipIf

from lintreview.review import Problems
from lintreview.review import Comment
from lintreview.tools.xo import Xo
from lintreview.utils import in_path
from lintreview.utils import npm_exists
from nose.tools import eq_

xo_missing = not (in_path('xo') or npm_exists('xo'))

FILE_WITH_NO_ERRORS = 'tests/samples/xo/no_errors.js',
FILE_WITH_ERRORS = 'tests/samples/xo/has_errors.js'


class TestXo(TestCase):

    needs_xo = skipIf(xo_missing, 'Needs xo to run')

    def setUp(self):
        self.problems = Problems()
        options = {'ignore': ''}
        self.tool = Xo(self.problems, options)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('test.js'))
Exemplo n.º 21
0
from __future__ import absolute_import
from lintreview.review import Problems
from lintreview.review import Comment
from lintreview.utils import in_path
from lintreview.utils import npm_exists
from lintreview.tools.sasslint import Sasslint
from unittest import TestCase
from unittest import skipIf
from nose.tools import eq_

sasslint_missing = not(in_path('sass-lint') or npm_exists('sass-lint'))


class TestSasslint(TestCase):

    needs_sasslint = skipIf(sasslint_missing, 'Needs sasslint')

    fixtures = [
        'tests/fixtures/sasslint/no_errors.scss',
        'tests/fixtures/sasslint/has_errors.scss',
    ]

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

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('test.sass'))
Exemplo n.º 22
0
from lintreview.review import Problems
from lintreview.review import Comment
from lintreview.tools.eslint import Eslint
from lintreview.utils import in_path
from lintreview.utils import npm_exists
from unittest import TestCase
from unittest import skipIf
from nose.tools import eq_

eslint_missing = not (in_path('eslint') or npm_exists('eslint'))


class TestEslint(TestCase):

    needs_eslint = skipIf(eslint_missing, 'Needs eslint to run')

    fixtures = [
        'tests/fixtures/eslint/no_errors.js',
        'tests/fixtures/eslint/has_errors.js'
    ]

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

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('test.js'))
        self.assertTrue(self.tool.match_file('dir/name/test.js'))
Exemplo n.º 23
0
 def check_dependencies(self):
     """
     See if csslint is on the system path.
     """
     return in_path('csslint') or npm_exists('csslint')
Exemplo n.º 24
0
from lintreview.review import Problems
from lintreview.review import Comment
from lintreview.tools.jscs import Jscs
from lintreview.utils import in_path
from lintreview.utils import npm_exists
from unittest import TestCase
from unittest import skipIf
from nose.tools import eq_

jscs_missing = not (in_path("jscs") or npm_exists("jscs"))


class TestJcs(TestCase):

    needs_jscs = skipIf(jscs_missing, "Needs jscs to run")

    fixtures = ["tests/fixtures/jscs/no_errors.js", "tests/fixtures/jscs/has_errors.js"]

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

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

    @needs_jscs
    def test_check_dependencies(self):
Exemplo n.º 25
0
from lintreview.review import Problems
from lintreview.review import Comment
from lintreview.tools.jshint import Jshint
from lintreview.utils import in_path
from lintreview.utils import npm_exists
from unittest import TestCase
from unittest import skipIf
from nose.tools import eq_

jshint_missing = not (in_path("jshint") or npm_exists("jshint"))


class TestJshint(TestCase):

    needs_jshint = skipIf(jshint_missing, "Needs jshint to run")

    fixtures = [
        "tests/fixtures/jshint/no_errors.js",
        "tests/fixtures/jshint/has_errors.js",
        "tests/fixtures/jshint/error_on_multiple_lines.js",
    ]

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

    def test_match_file(self):
        self.assertFalse(self.tool.match_file("test.php"))
        self.assertFalse(self.tool.match_file("dir/name/test.py"))
        self.assertFalse(self.tool.match_file("test.py"))
        self.assertTrue(self.tool.match_file("test.js"))
Exemplo n.º 26
0
from __future__ import absolute_import
from unittest import TestCase
from unittest import skipIf

from lintreview.review import Problems
from lintreview.review import Comment
from lintreview.tools.standardjs import Standardjs
from lintreview.utils import in_path
from lintreview.utils import npm_exists
from nose.tools import eq_

standardjs_missing = not(in_path('standard') or npm_exists('standard'))

FILE_WITH_NO_ERRORS = 'tests/fixtures/standardjs/no_errors.js',
FILE_WITH_ERRORS = 'tests/fixtures/standardjs/has_errors.js'


class TestStandardjs(TestCase):

    needs_standardjs = skipIf(standardjs_missing, 'Needs standardjs to run')

    def setUp(self):
        self.problems = Problems()
        options = {}
        self.tool = Standardjs(self.problems, options)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('test.js'))
Exemplo n.º 27
0
from lintreview.review import Problems
from lintreview.review import Comment
from lintreview.utils import in_path
from lintreview.utils import npm_exists
from lintreview.tools.sasslint import Sasslint
from unittest import TestCase
from unittest import skipIf
from nose.tools import eq_

sasslint_missing = not (in_path("sass-lint") or npm_exists("sass-lint"))


class TestSasslint(TestCase):

    needs_sasslint = skipIf(sasslint_missing, "Needs sasslint")

    fixtures = ["tests/fixtures/sasslint/no_errors.scss", "tests/fixtures/sasslint/has_errors.scss"]

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

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

    @needs_sasslint
Exemplo n.º 28
0
from unittest import TestCase
from unittest import skipIf

from lintreview.review import Problems
from lintreview.review import Comment
from lintreview.tools.standardjs import Standardjs
from lintreview.utils import in_path
from lintreview.utils import npm_exists
from nose.tools import eq_

standardjs_missing = not (in_path('standard') or npm_exists('standard'))

FILE_WITH_NO_ERRORS = 'tests/fixtures/standardjs/no_errors.js',
FILE_WITH_ERRORS = 'tests/fixtures/standardjs/has_errors.js'


class TestStandardjs(TestCase):

    needs_standardjs = skipIf(standardjs_missing, 'Needs standardjs to run')

    def setUp(self):
        self.problems = Problems()
        options = {}
        self.tool = Standardjs(self.problems, options)

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('test.js'))
        self.assertTrue(self.tool.match_file('dir/name/test.js'))
Exemplo n.º 29
0
from __future__ import absolute_import
from lintreview.review import Problems
from lintreview.review import Comment
from lintreview.tools.jscs import Jscs
from lintreview.utils import in_path
from lintreview.utils import npm_exists
from unittest import TestCase
from unittest import skipIf
from nose.tools import eq_

jscs_missing = not (in_path('jscs') or npm_exists('jscs'))


class TestJscs(TestCase):

    needs_jscs = skipIf(jscs_missing, 'Needs jscs to run')

    fixtures = [
        'tests/fixtures/jscs/no_errors.js',
        'tests/fixtures/jscs/has_errors.js',
    ]

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

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('test.js'))
Exemplo n.º 30
0
 def check_dependencies(self):
     """
     See if standard is on the system path.
     """
     return in_path('standard') or npm_exists('standard')
Exemplo n.º 31
0
from lintreview.review import Problems
from lintreview.review import Comment
from lintreview.tools.eslint import Eslint
from lintreview.utils import in_path
from lintreview.utils import npm_exists
from unittest import TestCase
from unittest import skipIf
from nose.tools import eq_

eslint_missing = not(in_path('eslint') or npm_exists('eslint'))

class TestEslint(TestCase):

    needs_eslint = skipIf(eslint_missing, 'Needs eslint to run')

    fixtures = [
        'tests/fixtures/eslint/no_errors.js',
        'tests/fixtures/eslint/has_errors.js'
    ]

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

    def test_match_file(self):
        self.assertFalse(self.tool.match_file('test.php'))
        self.assertFalse(self.tool.match_file('dir/name/test.py'))
        self.assertFalse(self.tool.match_file('test.py'))
        self.assertTrue(self.tool.match_file('test.js'))
        self.assertTrue(self.tool.match_file('dir/name/test.js'))
Exemplo n.º 32
0
def test_npm_exists():
    assert utils.npm_exists('jshint'), 'Should be there.'
    assert not utils.npm_exists('not there'), 'Should not be there.'