def run_checks(self): for file in self.files: model = self.files[file][1] found_issues = self.run_check(model, str(file)) issues_to_lsp_diagnostic(found_issues) found_issues.sort() for issue in found_issues: self.report(issue) if 'file_stats' in self.reports: self.reports['file_stats'].files_count = len(self.files)
def run_checks(self): for file in self.files: if self.config.verbose: print(f"Scanning file: {file}") model = self.files[file][1] found_issues = self.run_check(model, str(file)) issues_to_lsp_diagnostic(found_issues) found_issues.sort() for issue in found_issues: self.report(issue) if 'file_stats' in self.reports: self.reports['file_stats'].files_count = len(self.files)
def test_robocop_api_no_trailing_blank_line_message(self): """ Bug from #307 """ in_memory = "*** Test Cases ***\nTest\n Fail\n \nTest\n Fail\n" issues = run_check_on_string(in_memory) diag_issues = issues_to_lsp_diagnostic(issues) assert all( d["message"] != "Missing trailing blank line at the end of file" for d in diag_issues)
def test_unicode_strings(self): in_memory = ( "*** Variables ***\n${MY_VARIABLE} Liian pitkä rivi, jossa on ääkkösiä. " "Pituuden tarkistuksen pitäisi laskea merkkejä, eikä tavuja.\n" ) issues = run_check_on_string(in_memory) diag_issues = issues_to_lsp_diagnostic(issues) assert all(d["message"] != "Line is too long" for d in diag_issues)
def test_lsp_diagnostic(self, rule): issues = [ Message( rule=rule, msg=rule.get_message(), source=r"C:\directory\file.robot", node=None, lineno=10, col=10, end_lineno=11, end_col=50, ), Message( rule=rule, msg=rule.get_message(), source=r"C:\directory\file.robot", node=None, lineno=1, col=1, end_lineno=None, end_col=None, ), ] expected_diagnostic = [ { "range": { "start": {"line": 9, "character": 9}, "end": {"line": 10, "character": 49}, }, "severity": 2, "code": "0101", "source": "robocop", "message": "Some description", "codeDescription": { "href": f"https://robocop.readthedocs.io/en/{__version__}/rules.html#some-message", }, }, { "range": { "start": {"line": 0, "character": 0}, "end": {"line": 0, "character": 0}, }, "severity": 2, "code": "0101", "source": "robocop", "message": "Some description", "codeDescription": { "href": f"https://robocop.readthedocs.io/en/{__version__}/rules.html#some-message", }, }, ] diagnostic = issues_to_lsp_diagnostic(issues) assert diagnostic == expected_diagnostic
def test_lsp_diagnostic(self, rule): issues = [ Message(rule=rule, source=r'C:\directory\file.robot', node=None, lineno=10, col=10, end_lineno=11, end_col=50), Message(rule=rule, source=r'C:\directory\file.robot', node=None, lineno=1, col=1, end_lineno=None, end_col=None) ] expected_diagnostic = [{ 'range': { 'start': { 'line': 9, 'character': 10 }, 'end': { 'line': 10, 'character': 50 } }, 'severity': 2, 'code': '0101', 'source': 'robocop', 'message': 'Some description' }, { 'range': { 'start': { 'line': 0, 'character': 1 }, 'end': { 'line': 0, 'character': 1 } }, 'severity': 2, 'code': '0101', 'source': 'robocop', 'message': 'Some description' }] diagnostic = issues_to_lsp_diagnostic(issues) assert diagnostic == expected_diagnostic
def test_robocop_api_no_trailing_blank_line_message(self): """ Bug from #307 """ source = "*** Test Cases ***\nTest\n Fail\n \nTest\n Fail\n" ast = get_model(source) config = robocop.Config() robocop_runner = robocop.Robocop(config=config) robocop_runner.reload_config() issues = robocop_runner.run_check(ast, 'target.robot', source) diag_issues = issues_to_lsp_diagnostic(issues) assert all( d["message"] != "Missing trailing blank line at the end of file" for d in diag_issues)
def collect_robocop_diagnostics(project_root: Path, ast_model, filename: str, source: str) -> List[Dict]: _import_robocop() import robocop from robocop.config import Config from robocop.utils import issues_to_lsp_diagnostic filename_parent = Path(filename).parent if filename_parent.exists(): config = Config(root=filename_parent) else: # Unsaved files. config = Config(root=project_root) robocop_runner = robocop.Robocop(config=config) robocop_runner.reload_config() issues = robocop_runner.run_check(ast_model, filename, source) diag_issues = issues_to_lsp_diagnostic(issues) return diag_issues