Beispiel #1
0
 def test_process_files__no_config_set_no_default(self):
     tool = Tslint(self.problems, options={})
     tool.process_files([FILE_WITH_ERRORS])
     problems = self.problems.all()
     eq_(1, len(problems), 'Missing config returns 1 error')
     msg = ('Your tslint config file is missing or invalid. '
            'Please ensure that `tslint.json` exists and is valid JSON.')
     expected = [IssueComment(msg)]
     eq_(expected, problems)
Beispiel #2
0
 def test_process_files__invalid_config(self):
     tool = Tslint(self.problems, options={'config': 'invalid-file'})
     tool.process_files([FILE_WITH_ERRORS])
     problems = self.problems.all()
     eq_(1, len(problems), 'Invalid config returns 1 error')
     msg = ('Your tslint config file is missing or invalid. '
            'Please ensure that `invalid-file` exists and is valid JSON.')
     expected = [IssueComment(msg)]
     eq_(expected, problems)
 def test_process_files__invalid_config(self):
     tool = Tslint(self.problems, options={'config': 'invalid-file'})
     tool.process_files([FILE_WITH_ERRORS])
     problems = self.problems.all()
     eq_(1, len(problems), 'Invalid config returns 1 error')
     msg = ('Your tslint config file is missing or invalid. '
            'Please ensure that `invalid-file` exists and is valid JSON.')
     expected = [IssueComment(msg)]
     eq_(expected, problems)
 def test_process_files__no_config_set_no_default(self):
     tool = Tslint(self.problems, options={}, base_path=root_dir)
     tool.process_files([FILE_WITH_ERRORS])
     problems = self.problems.all()
     eq_(1, len(problems), 'Missing config returns 1 error')
     msg = ('Your tslint config file is missing or invalid. '
            'Please ensure that `tslint.json` exists and is valid JSON.')
     expected = [IssueComment(msg)]
     eq_(expected, problems)
Beispiel #5
0
    def test_process_files__warnings(self):
        options = {'config': 'tests/fixtures/tslint/tslint_warning_rule.json'}
        tool = Tslint(self.problems, options, base_path=root_dir)
        tool.process_files([FILE_WITH_ERRORS])

        problems = self.problems.all()
        self.assertEqual(4, len(problems))
        expected = ('`tslint` output the following warnings:\n'
                    '\n'
                    "* The 'no-boolean-literal-compare' rule requires type "
                    "information.")
        self.assertEqual(expected, problems[0].body)
        self.assertIn("Shadowed name: 'range'", problems[1].body)
    def test_process_files__unknown_module(self):
        options = {
            'config': 'tests/fixtures/tslint/tslint_missing_plugin.json'
        }
        tool = Tslint(self.problems, options, base_path=root_dir)
        tool.process_files([FILE_WITH_ERRORS])

        problems = self.problems.all()
        eq_(1, len(problems), 'Invalid config should report an error')

        error = problems[0]
        ok_('Your tslint configuration output the following error:' in
            error.body)
        ok_('Invalid "extends" configuration value' in error.body)
        ok_('could not require "tslint-lol"' in error.body)
    def test_process_files_with_config(self):
        options = {'config': 'tests/fixtures/tslint/tslint_good.json'}
        tool = Tslint(self.problems, options, root_dir)
        tool.process_files([FILE_WITH_ERRORS])

        problems = self.problems.all(FILE_WITH_ERRORS)

        msg = ("Shadowed name: 'range'\n"
               'Spaces before function parens are disallowed')
        expected = Comment(FILE_WITH_ERRORS, 1, 1, msg)
        eq_(expected, problems[0])

        msg = "The key 'middle' is not sorted alphabetically"
        expected = Comment(FILE_WITH_ERRORS, 11, 11, msg)
        eq_(expected, problems[1])
