node/test/parallel/test-eslint-prefer-optional-chaining.js
Aviv Keller 574f2dd517
lib: prefer optional chaining
PR-URL: https://github.com/nodejs/node/pull/55045
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2024-09-24 19:48:15 +00:00

35 lines
839 B
JavaScript

'use strict';
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-optional-chaining');
new RuleTester().run('prefer-optional-chaining', rule, {
valid: [
{
code: 'hello?.world',
options: []
},
],
invalid: [
{
code: 'hello && hello.world',
options: [],
errors: [{ message: 'Prefer optional chaining.' }],
output: 'hello?.world'
},
{
code: 'hello && hello.world && hello.world.foobar',
options: [],
errors: [{ message: 'Prefer optional chaining.' }],
output: 'hello?.world?.foobar'
},
]
});