What version of Oxlint are you using?
1.65.0
What command did you run?
oxlint -c ./oxlint.config.ts --type-aware .
What does your .oxlintrc.json (or oxlint.config.ts) config file look like?
What happened?
Description
unicorn/no-array-sort reports false positives for non-array .sort() methods, specifically Mongoose query sorting.
The rule is intended to discourage mutating Array.prototype.sort() and suggest toSorted() instead. However, Mongoose’s .sort() is not Array#sort; it is a query builder method used to specify database sort order.
Reproduction
import mongoose from "mongoose";
const userSchema = new mongoose.Schema({
name: String,
createdAt: Date,
});
const User = mongoose.model("User", userSchema);
async function getUsers() {
return User.find().sort({ createdAt: -1 });
}
Actual behavior
Oxlint reports unicorn/no-array-sort on the Mongoose .sort() call:
User.find().sort({ createdAt: -1 });
^^^^
It suggests avoiding Array#sort() / using toSorted().
Expected behavior
The rule should not report this code, because User.find().sort(...) is not Array.prototype.sort().
This .sort() call belongs to Mongoose’s query API and does not mutate a JavaScript array.
Why this matters
In Node.js/TypeScript backend projects, .sort() is commonly used by database query builders and ORMs/ODMs, for example:
User.find().sort({ createdAt: -1 });
User.find().sort("-createdAt");
Post.find({ published: true }).sort({ updatedAt: "desc" });
Flagging these as unicorn/no-array-sort creates noisy false positives and makes the rule difficult to enable in projects using Mongoose.
Expected scope of the rule
This should still be reported:
const items = [3, 1, 2];
items.sort();
But this should not be reported:
User.find().sort({ createdAt: -1 });
What version of Oxlint are you using?
1.65.0
What command did you run?
oxlint -c ./oxlint.config.ts --type-aware .What does your
.oxlintrc.json(oroxlint.config.ts) config file look like?{ "categories": { "correctness": "off" }, "plugins": ["unicorn"], "rules": { "unicorn/no-array-sort": "error", } }What happened?
Description
unicorn/no-array-sortreports false positives for non-array.sort()methods, specifically Mongoose query sorting.The rule is intended to discourage mutating
Array.prototype.sort()and suggesttoSorted()instead. However, Mongoose’s.sort()is notArray#sort; it is a query builder method used to specify database sort order.Reproduction
Actual behavior
Oxlint reports
unicorn/no-array-sorton the Mongoose.sort()call:It suggests avoiding
Array#sort()/ usingtoSorted().Expected behavior
The rule should not report this code, because
User.find().sort(...)is notArray.prototype.sort().This
.sort()call belongs to Mongoose’s query API and does not mutate a JavaScript array.Why this matters
In Node.js/TypeScript backend projects,
.sort()is commonly used by database query builders and ORMs/ODMs, for example:Flagging these as
unicorn/no-array-sortcreates noisy false positives and makes the rule difficult to enable in projects using Mongoose.Expected scope of the rule
This should still be reported:
But this should not be reported: