src/eric7/Plugins/CheckerPlugins/SyntaxChecker/yamlCheckSyntax.py

branch
eric7
changeset 9507
1f39839655ea
parent 9482
a2bc06a54d9d
child 9653
e67609152c5e
equal deleted inserted replaced
9506:62397ab8df8c 9507:1f39839655ea
27 27
28 @return the entry point for the background client 28 @return the entry point for the background client
29 @rtype func 29 @rtype func
30 """ 30 """
31 return yamlSyntaxBatchCheck 31 return yamlSyntaxBatchCheck
32
33
34 def normalizeCode(codestring):
35 """
36 Function to normalize the given code.
37
38 @param codestring code to be normalized
39 @type str
40 @return normalized code
41 @rtype str
42 """
43 codestring = codestring.replace("\r\n", "\n").replace("\r", "\n")
44
45 if codestring and codestring[-1] != "\n":
46 codestring += "\n"
47
48 return codestring
49 32
50 33
51 def yamlSyntaxCheck(file, codestring): 34 def yamlSyntaxCheck(file, codestring):
52 """ 35 """
53 Function to check a YAML source file for syntax errors. 36 Function to check a YAML source file for syntax errors.
178 from yaml import MarkedYAMLError, safe_load_all # __IGNORE_WARNING_I10__ 161 from yaml import MarkedYAMLError, safe_load_all # __IGNORE_WARNING_I10__
179 except ImportError: 162 except ImportError:
180 error = "pyyaml not available. Install it via the PyPI interface." 163 error = "pyyaml not available. Install it via the PyPI interface."
181 return [{"error": (file, 0, 0, "", error)}] 164 return [{"error": (file, 0, 0, "", error)}]
182 165
183 codestring = normalizeCode(codestring)
184
185 try: 166 try:
186 for _obj in safe_load_all(codestring): 167 for _obj in safe_load_all(codestring):
187 # do nothing with it, just to get parse errors 168 # do nothing with it, just to get parse errors
188 pass 169 pass
189 except MarkedYAMLError as exc: 170 except MarkedYAMLError as exc:

eric ide

mercurial