Beispiel #8
0
    def test_process_files_with_config(self):
        options = {
            'config': 'tests/fixtures/tslint/tslint_good.json'
        }
        tool = Tslint(self.problems, options)
        tool.process_files([FILE_WITH_ERRORS])

        problems = self.problems.all(FILE_WITH_ERRORS)

        msg = ("Shadowed name: 'range'\n"
               'Spaces before function parens are disallowed')
        expected = Comment(FILE_WITH_ERRORS, 1, 1, msg)
        eq_(expected, problems[0])

        msg = "The key 'middle' is not sorted alphabetically"
        expected = Comment(FILE_WITH_ERRORS, 11, 11, msg)
        eq_(expected, problems[1])
    def test_process_files__invalid_rule(self):
        options = {'config': 'tests/fixtures/tslint/tslint_invalid_rule.json'}
        tool = Tslint(self.problems, options, base_path=root_dir)
        tool.process_files([FILE_WITH_ERRORS])

        problems = self.problems.all()
        eq_(1, len(problems))
        msg = ('Your tslint configuration output the following error:\n'
               '```\n'
               'Could not find implementations for the following rules '
               'specified in the configuration:\n'
               '    not_a_real_rule\n'
               'Try upgrading TSLint and/or ensuring that you have all '
               'necessary custom rules installed.\n'
               'If TSLint was recently upgraded, you may '
               'have old rules configured which need to be cleaned up.\n'
               '```')
        expected = [IssueComment(msg)]
        eq_(expected, problems)
    def test_process_output__ancestor_directory(self):
        # Simulate XML with ../file in the output
        # which happens with tslint
        options = {'config': 'tests/fixtures/tslint/tslint_good.json'}
        restore = os.getcwd()
        tool = Tslint(self.problems, options, restore)
        xml = """<?xml version="1.0" encoding="utf-8"?>
<checkstyle version="4.3">
  <file name="../tests/fixtures/tslint/has_errors.ts">
    <error line="11" column="3" severity="error" message="bad code"
      source="failure.tslint.object-literal-sort-keys" />
  </file>
</checkstyle>"""
        os.chdir(os.path.join('.', 'lintreview'))
        tool._process_output(xml, [FILE_WITH_ERRORS])
        os.chdir(restore)

        problems = self.problems.all(FILE_WITH_ERRORS)
        expected = Comment(FILE_WITH_ERRORS, 11, 11, 'bad code')
        eq_(expected, problems[0])
Beispiel #11
0
    def test_process_files_with_config(self):
        options = {
            'config': 'tests/fixtures/tslint/tslint_good.json'
        }
        tool = Tslint(self.problems, options)
        tool.process_files([FILE_WITH_ERRORS])

        problems = self.problems.all(FILE_WITH_ERRORS)

        msg = "The key 'middle' is not sorted alphabetically"
        expected = Comment(FILE_WITH_ERRORS, 11, 11, msg)
        eq_(expected, problems[0])

        msg = 'Spaces before function parens are disallowed'
        expected = Comment(FILE_WITH_ERRORS, 1, 1, msg)
        eq_(expected, problems[1])

        msg = 'Missing trailing comma'
        expected = Comment(FILE_WITH_ERRORS, 12, 12, msg)
        eq_(expected, problems[2])
Beispiel #12
0
    def test_process_files__invalid_rule(self):
        options = {
            'config': 'tests/fixtures/tslint/tslint_invalid_rule.json'
        }
        tool = Tslint(self.problems, options)
        tool.process_files([FILE_WITH_ERRORS])

        problems = self.problems.all()
        eq_(1, len(problems))
        msg = ('Your tslint configuration output the following error:\n'
               '```\n'
               'Could not find implementations for the following rules '
               'specified in the configuration:\n'
               '    not_a_real_rule\n'
               'Try upgrading TSLint and/or ensuring that you have all '
               'necessary custom rules installed.\n'
               'If TSLint was recently upgraded, you may '
               'have old rules configured which need to be cleaned up.\n'
               '```')
        expected = [IssueComment(msg)]
        eq_(expected, problems)
