Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/etc/is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ export function isRestElement(node: TSESTree.Node): node is TSESTree.RestElement
return node.type === AST_NODE_TYPES.RestElement;
}

export function isSpreadElement(node: TSESTree.Node): node is TSESTree.SpreadElement {
return node.type === AST_NODE_TYPES.SpreadElement;
}

export function isThisExpression(node: TSESTree.Node): node is TSESTree.ThisExpression {
return node.type === AST_NODE_TYPES.ThisExpression;
}
Expand Down
4 changes: 2 additions & 2 deletions src/rules/no-unnecessary-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
TSESTree as es,
} from '@typescript-eslint/utils';
import { MULTIPLE_OBSERVABLE_ACCEPTING_STATIC_OBSERVABLE_CREATORS, SOURCES_OBJECT_ACCEPTING_STATIC_OBSERVABLE_CREATORS } from '../constants';
import { getTypeServices, isArrayExpression, isObjectExpression, isProperty } from '../etc';
import { getTypeServices, isArrayExpression, isObjectExpression, isProperty, isSpreadElement } from '../etc';
import { ruleCreator } from '../utils';

export const noUnnecessaryCollectionRule = ruleCreator({
Expand Down Expand Up @@ -71,7 +71,7 @@ export const noUnnecessaryCollectionRule = ruleCreator({
}

// Single rest parameter argument.
if (args.length === 1 && couldBeObservable(firstArg)) {
if (args.length === 1 && !isSpreadElement(firstArg) && couldBeObservable(firstArg)) {
context.report({
messageId: 'forbidden',
node: node.callee,
Expand Down
7 changes: 7 additions & 0 deletions tests/rules/no-unnecessary-collection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ ruleTester({ types: true }).run('no-unnecessary-collection', noUnnecessaryCollec
const b$ = of(2);
const merged$ = merge(a$, b$);
`,
stripIndent`
// merge with spread
import { merge, of } from "rxjs";
const arr = [of(1), of(2)];
const merged$ = merge(...arr);
`,
stripIndent`
// zip with multiple observables
import { zip, of } from "rxjs";
Expand Down