How to use the eslint-plugin-vue/lib/utils.defineTemplateBodyVisitor function in eslint-plugin-vue

To help you get started, we’ve selected a few eslint-plugin-vue examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github maranran / eslint-plugin-vue-a11y / lib / rules / label-has-for.js View on Github external
create (context) {
    return VueUtils.defineTemplateBodyVisitor(context, {
      "VElement" (node) {
        const options = context.options[0] || {};
        const componentOptions = options.components || [];
        const typesToValidate = ['label'].concat(componentOptions);
        const nodeType = utils.getElementType(node);

        // Only check 'label' elements and custom types.
        if (typesToValidate.indexOf(nodeType) === -1) {
          return;
        }
        const required = options.required || { every: ['nesting', 'id'] };
        const allowChildren = options.allowChildren || false;
        if (!isValid(node, required, allowChildren)) {
          context.report({
            node,
            message: errorMessage,
github maranran / eslint-plugin-vue-a11y / lib / rules / aria-props.js View on Github external
create (context) {
    return VueUtils.defineTemplateBodyVisitor(context, {
      "VAttribute" (node) {
        const name = utils.getAttributeName(node);
        if (name) {
          const normalizedName = name.toLowerCase();
          if (normalizedName.indexOf('aria-') !== 0) {
            return;
          }
          const isValid = [...aria.keys()].indexOf(normalizedName) > -1;
          if (isValid) {
            return
          }
          context.report({
            node,
            message: `${name}: This attribute is an invalid ARIA attribute.`
          });
        }
github learningequality / kolibri / packages / eslint-plugin-kolibri / lib / rules / vue-no-unused-vuex-properties.js View on Github external
remove(unusedVuexProperties, property => {
        return argName === property.name;
      });
    }),
    utils.executeOnRootTemplateEnd(() => {
      if (unusedVuexProperties.length) {
        utils.reportUnusedVuexProperties(context, unusedVuexProperties);
      }
    })
  );

  return Object.assign(
    {},
    initialize,
    eslintPluginVueUtils.defineTemplateBodyVisitor(context, templateVisitor, scriptVisitor)
  );
};
github learningequality / kolibri / packages / eslint-plugin-kolibri / lib / rules / vue-no-undefined-string-uses.js View on Github external
if (arg.type == 'Literal') {
              usedStringNodes.push(arg);
            }
          });
        }
      },
    },
    utils.executeOnRootTemplateEnd(() => {
      utils.reportUseOfUndefinedTranslation(context, definitionNodes, usedStringNodes);
    })
  );

  return Object.assign(
    {},
    initialize,
    eslintPluginVueUtils.defineTemplateBodyVisitor(context, templateVisitor, scriptVisitor)
  );
};
github learningequality / kolibri / packages / eslint-plugin-kolibri / lib / rules / vue-no-unused-translations.js View on Github external
if (get(arg, ['value'])) {
              usedStrings.push(arg.value);
            }
          });
        }
      },
    },
    utils.executeOnRootTemplateEnd(() => {
      utils.reportUnusedTranslations(context, definitionNodes, usedStrings);
    })
  );

  return Object.assign(
    {},
    initialize,
    eslintPluginVueUtils.defineTemplateBodyVisitor(context, templateVisitor, scriptVisitor)
  );
};
github maranran / eslint-plugin-vue-a11y / lib / rules / media-has-caption.js View on Github external
create (context) {
    return VueUtils.defineTemplateBodyVisitor(context, {
      "VStartTag" (node) {
        const element = node.parent;
        const type = utils.getElementType(element);
        if (!isMediaType(context, type)) {
          return;
        }
        const mutedProp = utils.getAttribute(element, 'muted');
        const mutedValue = mutedProp && utils.getAttributeValue(mutedProp);
        if (mutedProp && mutedValue.toString() === 'true') {
          return
        }
        const trackChildren = element.children.filter((child) => {
          if (child.type !== 'VElement') {
            return false;
          }
          return isTrackType(context, utils.getElementType(child));
github maranran / eslint-plugin-vue-a11y / lib / rules / aria-role.js View on Github external
create (context) {
    return VueUtils.defineTemplateBodyVisitor(context, {
      "VAttribute" (node) {
        const options = context.options[0] || {};
        const ignoreNonDOM = !!options.ignoreNonDOM;
        if (ignoreNonDOM) {
          const type = utils.getElementType(node.parent.parent);
          if (!dom.get(type)) {
            return;
          }
        }
        const isRole = utils.isAttribute(node, 'role')
        if (!isRole) { return; }

        const value = utils.getAttributeValue(node);
        if (value === null || typeof value !== 'string') {
          return;
        }
github learningequality / kolibri / packages / eslint-plugin-kolibri / lib / rules / vue-no-unused-properties.js View on Github external
remove(unusedProperties, property => {
        return argName === property.name;
      });
    }),
    utils.executeOnRootTemplateEnd(() => {
      if (unusedProperties.length) {
        utils.reportUnusedProperties(context, unusedProperties);
      }
    })
  );

  return Object.assign(
    {},
    initialize,
    eslintPluginVueUtils.defineTemplateBodyVisitor(context, templateVisitor, scriptVisitor)
  );
};
github maranran / eslint-plugin-vue-a11y / lib / rules / heading-has-content.js View on Github external
create (context) {
    return VueUtils.defineTemplateBodyVisitor(context, {
      "VElement" (node) {
        const typeCheck = headings.concat(context.options[0]);
        const nodeType = utils.getElementType(node);
        if (typeCheck.indexOf(nodeType) === -1) {
          return;
        } else if (utils.hasAccessibleChild(node)) {
          return;
        }

        context.report({
          node,
          message: errorMessage,
        });
      }
    }, altRule.create(context))
  }
github learningequality / kolibri / packages / eslint-plugin-kolibri / lib / rules / vue-no-unused-methods.js View on Github external
remove(unusedProperties, property => {
          return referencesNames.includes(property.name);
        });
      },
    },
    utils.executeOnRootTemplateEnd(() => {
      if (unusedProperties.length) {
        utils.reportUnusedProperties(context, unusedProperties, disabledLines);
      }
    })
  );

  return Object.assign(
    {},
    initialize,
    eslintPluginVueUtils.defineTemplateBodyVisitor(context, templateVisitor, scriptVisitor)
  );
};