Skip to content

Commit c8e1352

Browse files
fix(eslint-plugin): report on-function-explicit-return-type for call expressions (#4904)
Closes #4901
1 parent e7eabd4 commit c8e1352

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

modules/eslint-plugin/spec/rules/store/on-function-explicit-return-type.spec.ts

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const reducer = createReducer(
2929
const reducer = createReducer(
3030
initialState,
3131
on(increment, incrementFunc),
32-
on(increment, s => incrementFunc(s)),
3332
on(increment, (s): State => incrementFunc(s)),
3433
)`,
3534
`
@@ -174,6 +173,57 @@ const reducer = createReducer(
174173
const reducer = createReducer(
175174
initialState,
176175
on(reset, (): State => initialState ),
176+
)`,
177+
},
178+
],
179+
},
180+
],
181+
},
182+
{
183+
code: `
184+
const reducer = createReducer(
185+
initialState,
186+
on(reset, s => foo(s)),
187+
)`,
188+
errors: [
189+
{
190+
column: 13,
191+
endColumn: 24,
192+
line: 4,
193+
messageId: onFunctionExplicitReturnType,
194+
suggestions: [
195+
{
196+
messageId: onFunctionExplicitReturnTypeSuggest,
197+
output: `
198+
const reducer = createReducer(
199+
initialState,
200+
on(reset, (s): State => foo(s)),
201+
)`,
202+
},
203+
],
204+
},
205+
],
206+
},
207+
// https://github.com/ngrx/platform/issues/4901
208+
{
209+
code: `
210+
const reducer = createReducer(
211+
initialState,
212+
on(reset, s => ({ ...s, counter: Number(1) })),
213+
)`,
214+
errors: [
215+
{
216+
column: 13,
217+
endColumn: 48,
218+
line: 4,
219+
messageId: onFunctionExplicitReturnType,
220+
suggestions: [
221+
{
222+
messageId: onFunctionExplicitReturnTypeSuggest,
223+
output: `
224+
const reducer = createReducer(
225+
initialState,
226+
on(reset, (s): State => ({ ...s, counter: Number(1) })),
177227
)`,
178228
},
179229
],

modules/eslint-plugin/src/utils/selectors/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const dispatchInEffects = (name: RegExp | string) =>
6969
export const createReducer = `CallExpression[callee.name='createReducer']`;
7070

7171
export const onFunctionWithoutType =
72-
`${createReducer} CallExpression[callee.name='on'] > ArrowFunctionExpression:not([returnType.typeAnnotation], :has(CallExpression))` as const;
72+
`${createReducer} CallExpression[callee.name='on'] > ArrowFunctionExpression:not([returnType.typeAnnotation])` as const;
7373

7474
export const storeActionReducerMap =
7575
`${ngModuleImports} CallExpression[callee.object.name='StoreModule'][callee.property.name=/^for(Root|Feature)$/] > ObjectExpression:first-child` as const;

0 commit comments

Comments
 (0)