The Buffer
class of buffer
module is defined as a global variable.
console.log(Buffer === require("buffer").Buffer) //→ true
It will be readable if we use either Buffer
consistently.
This rule enforces which Buffer
we should use.
This rule has a string option.
{
"n/prefer-global/buffer": ["error", "always" | "never"]
}
"always"
(default) ... enforces to use the global variableBuffer
rather thanrequire("buffer").Buffer
."never"
... enforces to userequire("buffer").Buffer
rather than the global variableBuffer
.
Examples of 👎 incorrect code for this rule:
/*eslint n/prefer-global/buffer: [error]*/
const { Buffer } = require("buffer")
const b = Buffer.alloc(16)
Examples of 👍 correct code for this rule:
/*eslint n/prefer-global/buffer: [error]*/
const b = Buffer.alloc(16)
Examples of 👎 incorrect code for the "never"
option:
/*eslint n/prefer-global/buffer: [error, never]*/
const b = Buffer.alloc(16)
Examples of 👍 correct code for the "never"
option:
/*eslint n/prefer-global/buffer: [error, never]*/
const { Buffer } = require("buffer")
const b = Buffer.alloc(16)