Beispiel #13
0
    def test_process_output__ancestor_directory(self):
        # Simulate XML with ../file in the output
        # which happens with tslint
        options = {
            'config': 'tests/fixtures/tslint/tslint_good.json'
        }
        restore = os.getcwd()
        tool = Tslint(self.problems, options, restore)
        xml = """<?xml version="1.0" encoding="utf-8"?>
<checkstyle version="4.3">
  <file name="../tests/fixtures/tslint/has_errors.ts">
    <error line="11" column="3" severity="error" message="bad code"
      source="failure.tslint.object-literal-sort-keys" />
  </file>
</checkstyle>"""
        os.chdir(os.path.join('.', 'lintreview'))
        tool._process_output(xml, [FILE_WITH_ERRORS])
        os.chdir(restore)

        problems = self.problems.all(FILE_WITH_ERRORS)
        expected = Comment(FILE_WITH_ERRORS, 11, 11, 'bad code')
        eq_(expected, problems[0])
Beispiel #14
0
class TestTslint(TestCase):
    def setUp(self):
        self.problems = Problems()
        options = {'config': 'tests/fixtures/tslint/tslint_good.json'}
        self.tool = Tslint(self.problems, options, root_dir)

    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.assertFalse(self.tool.match_file('test.js'))
        self.assertTrue(self.tool.match_file('test.ts'))
        self.assertTrue(self.tool.match_file('test.tsx'))
        self.assertTrue(self.tool.match_file('dir/name/test.ts'))

    @requires_image('nodejs')
    def test_check_dependencies(self):
        self.assertTrue(self.tool.check_dependencies())

    @requires_image('nodejs')
    def test_process_files__pass(self):
        self.tool.process_files(FILE_WITH_NO_ERRORS)
        self.assertEqual([], self.problems.all(FILE_WITH_NO_ERRORS))

    @requires_image('nodejs')
    def test_process_files__fail(self):
        self.tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all(FILE_WITH_ERRORS)
        self.assertEqual(3, len(problems))

        msg = ("Shadowed name: 'range'\n"
               "Spaces before function parens are disallowed")
        expected = Comment(FILE_WITH_ERRORS, 1, 1, msg)
        self.assertEqual(expected, problems[0])

    @requires_image('nodejs')
    def test_process_files__invalid_config(self):
        tool = Tslint(self.problems,
                      options={'config': 'invalid-file'},
                      base_path=root_dir)
        tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all()
        self.assertEqual(1, len(problems), 'Invalid config returns 1 error')
        msg = ('Your tslint configuration file is missing or invalid. '
               'Please ensure that `invalid-file` exists and is valid JSON.')
        expected = [IssueComment(msg)]
        self.assertEqual(expected, problems)

    @requires_image('nodejs')
    def test_process_files__no_config_set_no_default(self):
        tool = Tslint(self.problems, options={}, base_path=root_dir)
        tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all()
        self.assertEqual(1, len(problems), 'Missing config returns 1 error')
        msg = ('Your tslint configuration file is missing or invalid. '
               'Please ensure that `tslint.json` exists and is valid JSON.')
        expected = [IssueComment(msg)]
        self.assertEqual(expected, problems)

    @requires_image('nodejs')
    def test_process_files_with_config(self):
        options = {'config': 'tests/fixtures/tslint/tslint_good.json'}
        tool = Tslint(self.problems, options, root_dir)
        tool.process_files([FILE_WITH_ERRORS])

        problems = self.problems.all(FILE_WITH_ERRORS)

        msg = ("Shadowed name: 'range'\n"
               'Spaces before function parens are disallowed')
        expected = Comment(FILE_WITH_ERRORS, 1, 1, msg)
        self.assertEqual(expected, problems[0])

        msg = "The key 'middle' is not sorted alphabetically"
        expected = Comment(FILE_WITH_ERRORS, 11, 11, msg)
        self.assertEqual(expected, problems[1])

    @requires_image('nodejs')
    def test_process_files_with_project(self):
        options = {
            'project': 'tests/fixtures/tslint/tsconfig.json',
            'config': 'tests/fixtures/tslint/tslint_good.json'
        }
        tool = Tslint(self.problems, options, root_dir)
        tool.process_files([FILE_WITH_ERRORS])

        problems = self.problems.all(FILE_WITH_ERRORS)

        msg = ("Shadowed name: 'range'\n"
               'Spaces before function parens are disallowed')
        expected = Comment(FILE_WITH_ERRORS, 1, 1, msg)
        self.assertEqual(expected, problems[0])

        msg = "The key 'middle' is not sorted alphabetically"
        expected = Comment(FILE_WITH_ERRORS, 11, 11, msg)
        self.assertEqual(expected, problems[1])

    @requires_image('nodejs')
    def test_process_files__invalid_rule(self):
        options = {'config': 'tests/fixtures/tslint/tslint_invalid_rule.json'}
        tool = Tslint(self.problems, options, base_path=root_dir)
        tool.process_files([FILE_WITH_ERRORS])

        problems = self.problems.all()
        self.assertEqual(1, len(problems))
        msg = ('Your tslint configuration output the following error:\n'
               '```\n'
               'Could not find implementations for the following rules '
               'specified in the configuration:\n'
               '    not_a_real_rule\n'
               'Try upgrading TSLint and/or ensuring that you have all '
               'necessary custom rules installed.\n'
               'If TSLint was recently upgraded, you may '
               'have old rules configured which need to be cleaned up.\n'
               '```')
        expected = [IssueComment(msg)]
        self.assertEqual(expected, problems)

    @requires_image('nodejs')
    def test_process_files__warnings(self):
        options = {'config': 'tests/fixtures/tslint/tslint_warning_rule.json'}
        tool = Tslint(self.problems, options, base_path=root_dir)
        tool.process_files([FILE_WITH_ERRORS])

        problems = self.problems.all()
        self.assertEqual(4, len(problems))
        expected = ('`tslint` output the following warnings:\n'
                    '\n'
                    "* The 'no-boolean-literal-compare' rule requires type "
                    "information.")
        self.assertEqual(expected, problems[0].body)
        self.assertIn("Shadowed name: 'range'", problems[1].body)

    @requires_image('nodejs')
    def test_process_files__unknown_module(self):
        options = {
            'config': 'tests/fixtures/tslint/tslint_missing_plugin.json'
        }
        tool = Tslint(self.problems, options, base_path=root_dir)
        tool.process_files([FILE_WITH_ERRORS])

        problems = self.problems.all()
        self.assertEqual(1, len(problems),
                         'Invalid config should report an error')

        error = problems[0]
        self.assertIn('Your tslint configuration output the following error:',
                      error.body)
        self.assertIn('Invalid "extends" configuration value', error.body)
        self.assertIn('could not require "tslint-lol"', error.body)
