Files
Sebastian McKenzie 86c98a62a7 Add missing commands (#439)
* add init command - closes #360

* list available commands and examples in cli help - fixes #345

* add outdated command - fixes #379

* rename uninstall command to remove

* add global command - fixes #227

* remove command aliases

* fix licenses not being shown due to integrity check shortcircuiting - fixes #424

* turn aliases back into js

* clean up single instance arguments - fixes #308

* ignore arguments that are included after -- - fixes #251

* add unlink command

* add lint rule against non-language keys

* clean up Config initialisation

* add link command - closes #336

* support array of string engines - fixes #447

* add missing request cache fixtures

* polish link command

* remove gulp file output

* add config command - fixes #378

* add yarn.lock and fix constants

* update aliases

* add missing i18n for CLI

* make `upgrade` command work how you'd expect

* update test metamethod

* require arguments for add command

* move dependency objects into constnats

* add init command - closes #360

* list available commands and examples in cli help - fixes #345

* add outdated command - fixes #379

* rename uninstall command to remove

* add global command - fixes #227

* remove command aliases

* fix licenses not being shown due to integrity check shortcircuiting - fixes #424

* turn aliases back into js

* clean up single instance arguments - fixes #308

* ignore arguments that are included after -- - fixes #251

* add unlink command

* add lint rule against non-language keys

* clean up Config initialisation

* add link command - closes #336

* support array of string engines - fixes #447

* polish link command

* remove gulp file output

* add config command - fixes #378

* add yarn.lock and fix constants

* fix lint, copy test fixtures to temp directory rather than mutating cwd

* fix lint

* add handler for extractor errors

* remove unused jest snapshot

* fix check-lockfile script

* fix lint

* fix check-lockfile

* try and fix test

* properly copy over lockfile scripts folder, ignore ds_store files in test directories

* remove problematic fixtures

* add back problematic fixtures

* disable test
2016-10-05 12:50:44 +01:00

70 lines
1.7 KiB
JavaScript

'use strict';
module.exports = function(context) {
var MESSAGE = 'Use a language key instead of a literal';
var LOG_METHODS = ['info', 'log', 'step', 'error', 'warn', 'success'];
function isLiteral(node) {
return node.type === 'Literal' ||
(node.type === 'BinaryExpression' && (isLiteral(node.left) || isLiteral(node.right)));
}
function getCallee(node) {
if (node.type !== 'CallExpression' || node.arguments.length === 0) {
return;
}
var callee = node.callee;
while (callee.type === 'MemberExpression' && callee.property.type === 'MemberExpression') {
callee = callee.property;
}
if (callee.type !== 'MemberExpression' || callee.computed) {
return;
}
var object = callee.object;
if (object.type !== 'Identifier' || object.name !== 'reporter') {
return;
}
return callee;
}
return {
CallExpression: function(node) {
var callee = getCallee(node);
if (callee && LOG_METHODS.indexOf(callee.property.name) >= 1) {
var arg = node.arguments[node.arguments.length - 1];
if (isLiteral(arg)) {
context.report(
arg,
MESSAGE
);
}
}
},
ThrowStatement: function(node) {
var argument = node.argument;
if (argument.type !== 'NewExpression') {
return;
}
var callee = argument.callee;
if (callee.type !== 'Identifier' || callee.name !== 'MessageError') {
return;
}
var args = argument.arguments;
if (args.length && isLiteral(args[0])) {
context.report(
args[0],
MESSAGE
);
}
}
};
};
module.exports.schema = [];