Skip to content

Add requireTypeCheck option to guard-super-call - #135

Open
anthony-unicare wants to merge 1 commit into
43081j:masterfrom
anthony-unicare:patch-1
Open

Add requireTypeCheck option to guard-super-call#135
anthony-unicare wants to merge 1 commit into
43081j:masterfrom
anthony-unicare:patch-1

Conversation

@anthony-unicare

Copy link
Copy Markdown

This fixes #134.

let errNode = null;
const source = context.getSourceCode();
const options = context.options?.[0] ?? {};
const requireTypeCheck = options.requireTypeCheck ?? false;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its probably better to just compare here, like options.requireTypeCheck === true

}
},
schema: [{
requireTypeCheck: {type: 'boolean'}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this object is meant to have a type i think, like:

    schema: [
      {
        type: 'object',
        properties: {
          requireTypeCheck: {type: 'boolean'}
        }
      }
    ]

if (isSuperHookExpression(node, hook)) {
errNode = node;
return true;
} else if (node.type === 'IfStatement' && !isSuperHook(node.test, hook)) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think i'd leave this as it is and just change isSuperHook to accept an extra requireTypeCheck parameter

inside isSuperHook, we could then:

if (requireTypeCheck) {
  return /* whatever a type checked super hook looks like */
}
return /* whatever a regular super hook looks like */

@43081j 43081j left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also add some tests? 👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Guard super call with typeof check

2 participants