Skip to content

Commit

Permalink
fix(eslint): allow use method inside other use methods (QwikDev#3804)
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat authored Apr 17, 2023
1 parent 99c6b23 commit 26fa4a0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
27 changes: 27 additions & 0 deletions packages/eslint-plugin-qwik/qwik.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,33 @@ test('no-use-after-await', () => {
ruleTester.run('my-rule', rules['use-method-usage'] as any, {
valid: [
`
export function useSession1() {
useContext();
}
export function useSession2() {
return useContext();
}
export function useSession3() {
return useContext().value;
}
`,
`
export const useSession1 = () => {
useContext();
}
export const useSession2 = () => {
return useContext();
}
export const useSession3 = () => useContext();
export const useSession4 = () => useContext().value;
export const useSession5 = () => useContext().value + 10;
`,
`
export const HelloWorld = component$(async () => {
useMethod();
await something();
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin-qwik/src/useMethodUsage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const useMethodUsage: Rule.RuleModule = {
case 'MemberExpression':
case 'BinaryExpression':
case 'UnaryExpression':
case 'ReturnStatement':
case 'BlockStatement':
break;
case 'ArrowFunctionExpression':
Expand Down Expand Up @@ -87,9 +88,8 @@ export const useMethodUsage: Rule.RuleModule = {
node,
messageId: 'use-wrong-function',
});
return;
}
break;
return;
default:
context.report({
node,
Expand Down

0 comments on commit 26fa4a0

Please sign in to comment.