Skip to content
This repository has been archived by the owner on Dec 11, 2017. It is now read-only.

Commit

Permalink
Configure jshint with same rules as core
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Aug 26, 2017
1 parent 533bd7a commit 2db0d27
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
29 changes: 29 additions & 0 deletions better-code-editing.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,35 @@ class Better_Code_Editing_Plugin {
'outline-none',
),
),
'jshint' => array(
'rules' => array(
// The following are copied from <https://github.com/WordPress/wordpress-develop/blob/4.8.1/.jshintrc>.
'boss' => true,
'curly' => true,
'eqeqeq' => true,
'eqnull' => true,
'es3' => true,
'expr' => true,
'immed' => true,
'noarg' => true,
'nonbsp' => true,
'onevar' => true,
'quotmark' => 'single',
'trailing' => true,
'undef' => true,
'unused' => true,

'browser' => true,

'globals' => array(
'_' => false,
'Backbone' => false,
'jQuery' => false,
'JSON' => false,
'wp' => false,
),
),
),
);

/**
Expand Down
14 changes: 12 additions & 2 deletions wp-admin/js/code-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,19 @@ if ( 'undefined' === typeof window.wp.codeEditor ) {
}

instanceSettings = $.extend( {}, wp.codeEditor.defaultSettings, settings );
instanceSettings.codemirror = $.extend( {}, instanceSettings.codemirror );

if ( 'undefined' !== typeof CSSLint && instanceSettings.csslint && instanceSettings.csslint.rules ) {
updateCSSLintRules( instanceSettings.csslint.rules );
if ( true === instanceSettings.codemirror.lint ) {

// Configure JSHint.
if ( 'text/javascript' === instanceSettings.codemirror.mode && true === instanceSettings.codemirror.lint && instanceSettings.jshint && instanceSettings.jshint.rules ) {
instanceSettings.codemirror.lint = instanceSettings.jshint.rules;
}

// Configure CSSLint.
if ( 'undefined' !== typeof CSSLint && instanceSettings.csslint && instanceSettings.csslint.rules ) {
updateCSSLintRules( instanceSettings.csslint.rules );
}
}

editor = CodeMirror.fromTextArea( $textarea[0], instanceSettings.codemirror );
Expand Down

0 comments on commit 2db0d27

Please sign in to comment.