node/test/parallel/test-eslint-prefer-util-format-errors.js
Michaël Zasso 2eff28fb7a
tools: move ESLint to tools/eslint
Greatly simplify how ESLint and its plugins are installed.

PR-URL: https://github.com/nodejs/node/pull/53413
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2024-06-19 19:54:08 +00:00

33 lines
934 B
JavaScript

'use strict';
/* eslint-disable no-template-curly-in-string */
const common = require('../common');
if ((!common.hasCrypto) || (!common.hasIntl)) {
common.skip('ESLint tests require crypto and Intl');
}
common.skipIfEslintMissing();
const RuleTester = require('../../tools/eslint/node_modules/eslint').RuleTester;
const rule = require('../../tools/eslint-rules/prefer-util-format-errors');
new RuleTester()
.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.'
}]
},
]
});