Skip to content

Instantly share code, notes, and snippets.

@SET001
Created November 21, 2018 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SET001/1208b5c2e7f3d014c95019449f3eeac3 to your computer and use it in GitHub Desktop.
Save SET001/1208b5c2e7f3d014c95019449f3eeac3 to your computer and use it in GitHub Desktop.
const jsLangs = (context, error) => node => node.arguments.map((arg) => {
if (arg.type === 'Identifier') {
context.report({
node,
messageId: error,
data: { name: arg.name }
});
}
});
module.exports = {
meta: {
type: 'problem',
messages: {
avoidDynKeysInLangGet: 'Avoid using dynamic translation keys with lang.get({{name}})',
avoidDynKeysInLangsGet: 'Avoid using dynamic translation keys with langs.get({{name}})',
avoidDynKeysInLang: 'Avoid using dynamic translation keys with lang({{name}})'
}
},
create(context) {
return {
"CallExpression[callee.object.name='lang'][callee.property.name='get']": jsLangs(context, 'avoidDynKeysInLangGet'),
"CallExpression[callee.object.name='langs'][callee.property.name='get']": jsLangs(context, 'avoidDynKeysInLangsGet'),
"CallExpression[callee.object.name='lang']": jsLangs(context, 'avoidDynKeysInLang')
};
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment