mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
574f2dd517
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>
35 lines
839 B
JavaScript
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'
|
|
},
|
|
]
|
|
});
|