Skip to content

Commit b48e38a

Browse files
Fix options handling in fakejshint.js.
Updates the `fakejshint.js` vendor shim to correctly store the provided options in `currentOptions` during parsing. Previously, `fakeJSHINT.data().options` would always return the initial empty object, failing to reflect the actual configuration used. This commit also: - Simplifies control flow in `getEcmaVersion()` by removing unnecessary `else` blocks. - Corrects a spelling error in the file header. - Updates JSDoc to correctly mark the `options` parameter as optional. Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 2263035 commit b48e38a

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/js/_enqueues/vendor/codemirror/fakejshint.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* globals espree: false */
22

33
/**
4-
* JSHINT has some GPL Compatability issues, so we are faking it out and using espree for validation
4+
* JSHINT has some GPL compatibility issues, so we are faking it out and using espree for validation
55
* Based on https://github.com/jquery/esprima/blob/gh-pages/demo/validate.js which is MIT licensed.
66
*
77
* This emulates the JSHint API <https://jshint.com/docs/api/>.
@@ -55,6 +55,7 @@ window.JSHINT = ( () => {
5555
* @param {SupportedJSHintOptions} [options={}] - Linting options.
5656
*/
5757
function parse( source, options = {} ) {
58+
currentOptions = options;
5859
errors.length = 0;
5960
try {
6061
espree.parse( source, {
@@ -69,7 +70,7 @@ window.JSHINT = ( () => {
6970
/**
7071
* Gets the options for Espree from the supported JSHint options.
7172
*
72-
* @param {SupportedJSHintOptions} [options={}] - Linting options for JSHint.
73+
* @param {SupportedJSHintOptions} options - Linting options for JSHint.
7374
* @return {{
7475
* ecmaVersion?: number|'latest',
7576
* ecmaFeatures?: {
@@ -109,25 +110,26 @@ window.JSHINT = ( () => {
109110
* Gets the ECMAScript version.
110111
*
111112
* @param {SupportedJSHintOptions} options - Options.
112-
* @return {number|'latest'}
113+
* @return {number|'latest'} ECMAScript version.
113114
*/
114115
function getEcmaVersion( options ) {
115116
if ( typeof options.esversion === 'number' ) {
116117
return options.esversion;
117-
} else if ( options.es5 ) {
118+
}
119+
if ( options.es5 ) {
118120
return 5;
119-
} else if ( options.es3 ) {
121+
}
122+
if ( options.es3 ) {
120123
return 3;
121-
} else {
122-
return 'latest';
123124
}
125+
return 'latest';
124126
}
125127

126128
/**
127129
* Parses JS code to find errors.
128130
*
129131
* @param {string} source - JavaScript source code.
130-
* @param {SupportedJSHintOptions} options - Linting options.
132+
* @param {SupportedJSHintOptions} [options] - Linting options.
131133
*/
132134
function fakeJSHINT( source, options ) {
133135
parse( source, options );

0 commit comments

Comments
 (0)