fix(lint): normalize fractional slice bounds
This commit is contained in:
parent
f2bfaba287
commit
ed7f3c140d
|
|
@ -83,8 +83,8 @@ function isBoundedSlice(node: ESTree.CallExpression): boolean {
|
|||
const start = numericLiteral(node.arguments[0])
|
||||
const end = numericLiteral(node.arguments[1])
|
||||
return (
|
||||
(start !== null && Number.isFinite(start) && start < 0) ||
|
||||
(end !== null && Number.isFinite(end) && end >= 0)
|
||||
(start !== null && Number.isFinite(start) && Math.trunc(start) < 0) ||
|
||||
(end !== null && Number.isFinite(end) && Math.trunc(end) >= 0)
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ describe('no-reduce-accumulator-copy', () => {
|
|||
'items.reduce((acc, item) => acc.concat([item]), [])',
|
||||
'items.reduce((acc, item) => acc.slice(0, -1), [])',
|
||||
'items.reduce((acc, item) => acc.slice(2), [])',
|
||||
'items.reduce((acc, item) => acc.slice(-0.5), [])',
|
||||
'items.reduce((acc, item) => acc.slice(-0), [])',
|
||||
'items.reduce((acc, item) => { const next = acc.slice(); next.push(item); return next }, [])',
|
||||
'items.reduce((acc, item) => Object.assign({}, acc, { [item.id]: item }), {})',
|
||||
'items.reduce((acc, item) => Array.from(acc), [])'
|
||||
|
|
@ -24,6 +26,8 @@ describe('no-reduce-accumulator-copy', () => {
|
|||
'items.reduce(namedReducer, [])',
|
||||
'items.reduce((acc, item) => acc.slice(0, 1), [0])',
|
||||
'items.reduce((acc, item) => acc.slice(-2), [0])',
|
||||
'items.reduce((acc, item) => acc.slice(-1.5), [0])',
|
||||
'items.reduce((acc, item) => acc.slice(0, -0.5), [0])',
|
||||
'items.reduce((acc, item) => acc.slice(0, 0), [0])'
|
||||
])('accepts owned mutation and unrelated copies: %s', async (source) => {
|
||||
expect(ruleDiagnostics(await lint(source, rules), rule)).toHaveLength(0)
|
||||
|
|
|
|||
Loading…
Reference in a new issue