summaryrefslogtreecommitdiff
path: root/test/parallel/test-eslint-prefer-util-format-errors.js
blob: a6c2662a382418bc9428b09594fc07290fa4a115 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'use strict';

/* eslint-disable no-template-curly-in-string */

const common = require('../common');
if (!common.hasCrypto)
  common.skip('missing crypto');

common.skipIfEslintMissing();

const RuleTester = require('../../tools/node_modules/eslint').RuleTester;
const rule = require('../../tools/eslint-rules/prefer-util-format-errors');

new RuleTester({ parserOptions: { ecmaVersion: 6 } })
  .run('prefer-util-format-errors', rule, {
    valid: [
      'E(\'ABC\', \'abc\');',
      'E(\'ABC\', (arg1, arg2) => `${arg2}${arg1}`);',
      'E(\'ABC\', (arg1, arg2) => `${arg1}{arg2.something}`);',
      'E(\'ABC\', (arg1, arg2) => fn(arg1, arg2));',
    ],
    invalid: [
      {
        code: 'E(\'ABC\', (arg1, arg2) => `${arg1}${arg2}`);',
        errors: [{
          message: 'Please use a printf-like formatted string that ' +
                   'util.format can consume.'
        }]
      },
    ]
  });