28 |
28 |
29 @return the entry point for the background client |
29 @return the entry point for the background client |
30 @rtype func |
30 @rtype func |
31 """ |
31 """ |
32 return jsonSyntaxBatchCheck |
32 return jsonSyntaxBatchCheck |
33 |
|
34 |
|
35 def normalizeCode(codestring): |
|
36 """ |
|
37 Function to normalize the given code. |
|
38 |
|
39 @param codestring code to be normalized |
|
40 @type str |
|
41 @return normalized code |
|
42 @rtype str |
|
43 """ |
|
44 codestring = codestring.replace("\r\n", "\n").replace("\r", "\n") |
|
45 |
|
46 if codestring and codestring[-1] != "\n": |
|
47 codestring += "\n" |
|
48 |
|
49 return codestring |
|
50 |
33 |
51 |
34 |
52 def jsonSyntaxCheck(file, codestring): |
35 def jsonSyntaxCheck(file, codestring): |
53 """ |
36 """ |
54 Function to check a JSON source file for syntax errors. |
37 Function to check a JSON source file for syntax errors. |
173 hold a list containing details about the error/ warnings |
156 hold a list containing details about the error/ warnings |
174 (file name, line number, column, codestring (only at syntax |
157 (file name, line number, column, codestring (only at syntax |
175 errors), the message, a list with arguments for the message) |
158 errors), the message, a list with arguments for the message) |
176 @rtype dict |
159 @rtype dict |
177 """ |
160 """ |
178 codestring = normalizeCode(codestring) |
|
179 |
|
180 try: |
161 try: |
181 json.loads(codestring) |
162 json.loads(codestring) |
182 except json.JSONDecodeError as exc: |
163 except json.JSONDecodeError as exc: |
183 line = exc.lineno |
164 line = exc.lineno |
184 column = exc.colno |
165 column = exc.colno |