The jQuery utility methods isArray(), parseJSON(), now(), and trim() are deprecated and have
native replacements. inArray() is not deprecated, but modern JavaScript provides the equivalent Array.prototype.indexOf()
method.
Deprecated jQuery utility methods keep an application tied to legacy APIs that jQuery itself recommends replacing with native JavaScript methods. Using the native alternatives makes the code clearer to developers familiar with standard APIs and reduces its dependence on jQuery utilities.
This rule reports direct, non-computed static calls through an unshadowed jQuery global reference or a jQuery or
$ binding imported or required from the jquery package. Replace deprecated methods with their native alternatives and use
Array.prototype.indexOf() instead of jQuery.inArray() when the collection is an array. The replacement should be made
deliberately: jQuery.trim() and jQuery.inArray() can handle non-string or array-like inputs differently from their native
counterparts.
const isList = jQuery.isArray(value); // Noncompliant: "jQuery.isArray()" is deprecated
const isList = Array.isArray(value);
import $ from "jquery"; const settings = $.parseJSON(source); // Noncompliant: "jQuery.parseJSON()" is deprecated
const settings = JSON.parse(source);
const startedAt = jQuery.now(); // Noncompliant: "jQuery.now()" is deprecated
const startedAt = Date.now();
import $ from "jquery"; const input = " Sonar "; const label = $.trim(input); // Noncompliant: "jQuery.trim()" is deprecated
const input = " Sonar "; const label = input.trim();
const values = ["Sonar"];
const position = jQuery.inArray("Sonar", values); // Noncompliant: reduce dependence on jQuery
const values = ["Sonar"]; const position = values.indexOf(value);
jQuery.isArray()jQuery.parseJSON()jQuery.now()jQuery.trim()jQuery.inArray()