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

branch
eric7
changeset 10111
049fbbd2253d
parent 9653
e67609152c5e
child 10341
3fdffd9cc21d
equal deleted inserted replaced
10110:009526532fa5 10111:049fbbd2253d
155 hold a list containing details about the error/ warnings 155 hold a list containing details about the error/ warnings
156 (file name, line number, column, codestring (only at syntax 156 (file name, line number, column, codestring (only at syntax
157 errors), the message, a list with arguments for the message) 157 errors), the message, a list with arguments for the message)
158 @rtype dict 158 @rtype dict
159 """ 159 """
160 try: 160 if codestring:
161 import tomlkit # __IGNORE_WARNING_I10__ 161 try:
162 import tomlkit # __IGNORE_WARNING_I10__
162 163
163 from tomlkit.exceptions import ( # __IGNORE_WARNING_I10__ 164 from tomlkit.exceptions import ( # __IGNORE_WARNING_I10__
164 KeyAlreadyPresent, 165 KeyAlreadyPresent,
165 ParseError, 166 ParseError,
166 ) 167 )
167 except ImportError: 168 except ImportError:
168 error = "tomlkit not available. Install it via the PyPI interface." 169 error = "tomlkit not available. Install it via the PyPI interface."
169 return [{"error": (file, 0, 0, "", error)}] 170 return [{"error": (file, 0, 0, "", error)}]
170 171
171 try: 172 try:
172 tomlkit.parse(codestring) 173 tomlkit.parse(codestring)
173 except ParseError as exc: 174 except ParseError as exc:
174 line = exc.line 175 line = exc.line
175 column = exc.col 176 column = exc.col
176 error = str(exc).split(" at ", 1)[0].strip() 177 error = str(exc).split(" at ", 1)[0].strip()
177 # get error message without location 178 # get error message without location
178 179
179 cline = min(len(codestring.splitlines()), int(line)) - 1 180 cline = min(len(codestring.splitlines()), int(line)) - 1
180 code = codestring.splitlines()[cline] 181 code = codestring.splitlines()[cline]
181 182
182 return [{"error": (file, line, column, code, error)}] 183 return [{"error": (file, line, column, code, error)}]
183 except KeyAlreadyPresent as exc: 184 except KeyAlreadyPresent as exc:
184 return [{"error": (file, 0, 0, "", str(exc))}] 185 return [{"error": (file, 0, 0, "", str(exc))}]
185 186
186 return [{}] 187 return [{}]

eric ide

mercurial