UNPKG

eslint-plugin-sonarjs

Version:
27 lines (26 loc) 1.07 kB
import type estree from 'estree'; import { type SortMatcherContext } from './helpers.js'; /** * False-positive shapes: * function normalize(values: string[]) { * return values.map(String).sort(); * } * JSON.stringify(normalize(a)) === JSON.stringify(normalize(b)) * * const normalize = (values: string[]) => values.toSorted(); * JSON.stringify(normalize(a)) !== JSON.stringify(normalize(b)) * * function normalize(values: number[]) { * return values.sort(); * } * JSON.stringify(normalize(before)) == JSON.stringify(normalize(after)) * * What can vary: * - function declaration vs local function expression / arrow function * - `sort()` vs `toSorted()` inside the helper * - the equality operator used around the JSON.stringify comparison * * The inner sort call is acceptable when the helper is only used as a * normalizer inside matching JSON.stringify equality/inequality comparisons. */ export declare function isSortReturnedByComparedNormalizer(call: estree.CallExpression, ruleContext: SortMatcherContext): boolean;