Exemple #1
0
    def _runChecks(self, file_contents, file_type):
        tmp_args = {
            'suffix': '.' + file_type,
            'dir': _HERE_PATH,
            'delete': False
        }
        with tempfile.NamedTemporaryFile(**tmp_args) as f:
            tmp_file = f.name
            self._tmp_files.append(tmp_file)
            f.write(file_contents.encode('utf-8'))

        input_api = MockInputApi()
        input_api.files = [MockFile(os.path.abspath(tmp_file), '')]
        input_api.presubmit_local_path = _HERE_PATH

        checker = js_checker.JSChecker(input_api, MockOutputApi())

        try:
            # ESLint JSON warnings come from stdout without error return.
            output = checker.RunEsLintChecks(input_api.AffectedFiles(),
                                             format='json')[0]
            json_error = str(output)
        except RuntimeError as err:
            # Extract ESLint's JSON error output from the error message.
            message = str(err)
            json_error = message[message.index('['):]

        return json.loads(json_error)[0].get('messages')
 def makeInputApi(self, files):
     input_api = MockInputApi()
     input_api.files = files
     # Override os_path.exists because the presubmit uses the actual
     # os.path.exists.
     input_api.CreateMockFileInPath([
         x.LocalPath()
         for x in input_api.AffectedFiles(include_deletes=True)
     ])
     return input_api
  def _runChecks(self, file_contents):
    tmp_args = {'suffix': '.js', 'dir': _HERE_PATH, 'delete': False}
    with tempfile.NamedTemporaryFile(**tmp_args) as f:
      self._tmp_file = f.name
      f.write(file_contents)

    input_api = MockInputApi()
    input_api.files = [MockFile(os.path.abspath(self._tmp_file), '')]
    input_api.presubmit_local_path = _HERE_PATH

    checker = js_checker.JSChecker(input_api, MockOutputApi())
    return checker.RunEsLintChecks(input_api.AffectedFiles(), format='json')
Exemple #4
0
    def _runChecks(self, file_contents):
        tmp_args = {'suffix': '.js', 'dir': _HERE_PATH, 'delete': False}
        with tempfile.NamedTemporaryFile(**tmp_args) as f:
            self._tmp_file = f.name
            f.write(file_contents)

        input_api = MockInputApi()
        input_api.files = [MockFile(os.path.abspath(self._tmp_file), '')]
        input_api.presubmit_local_path = _HERE_PATH

        checker = js_checker.JSChecker(input_api, MockOutputApi())

        try:
            return checker.RunEsLintChecks(input_api.AffectedFiles(),
                                           format='json')
        except RuntimeError as err:
            # Extract ESLint's JSON error output from the error message.
            json_error = err.message[err.message.index('['):]
            return json.loads(json_error)[0].get('messages')