Isaac Dontje Lindell
Isaac Dontje Lindell

Reputation: 3446

Disable JSHint warnings in CodeMirror

I thought this would be a trivial question, but I've done a ton of searching and haven't been able to find anything.

I have a CodeMirror div that has linting turned on. I've included JSHint.js, which is working properly; syntax errors and warnings are being displayed in my CodeMirror editor. However, I need to disable a few warnings (most importantly, I want to allow unquoted object keys).

Where can I pass preferences or disable warnings to JSHint so that it only shows the issues that I actually care about?

Or, alternatively, is there a alternative to JSHint that allows more configuration (and is usable with the CodeMirror linting framework)?

Upvotes: 4

Views: 2366

Answers (4)

user1807334
user1807334

Reputation: 129

Use the lint property from the CodeMirror config object, to set any valid jshint configuration.

Example:

 const config = {
            lineNumbers: true, 
            lineWrapping: true, 
            mode: 'javascript',
            indentWithTabs: true,
            gutters: ['CodeMirror-lint-markers'], 
            lint: { 'esversion': '8' }, 
            theme: 'monokai'
        };

 var myCodeMirror = CodeMirror(document.body, config);

Upvotes: 1

user1711838
user1711838

Reputation:

Just set lint option = false when initializing an instance of the codemirror

var editorSettings = CodeMirror.defaults;   
editorSettings.codemirror.lint = false;
var myCodeMirror = CodeMirror(document.body, editorSettings);

In Wordpress 4.9+:

var editorSettings = wp.codeEditor.defaultSettings;
editorSettings.codemirror.lint = false;
var editor = wp.codeEditor.initialize( $('#whatever'), editorSettings);

Upvotes: 0

Petr Felzmann
Petr Felzmann

Reputation: 1313

codemirror.setOption('lint', { options: { bitwise: true }});

Upvotes: 1

Marijn
Marijn

Reputation: 8929

You should be able to set JSHint-specific options directly in the object you use as the value of CodeMirror's "lint" option.

Upvotes: 2

Related Questions