Beispiel #15
0
class TestTslint(TestCase):
    def setUp(self):
        self.problems = Problems()
        options = {'config': 'tests/fixtures/tslint/tslint_good.json'}
        self.tool = Tslint(self.problems, options, root_dir)

    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.assertFalse(self.tool.match_file('test.js'))
        self.assertTrue(self.tool.match_file('test.ts'))
        self.assertTrue(self.tool.match_file('dir/name/test.ts'))

    @requires_image('nodejs')
    def test_check_dependencies(self):
        self.assertTrue(self.tool.check_dependencies())

    @requires_image('nodejs')
    def test_process_files__pass(self):
        self.tool.process_files(FILE_WITH_NO_ERRORS)
        eq_([], self.problems.all(FILE_WITH_NO_ERRORS))

    @requires_image('nodejs')
    def test_process_files__fail(self):
        self.tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all(FILE_WITH_ERRORS)
        eq_(3, len(problems))

        msg = ("Shadowed name: 'range'\n"
               "Spaces before function parens are disallowed")
        expected = Comment(FILE_WITH_ERRORS, 1, 1, msg)
        eq_(expected, problems[0])

    @requires_image('nodejs')
    def test_process_files__invalid_config(self):
        tool = Tslint(self.problems,
                      options={'config': 'invalid-file'},
                      base_path=root_dir)
        tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all()
        eq_(1, len(problems), 'Invalid config returns 1 error')
        msg = ('Your tslint config file is missing or invalid. '
               'Please ensure that `invalid-file` exists and is valid JSON.')
        expected = [IssueComment(msg)]
        eq_(expected, problems)

    @requires_image('nodejs')
    def test_process_files__no_config_set_no_default(self):
        tool = Tslint(self.problems, options={}, base_path=root_dir)
        tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all()
        eq_(1, len(problems), 'Missing config returns 1 error')
        msg = ('Your tslint config file is missing or invalid. '
               'Please ensure that `tslint.json` exists and is valid JSON.')
        expected = [IssueComment(msg)]
        eq_(expected, problems)

    @requires_image('nodejs')
    def test_process_files_with_config(self):
        options = {'config': 'tests/fixtures/tslint/tslint_good.json'}
        tool = Tslint(self.problems, options, root_dir)
        tool.process_files([FILE_WITH_ERRORS])

        problems = self.problems.all(FILE_WITH_ERRORS)

        msg = ("Shadowed name: 'range'\n"
               'Spaces before function parens are disallowed')
        expected = Comment(FILE_WITH_ERRORS, 1, 1, msg)
        eq_(expected, problems[0])

        msg = "The key 'middle' is not sorted alphabetically"
        expected = Comment(FILE_WITH_ERRORS, 11, 11, msg)
        eq_(expected, problems[1])

    @requires_image('nodejs')
    def test_process_files__invalid_rule(self):
        options = {'config': 'tests/fixtures/tslint/tslint_invalid_rule.json'}
        tool = Tslint(self.problems, options, base_path=root_dir)
        tool.process_files([FILE_WITH_ERRORS])

        problems = self.problems.all()
        eq_(1, len(problems))
        msg = ('Your tslint configuration output the following error:\n'
               '```\n'
               'Could not find implementations for the following rules '
               'specified in the configuration:\n'
               '    not_a_real_rule\n'
               'Try upgrading TSLint and/or ensuring that you have all '
               'necessary custom rules installed.\n'
               'If TSLint was recently upgraded, you may '
               'have old rules configured which need to be cleaned up.\n'
               '```')
        expected = [IssueComment(msg)]
        eq_(expected, problems)
