Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dose this support Jsonlint? #108

Open
AmberCheng opened this issue Oct 15, 2019 · 1 comment
Open

Dose this support Jsonlint? #108

AmberCheng opened this issue Oct 15, 2019 · 1 comment

Comments

@AmberCheng
Copy link

I don't find an example which contains the lint for json editor. However,when I use the lint as this :
component.js
import { codemirror } from 'vue-codemirror'
// lint
import 'codemirror/addon/lint/lint.css'
import 'codemirror/addon/lint/lint.js'
import 'codemirror/addon/lint/json-lint.js'

editor.vue
cmOptions: {
lint: true
},

I cannot get lint for json..
I wonder whether it supports the json-lint as codeMirror does?

@wuyax
Copy link

wuyax commented Dec 30, 2019

json-lint.js dependent on jsonlint,but you can't use it directly in the webpack environment.
In my usecase, i copy jsonlint/lib/jsonlint.jsto my project and delete the following lines.

if (typeof require !== 'undefined' && typeof exports !== 'undefined') {

exports.parse = function () { return jsonlint.parse.apply(jsonlint, arguments); }
exports.main = function commonjsMain(args) {
    if (!args[1])
        throw new Error('Usage: '+args[0]+' FILE');
    if (typeof process !== 'undefined') {
        var source = require('fs').readFileSync(require('path').join(process.cwd(), args[1]), "utf8");
    } else {
        var cwd = require("file").path(require("file").cwd());
        var source = cwd.join(args[1]).read({charset: "utf-8"});
    }
    return exports.parser.parse(source);
}
if (typeof module !== 'undefined' && require.main === module) {
  exports.main(typeof process !== 'undefined' ? process.argv.slice(1) : require("system").args);
} 
}

add a line window.jsonlint = jsonlint

In vue component import the file:
import "./jsonlint"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants