2017-11-09 10:18:12 -05:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/* eslint-disable no-template-curly-in-string */
|
|
|
|
|
2018-02-15 18:47:10 -05:00
|
|
|
const common = require('../common');
|
2021-12-07 02:01:36 -08:00
|
|
|
if ((!common.hasCrypto) || (!common.hasIntl)) {
|
|
|
|
common.skip('ESLint tests require crypto and Intl');
|
|
|
|
}
|
2018-02-15 18:47:10 -05:00
|
|
|
|
|
|
|
common.skipIfEslintMissing();
|
2017-11-09 10:18:12 -05:00
|
|
|
|
2024-06-19 21:54:08 +02:00
|
|
|
const RuleTester = require('../../tools/eslint/node_modules/eslint').RuleTester;
|
2017-11-09 10:18:12 -05:00
|
|
|
const rule = require('../../tools/eslint-rules/prefer-util-format-errors');
|
|
|
|
|
2024-05-23 21:45:18 +02:00
|
|
|
new RuleTester()
|
2017-11-09 10:18:12 -05:00
|
|
|
.run('prefer-util-format-errors', rule, {
|
|
|
|
valid: [
|
|
|
|
'E(\'ABC\', \'abc\');',
|
|
|
|
'E(\'ABC\', (arg1, arg2) => `${arg2}${arg1}`);',
|
|
|
|
'E(\'ABC\', (arg1, arg2) => `${arg1}{arg2.something}`);',
|
2021-03-26 08:51:08 -07:00
|
|
|
'E(\'ABC\', (arg1, arg2) => fn(arg1, arg2));',
|
2017-11-09 10:18:12 -05:00
|
|
|
],
|
|
|
|
invalid: [
|
|
|
|
{
|
|
|
|
code: 'E(\'ABC\', (arg1, arg2) => `${arg1}${arg2}`);',
|
|
|
|
errors: [{
|
|
|
|
message: 'Please use a printf-like formatted string that ' +
|
|
|
|
'util.format can consume.'
|
|
|
|
}]
|
2021-03-26 08:51:08 -07:00
|
|
|
},
|
2017-11-09 10:18:12 -05:00
|
|
|
]
|
|
|
|
});
|