Beispiel #16
0
 def setUp(self):
     self.problems = Problems()
     options = {'config': 'tests/fixtures/tslint/tslint_good.json'}
     self.tool = Tslint(self.problems, options, root_dir)
Beispiel #17
0
 def setUp(self):
     self.problems = Problems()
     options = {
         'config': 'tests/fixtures/tslint/tslint_good.json'
     }
     self.tool = Tslint(self.problems, options)
Beispiel #18
0
class TestTslint(TestCase):

    needs_tslint = skipIf(tslint_missing, 'Needs tslint to run')

    def setUp(self):
        self.problems = Problems()
        options = {
            'config': 'tests/fixtures/tslint/tslint_good.json'
        }
        self.tool = Tslint(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.assertFalse(self.tool.match_file('test.js'))
        self.assertTrue(self.tool.match_file('test.ts'))
        self.assertTrue(self.tool.match_file('dir/name/test.ts'))

    @needs_tslint
    def test_check_dependencies(self):
        self.assertTrue(self.tool.check_dependencies())

    @needs_tslint
    def test_process_files__pass(self):
        self.tool.process_files(FILE_WITH_NO_ERRORS)
        eq_([], self.problems.all(FILE_WITH_NO_ERRORS))

    @needs_tslint
    def test_process_files__fail(self):
        self.tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all(FILE_WITH_ERRORS)
        eq_(3, len(problems))

        msg = ("Shadowed name: 'range'\n"
               "Spaces before function parens are disallowed")
        expected = Comment(FILE_WITH_ERRORS, 1, 1, msg)
        eq_(expected, problems[0])

    @needs_tslint
    def test_process_files__invalid_config(self):
        tool = Tslint(self.problems, options={'config': 'invalid-file'})
        tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all()
        eq_(1, len(problems), 'Invalid config returns 1 error')
        msg = ('Your tslint config file is missing or invalid. '
               'Please ensure that `invalid-file` exists and is valid JSON.')
        expected = [IssueComment(msg)]
        eq_(expected, problems)

    @needs_tslint
    def test_process_files__no_config_set_no_default(self):
        tool = Tslint(self.problems, options={})
        tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all()
        eq_(1, len(problems), 'Missing config returns 1 error')
        msg = ('Your tslint config file is missing or invalid. '
               'Please ensure that `tslint.json` exists and is valid JSON.')
        expected = [IssueComment(msg)]
        eq_(expected, problems)

    @needs_tslint
    def test_process_files_with_config(self):
        options = {
            'config': 'tests/fixtures/tslint/tslint_good.json'
        }
        tool = Tslint(self.problems, options)
        tool.process_files([FILE_WITH_ERRORS])

        problems = self.problems.all(FILE_WITH_ERRORS)

        msg = ("Shadowed name: 'range'\n"
               'Spaces before function parens are disallowed')
        expected = Comment(FILE_WITH_ERRORS, 1, 1, msg)
        eq_(expected, problems[0])

        msg = "The key 'middle' is not sorted alphabetically"
        expected = Comment(FILE_WITH_ERRORS, 11, 11, msg)
        eq_(expected, problems[1])

    @needs_tslint
    def test_process_output__ancestor_directory(self):
        # Simulate XML with ../file in the output
        # which happens with tslint
        options = {
            'config': 'tests/fixtures/tslint/tslint_good.json'
        }
        restore = os.getcwd()
        tool = Tslint(self.problems, options, restore)
        xml = """<?xml version="1.0" encoding="utf-8"?>
<checkstyle version="4.3">
  <file name="../tests/fixtures/tslint/has_errors.ts">
    <error line="11" column="3" severity="error" message="bad code"
      source="failure.tslint.object-literal-sort-keys" />
  </file>
</checkstyle>"""
        os.chdir(os.path.join('.', 'lintreview'))
        tool._process_output(xml, [FILE_WITH_ERRORS])
        os.chdir(restore)

        problems = self.problems.all(FILE_WITH_ERRORS)
        expected = Comment(FILE_WITH_ERRORS, 11, 11, 'bad code')
        eq_(expected, problems[0])

    @needs_tslint
    def test_process_files__invalid_rule(self):
        options = {
            'config': 'tests/fixtures/tslint/tslint_invalid_rule.json'
        }
        tool = Tslint(self.problems, options)
        tool.process_files([FILE_WITH_ERRORS])

        problems = self.problems.all()
        eq_(1, len(problems))
        msg = ('Your tslint configuration output the following error:\n'
               '```\n'
               'Could not find implementations for the following rules '
               'specified in the configuration:\n'
               '    not_a_real_rule\n'
               'Try upgrading TSLint and/or ensuring that you have all '
               'necessary custom rules installed.\n'
               'If TSLint was recently upgraded, you may '
               'have old rules configured which need to be cleaned up.\n'
               '```')
        expected = [IssueComment(msg)]
        eq_(expected, problems)
class TestTslint(TestCase):

    needs_tslint = skipIf(tslint_missing, 'Needs tslint to run')

    def setUp(self):
        self.problems = Problems()
        options = {'config': 'tests/fixtures/tslint/tslint_good.json'}
        self.tool = Tslint(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.assertFalse(self.tool.match_file('test.js'))
        self.assertTrue(self.tool.match_file('test.ts'))
        self.assertTrue(self.tool.match_file('dir/name/test.ts'))

    @needs_tslint
    def test_check_dependencies(self):
        self.assertTrue(self.tool.check_dependencies())

    @needs_tslint
    def test_process_files__pass(self):
        self.tool.process_files(FILE_WITH_NO_ERRORS)
        eq_([], self.problems.all(FILE_WITH_NO_ERRORS))

    @needs_tslint
    def test_process_files__fail(self):
        self.tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all(FILE_WITH_ERRORS)
        eq_(3, len(problems))

        msg = ("Shadowed name: 'range'\n"
               "Spaces before function parens are disallowed")
        expected = Comment(FILE_WITH_ERRORS, 1, 1, msg)
        eq_(expected, problems[0])

    @needs_tslint
    def test_process_files__invalid_config(self):
        tool = Tslint(self.problems, options={'config': 'invalid-file'})
        tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all()
        eq_(1, len(problems), 'Invalid config returns 1 error')
        msg = ('Your tslint config file is missing or invalid. '
               'Please ensure that `invalid-file` exists and is valid JSON.')
        expected = [IssueComment(msg)]
        eq_(expected, problems)

    @needs_tslint
    def test_process_files__no_config_set_no_default(self):
        tool = Tslint(self.problems, options={})
        tool.process_files([FILE_WITH_ERRORS])
        problems = self.problems.all()
        eq_(1, len(problems), 'Missing config returns 1 error')
        msg = ('Your tslint config file is missing or invalid. '
               'Please ensure that `tslint.json` exists and is valid JSON.')
        expected = [IssueComment(msg)]
        eq_(expected, problems)

    @needs_tslint
    def test_process_files_with_config(self):
        options = {'config': 'tests/fixtures/tslint/tslint_good.json'}
        tool = Tslint(self.problems, options)
        tool.process_files([FILE_WITH_ERRORS])

        problems = self.problems.all(FILE_WITH_ERRORS)

        msg = ("Shadowed name: 'range'\n"
               'Spaces before function parens are disallowed')
        expected = Comment(FILE_WITH_ERRORS, 1, 1, msg)
        eq_(expected, problems[0])

        msg = "The key 'middle' is not sorted alphabetically"
        expected = Comment(FILE_WITH_ERRORS, 11, 11, msg)
        eq_(expected, problems[1])

    @needs_tslint
    def test_process_output__ancestor_directory(self):
        # Simulate XML with ../file in the output
        # which happens with tslint
        options = {'config': 'tests/fixtures/tslint/tslint_good.json'}
        restore = os.getcwd()
        tool = Tslint(self.problems, options, restore)
        xml = """<?xml version="1.0" encoding="utf-8"?>
<checkstyle version="4.3">
  <file name="../tests/fixtures/tslint/has_errors.ts">
    <error line="11" column="3" severity="error" message="bad code"
      source="failure.tslint.object-literal-sort-keys" />
  </file>
</checkstyle>"""
        os.chdir(os.path.join('.', 'lintreview'))
        tool._process_output(xml, [FILE_WITH_ERRORS])
        os.chdir(restore)

        problems = self.problems.all(FILE_WITH_ERRORS)
        expected = Comment(FILE_WITH_ERRORS, 11, 11, 'bad code')
        eq_(expected, problems[0])

    @needs_tslint
    def test_process_files__invalid_rule(self):
        options = {'config': 'tests/fixtures/tslint/tslint_invalid_rule.json'}
        tool = Tslint(self.problems, options)
        tool.process_files([FILE_WITH_ERRORS])

        problems = self.problems.all()
        eq_(1, len(problems))
        msg = ('Your tslint configuration output the following error:\n'
               '```\n'
               'Could not find implementations for the following rules '
               'specified in the configuration:\n'
               '    not_a_real_rule\n'
               'Try upgrading TSLint and/or ensuring that you have all '
               'necessary custom rules installed.\n'
               'If TSLint was recently upgraded, you may '
               'have old rules configured which need to be cleaned up.\n'
               '```')
        expected = [IssueComment(msg)]
        eq_(expected, problems)