Skip to content

Commit 95c53fd

Browse files
chore(no-misused-observables): boilerplate for void return
1 parent 438bdfc commit 95c53fd

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

docs/rules/no-misused-observables.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
<!-- begin auto-generated rule options list -->
1010

11-
| Name | Description | Type | Default |
12-
| :-------------- | :-------------------------------------- | :------ | :------ |
13-
| `checksSpreads` | Disallow `...` spreading an Observable. | Boolean | `true` |
11+
| Name | Description | Type | Default |
12+
| :----------------- | :-------------------------------------------------------------------------- | :------ | :------ |
13+
| `checksSpreads` | Disallow `...` spreading an Observable. | Boolean | `true` |
14+
| `checksVoidReturn` | Disallow returning an Observable from a function typed as returning `void`. | Boolean | `true` |
1415

1516
<!-- end auto-generated rule options list -->

src/rules/no-misused-observables.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ruleCreator } from '../utils';
66
// https://github.com/typescript-eslint/typescript-eslint/blob/fcd6cf063a774f73ea00af23705117a197f826d4/packages/eslint-plugin/src/rules/no-misused-promises.ts
77

88
const defaultOptions: readonly {
9+
checksVoidReturn?: boolean;
910
checksSpreads?: boolean;
1011
}[] = [];
1112

@@ -17,11 +18,18 @@ export const noMisusedObservablesRule = ruleCreator({
1718
requiresTypeChecking: true,
1819
},
1920
messages: {
21+
forbiddenVoidReturnArgument: 'Observable returned in function argument where a void return was expected.',
22+
forbiddenVoidReturnAttribute: 'Observable-returning function provided to attribute where a void return was expected.',
23+
forbiddenVoidReturnInheritedMethod: 'Observable-returning method provided where a void return was expected by extended/implemented type \'{{heritageTypeName}}\'.',
24+
forbiddenVoidReturnProperty: 'Observable-returning function provided to property where a void return was expected.',
25+
forbiddenVoidReturnReturnValue: 'Observable-returning function provided to return value where a void return was expected.',
26+
forbiddenVoidReturnVariable: 'Observable-returning function provided to variable where a void return was expected.',
2027
forbiddenSpread: 'Expected a non-Observable value to be spread into an object.',
2128
},
2229
schema: [
2330
{
2431
properties: {
32+
checksVoidReturn: { type: 'boolean', default: true, description: 'Disallow returning an Observable from a function typed as returning `void`.' },
2533
checksSpreads: { type: 'boolean', default: true, description: 'Disallow `...` spreading an Observable.' },
2634
},
2735
type: 'object',
@@ -33,7 +41,11 @@ export const noMisusedObservablesRule = ruleCreator({
3341
create: (context) => {
3442
const { couldBeObservable } = getTypeServices(context);
3543
const [config = {}] = context.options;
36-
const { checksSpreads = true } = config;
44+
const { checksVoidReturn = true, checksSpreads = true } = config;
45+
46+
const voidReturnChecks: TSESLint.RuleListener = {
47+
48+
};
3749

3850
const spreadChecks: TSESLint.RuleListener = {
3951
SpreadElement: (node) => {
@@ -47,6 +59,7 @@ export const noMisusedObservablesRule = ruleCreator({
4759
};
4860

4961
return {
62+
...(checksVoidReturn ? voidReturnChecks : {}),
5063
...(checksSpreads ? spreadChecks : {}),
5164
};
5265
},

0 commit comments

Comments
 (0)