| 12 | |
| 13 | module.exports = { |
| 14 | create(context) { |
| 15 | return { |
| 16 | [selector]: function (node) { |
| 17 | // Don't evaluate or transform log.js |
| 18 | if (context.getFilename().endsWith(definitionFile)) { |
| 19 | return; |
| 20 | } |
| 21 | |
| 22 | let methodInvokedName; |
| 23 | |
| 24 | // Make sure that callee is a CallExpression as well. |
| 25 | |
| 26 | const {callee} = node; |
| 27 | |
| 28 | // userAssert() and devAssert() aliases |
| 29 | if ( |
| 30 | callee.type == 'Identifier' && |
| 31 | assertAliases.includes(callee.name) |
| 32 | ) { |
| 33 | methodInvokedName = 'assert'; |
| 34 | } else { |
| 35 | // dev().assert() // enforce rule |
| 36 | // dev.assert() // ignore |
| 37 | const calleeObject = callee.object; |
| 38 | if (!calleeObject || calleeObject.type !== 'CallExpression') { |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | // Make sure that the CallExpression is one of dev() or user(). |
| 43 | if (!singletonFunctions.includes(calleeObject.callee.name)) { |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | methodInvokedName = callee.property.name; |
| 48 | } |
| 49 | |
| 50 | // Find the position of the argument we care about. |
| 51 | const metadata = transformableMethods[methodInvokedName]; |
| 52 | |
| 53 | // If there's no metadata, this is most likely a test file running |
| 54 | // private methods on log. |
| 55 | if (!metadata) { |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | const {messageArgPos} = metadata; |
| 60 | |
| 61 | const argToEval = node.arguments[messageArgPos]; |
| 62 | if (!argToEval || argToEval.type != 'ArrayExpression') { |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | const errMsg = |
| 67 | `Don't pass an array to ${methodInvokedName}. ` + |
| 68 | 'Array syntax is to be used by compiled output only. ' + |
| 69 | 'Use variadic or sprintf (%s) syntax.'; |
| 70 | |
| 71 | context.report({ |