How to use the eslint-plugin-vue/lib/utils.executeOnVue 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 learningequality / kolibri / packages / eslint-plugin-kolibri / lib / rules / vue-filename-and-component-name-match.js View on Github external
function create(context) {
  return utils.executeOnVue(context, obj => {
    const filePath = context.getFilename();

    // Skip if not .vue file
    if (!filePath.endsWith('vue')) {
      return;
    }

    const node = obj.properties.find(
      item => item.type === 'Property' && item.key.name === 'name' && item.value.type === 'Literal'
    );

    // Components require a name
    if (!node) {
      context.report({
        message: 'Component is missing a component name',
        loc: {
github learningequality / kolibri / packages / eslint-plugin-kolibri / lib / rules / vue-no-unused-translations.js View on Github external
if (get(prop, ['value', 'value'])) {
            usedStrings.push(prop.value.value);
          }
        });
      },
    },
    {
      ArrayExpression(node) {
        node.elements.forEach(elem => {
          if (get(elem, ['value'])) {
            usedStrings.push(elem.value);
          }
        });
      },
    },
    eslintPluginVueUtils.executeOnVue(context, obj => {
      definitionNodes = Array.from(
        eslintPluginVueUtils.iterateProperties(obj, new Set([GROUP_$TRS]))
      );

      if (!hasTemplate) {
        utils.reportUnusedTranslations(context, definitionNodes, usedStrings);
      }
    })
  );

  const templateVisitor = Object.assign(
    {},
    {
      'CallExpression[callee.type="Identifier"]'(node) {
        if (node.callee.name == $TR_FUNCTION && node.arguments.length) {
          node.arguments.forEach(arg => {
github learningequality / kolibri / packages / eslint-plugin-kolibri / lib / rules / vue-no-unused-vuex-properties.js View on Github external
{
      'CallExpression[callee.name=mapGetters][arguments] ObjectExpression Identifier[name]'(node) {
        unusedVuexProperties.push({
          kind: VUEX_GETTER,
          name: node.name,
          node,
        });
      },
    },
    utils.executeOnThisExpressionProperty(property => {
      thisExpressionsVariablesNames.push(property.name);
    }),
    utils.executeOnBefoureRouteEnterInstanceProperty(property => {
      befoureRouteEnterInstanceProperties.push(property.name);
    }),
    eslintPluginVueUtils.executeOnVue(context, obj => {
      const watchersNames = utils.getWatchersNames(obj);

      remove(unusedVuexProperties, property => {
        return (
          thisExpressionsVariablesNames.includes(property.name) ||
          befoureRouteEnterInstanceProperties.includes(property.name) ||
          watchersNames.includes(property.name)
        );
      });

      if (!hasTemplate && unusedVuexProperties.length) {
        utils.reportUnusedVuexProperties(context, unusedVuexProperties);
      }
    })
  );
github learningequality / kolibri / packages / eslint-plugin-kolibri / lib / rules / vue-no-unused-vuex-methods.js View on Github external
kind: VUEX_ACTION,
          name: node.value,
          node,
        });
      },
    },
    utils.executeOnThisExpressionProperty(property => {
      thisExpressionsVariablesNames.push(property.name);
    }),
    utils.executeOnBefoureRouteEnterInstanceProperty(property => {
      befoureRouteEnterInstanceProperties.push(property.name);
    }),
    utils.executeOnWatchStringMethod(node => {
      watchStringMethods.push(node.value);
    }),
    eslintPluginVueUtils.executeOnVue(context, () => {
      remove(unusedVuexProperties, property => {
        return (
          thisExpressionsVariablesNames.includes(property.name) ||
          befoureRouteEnterInstanceProperties.includes(property.name) ||
          watchStringMethods.includes(property.name)
        );
      });

      if (!hasTemplate && unusedVuexProperties.length) {
        utils.reportUnusedVuexProperties(context, unusedVuexProperties);
      }
    })
  );

  const templateVisitor = Object.assign(
    {},
github learningequality / kolibri / packages / eslint-plugin-kolibri / lib / rules / vue-no-unused-properties.js View on Github external
return;
      }

      hasTemplate = Boolean(node.templateBody);
    },
  };

  const scriptVisitor = Object.assign(
    {},
    utils.executeOnThisExpressionProperty(property => {
      thisExpressionsVariablesNames.push(property.name);
    }),
    utils.executeOnBefoureRouteEnterInstanceProperty(property => {
      befoureRouteEnterInstanceProperties.push(property.name);
    }),
    eslintPluginVueUtils.executeOnVue(context, obj => {
      unusedProperties = Array.from(
        eslintPluginVueUtils.iterateProperties(
          obj,
          new Set([GROUP_PROPS, GROUP_DATA, GROUP_COMPUTED])
        )
      );

      const watchersNames = utils.getWatchersNames(obj);

      remove(unusedProperties, property => {
        return (
          thisExpressionsVariablesNames.includes(property.name) ||
          befoureRouteEnterInstanceProperties.includes(property.name) ||
          watchersNames.includes(property.name)
        );
      });
github learningequality / kolibri / packages / eslint-plugin-kolibri / lib / rules / vue-no-undefined-string-uses.js View on Github external
usedStringNodes.push(arg);
            }
          });
        }
      },
    },
    {
      ObjectExpression(node) {
        if (get(node, 'parent.key.name') === '$trs') {
          node.properties.forEach(prop => {
            definitionNodes.push({ name: prop.key.name });
          });
        }
      },
    },
    eslintPluginVueUtils.executeOnVue(context, () => {
      if (!hasTemplate) {
        utils.reportUseOfUndefinedTranslation(context, definitionNodes, usedStringNodes);
      }
    })
  );

  const templateVisitor = Object.assign(
    {},
    {
      'CallExpression[callee.type="Identifier"]'(node) {
        if (node.callee.name == $TR_FUNCTION && node.arguments.length) {
          node.arguments.forEach(arg => {
            if (arg.type == 'Literal') {
              usedStringNodes.push(arg);
            }
          });
github learningequality / kolibri / packages / eslint-plugin-kolibri / lib / rules / vue-no-unused-methods.js View on Github external
thisExpressionsVariablesNames.push(property.name);
    }),
    utils.executeOnBefoureRouteEnterInstanceProperty(property => {
      befoureRouteEnterInstanceProperties.push(property.name);
    }),
    /*
      watch: {
        counter: 'getCount'
      }
    */
    {
      'Property[key.name=watch] ObjectExpression[properties] Literal[value]'(node) {
        watchStringMethods.push(node.value);
      },
    },
    eslintPluginVueUtils.executeOnVue(context, obj => {
      unusedProperties = Array.from(
        eslintPluginVueUtils.iterateProperties(obj, new Set([GROUP_METHODS]))
      );

      remove(unusedProperties, property => {
        return (
          thisExpressionsVariablesNames.includes(property.name) ||
          befoureRouteEnterInstanceProperties.includes(property.name) ||
          watchStringMethods.includes(property.name)
        );
      });

      if (!hasTemplate && unusedProperties.length) {
        utils.reportUnusedProperties(context, unusedProperties, disabledLines);
      }
    })
github learningequality / kolibri / packages / eslint-plugin-kolibri / lib / rules / vue-component-registration-casing.js View on Github external
function create(context) {
  const selectedCase = context.options[0];
  const caseType =
    allowedCaseOptions.indexOf(selectedCase) !== -1 ? selectedCase : allowedCaseOptions[0];
  const converter = casing.getConverter(caseType);

  return utils.executeOnVue(context, obj => {
    const node = obj.properties.find(
      p =>
        p.type === 'Property' &&
        p.key.type === 'Identifier' &&
        p.key.name === 'components' &&
        p.value.type === 'ObjectExpression'
    );

    if (!node) {
      return;
    }

    const items = node.value.properties;
    for (const item of items) {
      const componentName = item.key.name;
      const convertedName = converter(componentName);