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 _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')
def check_contents(self, file_contents): tmp_args = {'suffix': '.svg', '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), file_contents.splitlines()) ] input_api.presubmit_local_path = _HERE_PATH return svgo_presubmit.CheckOptimized(input_api, MockOutputApi())
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')