Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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: {
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 => {
{
'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);
}
})
);
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(
{},
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)
);
});
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);
}
});
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);
}
})
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);