📜 ⬆️ ⬇️

How to configure or disable lint in the built-in code editor

Under the cut there is a small note on how you can set up rules for linting in the built-in WordPress code editor.

Starting with version 4.9 , CodeMirror is built into WordPress. It supports syntax highlighting for more than 100 languages, and also has a built-in code analyzer.

So, to change the parameters, the wp_code_editor_settings filter will help us .

The first parameter it takes is an array of options for the code editor. In it we are interested in only a few properties. See the documentation for details .
')
add_filter( 'wp_code_editor_settings', 'change_code_editor_settings'); function change_code_editor_settings( $settings ) { /** *     codemirror * @see https://codemirror.net/doc/manual.html#config */ $settings['codemirror'] /** *    CSSLint * @see https://github.com/CSSLint/csslint/wiki */ $settings['csslint'] /** *    JSHint * @see https://jshint.com/docs/options */ $settings['jshint'] /** *    HTMLHint * @see https://github.com/htmlhint/HTMLHint/wiki/Rules */ $settings['htmlhint'] return $settings; } 

Examples


Turn off CSSLint checking while keeping syntax highlighting . (It can be useful if you use css variables in the theme. # 720 )

 add_filter( 'wp_code_editor_settings', 'disable_csslint' ); function disable_csslint( $settings ){ if ($settings['codemirror']['mode'] === 'css') { $settings['codemirror']['lint'] = false; } return $settings; } 

Register a global variable.

 add_filter( 'wp_code_editor_settings', 'change_code_editor_settings'); function change_code_editor_settings( $settings ) { $settings['jshint']['globals']['axios'] = false //    $settings['jshint']['globals']['user_rates'] = true //        return $settings; } 

Prohibit the use of anti-boots without values

 add_filter( 'wp_code_editor_settings', 'change_code_editor_settings'); function change_code_editor_settings( $settings ) { $settings['htmlhint']['attr-value-not-empty'] = true return $settings; } 

Source: https://habr.com/ru/post/428135/


All Articles