The Axios concurrency helpers all() and spread(), and the CancelToken cancellation API, are deprecated and have native replacements.

Why is this an issue?

Deprecated Axios helpers and the CancelToken API keep an application tied to legacy APIs that Axios itself recommends replacing with standard platform APIs. Using the native alternatives makes the code clearer to developers familiar with Promise.all(), array destructuring, and AbortController.

This rule reports all(), spread(), and CancelToken usage through a binding imported or required from the axios package, as well as the cancelToken option passed to an Axios request method. It does not report ordinary request helpers such as axios.get() or instance setup such as axios.create(), because those APIs do not map one-to-one onto fetch().

Replace all() with Promise.all(), replace spread() with array destructuring, and replace CancelToken with AbortController. The replacement can keep using Axios for HTTP requests.

Code examples

Noncompliant code example

import axios from "axios";

axios.all([axios.get("/a"), axios.get("/b")]); // Noncompliant: "axios.all()" is a deprecated Axios helper

Compliant solution

import axios from "axios";

Promise.all([axios.get("/a"), axios.get("/b")]);

Noncompliant code example

import axios from "axios";

Promise.all([axios.get("/a"), axios.get("/b")])
  .then(axios.spread((a, b) => { // Noncompliant: "axios.spread()" is a deprecated Axios helper
    console.log(a.data, b.data);
  }));

Compliant solution

import axios from "axios";

Promise.all([axios.get("/a"), axios.get("/b")])
  .then(([a, b]) => {
    console.log(a.data, b.data);
  });

Noncompliant code example

import axios from "axios";

const source = axios.CancelToken.source(); // Noncompliant: "CancelToken" is a deprecated Axios API
axios.get("/user", { cancelToken: source.token }); // Noncompliant: "CancelToken" is a deprecated Axios API
source.cancel();

Compliant solution

import axios from "axios";

const controller = new AbortController();
axios.get("/user", { signal: controller.signal });
controller.abort();

Resources

Documentation

Related rules