예제 #1
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)
예제 #2
0
 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)
예제 #3
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)
예제 #4
0
    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])
예제 #5
0
    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)
예제 #6
0
    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)
예제 #7
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])
예제 #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 = "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])
예제 #9
0
 def setUp(self):
     self.problems = Problems()
     options = {'config': 'tests/fixtures/tslint/tslint_good.json'}
     self.tool = Tslint(self.problems, options, root_dir)