0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-eslint-require-buffer.js
Ruben Bridgewater 684c1bb42d
tools: enable eslint strict key-spacing
PR-URL: https://github.com/nodejs/node/pull/18831
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matheus Marchini <matheus@sthima.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2018-02-22 14:56:12 +00:00

50 lines
1.3 KiB
JavaScript

'use strict';
const common = require('../common');
common.skipIfEslintMissing();
const RuleTester = require('../../tools/node_modules/eslint').RuleTester;
const rule = require('../../tools/eslint-rules/require-buffer');
const ruleTester = new RuleTester({
parserOptions: { ecmaVersion: 6 },
env: { node: true }
});
const message = "Use const Buffer = require('buffer').Buffer; " +
'at the beginning of this file';
const useStrict = '\'use strict\';\n\n';
const bufferModule = 'const { Buffer } = require(\'buffer\');\n';
const mockComment = '// Some Comment\n//\n// Another Comment\n\n';
const useBuffer = 'Buffer;';
ruleTester.run('require-buffer', rule, {
valid: [
'foo',
'const Buffer = require("Buffer"); Buffer;',
'const { Buffer } = require(\'buffer\'); Buffer;',
],
invalid: [
{
code: useBuffer,
errors: [{ message }],
output: bufferModule + useBuffer,
},
{
code: useStrict + useBuffer,
errors: [{ message }],
output: useStrict + bufferModule + useBuffer,
},
{
code: mockComment + useBuffer,
errors: [{ message }],
output: mockComment + bufferModule + useBuffer,
},
{
code: mockComment + useStrict + useBuffer,
errors: [{ message }],
output: mockComment + useStrict + bufferModule + useBuffer,
},
]
});