Skip to content

Commit

Permalink
Merge pull request #2 from jonboiser/lint-undefined-string-uses
Browse files Browse the repository at this point in the history
Patches for  Lint undefined string uses
  • Loading branch information
nucleogenesis authored Aug 9, 2019
2 parents 5e27158 + c19ae35 commit 0fc3712
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

const eslintPluginVueUtils = require('eslint-plugin-vue/lib/utils');

const get = require('lodash/get');
const utils = require('../utils');
const constants = require('../constants');

Expand Down Expand Up @@ -33,7 +34,11 @@ const create = context => {
{
'CallExpression[callee.type="MemberExpression"]'(node) {
if (node.callee.property.name == $TR_FUNCTION && node.arguments.length) {
node.arguments.forEach(arg => usedStrings.push(arg.value));
node.arguments.forEach(arg => {
if (get(arg, ['value'])) {
usedStrings.push(arg.value);
}
});
}
},
},
Expand All @@ -43,7 +48,7 @@ const create = context => {
{
ObjectExpression(node) {
node.properties.forEach(prop => {
if (prop.value.value) {
if (get(prop, ['value', 'value'])) {
usedStrings.push(prop.value.value);
}
});
Expand All @@ -52,7 +57,7 @@ const create = context => {
{
ArrayExpression(node) {
node.elements.forEach(elem => {
if (elem.value) {
if (get(elem, ['value'])) {
usedStrings.push(elem.value);
}
});
Expand All @@ -74,7 +79,11 @@ const create = context => {
{
'CallExpression[callee.type="Identifier"]'(node) {
if (node.callee.name == $TR_FUNCTION && node.arguments.length) {
node.arguments.forEach(arg => Boolean(arg.value) && usedStrings.push(arg.value));
node.arguments.forEach(arg => {
if (get(arg, ['value'])) {
usedStrings.push(arg.value);
}
});
}
},
},
Expand Down
2 changes: 2 additions & 0 deletions packages/kolibri-tools/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,7 @@ module.exports = {
'kolibri/vue-no-unused-methods': ERROR,
'kolibri/vue-no-unused-vuex-methods': ERROR,
'kolibri/vue-watch-no-string': ERROR,
'kolibri/vue-no-undefined-string-uses': ERROR,
'kolibri/vue-no-unused-translations': ERROR,
},
};

0 comments on commit 0fc3712

Please sign in to comment.