[eslint] don't drop multiple uses when one is in a function (#119252) (#119368)

Co-authored-by: Spencer <email@spalger.com>
This commit is contained in:
Kibana Machine 2021-11-22 15:21:25 -05:00 committed by GitHub
parent f8529850bb
commit 5345b4b68b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 11 deletions

View file

@ -79,7 +79,7 @@ module.exports = {
node.type === esTypes.FunctionExpression ||
node.type === esTypes.ArrowFunctionExpression
) {
return traverse.STOP;
return traverse.SKIP;
}
if (

View file

@ -96,5 +96,25 @@ ruleTester.run('@kbn/eslint/no_constructor_args_in_property_initializers', rule,
},
],
},
{
code: dedent`
class Foo {
readonly bar = y(this.deps.history).x(
() => {
this.deps.usage()
}
);
constructor(private readonly deps: unknown) {}
}
`,
errors: [
{
line: 2,
message: `The constructor argument "deps" can't be used in a class property intializer, define the property in the constructor instead`,
},
],
},
],
});

View file

@ -7,6 +7,7 @@
*/
import { History } from 'history';
import * as Rx from 'rxjs';
import { filter } from 'rxjs/operators';
import { DataPublicPluginStart } from '../../../../../../data/public';
import {
@ -29,17 +30,19 @@ export class DiscoverSearchSessionManager {
* Notifies about `searchSessionId` changes in the URL,
* skips if `searchSessionId` matches current search session id
*/
readonly newSearchSessionIdFromURL$ = createQueryParamObservable<string>(
this.deps.history,
SEARCH_SESSION_ID_QUERY_PARAM
).pipe(
filter((searchSessionId) => {
if (!searchSessionId) return true;
return !this.deps.session.isCurrentSession(searchSessionId);
})
);
readonly newSearchSessionIdFromURL$: Rx.Observable<string | null>;
constructor(private readonly deps: DiscoverSearchSessionManagerDeps) {}
constructor(private readonly deps: DiscoverSearchSessionManagerDeps) {
this.newSearchSessionIdFromURL$ = createQueryParamObservable<string>(
this.deps.history,
SEARCH_SESSION_ID_QUERY_PARAM
).pipe(
filter((searchSessionId) => {
if (!searchSessionId) return true;
return !this.deps.session.isCurrentSession(searchSessionId);
})
);
}
/**
* Get next session id by either starting or restoring a session.