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.

Why is this an issue?

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.

Code examples

Noncompliant code example

const isList = jQuery.isArray(value); // Noncompliant: "jQuery.isArray()" is deprecated

Compliant solution

const isList = Array.isArray(value);

Noncompliant code example

import $ from "jquery";

const settings = $.parseJSON(source); // Noncompliant: "jQuery.parseJSON()" is deprecated

Compliant solution

const settings = JSON.parse(source);

Noncompliant code example

const startedAt = jQuery.now(); // Noncompliant: "jQuery.now()" is deprecated

Compliant solution

const startedAt = Date.now();

Noncompliant code example

import $ from "jquery";

const input = "  Sonar  ";
const label = $.trim(input); // Noncompliant: "jQuery.trim()" is deprecated

Compliant solution

const input = "  Sonar  ";
const label = input.trim();

Noncompliant code example

const values = ["Sonar"];
const position = jQuery.inArray("Sonar", values); // Noncompliant: reduce dependence on jQuery

Compliant solution

const values = ["Sonar"];
const position = values.indexOf(value);

Resources

Documentation