json.ts 525 B

123456789101112131415161718192021
  1. import { convertIndexToLineCh } from "../utils"
  2. import { LinterDefinition, LinterResult } from "./linter"
  3. import jsonParse from "~/helpers/jsonParse"
  4. const linter: LinterDefinition = (text) => {
  5. try {
  6. jsonParse(text)
  7. return Promise.resolve([])
  8. } catch (e: any) {
  9. return Promise.resolve([
  10. <LinterResult>{
  11. from: convertIndexToLineCh(text, e.start),
  12. to: convertIndexToLineCh(text, e.end),
  13. message: e.message,
  14. severity: "error",
  15. },
  16. ])
  17. }
  18. }
  19. export default linter