4444 VariableDefinitionType ,
4545 VariableNotFoundDefinition ,
4646)
47+ from .errors import DIAGNOSTICS_SOURCE_NAME , Error
4748from .library_doc import KeywordDoc , KeywordMatcher , is_embedded_keyword
4849from .namespace import (
49- DIAGNOSTICS_SOURCE_NAME ,
5050 KeywordFinder ,
5151 Namespace ,
5252)
@@ -225,7 +225,7 @@ async def visit(self, node: ast.AST) -> None:
225225 message = f"Variable '{ var .name } ' not found." ,
226226 severity = severity ,
227227 source = DIAGNOSTICS_SOURCE_NAME ,
228- code = "VariableNotFound" ,
228+ code = Error . VARIABLE_NOT_FOUND ,
229229 )
230230 else :
231231 if isinstance (var , EnvironmentVariableDefinition ) and var .default_value is None :
@@ -236,7 +236,7 @@ async def visit(self, node: ast.AST) -> None:
236236 message = f"Environment variable '{ var .name } ' not found." ,
237237 severity = severity ,
238238 source = DIAGNOSTICS_SOURCE_NAME ,
239- code = "EnvirommentVariableNotFound" ,
239+ code = Error . ENVIROMMENT_VARIABLE_NOT_FOUND ,
240240 )
241241
242242 if self .namespace .document is not None :
@@ -296,7 +296,7 @@ async def visit(self, node: ast.AST) -> None:
296296 message = f"Variable '{ var .name } ' not found." ,
297297 severity = DiagnosticSeverity .ERROR ,
298298 source = DIAGNOSTICS_SOURCE_NAME ,
299- code = "VariableNotFound" ,
299+ code = Error . VARIABLE_NOT_FOUND ,
300300 )
301301 else :
302302 if self .namespace .document is not None :
@@ -507,21 +507,21 @@ async def _analyze_keyword_call(
507507 f"{ f': { result .deprecated_message } ' if result .deprecated_message else '' } ." ,
508508 severity = DiagnosticSeverity .HINT ,
509509 tags = [DiagnosticTag .DEPRECATED ],
510- code = "DeprecatedKeyword" ,
510+ code = Error . DEPRECATED_KEYWORD ,
511511 )
512512 if result .is_error_handler :
513513 self .append_diagnostics (
514514 range = kw_range ,
515515 message = f"Keyword definition contains errors: { result .error_handler_message } " ,
516516 severity = DiagnosticSeverity .ERROR ,
517- code = "KeywordContainsErrors" ,
517+ code = Error . KEYWORD_CONTAINS_ERRORS ,
518518 )
519519 if result .is_reserved ():
520520 self .append_diagnostics (
521521 range = kw_range ,
522522 message = f"'{ result .name } ' is a reserved keyword." ,
523523 severity = DiagnosticSeverity .ERROR ,
524- code = "ReservedKeyword" ,
524+ code = Error . RESERVED_KEYWORD ,
525525 )
526526
527527 if get_robot_version () >= (6 , 0 ) and result .is_resource_keyword and result .is_private ():
@@ -531,7 +531,7 @@ async def _analyze_keyword_call(
531531 message = f"Keyword '{ result .longname } ' is private and should only be called by"
532532 f" keywords in the same file." ,
533533 severity = DiagnosticSeverity .WARNING ,
534- code = "PrivateKeyword" ,
534+ code = Error . PRIVATE_KEYWORD ,
535535 )
536536
537537 if not isinstance (node , (Template , TestTemplate )):
@@ -595,7 +595,7 @@ async def _analyze_keyword_call(
595595 range = range_from_token (var_token ),
596596 message = f"Variable '{ var .name } ' not found." ,
597597 severity = DiagnosticSeverity .ERROR ,
598- code = "VariableNotFound" ,
598+ code = Error . VARIABLE_NOT_FOUND ,
599599 )
600600 else :
601601 if self .namespace .document is not None :
@@ -675,7 +675,7 @@ async def _analyse_run_keyword(
675675 range = range_from_token (t ),
676676 message = f"Incorrect use of { t .value } ." ,
677677 severity = DiagnosticSeverity .ERROR ,
678- code = "IncorrectUse" ,
678+ code = Error . INCORRECT_USE ,
679679 )
680680 continue
681681
@@ -843,7 +843,7 @@ async def visit_KeywordCall(self, node: ast.AST) -> None: # noqa: N802
843843 range = range_from_node_or_token (value , value .get_token (RobotToken .ASSIGN )),
844844 message = "Keyword name cannot be empty." ,
845845 severity = DiagnosticSeverity .ERROR ,
846- code = "KeywordNameEmpty" ,
846+ code = Error . KEYWORD_NAME_EMPTY ,
847847 )
848848 else :
849849 await self ._analyze_keyword_call (
@@ -856,7 +856,7 @@ async def visit_KeywordCall(self, node: ast.AST) -> None: # noqa: N802
856856 message = "Code is unreachable." ,
857857 severity = DiagnosticSeverity .HINT ,
858858 tags = [DiagnosticTag .UNNECESSARY ],
859- code = "CodeUnreachable" ,
859+ code = Error . CODE_UNREACHABLE ,
860860 )
861861
862862 await self .generic_visit (node )
@@ -874,7 +874,7 @@ async def visit_TestCase(self, node: ast.AST) -> None: # noqa: N802
874874 range = range_from_node_or_token (testcase , name_token ),
875875 message = "Test case name cannot be empty." ,
876876 severity = DiagnosticSeverity .ERROR ,
877- code = "TestCaseNameEmpty" ,
877+ code = Error . TESTCASE_NAME_EMPTY ,
878878 )
879879
880880 self .current_testcase_or_keyword_name = testcase .name
@@ -907,15 +907,15 @@ async def visit_Keyword(self, node: ast.AST) -> None: # noqa: N802
907907 range = range_from_node_or_token (keyword , name_token ),
908908 message = "Keyword cannot have both normal and embedded arguments." ,
909909 severity = DiagnosticSeverity .ERROR ,
910- code = "KeywordNormalAndEmbbededError" ,
910+ code = Error . KEYWORD_CONTAINS_NORMAL_AND_EMBBEDED_ARGUMENTS ,
911911 )
912912 else :
913913 name_token = cast (KeywordName , keyword .header ).get_token (RobotToken .KEYWORD_NAME )
914914 self .append_diagnostics (
915915 range = range_from_node_or_token (keyword , name_token ),
916916 message = "Keyword name cannot be empty." ,
917917 severity = DiagnosticSeverity .ERROR ,
918- code = "KeywordNameEmpty" ,
918+ code = Error . KEYWORD_NAME_EMPTY ,
919919 )
920920
921921 self .current_testcase_or_keyword_name = keyword .name
@@ -992,7 +992,7 @@ async def visit_ForceTags(self, node: ast.AST) -> None: # noqa: N802
992992 message = "`Force Tags` is deprecated in favour of new `Test Tags` setting." ,
993993 severity = DiagnosticSeverity .INFORMATION ,
994994 tags = [DiagnosticTag .DEPRECATED ],
995- code = "DeprecatedHyphenTag" ,
995+ code = Error . DEPRECATED_HYPHEN_TAG ,
996996 )
997997
998998 async def visit_DefaultTags (self , node : ast .AST ) -> None : # noqa: N802
@@ -1006,7 +1006,7 @@ async def visit_DefaultTags(self, node: ast.AST) -> None: # noqa: N802
10061006 message = "`Force Tags` is deprecated in favour of new `Test Tags` setting." ,
10071007 severity = DiagnosticSeverity .INFORMATION ,
10081008 tags = [DiagnosticTag .DEPRECATED ],
1009- code = "DeprecatedHyphenTag" ,
1009+ code = Error . DEPRECATED_HYPHEN_TAG ,
10101010 )
10111011
10121012 async def visit_Tags (self , node : ast .AST ) -> None : # noqa: N802
@@ -1026,7 +1026,7 @@ async def visit_Tags(self, node: ast.AST) -> None: # noqa: N802
10261026 f"literal value and to avoid this warning." ,
10271027 severity = DiagnosticSeverity .WARNING ,
10281028 tags = [DiagnosticTag .DEPRECATED ],
1029- code = "DeprecatedHyphenTag" ,
1029+ code = Error . DEPRECATED_HYPHEN_TAG ,
10301030 )
10311031
10321032 def _check_import_name (self , value : Optional [str ], node : ast .AST , type : str ) -> None :
@@ -1035,7 +1035,7 @@ def _check_import_name(self, value: Optional[str], node: ast.AST, type: str) ->
10351035 range = range_from_node (node ),
10361036 message = f"{ type } setting requires value." ,
10371037 severity = DiagnosticSeverity .ERROR ,
1038- code = "ImportRequiresValue" ,
1038+ code = Error . IMPORT_REQUIRES_VALUE ,
10391039 )
10401040
10411041 async def visit_VariablesImport (self , node : ast .AST ) -> None : # noqa: N802
0 commit comments