The prefer-reflect rule will flag usage of any older method, suggesting to instead use the newer Reflect version.

Rule Details

Options

Exceptions

"prefer-reflect": [<enabled>, { exceptions: [<...exceptions>] }]

The exceptions option allows you to pass an array of methods names you’d like to continue to use in the old style.

For example if you wish to use all Reflect methods, except for Function.prototype.apply then your config would look like prefer-reflect: [2, { exceptions: ["apply"] }].

If you want to use Reflect methods, but keep using the delete keyword, then your config would look like prefer-reflect: [2, { exceptions: ["delete"] }].

These can be combined as much as you like. To make all methods exceptions (thereby rendering this rule useless), use prefer-reflect: [2, { exceptions: ["apply", "call", "defineProperty", "getOwnPropertyDescriptor", "getPrototypeOf", "setPrototypeOf", "isExtensible", "getOwnPropertyNames", "preventExtensions", "delete"] }]

Reflect.apply (Function.prototype.apply/Function.prototype.call)

The following patterns are considered problems:

/*eslint prefer-reflect: 2*/foo.apply(undefined,args);/*error Avoid using Function.prototype.apply, instead use Reflect.apply*/foo.apply(null,args);/*error Avoid using Function.prototype.apply, instead use Reflect.apply*/obj.foo.apply(obj,args);/*error Avoid using Function.prototype.apply, instead use Reflect.apply*/obj.foo.apply(other,args);/*error Avoid using Function.prototype.apply, instead use Reflect.apply*/foo.call(undefined,arg);/*error Avoid using Function.prototype.call, instead use Reflect.apply*/foo.call(null,arg);/*error Avoid using Function.prototype.call, instead use Reflect.apply*/obj.foo.call(obj,arg);/*error Avoid using Function.prototype.call, instead use Reflect.apply*/obj.foo.call(other,arg);/*error Avoid using Function.prototype.call, instead use Reflect.apply*/