Created
November 21, 2018 16:49
-
-
Save SET001/1208b5c2e7f3d014c95019449f3eeac3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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