'How to identify functional component with vue-eslint-parser

I am writing my eslint rule using vue-eslint-parser. It's required to prevent functional components from using vue template syntax.

I have already written a rule for prohibiting the syntax <template functional> :

create(context) {
    return context.parserServices.defineDocumentVisitor(
      {
        VDocumentFragment(node) {
          const template = node.children.find(item => item.type === 'VElement' && item.name === 'template');

          if (!template) return;

          const functionalAttr = template.startTag.attributes.find(item => !item.directive && item.key.name === 'functional');


          if (functionalAttr) {
            context.report({
              message: "Don't use vue templates with functional components",
              loc: node.loc
            });
          }
        }
      }
    );
  }

Question: How do I make the following code also invalid ? (in other words, how to check the script tag and the code inside it).

<template>

</template>

<script>
export default {
  functional: true,
};
</script>

Thank you!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source