From 4755533e3fd17aa56093454722e12afe3f3f31c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Tue, 2 Jan 2024 17:17:14 +0800 Subject: [PATCH] chore: move rule tests parserOptions to ruleTester it can help migrating to the eslint v9 RuleTester --- package.json | 4 +- tests/lib/rules/callback-return.js | 14 +- tests/lib/rules/exports-style.js | 77 +-- tests/lib/rules/file-extension-in-import.js | 4 - tests/lib/rules/global-require.js | 4 +- tests/lib/rules/handle-callback-err.js | 24 +- tests/lib/rules/no-callback-literal.js | 2 +- tests/lib/rules/no-deprecated-api.js | 115 +--- tests/lib/rules/no-extraneous-import.js | 6 +- tests/lib/rules/no-hide-core-modules.js | 7 +- tests/lib/rules/no-missing-import.js | 25 +- tests/lib/rules/no-missing-require.js | 69 +-- tests/lib/rules/no-mixed-requires.js | 3 +- tests/lib/rules/no-new-require.js | 2 +- tests/lib/rules/no-path-concat.js | 10 +- tests/lib/rules/no-process-env.js | 2 +- tests/lib/rules/no-process-exit.js | 3 +- tests/lib/rules/no-restricted-import.js | 6 +- tests/lib/rules/no-sync.js | 2 +- tests/lib/rules/no-unpublished-bin.js | 534 +++++++++--------- tests/lib/rules/no-unpublished-require.js | 55 +- tests/lib/rules/no-unsupported-features.js | 2 +- .../no-unsupported-features/node-builtins.js | 14 +- tests/lib/rules/prefer-global/buffer.js | 8 +- tests/lib/rules/prefer-global/console.js | 8 +- tests/lib/rules/prefer-global/process.js | 8 +- tests/lib/rules/prefer-global/text-decoder.js | 8 +- tests/lib/rules/prefer-global/text-encoder.js | 8 +- .../rules/prefer-global/url-search-params.js | 8 +- tests/lib/rules/prefer-global/url.js | 8 +- tests/lib/rules/prefer-promises/dns.js | 9 +- tests/lib/rules/prefer-promises/fs.js | 9 +- tests/lib/rules/shebang.js | 2 +- 33 files changed, 352 insertions(+), 708 deletions(-) diff --git a/package.json b/package.json index edf8f74e..bedd6bf5 100644 --- a/package.json +++ b/package.json @@ -31,10 +31,10 @@ "@types/eslint": "^8.44.6", "@typescript-eslint/parser": "^5.60.0", "esbuild": "^0.18.7", - "eslint": "^8.53.0", + "eslint": "^8.56.0", "eslint-config-prettier": "^8.8.0", "eslint-doc-generator": "^1.6.1", - "eslint-plugin-eslint-plugin": "^5.1.0", + "eslint-plugin-eslint-plugin": "^5.2.1", "eslint-plugin-n": "file:.", "fast-glob": "^3.2.12", "husky": "^8.0.3", diff --git a/tests/lib/rules/callback-return.js b/tests/lib/rules/callback-return.js index 515760c6..56e48492 100644 --- a/tests/lib/rules/callback-return.js +++ b/tests/lib/rules/callback-return.js @@ -6,8 +6,9 @@ const RuleTester = require("eslint").RuleTester const rule = require("../../../lib/rules/callback-return") +const ruleTester = new RuleTester({ env: { node: true, es6: true } }) -new RuleTester().run("callback-return", rule, { +ruleTester.run("callback-return", rule, { valid: [ // callbacks inside of functions should return "function a(err) { if (err) return callback (err); }", @@ -40,25 +41,20 @@ new RuleTester().run("callback-return", rule, { // arrow functions { code: "var x = err => { if (err) { callback(); return; } }", - parserOptions: { ecmaVersion: 6 }, }, { code: "var x = err => callback(err)", - parserOptions: { ecmaVersion: 6 }, }, { code: "var x = err => { setTimeout( () => { callback(); }); }", - parserOptions: { ecmaVersion: 6 }, }, // classes { code: "class x { horse() { callback(); } } ", - parserOptions: { ecmaVersion: 6 }, }, { code: "class x { horse() { if (err) { return callback(); } callback(); } } ", - parserOptions: { ecmaVersion: 6 }, }, // options (only warns with the correct callback name) @@ -188,7 +184,6 @@ new RuleTester().run("callback-return", rule, { }, { code: "var x = (err) => { if (err) { callback (err); } }", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturn", @@ -200,7 +195,6 @@ new RuleTester().run("callback-return", rule, { }, { code: "var x = { x(err) { if (err) { callback (err); } } }", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturn", @@ -223,7 +217,6 @@ new RuleTester().run("callback-return", rule, { }, { code: "var x = { x(err) { if (err) { callback && callback (err); } } }", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturn", @@ -268,7 +261,6 @@ new RuleTester().run("callback-return", rule, { }, { code: "var a = (err) => { callback (err); callback(); }", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturn", @@ -302,7 +294,6 @@ new RuleTester().run("callback-return", rule, { }, { code: "class x { horse() { if (err) { callback(); } callback(); } } ", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturn", @@ -344,7 +335,6 @@ new RuleTester().run("callback-return", rule, { }, { code: "() => { if (x) { callback(); } }", - parserOptions: { ecmaVersion: 6 }, errors: [ { messageId: "missingReturn", diff --git a/tests/lib/rules/exports-style.js b/tests/lib/rules/exports-style.js index 6e2dd033..b5f926cb 100644 --- a/tests/lib/rules/exports-style.js +++ b/tests/lib/rules/exports-style.js @@ -7,69 +7,69 @@ const RuleTester = require("eslint").RuleTester const rule = require("../../../lib/rules/exports-style") -new RuleTester().run("exports-style", rule, { +new RuleTester({ + env: { node: true, es6: true }, + parserOptions: { ecmaVersion: 11 }, +}).run("exports-style", rule, { valid: [ { code: "module.exports = {foo: 1}", - globals: { module: false, exports: true }, }, { code: "module.exports = {foo: 1}", options: ["module.exports"], - globals: { module: false, exports: true }, }, { code: "exports.foo = 1", options: ["exports"], - globals: { module: false, exports: true }, }, { code: "exports = module.exports = {foo: 1}", options: ["module.exports", { allowBatchAssign: true }], - globals: { module: false, exports: true }, }, { code: "module.exports = exports = {foo: 1}", options: ["module.exports", { allowBatchAssign: true }], - globals: { module: false, exports: true }, }, { code: "exports = module.exports = {foo: 1}", options: ["exports", { allowBatchAssign: true }], - globals: { module: false, exports: true }, }, { code: "module.exports = exports = {foo: 1}", options: ["exports", { allowBatchAssign: true }], - globals: { module: false, exports: true }, }, { code: "exports = module.exports = {foo: 1}; exports.bar = 2", options: ["exports", { allowBatchAssign: true }], - globals: { module: false, exports: true }, }, { code: "module.exports = exports = {foo: 1}; exports.bar = 2", options: ["exports", { allowBatchAssign: true }], - globals: { module: false, exports: true }, }, // allow accesses of `modules` except `module.exports` { code: "module = {}; module.foo = 1", options: ["exports"], - globals: { module: false, exports: true }, }, // Ignores if it's not defined. - { code: "exports.foo = 1", options: ["module.exports"] }, - { code: "module.exports = {foo: 1}", options: ["exports"] }, + { + code: "exports.foo = 1", + options: ["module.exports"], + globals: { exports: "off" }, + }, + { + code: "module.exports = {foo: 1}", + options: ["exports"], + globals: { module: "off" }, + }, ], invalid: [ { code: "exports = {foo: 1}", output: null, - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'exports'. Use 'module.exports' instead.", ], @@ -77,7 +77,6 @@ new RuleTester().run("exports-style", rule, { { code: "exports.foo = 1", output: null, - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'exports'. Use 'module.exports' instead.", ], @@ -85,7 +84,6 @@ new RuleTester().run("exports-style", rule, { { code: "module.exports = exports = {foo: 1}", output: null, - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'exports'. Use 'module.exports' instead.", ], @@ -93,7 +91,6 @@ new RuleTester().run("exports-style", rule, { { code: "exports = module.exports = {foo: 1}", output: null, - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'exports'. Use 'module.exports' instead.", ], @@ -103,7 +100,6 @@ new RuleTester().run("exports-style", rule, { code: "exports = {foo: 1}", output: null, options: ["module.exports"], - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'exports'. Use 'module.exports' instead.", ], @@ -112,7 +108,6 @@ new RuleTester().run("exports-style", rule, { code: "exports.foo = 1", output: null, options: ["module.exports"], - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'exports'. Use 'module.exports' instead.", ], @@ -121,7 +116,6 @@ new RuleTester().run("exports-style", rule, { code: "module.exports = exports = {foo: 1}", output: null, options: ["module.exports"], - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'exports'. Use 'module.exports' instead.", ], @@ -130,7 +124,6 @@ new RuleTester().run("exports-style", rule, { code: "exports = module.exports = {foo: 1}", output: null, options: ["module.exports"], - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'exports'. Use 'module.exports' instead.", ], @@ -140,7 +133,6 @@ new RuleTester().run("exports-style", rule, { code: "exports = {foo: 1}", output: null, options: ["exports"], - globals: { module: false, exports: true }, errors: [ "Unexpected assignment to 'exports'. Don't modify 'exports' itself.", ], @@ -149,7 +141,6 @@ new RuleTester().run("exports-style", rule, { code: "module.exports = {foo: 1}", output: "exports.foo = 1;", options: ["exports"], - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'module.exports'. Use 'exports' instead.", ], @@ -158,7 +149,6 @@ new RuleTester().run("exports-style", rule, { code: "module.exports.foo = 1", output: "exports.foo = 1", options: ["exports"], - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'module.exports'. Use 'exports' instead.", ], @@ -167,7 +157,6 @@ new RuleTester().run("exports-style", rule, { code: "module.exports = { a: 1 }", output: "exports.a = 1;", options: ["exports"], - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'module.exports'. Use 'exports' instead.", ], @@ -176,18 +165,14 @@ new RuleTester().run("exports-style", rule, { code: "module.exports = { a: 1, b: 2 }", output: "exports.a = 1;\n\nexports.b = 2;", options: ["exports"], - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'module.exports'. Use 'exports' instead.", ], }, { - code: - "module.exports = { // before a\na: 1, // between a and b\nb: 2 // after b\n}", - output: - "// before a\nexports.a = 1;\n\n// between a and b\nexports.b = 2;\n// after b", + code: "module.exports = { // before a\na: 1, // between a and b\nb: 2 // after b\n}", + output: "// before a\nexports.a = 1;\n\n// between a and b\nexports.b = 2;\n// after b", options: ["exports"], - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'module.exports'. Use 'exports' instead.", ], @@ -196,17 +181,14 @@ new RuleTester().run("exports-style", rule, { code: "foo(module.exports = {foo: 1})", output: null, options: ["exports"], - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'module.exports'. Use 'exports' instead.", ], }, { - code: - "if(foo){ module.exports = { foo: 1};} else { module.exports = {foo: 2};}", + code: "if(foo){ module.exports = { foo: 1};} else { module.exports = {foo: 2};}", output: null, options: ["exports"], - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'module.exports'. Use 'exports' instead.", "Unexpected access to 'module.exports'. Use 'exports' instead.", @@ -216,7 +198,6 @@ new RuleTester().run("exports-style", rule, { code: "function bar() { module.exports = { foo: 1 }; }", output: null, options: ["exports"], - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'module.exports'. Use 'exports' instead.", ], @@ -225,7 +206,6 @@ new RuleTester().run("exports-style", rule, { code: "module.exports = { get a() {} }", output: null, options: ["exports"], - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'module.exports'. Use 'exports' instead.", ], @@ -234,7 +214,6 @@ new RuleTester().run("exports-style", rule, { code: "module.exports = { set a(a) {} }", output: null, options: ["exports"], - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'module.exports'. Use 'exports' instead.", ], @@ -243,8 +222,6 @@ new RuleTester().run("exports-style", rule, { code: "module.exports = { a }", output: "exports.a = a;", options: ["exports"], - parserOptions: { ecmaVersion: 6 }, - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'module.exports'. Use 'exports' instead.", ], @@ -253,8 +230,6 @@ new RuleTester().run("exports-style", rule, { code: "module.exports = { ...a }", output: null, options: ["exports"], - parserOptions: { ecmaVersion: 9 }, - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'module.exports'. Use 'exports' instead.", ], @@ -263,8 +238,6 @@ new RuleTester().run("exports-style", rule, { code: "module.exports = { ['a' + 'b']: 1 }", output: "exports['a' + 'b'] = 1;", options: ["exports"], - parserOptions: { ecmaVersion: 6 }, - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'module.exports'. Use 'exports' instead.", ], @@ -273,8 +246,6 @@ new RuleTester().run("exports-style", rule, { code: "module.exports = { 'foo': 1 }", output: "exports['foo'] = 1;", options: ["exports"], - parserOptions: { ecmaVersion: 6 }, - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'module.exports'. Use 'exports' instead.", ], @@ -283,8 +254,6 @@ new RuleTester().run("exports-style", rule, { code: "module.exports = { foo(a) {} }", output: "exports.foo = function (a) {};", options: ["exports"], - parserOptions: { ecmaVersion: 8 }, - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'module.exports'. Use 'exports' instead.", ], @@ -293,8 +262,6 @@ new RuleTester().run("exports-style", rule, { code: "module.exports = { *foo(a) {} }", output: "exports.foo = function* (a) {};", options: ["exports"], - parserOptions: { ecmaVersion: 6 }, - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'module.exports'. Use 'exports' instead.", ], @@ -303,8 +270,6 @@ new RuleTester().run("exports-style", rule, { code: "module.exports = { async foo(a) {} }", output: "exports.foo = async function (a) {};", options: ["exports"], - parserOptions: { ecmaVersion: 8 }, - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'module.exports'. Use 'exports' instead.", ], @@ -313,8 +278,6 @@ new RuleTester().run("exports-style", rule, { code: "module.exports.foo()", output: "exports.foo()", options: ["exports"], - parserOptions: { ecmaVersion: 8 }, - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'module.exports'. Use 'exports' instead.", ], @@ -323,8 +286,6 @@ new RuleTester().run("exports-style", rule, { code: "a = module.exports.foo + module.exports['bar']", output: "a = exports.foo + exports['bar']", options: ["exports"], - parserOptions: { ecmaVersion: 8 }, - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'module.exports'. Use 'exports' instead.", "Unexpected access to 'module.exports'. Use 'exports' instead.", @@ -334,7 +295,6 @@ new RuleTester().run("exports-style", rule, { code: "module.exports = exports = {foo: 1}", output: null, options: ["exports"], - globals: { module: false, exports: true }, errors: [ "Unexpected access to 'module.exports'. Use 'exports' instead.", "Unexpected assignment to 'exports'. Don't modify 'exports' itself.", @@ -344,7 +304,6 @@ new RuleTester().run("exports-style", rule, { code: "exports = module.exports = {foo: 1}", output: null, options: ["exports"], - globals: { module: false, exports: true }, errors: [ "Unexpected assignment to 'exports'. Don't modify 'exports' itself.", "Unexpected access to 'module.exports'. Use 'exports' instead.", @@ -354,7 +313,6 @@ new RuleTester().run("exports-style", rule, { code: "module.exports = exports = {foo: 1}; exports = obj", output: null, options: ["exports", { allowBatchAssign: true }], - globals: { module: false, exports: true }, errors: [ "Unexpected assignment to 'exports'. Don't modify 'exports' itself.", ], @@ -363,7 +321,6 @@ new RuleTester().run("exports-style", rule, { code: "exports = module.exports = {foo: 1}; exports = obj", output: null, options: ["exports", { allowBatchAssign: true }], - globals: { module: false, exports: true }, errors: [ "Unexpected assignment to 'exports'. Don't modify 'exports' itself.", ], diff --git a/tests/lib/rules/file-extension-in-import.js b/tests/lib/rules/file-extension-in-import.js index 54dde82c..b8504233 100644 --- a/tests/lib/rules/file-extension-in-import.js +++ b/tests/lib/rules/file-extension-in-import.js @@ -176,25 +176,21 @@ new RuleTester({ { filename: fixture("test.tsx"), code: "require('./d.js');", - env: { node: true }, settings: { node: { typescriptExtensionMap: tsReactExtensionMap } }, }, { filename: fixture("test.tsx"), code: "require('./e.js');", - env: { node: true }, settings: { node: { typescriptExtensionMap: tsReactExtensionMap } }, }, { filename: fixture("test.ts"), code: "require('./d.js');", - env: { node: true }, settings: { node: { typescriptExtensionMap: tsReactExtensionMap } }, }, { filename: fixture("test.ts"), code: "require('./e.js');", - env: { node: true }, settings: { node: { typescriptExtensionMap: tsReactExtensionMap } }, }, ], diff --git a/tests/lib/rules/global-require.js b/tests/lib/rules/global-require.js index 9f99b64e..d2b164ec 100644 --- a/tests/lib/rules/global-require.js +++ b/tests/lib/rules/global-require.js @@ -9,7 +9,7 @@ const rule = require("../../../lib/rules/global-require") const ERROR = { messageId: "unexpected", type: "CallExpression" } -new RuleTester().run("global-require", rule, { +new RuleTester({ env: { node: true, es6: true } }).run("global-require", rule, { valid: [ "var x = require('y');", "if (x) { x.require('y'); }", @@ -51,12 +51,10 @@ new RuleTester().run("global-require", rule, { // non-block statements { code: "var getModule = x => require(x);", - parserOptions: { ecmaVersion: 6 }, errors: [ERROR], }, { code: "var x = (x => require(x))('weird')", - parserOptions: { ecmaVersion: 6 }, errors: [ERROR], }, { diff --git a/tests/lib/rules/handle-callback-err.js b/tests/lib/rules/handle-callback-err.js index 4956c693..0fc48bd6 100644 --- a/tests/lib/rules/handle-callback-err.js +++ b/tests/lib/rules/handle-callback-err.js @@ -6,6 +6,7 @@ const RuleTester = require("eslint").RuleTester const rule = require("../../../lib/rules/handle-callback-err") +const ruleTester = new RuleTester({ env: { node: true, es6: true } }) const EXPECTED_DECL_ERROR = { messageId: "expected", @@ -16,7 +17,7 @@ const EXPECTED_FUNC_ERROR = { type: "FunctionExpression", } -new RuleTester().run("handle-callback-err", rule, { +ruleTester.run("handle-callback-err", rule, { valid: [ "function test(error) {}", "function test(err) {console.log(err);}", @@ -34,11 +35,14 @@ new RuleTester().run("handle-callback-err", rule, { "function userHandler(err) {process.nextTick(function() {if (err) {}})}", "function help() { function userHandler(err) {function tester() { err; process.nextTick(function() { err; }); } } }", "function help(done) { var err = new Error('error'); done(); }", - { code: "var test = err => err;", parserOptions: { ecmaVersion: 6 } }, - { code: "var test = err => !err;", parserOptions: { ecmaVersion: 6 } }, + { + code: "var test = err => err;", + }, + { + code: "var test = err => !err;", + }, { code: "var test = err => err.message;", - parserOptions: { ecmaVersion: 6 }, }, { code: "var test = function(error) {if(error){/* do nothing */}};", @@ -47,7 +51,6 @@ new RuleTester().run("handle-callback-err", rule, { { code: "var test = (error) => {if(error){/* do nothing */}};", options: ["error"], - parserOptions: { ecmaVersion: 6 }, }, { code: "var test = function(error) {if(! error){doSomethingHere();}};", @@ -76,7 +79,10 @@ new RuleTester().run("handle-callback-err", rule, { ], invalid: [ { code: "function test(err) {}", errors: [EXPECTED_DECL_ERROR] }, - { code: "function test(err, data) {}", errors: [EXPECTED_DECL_ERROR] }, + { + code: "function test(err, data) {}", + errors: [EXPECTED_DECL_ERROR], + }, { code: "function test(err) {errorLookingWord();}", errors: [EXPECTED_DECL_ERROR], @@ -91,10 +97,12 @@ new RuleTester().run("handle-callback-err", rule, { }, { code: "var test = (err) => {};", - parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expected" }], }, - { code: "var test = function(err) {};", errors: [EXPECTED_FUNC_ERROR] }, + { + code: "var test = function(err) {};", + errors: [EXPECTED_FUNC_ERROR], + }, { code: "var test = function test(err, data) {};", errors: [EXPECTED_FUNC_ERROR], diff --git a/tests/lib/rules/no-callback-literal.js b/tests/lib/rules/no-callback-literal.js index 9548f921..42f5b6bf 100644 --- a/tests/lib/rules/no-callback-literal.js +++ b/tests/lib/rules/no-callback-literal.js @@ -7,7 +7,7 @@ const RuleTester = require("eslint").RuleTester const rule = require("../../../lib/rules/no-callback-literal") -const ruleTester = new RuleTester() +const ruleTester = new RuleTester({ env: { node: true, es6: true } }) ruleTester.run("no-callback-literal", rule, { valid: [ // random stuff diff --git a/tests/lib/rules/no-deprecated-api.js b/tests/lib/rules/no-deprecated-api.js index d221e91a..5f78ce0e 100644 --- a/tests/lib/rules/no-deprecated-api.js +++ b/tests/lib/rules/no-deprecated-api.js @@ -7,40 +7,32 @@ const { RuleTester } = require("eslint") const rule = require("../../../lib/rules/no-deprecated-api") -const ruleTester = new RuleTester() +const ruleTester = new RuleTester({ env: { node: true, es6: true } }) ruleTester.run("no-deprecated-api", rule, { valid: [ { code: "require('buffer').Buffer", - env: { node: true }, }, { code: "require('node:buffer').Buffer", - env: { node: true }, }, { code: "foo(require('buffer').Buffer)", - env: { node: true }, }, { code: "new (require('another-buffer').Buffer)()", - env: { node: true }, }, { code: "var http = require('http'); http.request()", - env: { node: true }, }, { code: "var {request} = require('http'); request()", - env: { node: true, es6: true }, }, { code: "(s ? require('https') : require('http')).request()", - env: { node: true }, }, { code: "require(HTTP).createClient", - env: { node: true }, }, { code: "import {Buffer} from 'another-buffer'; new Buffer()", @@ -56,13 +48,11 @@ ruleTester.run("no-deprecated-api", rule, { // On Node v6.8.0, fs.existsSync revived. { code: "require('fs').existsSync;", - env: { node: true }, }, // use third parties. { code: "require('domain/');", - env: { node: true }, }, { code: "import domain from 'domain/';", @@ -73,7 +63,6 @@ ruleTester.run("no-deprecated-api", rule, { // https://github.com/mysticatea/eslint-plugin-node/issues/55 { code: "undefinedVar = require('fs')", - env: { node: true }, }, // ignore options @@ -85,7 +74,6 @@ ruleTester.run("no-deprecated-api", rule, { ignoreModuleItems: ["new buffer.Buffer()"], }, ], - env: { node: true }, }, { code: "require('buffer').Buffer()", @@ -95,7 +83,6 @@ ruleTester.run("no-deprecated-api", rule, { ignoreModuleItems: ["buffer.Buffer()"], }, ], - env: { node: true }, }, { code: "require('node:buffer').Buffer()", @@ -105,7 +92,6 @@ ruleTester.run("no-deprecated-api", rule, { ignoreModuleItems: ["buffer.Buffer()"], }, ], - env: { node: true }, }, { code: "require('domain');", @@ -115,7 +101,6 @@ ruleTester.run("no-deprecated-api", rule, { ignoreModuleItems: ["domain"], }, ], - env: { node: true }, }, { code: "require('events').EventEmitter.listenerCount;", @@ -125,7 +110,6 @@ ruleTester.run("no-deprecated-api", rule, { ignoreModuleItems: ["events.EventEmitter.listenerCount"], }, ], - env: { node: true }, }, { code: "require('events').listenerCount;", @@ -135,7 +119,6 @@ ruleTester.run("no-deprecated-api", rule, { ignoreModuleItems: ["events.listenerCount"], }, ], - env: { node: true }, }, { code: "new Buffer;", @@ -145,7 +128,6 @@ ruleTester.run("no-deprecated-api", rule, { ignoreGlobalItems: ["new Buffer()"], }, ], - env: { node: true }, }, { code: "Buffer();", @@ -155,7 +137,6 @@ ruleTester.run("no-deprecated-api", rule, { ignoreGlobalItems: ["Buffer()"], }, ], - env: { node: true }, }, { code: "Intl.v8BreakIterator;", @@ -165,7 +146,6 @@ ruleTester.run("no-deprecated-api", rule, { ignoreGlobalItems: ["Intl.v8BreakIterator"], }, ], - env: { node: true }, }, { code: "let {env: {NODE_REPL_HISTORY_FILE}} = process;", @@ -175,20 +155,17 @@ ruleTester.run("no-deprecated-api", rule, { ignoreGlobalItems: ["process.env.NODE_REPL_HISTORY_FILE"], }, ], - env: { node: true, es6: true }, }, // https://github.com/mysticatea/eslint-plugin-node/issues/65 { code: 'require("domain/")', options: [{ ignoreIndirectDependencies: true }], - env: { node: true }, }, // https://github.com/mysticatea/eslint-plugin-node/issues/87 { code: 'let fs = fs || require("fs")', - env: { node: true, es6: true }, }, ], invalid: [ @@ -198,7 +175,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "new (require('buffer').Buffer)()", options: [{ version: "6.0.0" }], - env: { node: true }, errors: [ "'new buffer.Buffer()' was deprecated since v6.0.0. Use 'buffer.Buffer.alloc()' or 'buffer.Buffer.from()' instead.", ], @@ -206,7 +182,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "new (require('node:buffer').Buffer)()", options: [{ version: "6.0.0" }], - env: { node: true }, errors: [ "'new buffer.Buffer()' was deprecated since v6.0.0. Use 'buffer.Buffer.alloc()' or 'buffer.Buffer.from()' instead.", ], @@ -214,7 +189,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('buffer').Buffer()", options: [{ version: "6.0.0" }], - env: { node: true }, errors: [ "'buffer.Buffer()' was deprecated since v6.0.0. Use 'buffer.Buffer.alloc()' or 'buffer.Buffer.from()' instead.", ], @@ -222,7 +196,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('node:buffer').Buffer()", options: [{ version: "6.0.0" }], - env: { node: true }, errors: [ "'buffer.Buffer()' was deprecated since v6.0.0. Use 'buffer.Buffer.alloc()' or 'buffer.Buffer.from()' instead.", ], @@ -230,7 +203,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "var b = require('buffer'); new b.Buffer()", options: [{ version: "6.0.0" }], - env: { node: true }, errors: [ "'new buffer.Buffer()' was deprecated since v6.0.0. Use 'buffer.Buffer.alloc()' or 'buffer.Buffer.from()' instead.", ], @@ -238,7 +210,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "var b = require('buffer'); new b['Buffer']()", options: [{ version: "6.0.0" }], - env: { node: true }, errors: [ "'new buffer.Buffer()' was deprecated since v6.0.0. Use 'buffer.Buffer.alloc()' or 'buffer.Buffer.from()' instead.", ], @@ -246,7 +217,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "var b = require('buffer'); new b[`Buffer`]()", options: [{ version: "6.0.0" }], - env: { node: true, es6: true }, errors: [ "'new buffer.Buffer()' was deprecated since v6.0.0. Use 'buffer.Buffer.alloc()' or 'buffer.Buffer.from()' instead.", ], @@ -254,7 +224,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "var b = require('buffer').Buffer; new b()", options: [{ version: "6.0.0" }], - env: { node: true }, errors: [ "'new buffer.Buffer()' was deprecated since v6.0.0. Use 'buffer.Buffer.alloc()' or 'buffer.Buffer.from()' instead.", ], @@ -262,7 +231,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "var b; new ((b = require('buffer')).Buffer)(); new b.Buffer()", options: [{ version: "6.0.0" }], - env: { node: true }, errors: [ "'new buffer.Buffer()' was deprecated since v6.0.0. Use 'buffer.Buffer.alloc()' or 'buffer.Buffer.from()' instead.", "'new buffer.Buffer()' was deprecated since v6.0.0. Use 'buffer.Buffer.alloc()' or 'buffer.Buffer.from()' instead.", @@ -271,7 +239,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "var {Buffer: b} = require('buffer'); new b()", options: [{ version: "6.0.0" }], - env: { node: true, es6: true }, errors: [ "'new buffer.Buffer()' was deprecated since v6.0.0. Use 'buffer.Buffer.alloc()' or 'buffer.Buffer.from()' instead.", ], @@ -279,7 +246,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "var {['Buffer']: b = null} = require('buffer'); new b()", options: [{ version: "6.0.0" }], - env: { node: true, es6: true }, errors: [ "'new buffer.Buffer()' was deprecated since v6.0.0. Use 'buffer.Buffer.alloc()' or 'buffer.Buffer.from()' instead.", ], @@ -287,7 +253,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "var {'Buffer': b = null} = require('buffer'); new b()", options: [{ version: "6.0.0" }], - env: { node: true, es6: true }, errors: [ "'new buffer.Buffer()' was deprecated since v6.0.0. Use 'buffer.Buffer.alloc()' or 'buffer.Buffer.from()' instead.", ], @@ -295,7 +260,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "var {Buffer: b = require('buffer').Buffer} = {}; new b()", options: [{ version: "6.0.0" }], - env: { node: true, es6: true }, errors: [ "'new buffer.Buffer()' was deprecated since v6.0.0. Use 'buffer.Buffer.alloc()' or 'buffer.Buffer.from()' instead.", ], @@ -303,7 +267,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('buffer').SlowBuffer", options: [{ version: "6.0.0" }], - env: { node: true }, errors: [ "'buffer.SlowBuffer' was deprecated since v6.0.0. Use 'buffer.Buffer.allocUnsafeSlow()' instead.", ], @@ -311,7 +274,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('node:buffer').SlowBuffer", options: [{ version: "6.0.0" }], - env: { node: true }, errors: [ "'buffer.SlowBuffer' was deprecated since v6.0.0. Use 'buffer.Buffer.allocUnsafeSlow()' instead.", ], @@ -319,7 +281,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "var b = require('buffer'); b.SlowBuffer", options: [{ version: "6.0.0" }], - env: { node: true }, errors: [ "'buffer.SlowBuffer' was deprecated since v6.0.0. Use 'buffer.Buffer.allocUnsafeSlow()' instead.", ], @@ -327,7 +288,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "var {SlowBuffer: b} = require('buffer');", options: [{ version: "6.0.0" }], - env: { node: true, es6: true }, errors: [ "'buffer.SlowBuffer' was deprecated since v6.0.0. Use 'buffer.Buffer.allocUnsafeSlow()' instead.", ], @@ -337,13 +297,11 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('_linklist');", options: [{ version: "5.0.0" }], - env: { node: true }, errors: ["'_linklist' module was deprecated since v5.0.0."], }, { code: "require('async_hooks').currentId;", options: [{ version: "8.2.0" }], - env: { node: true }, errors: [ "'async_hooks.currentId' was deprecated since v8.2.0. Use 'async_hooks.executionAsyncId()' instead.", ], @@ -351,7 +309,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('async_hooks').triggerId;", options: [{ version: "8.2.0" }], - env: { node: true }, errors: [ "'async_hooks.triggerId' was deprecated since v8.2.0. Use 'async_hooks.triggerAsyncId()' instead.", ], @@ -359,7 +316,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('constants');", options: [{ version: "6.3.0" }], - env: { node: true }, errors: [ "'constants' module was deprecated since v6.3.0. Use 'constants' property of each module instead.", ], @@ -367,7 +323,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('crypto').Credentials;", options: [{ version: "0.12.0" }], - env: { node: true }, errors: [ "'crypto.Credentials' was deprecated since v0.12.0. Use 'tls.SecureContext' instead.", ], @@ -375,7 +330,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('crypto').createCredentials;", options: [{ version: "0.12.0" }], - env: { node: true }, errors: [ "'crypto.createCredentials' was deprecated since v0.12.0. Use 'tls.createSecureContext()' instead.", ], @@ -383,13 +337,11 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('domain');", options: [{ version: "4.0.0" }], - env: { node: true }, errors: ["'domain' module was deprecated since v4.0.0."], }, { code: "require('events').EventEmitter.listenerCount;", options: [{ version: "4.0.0" }], - env: { node: true }, errors: [ "'events.EventEmitter.listenerCount' was deprecated since v4.0.0. Use 'events.EventEmitter#listenerCount()' instead.", ], @@ -397,7 +349,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('events').listenerCount;", options: [{ version: "4.0.0" }], - env: { node: true }, errors: [ "'events.listenerCount' was deprecated since v4.0.0. Use 'events.EventEmitter#listenerCount()' instead.", ], @@ -405,19 +356,16 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('freelist');", options: [{ version: "4.0.0" }], - env: { node: true }, errors: ["'freelist' module was deprecated since v4.0.0."], }, { code: "require('fs').SyncWriteStream;", options: [{ version: "4.0.0" }], - env: { node: true }, errors: ["'fs.SyncWriteStream' was deprecated since v4.0.0."], }, { code: "require('fs').exists;", options: [{ version: "4.0.0" }], - env: { node: true }, errors: [ "'fs.exists' was deprecated since v4.0.0. Use 'fs.stat()' or 'fs.access()' instead.", ], @@ -425,19 +373,16 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('fs').lchmod;", options: [{ version: "0.4.0" }], - env: { node: true }, errors: ["'fs.lchmod' was deprecated since v0.4.0."], }, { code: "require('fs').lchmodSync;", options: [{ version: "0.4.0" }], - env: { node: true }, errors: ["'fs.lchmodSync' was deprecated since v0.4.0."], }, { code: "require('http').createClient;", options: [{ version: "0.10.0" }], - env: { node: true }, errors: [ "'http.createClient' was deprecated since v0.10.0. Use 'http.request()' instead.", ], @@ -445,7 +390,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('module').requireRepl;", options: [{ version: "6.0.0" }], - env: { node: true }, errors: [ "'module.requireRepl' was deprecated since v6.0.0. Use 'require(\"repl\")' instead.", ], @@ -453,7 +397,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('module').Module.requireRepl;", options: [{ version: "6.0.0" }], - env: { node: true }, errors: [ "'module.Module.requireRepl' was deprecated since v6.0.0. Use 'require(\"repl\")' instead.", ], @@ -461,19 +404,16 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('module')._debug;", options: [{ version: "9.0.0" }], - env: { node: true }, errors: ["'module._debug' was deprecated since v9.0.0."], }, { code: "require('module').Module._debug;", options: [{ version: "9.0.0" }], - env: { node: true }, errors: ["'module.Module._debug' was deprecated since v9.0.0."], }, { code: "require('os').getNetworkInterfaces;", options: [{ version: "0.6.0" }], - env: { node: true }, errors: [ "'os.getNetworkInterfaces' was deprecated since v0.6.0. Use 'os.networkInterfaces()' instead.", ], @@ -481,7 +421,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('os').tmpDir;", options: [{ version: "7.0.0" }], - env: { node: true }, errors: [ "'os.tmpDir' was deprecated since v7.0.0. Use 'os.tmpdir()' instead.", ], @@ -489,7 +428,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('path')._makeLong;", options: [{ version: "9.0.0" }], - env: { node: true }, errors: [ "'path._makeLong' was deprecated since v9.0.0. Use 'path.toNamespacedPath()' instead.", ], @@ -497,7 +435,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('punycode');", options: [{ version: "7.0.0" }], - env: { node: true }, errors: [ "'punycode' module was deprecated since v7.0.0. Use 'https://www.npmjs.com/package/punycode' instead.", ], @@ -505,19 +442,16 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('readline').codePointAt;", options: [{ version: "4.0.0" }], - env: { node: true }, errors: ["'readline.codePointAt' was deprecated since v4.0.0."], }, { code: "require('readline').getStringWidth;", options: [{ version: "6.0.0" }], - env: { node: true }, errors: ["'readline.getStringWidth' was deprecated since v6.0.0."], }, { code: "require('readline').isFullWidthCodePoint;", options: [{ version: "6.0.0" }], - env: { node: true }, errors: [ "'readline.isFullWidthCodePoint' was deprecated since v6.0.0.", ], @@ -525,7 +459,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('readline').stripVTControlCharacters;", options: [{ version: "6.0.0" }], - env: { node: true }, errors: [ "'readline.stripVTControlCharacters' was deprecated since v6.0.0.", ], @@ -533,7 +466,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('sys');", options: [{ version: "0.3.0" }], - env: { node: true }, errors: [ "'sys' module was deprecated since v0.3.0. Use 'util' module instead.", ], @@ -541,13 +473,11 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('tls').CleartextStream;", options: [{ version: "0.10.0" }], - env: { node: true }, errors: ["'tls.CleartextStream' was deprecated since v0.10.0."], }, { code: "require('tls').CryptoStream;", options: [{ version: "0.12.0" }], - env: { node: true }, errors: [ "'tls.CryptoStream' was deprecated since v0.12.0. Use 'tls.TLSSocket' instead.", ], @@ -555,7 +485,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('tls').SecurePair;", options: [{ version: "6.0.0" }], - env: { node: true }, errors: [ "'tls.SecurePair' was deprecated since v6.0.0. Use 'tls.TLSSocket' instead.", ], @@ -563,7 +492,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('tls').createSecurePair;", options: [{ version: "6.0.0" }], - env: { node: true }, errors: [ "'tls.createSecurePair' was deprecated since v6.0.0. Use 'tls.TLSSocket' instead.", ], @@ -571,7 +499,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('tls').parseCertString;", options: [{ version: "8.6.0" }], - env: { node: true }, errors: [ "'tls.parseCertString' was deprecated since v8.6.0. Use 'querystring.parse()' instead.", ], @@ -579,7 +506,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('tty').setRawMode;", options: [{ version: "0.10.0" }], - env: { node: true }, errors: [ "'tty.setRawMode' was deprecated since v0.10.0. Use 'tty.ReadStream#setRawMode()' (e.g. 'process.stdin.setRawMode()') instead.", ], @@ -587,7 +513,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('util').debug;", options: [{ version: "0.12.0" }], - env: { node: true }, errors: [ "'util.debug' was deprecated since v0.12.0. Use 'console.error()' instead.", ], @@ -595,7 +520,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('util').error;", options: [{ version: "0.12.0" }], - env: { node: true }, errors: [ "'util.error' was deprecated since v0.12.0. Use 'console.error()' instead.", ], @@ -603,7 +527,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('util').isArray;", options: [{ version: "4.0.0" }], - env: { node: true }, errors: [ "'util.isArray' was deprecated since v4.0.0. Use 'Array.isArray()' instead.", ], @@ -611,13 +534,11 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('util').isBoolean;", options: [{ version: "4.0.0" }], - env: { node: true }, errors: ["'util.isBoolean' was deprecated since v4.0.0."], }, { code: "require('util').isBuffer;", options: [{ version: "4.0.0" }], - env: { node: true }, errors: [ "'util.isBuffer' was deprecated since v4.0.0. Use 'Buffer.isBuffer()' instead.", ], @@ -625,79 +546,66 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('util').isDate;", options: [{ version: "4.0.0" }], - env: { node: true }, errors: ["'util.isDate' was deprecated since v4.0.0."], }, { code: "require('util').isError;", options: [{ version: "4.0.0" }], - env: { node: true }, errors: ["'util.isError' was deprecated since v4.0.0."], }, { code: "require('util').isFunction;", options: [{ version: "4.0.0" }], - env: { node: true }, errors: ["'util.isFunction' was deprecated since v4.0.0."], }, { code: "require('util').isNull;", options: [{ version: "4.0.0" }], - env: { node: true }, errors: ["'util.isNull' was deprecated since v4.0.0."], }, { code: "require('util').isNullOrUndefined;", options: [{ version: "4.0.0" }], - env: { node: true }, errors: ["'util.isNullOrUndefined' was deprecated since v4.0.0."], }, { code: "require('util').isNumber;", options: [{ version: "4.0.0" }], - env: { node: true }, errors: ["'util.isNumber' was deprecated since v4.0.0."], }, { code: "require('util').isObject;", options: [{ version: "4.0.0" }], - env: { node: true }, errors: ["'util.isObject' was deprecated since v4.0.0."], }, { code: "require('util').isPrimitive;", options: [{ version: "4.0.0" }], - env: { node: true }, errors: ["'util.isPrimitive' was deprecated since v4.0.0."], }, { code: "require('util').isRegExp;", options: [{ version: "4.0.0" }], - env: { node: true }, errors: ["'util.isRegExp' was deprecated since v4.0.0."], }, { code: "require('util').isString;", options: [{ version: "4.0.0" }], - env: { node: true }, errors: ["'util.isString' was deprecated since v4.0.0."], }, { code: "require('util').isSymbol;", options: [{ version: "4.0.0" }], - env: { node: true }, errors: ["'util.isSymbol' was deprecated since v4.0.0."], }, { code: "require('util').isUndefined;", options: [{ version: "4.0.0" }], - env: { node: true }, errors: ["'util.isUndefined' was deprecated since v4.0.0."], }, { code: "require('util').log;", options: [{ version: "6.0.0" }], - env: { node: true }, errors: [ "'util.log' was deprecated since v6.0.0. Use a third party module instead.", ], @@ -705,7 +613,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('util').print;", options: [{ version: "0.12.0" }], - env: { node: true }, errors: [ "'util.print' was deprecated since v0.12.0. Use 'console.log()' instead.", ], @@ -713,7 +620,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('util').pump;", options: [{ version: "0.10.0" }], - env: { node: true }, errors: [ "'util.pump' was deprecated since v0.10.0. Use 'stream.Readable#pipe()' instead.", ], @@ -721,7 +627,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('util').puts;", options: [{ version: "0.12.0" }], - env: { node: true }, errors: [ "'util.puts' was deprecated since v0.12.0. Use 'console.log()' instead.", ], @@ -729,7 +634,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('util')._extend;", options: [{ version: "6.0.0" }], - env: { node: true }, errors: [ "'util._extend' was deprecated since v6.0.0. Use 'Object.assign()' instead.", ], @@ -737,7 +641,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('vm').runInDebugContext;", options: [{ version: "8.0.0" }], - env: { node: true }, errors: ["'vm.runInDebugContext' was deprecated since v8.0.0."], }, @@ -841,7 +744,6 @@ ruleTester.run("no-deprecated-api", rule, { version: "6.0.0", }, ], - env: { node: true }, errors: [ "'new buffer.Buffer()' was deprecated since v6.0.0. Use 'buffer.Buffer.alloc()' or 'buffer.Buffer.from()' instead.", ], @@ -856,7 +758,6 @@ ruleTester.run("no-deprecated-api", rule, { version: "6.0.0", }, ], - env: { node: true }, errors: [ "'buffer.Buffer()' was deprecated since v6.0.0. Use 'buffer.Buffer.alloc()' or 'buffer.Buffer.from()' instead.", ], @@ -864,7 +765,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('module').createRequireFromPath()", options: [{ version: "12.0.0" }], - env: { node: true }, errors: [ "'module.createRequireFromPath' was deprecated since v12.2.0.", ], @@ -872,7 +772,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "require('module').createRequireFromPath()", options: [{ version: "12.2.0" }], - env: { node: true }, errors: [ "'module.createRequireFromPath' was deprecated since v12.2.0. Use 'module.createRequire()' instead.", ], @@ -884,7 +783,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "new Buffer;", options: [{ version: "6.0.0" }], - env: { node: true }, errors: [ "'new Buffer()' was deprecated since v6.0.0. Use 'Buffer.alloc()' or 'Buffer.from()' instead.", ], @@ -892,7 +790,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "Buffer();", options: [{ version: "6.0.0" }], - env: { node: true }, errors: [ "'Buffer()' was deprecated since v6.0.0. Use 'Buffer.alloc()' or 'Buffer.from()' instead.", ], @@ -900,7 +797,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "GLOBAL; /*globals GLOBAL*/", options: [{ version: "6.0.0" }], - env: { node: true }, errors: [ "'GLOBAL' was deprecated since v6.0.0. Use 'global' instead.", ], @@ -908,13 +804,11 @@ ruleTester.run("no-deprecated-api", rule, { { code: "Intl.v8BreakIterator;", options: [{ version: "7.0.0" }], - env: { node: true }, errors: ["'Intl.v8BreakIterator' was deprecated since v7.0.0."], }, { code: "require.extensions;", options: [{ version: "0.12.0" }], - env: { node: true }, errors: [ "'require.extensions' was deprecated since v0.12.0. Use compiling them ahead of time instead.", ], @@ -923,7 +817,6 @@ ruleTester.run("no-deprecated-api", rule, { code: "root;", options: [{ version: "6.0.0" }], globals: { root: false }, - env: { node: true }, errors: [ "'root' was deprecated since v6.0.0. Use 'global' instead.", ], @@ -931,7 +824,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "process.EventEmitter;", options: [{ version: "0.6.0" }], - env: { node: true }, errors: [ "'process.EventEmitter' was deprecated since v0.6.0. Use 'require(\"events\")' instead.", ], @@ -939,7 +831,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "process.env.NODE_REPL_HISTORY_FILE;", options: [{ version: "4.0.0" }], - env: { node: true }, errors: [ "'process.env.NODE_REPL_HISTORY_FILE' was deprecated since v4.0.0. Use 'NODE_REPL_HISTORY' instead.", ], @@ -947,7 +838,6 @@ ruleTester.run("no-deprecated-api", rule, { { code: "let {env: {NODE_REPL_HISTORY_FILE}} = process;", options: [{ version: "4.0.0" }], - env: { node: true, es6: true }, errors: [ "'process.env.NODE_REPL_HISTORY_FILE' was deprecated since v4.0.0. Use 'NODE_REPL_HISTORY' instead.", ], @@ -966,7 +856,6 @@ ruleTester.run("no-deprecated-api", rule, { version: "6.0.0", }, ], - env: { node: true }, errors: [ "'new Buffer()' was deprecated since v6.0.0. Use 'Buffer.alloc()' or 'Buffer.from()' instead.", ], @@ -984,7 +873,6 @@ ruleTester.run("no-deprecated-api", rule, { version: "6.0.0", }, ], - env: { node: true }, errors: [ "'Buffer()' was deprecated since v6.0.0. Use 'Buffer.alloc()' or 'Buffer.from()' instead.", ], @@ -1006,7 +894,6 @@ ruleTester.run("no-deprecated-api", rule, { ignoreGlobalItems: ["new Buffer()"], }, ], - env: { node: true }, errors: [ "'Buffer()' was deprecated since v6.0.0. Use 'Buffer.alloc()' or 'Buffer.from()' instead.", ], diff --git a/tests/lib/rules/no-extraneous-import.js b/tests/lib/rules/no-extraneous-import.js index b99b004e..e03fa971 100644 --- a/tests/lib/rules/no-extraneous-import.js +++ b/tests/lib/rules/no-extraneous-import.js @@ -31,10 +31,8 @@ function fixture(name) { } const ruleTester = new RuleTester({ - parserOptions: { - ecmaVersion: 2015, - sourceType: "module", - }, + parserOptions: { sourceType: "module" }, + env: { node: true, es6: true }, }) ruleTester.run("no-extraneous-import", rule, { valid: [ diff --git a/tests/lib/rules/no-hide-core-modules.js b/tests/lib/rules/no-hide-core-modules.js index 057635ec..8f4885aa 100644 --- a/tests/lib/rules/no-hide-core-modules.js +++ b/tests/lib/rules/no-hide-core-modules.js @@ -39,11 +39,8 @@ const INDIRECT_THIRD_PERTY = path.resolve( //------------------------------------------------------------------------------ const tester = new RuleTester({ - parserOptions: { - ecmaVersion: 2015, - sourceType: "module", - }, - globals: { require: false }, + parserOptions: { sourceType: "module" }, + env: { node: true, es6: true }, }) tester.run("no-hide-core-modules", rule, { diff --git a/tests/lib/rules/no-missing-import.js b/tests/lib/rules/no-missing-import.js index af2dc125..79133439 100644 --- a/tests/lib/rules/no-missing-import.js +++ b/tests/lib/rules/no-missing-import.js @@ -40,9 +40,12 @@ function fixture(name) { const ruleTester = new RuleTester({ parserOptions: { - ecmaVersion: 2015, sourceType: "module", }, + env: { + node: true, + es6: true, + }, }) ruleTester.run("no-missing-import", rule, { valid: [ @@ -142,7 +145,6 @@ ruleTester.run("no-missing-import", rule, { { filename: fixture("test.js"), code: "import a from './fixtures/no-missing/a.js';", - env: { node: true }, settings: { node: { resolvePaths: [path.resolve(__dirname, "../../")] }, }, @@ -151,7 +153,6 @@ ruleTester.run("no-missing-import", rule, { filename: fixture("test.js"), code: "import a from './fixtures/no-missing/a.js';", options: [{ resolvePaths: ["tests"] }], - env: { node: true }, }, // typescriptExtensionMap @@ -159,14 +160,12 @@ ruleTester.run("no-missing-import", rule, { // name: "settings.node - [] as react - d.ts as d.js", filename: fixture("test.tsx"), code: "import d from './d.js';", - env: { node: true }, settings: { node: { typescriptExtensionMap: tsReactExtensionMap } }, }, { // name: "settings.node - [] as react - e.tsx as e.js", filename: fixture("test.tsx"), code: "import e from './e.js';", - env: { node: true }, settings: { node: { typescriptExtensionMap: tsReactExtensionMap } }, }, { @@ -174,14 +173,12 @@ ruleTester.run("no-missing-import", rule, { filename: fixture("test.tsx"), code: "import d from './d.js';", options: [{ typescriptExtensionMap: tsReactExtensionMap }], - env: { node: true }, }, { // name: "options[0] - [] as react - e.tsx as e.js", filename: fixture("test.tsx"), code: "import e from './e.js';", options: [{ typescriptExtensionMap: tsReactExtensionMap }], - env: { node: true }, }, // tsx mapping by name @@ -190,28 +187,24 @@ ruleTester.run("no-missing-import", rule, { filename: fixture("test.tsx"), code: "import e from './e.jsx';", options: [{ typescriptExtensionMap: "preserve" }], - env: { node: true }, }, { // name: "options[0] - react - e.tsx as e.js", filename: fixture("test.tsx"), code: "import e from './e.js';", options: [{ typescriptExtensionMap: "react" }], - env: { node: true }, }, { // name: "settings.node - preserve - e.tsx as e.jsx", filename: fixture("test.tsx"), code: "import e from './e.jsx';", settings: { node: { typescriptExtensionMap: "preserve" } }, - env: { node: true }, }, { // name: "settings.node - react - e.tsx as e.js", filename: fixture("test.tsx"), code: "import e from './e.js';", settings: { node: { typescriptExtensionMap: "react" } }, - env: { node: true }, }, // explicit tsx from config @@ -220,14 +213,12 @@ ruleTester.run("no-missing-import", rule, { filename: fixture("ts-react/test.tsx"), code: "import e from './e.jsx';", options: [{ tsconfigPath: fixture("ts-preserve/tsconfig.json") }], - env: { node: true }, }, { // name: "options[0] - react - e.tsx as e.js", filename: fixture("ts-preserve/test.tsx"), code: "import e from './e.js';", options: [{ tsconfigPath: fixture("ts-react/tsconfig.json") }], - env: { node: true }, }, { // name: "settings.node - preserve - e.tsx as e.jsx", @@ -236,7 +227,6 @@ ruleTester.run("no-missing-import", rule, { settings: { node: { tsconfigPath: fixture("ts-preserve/tsconfig.json") }, }, - env: { node: true }, }, { // name: "settings.node - react - e.tsx as e.js", @@ -245,7 +235,6 @@ ruleTester.run("no-missing-import", rule, { settings: { node: { tsconfigPath: fixture("ts-react/tsconfig.json") }, }, - env: { node: true }, }, // implicit tsx from config @@ -253,37 +242,31 @@ ruleTester.run("no-missing-import", rule, { // name: "tsconfig - jsx: react - e.tsx as e.js", filename: fixture("ts-react/test.tsx"), code: "import e from './e.js';", - env: { node: true }, }, { // name: "tsconfig - jsx: react - d.ts as d.js", filename: fixture("ts-react/test.ts"), code: "import d from './d.js';", - env: { node: true }, }, { // name: "tsconfig - jsx: preserve - e.tsx as e.jsx", filename: fixture("ts-preserve/test.tsx"), code: "import e from './e.jsx';", - env: { node: true }, }, { // name: "tsconfig - jsx: preserve - d.ts as d.js", filename: fixture("ts-preserve/test.ts"), code: "import d from './d.js';", - env: { node: true }, }, { // name: "tsconfig - extends: base (jsx: react) - e.tsx as e.js", filename: fixture("ts-extends/test.tsx"), code: "import e from './e.js';", - env: { node: true }, }, { // name: "tsconfig - extends: base (jsx: react) - d.ts as d.js", filename: fixture("ts-extends/test.ts"), code: "import d from './d.js';", - env: { node: true }, }, // import() diff --git a/tests/lib/rules/no-missing-require.js b/tests/lib/rules/no-missing-require.js index 74381147..788f8311 100644 --- a/tests/lib/rules/no-missing-require.js +++ b/tests/lib/rules/no-missing-require.js @@ -25,68 +25,56 @@ function fixture(name) { return path.resolve(__dirname, "../../fixtures/no-missing", name) } -const ruleTester = new RuleTester() +const ruleTester = new RuleTester({ env: { node: true, es6: true } }) ruleTester.run("no-missing-require", rule, { valid: [ { filename: fixture("test.js"), code: "require('fs');", - env: { node: true }, }, { filename: fixture("test.js"), code: "require('node:fs');", - env: { node: true }, }, { filename: fixture("test.js"), code: "require('eslint');", - env: { node: true }, }, { filename: fixture("test.js"), code: "require('eslint/lib/api');", - env: { node: true }, }, { filename: fixture("test.js"), code: "require('./a');", - env: { node: true }, }, { filename: fixture("test.js"), code: "require('./a.js');", - env: { node: true }, }, { filename: fixture("test.js"), code: "require('./a.config');", - env: { node: true }, }, { filename: fixture("test.js"), code: "require('./a.config.js');", - env: { node: true }, }, { filename: fixture("test.js"), code: "require('./b');", - env: { node: true }, }, { filename: fixture("test.js"), code: "require('./b.json');", - env: { node: true }, }, { filename: fixture("test.js"), code: "require('./c.coffee');", - env: { node: true }, }, { filename: fixture("test.js"), code: "require('mocha');", - env: { node: true }, }, { filename: fixture("test.js"), @@ -96,7 +84,6 @@ ruleTester.run("no-missing-require", rule, { { filename: fixture("test.js"), code: "require('mocha!foo?a=b&c=d');", - env: { node: true }, }, // tryExtensions @@ -104,12 +91,10 @@ ruleTester.run("no-missing-require", rule, { filename: fixture("test.js"), code: "require('./c');", options: [{ tryExtensions: [".coffee"] }], - env: { node: true }, }, { filename: fixture("test.js"), code: "require('./c');", - env: { node: true }, settings: { node: { tryExtensions: [".coffee"] } }, }, @@ -117,7 +102,6 @@ ruleTester.run("no-missing-require", rule, { { filename: fixture("test.js"), code: "require('fixtures/no-missing/a');", - env: { node: true }, settings: { node: { resolvePaths: [path.resolve(__dirname, "../../")] }, }, @@ -126,48 +110,42 @@ ruleTester.run("no-missing-require", rule, { filename: fixture("test.js"), code: "require('fixtures/no-missing/a');", options: [{ resolvePaths: [path.resolve(__dirname, "../../")] }], - env: { node: true }, }, { filename: fixture("test.js"), code: "require('fixtures/no-missing/a');", options: [{ resolvePaths: ["tests"] }], - env: { node: true }, }, // Ignores it if not callee. { filename: fixture("test.js"), code: "require;", - env: { node: true }, }, // Ignores it if the global variable of `require` is not defined. { filename: fixture("test.js"), code: "require('no-exist-package-0');", + globals: { require: "off" }, }, // Ignores it if the filename is unknown. { code: "require('no-exist-package-0');", - env: { node: true }, }, { code: "require('./b');", - env: { node: true }, }, // Ignores it if the target is not string. { filename: fixture("test.js"), code: "require();", - env: { node: true }, }, { filename: fixture("test.js"), code: "require(foo);", - env: { node: true }, }, { filename: fixture("test.js"), @@ -179,34 +157,28 @@ ruleTester.run("no-missing-require", rule, { { filename: "tests/fixtures/no-missing/test.js", code: "require('eslint');", - env: { node: true }, }, { filename: "tests/fixtures/no-missing/test.js", code: "require('./a');", - env: { node: true }, }, // Relative paths to a directory should work. { filename: fixture("test.js"), code: "require('.');", - env: { node: true }, }, { filename: fixture("test.js"), code: "require('./');", - env: { node: true }, }, { filename: fixture("test.js"), code: "require('./foo');", - env: { node: true }, }, { filename: fixture("test.js"), code: "require('./foo/');", - env: { node: true }, }, // allow option @@ -214,20 +186,17 @@ ruleTester.run("no-missing-require", rule, { filename: fixture("test.js"), code: "require('electron');", options: [{ allowModules: ["electron"] }], - env: { node: true }, }, { filename: fixture("test.js"), code: "require('jquery.cookie');", options: [{ allowModules: ["jquery.cookie"] }], - env: { node: true }, }, // typescriptExtensionMap { filename: fixture("test.tsx"), code: "require('./d.js');", - env: { node: true }, settings: { node: { typescriptExtensionMap: tsReactExtensionMap }, }, @@ -235,7 +204,6 @@ ruleTester.run("no-missing-require", rule, { { filename: fixture("test.ts"), code: "require('./d.js');", - env: { node: true }, settings: { node: { typescriptExtensionMap: tsReactExtensionMap }, }, @@ -243,7 +211,6 @@ ruleTester.run("no-missing-require", rule, { { filename: fixture("test.tsx"), code: "require('./e.js');", - env: { node: true }, settings: { node: { typescriptExtensionMap: tsReactExtensionMap }, }, @@ -251,7 +218,6 @@ ruleTester.run("no-missing-require", rule, { { filename: fixture("test.ts"), code: "require('./e.js');", - env: { node: true }, settings: { node: { typescriptExtensionMap: tsReactExtensionMap }, }, @@ -260,25 +226,21 @@ ruleTester.run("no-missing-require", rule, { filename: fixture("test.tsx"), code: "require('./d.js');", options: [{ typescriptExtensionMap: tsReactExtensionMap }], - env: { node: true }, }, { filename: fixture("test.ts"), code: "require('./d.js');", options: [{ typescriptExtensionMap: tsReactExtensionMap }], - env: { node: true }, }, { filename: fixture("test.tsx"), code: "require('./e.js');", options: [{ typescriptExtensionMap: tsReactExtensionMap }], - env: { node: true }, }, { filename: fixture("test.ts"), code: "require('./e.js');", options: [{ typescriptExtensionMap: tsReactExtensionMap }], - env: { node: true }, }, // tsx mapping by name @@ -286,25 +248,21 @@ ruleTester.run("no-missing-require", rule, { filename: fixture("test.tsx"), code: "require('./e.jsx');", options: [{ typescriptExtensionMap: "preserve" }], - env: { node: true }, }, { filename: fixture("test.tsx"), code: "require('./e.js');", options: [{ typescriptExtensionMap: "react" }], - env: { node: true }, }, { filename: fixture("test.tsx"), code: "require('./e.jsx');", settings: { node: { typescriptExtensionMap: "preserve" } }, - env: { node: true }, }, { filename: fixture("test.tsx"), code: "require('./e.js');", settings: { node: { typescriptExtensionMap: "react" } }, - env: { node: true }, }, // explicit tsx from config @@ -313,14 +271,12 @@ ruleTester.run("no-missing-require", rule, { filename: fixture("ts-react/test.tsx"), code: "require('./e.jsx');", options: [{ tsconfigPath: fixture("ts-preserve/tsconfig.json") }], - env: { node: true }, }, { // name: "options[0] - react - e.tsx as e.js", filename: fixture("ts-preserve/test.tsx"), code: "require('./e.js');", options: [{ tsconfigPath: fixture("ts-react/tsconfig.json") }], - env: { node: true }, }, { // name: "settings.node - preserve - e.tsx as e.jsx", @@ -329,7 +285,6 @@ ruleTester.run("no-missing-require", rule, { settings: { node: { tsconfigPath: fixture("ts-preserve/tsconfig.json") }, }, - env: { node: true }, }, { // name: "settings.node - react - e.tsx as e.js", @@ -338,77 +293,64 @@ ruleTester.run("no-missing-require", rule, { settings: { node: { tsconfigPath: fixture("ts-react/tsconfig.json") }, }, - env: { node: true }, }, // implicit tsx from config { filename: fixture("ts-react/test.tsx"), code: "require('./e.js');", - env: { node: true }, }, { filename: fixture("ts-react/test.ts"), code: "require('./d.js');", - env: { node: true }, }, { filename: fixture("ts-preserve/test.tsx"), code: "require('./e.jsx');", - env: { node: true }, }, { filename: fixture("ts-preserve/test.ts"), code: "require('./d.js');", - env: { node: true }, }, { filename: fixture("ts-extends/test.tsx"), code: "require('./e.js');", - env: { node: true }, }, { filename: fixture("ts-extends/test.ts"), code: "require('./d.js');", - env: { node: true }, }, // require.resolve { filename: fixture("test.js"), code: "require.resolve('eslint');", - env: { node: true }, }, ], invalid: [ { filename: fixture("test.js"), code: "require('no-exist-package-0');", - env: { node: true }, errors: ['"no-exist-package-0" is not found.'], }, { filename: fixture("test.js"), code: "require('@mysticatea/test');", - env: { node: true }, errors: ['"@mysticatea/test" is not found.'], }, { filename: fixture("test.js"), code: "require('./c');", - env: { node: true }, errors: ['"./c" is not found.'], }, { filename: fixture("test.js"), code: "require('./d');", - env: { node: true }, errors: ['"./d" is not found.'], }, { filename: fixture("test.js"), code: "require('./a.json');", - env: { node: true }, errors: ['"./a.json" is not found.'], }, @@ -416,13 +358,11 @@ ruleTester.run("no-missing-require", rule, { { filename: "tests/fixtures/no-missing/test.js", code: "require('no-exist-package-0');", - env: { node: true }, errors: ['"no-exist-package-0" is not found.'], }, { filename: "tests/fixtures/no-missing/test.js", code: "require('./c');", - env: { node: true }, errors: ['"./c" is not found.'], }, @@ -430,13 +370,11 @@ ruleTester.run("no-missing-require", rule, { { filename: fixture("test.js"), code: "require('./bar');", - env: { node: true }, errors: ['"./bar" is not found.'], }, { filename: fixture("test.js"), code: "require('./bar/');", - env: { node: true }, errors: ['"./bar/" is not found.'], }, @@ -444,7 +382,6 @@ ruleTester.run("no-missing-require", rule, { { filename: fixture("test.js"), code: "require('./A');", - env: { node: true }, errors: ['"./A" is not found.'], }, @@ -452,7 +389,6 @@ ruleTester.run("no-missing-require", rule, { { filename: fixture("test.js"), code: "require.resolve('no-exist-package-0');", - env: { node: true }, errors: ['"no-exist-package-0" is not found.'], }, ], @@ -475,7 +411,6 @@ describe("On specific working directory:", () => { { filename: fixture("test.js"), code: "require('../../lib/rules/no-missing-require');", - env: { node: true }, }, ], invalid: [], diff --git a/tests/lib/rules/no-mixed-requires.js b/tests/lib/rules/no-mixed-requires.js index 2ee264cc..7e70e64c 100644 --- a/tests/lib/rules/no-mixed-requires.js +++ b/tests/lib/rules/no-mixed-requires.js @@ -6,8 +6,9 @@ const RuleTester = require("eslint").RuleTester const rule = require("../../../lib/rules/no-mixed-requires") +const ruleTester = new RuleTester({ env: { node: true, es6: true } }) -new RuleTester().run("no-mixed-requires", rule, { +ruleTester.run("no-mixed-requires", rule, { valid: [ { code: "var a, b = 42, c = doStuff()", options: [false] }, { diff --git a/tests/lib/rules/no-new-require.js b/tests/lib/rules/no-new-require.js index 9aca0c32..e4b68786 100644 --- a/tests/lib/rules/no-new-require.js +++ b/tests/lib/rules/no-new-require.js @@ -7,7 +7,7 @@ const RuleTester = require("eslint").RuleTester const rule = require("../../../lib/rules/no-new-require") -new RuleTester().run("no-new-require", rule, { +new RuleTester({ env: { node: true, es6: true } }).run("no-new-require", rule, { valid: [ "var appHeader = require('app-header')", "var AppHeader = new (require('app-header'))", diff --git a/tests/lib/rules/no-path-concat.js b/tests/lib/rules/no-path-concat.js index 146f554e..987fb838 100644 --- a/tests/lib/rules/no-path-concat.js +++ b/tests/lib/rules/no-path-concat.js @@ -9,13 +9,9 @@ const RuleTester = require("eslint").RuleTester const rule = require("../../../lib/rules/no-path-concat") new RuleTester({ - parserOptions: { - ecmaVersion: 2015, - }, - globals: { - __dirname: "readonly", - __filename: "readonly", - require: "readonly", + env: { + node: true, + es6: true, }, }).run("no-path-concat", rule, { valid: [ diff --git a/tests/lib/rules/no-process-env.js b/tests/lib/rules/no-process-env.js index e870b5e8..356f72de 100644 --- a/tests/lib/rules/no-process-env.js +++ b/tests/lib/rules/no-process-env.js @@ -7,7 +7,7 @@ const RuleTester = require("eslint").RuleTester const rule = require("../../../lib/rules/no-process-env") -new RuleTester().run("no-process-env", rule, { +new RuleTester({ env: { node: true, es6: true } }).run("no-process-env", rule, { valid: [ "Process.env", "process[env]", diff --git a/tests/lib/rules/no-process-exit.js b/tests/lib/rules/no-process-exit.js index 1c1c03de..0c8a1fe4 100644 --- a/tests/lib/rules/no-process-exit.js +++ b/tests/lib/rules/no-process-exit.js @@ -6,8 +6,9 @@ const RuleTester = require("eslint").RuleTester const rule = require("../../../lib/rules/no-process-exit") +const ruleTester = new RuleTester({ env: { node: true, es6: true } }) -new RuleTester().run("no-process-exit", rule, { +ruleTester.run("no-process-exit", rule, { valid: ["Process.exit()", "var exit = process.exit;", "f(process.exit)"], invalid: [ diff --git a/tests/lib/rules/no-restricted-import.js b/tests/lib/rules/no-restricted-import.js index a5e6de13..03619122 100644 --- a/tests/lib/rules/no-restricted-import.js +++ b/tests/lib/rules/no-restricted-import.js @@ -22,10 +22,8 @@ if (!DynamicImportSupported) { } new RuleTester({ - parserOptions: { - ecmaVersion: 2015, - sourceType: "module", - }, + parserOptions: { sourceType: "module" }, + env: { node: true, es6: true }, }).run("no-restricted-import", rule, { valid: [ { code: 'import "fs"', options: [["crypto"]] }, diff --git a/tests/lib/rules/no-sync.js b/tests/lib/rules/no-sync.js index 91c165b1..223d8f1a 100644 --- a/tests/lib/rules/no-sync.js +++ b/tests/lib/rules/no-sync.js @@ -7,7 +7,7 @@ const RuleTester = require("eslint").RuleTester const rule = require("../../../lib/rules/no-sync") -new RuleTester().run("no-sync", rule, { +new RuleTester({ env: { node: true, es6: true } }).run("no-sync", rule, { valid: [ "var foo = fs.foo.foo();", { diff --git a/tests/lib/rules/no-unpublished-bin.js b/tests/lib/rules/no-unpublished-bin.js index e65c17d4..83845a2f 100644 --- a/tests/lib/rules/no-unpublished-bin.js +++ b/tests/lib/rules/no-unpublished-bin.js @@ -17,272 +17,286 @@ function fixture(name) { return path.resolve(__dirname, "../../fixtures/no-unpublished-bin", name) } -new RuleTester().run("no-unpublished-bin", rule, { - valid: [ - { - filename: fixture("simple-ok/a.js"), - code: "'simple-ok/a.js'", - }, - { - filename: fixture("multi-ok/a.js"), - code: "'multi-ok/a.js'", - }, - { - filename: fixture("multi-ok/b.js"), - code: "'multi-ok/b.js'", - }, - { - filename: fixture("simple-files/x.js"), - code: "'simple-files/x.js'", - }, - { - filename: fixture("multi-files/x.js"), - code: "'multi-files/x.js'", - }, - { - filename: fixture("simple-files/lib/a.js"), - code: "'simple-files/lib/a.js'", - }, - { - filename: fixture("multi-files/lib/a.js"), - code: "'multi-files/lib/a.js'", - }, - { - filename: fixture("simple-npmignore/x.js"), - code: "'simple-npmignore/x.js'", - }, - { - filename: fixture("multi-npmignore/x.js"), - code: "'multi-npmignore/x.js'", - }, - { - filename: fixture("simple-npmignore/lib/a.js"), - code: "'simple-npmignore/lib/a.js'", - }, - { - filename: fixture("multi-npmignore/lib/a.js"), - code: "'multi-npmignore/lib/a.js'", - }, - { - filename: fixture("issue115/lib/a.js"), - code: "'issue115/lib/a.js'", - }, +new RuleTester({ env: { node: true, es6: true } }).run( + "no-unpublished-bin", + rule, + { + valid: [ + { + filename: fixture("simple-ok/a.js"), + code: "'simple-ok/a.js'", + }, + { + filename: fixture("multi-ok/a.js"), + code: "'multi-ok/a.js'", + }, + { + filename: fixture("multi-ok/b.js"), + code: "'multi-ok/b.js'", + }, + { + filename: fixture("simple-files/x.js"), + code: "'simple-files/x.js'", + }, + { + filename: fixture("multi-files/x.js"), + code: "'multi-files/x.js'", + }, + { + filename: fixture("simple-files/lib/a.js"), + code: "'simple-files/lib/a.js'", + }, + { + filename: fixture("multi-files/lib/a.js"), + code: "'multi-files/lib/a.js'", + }, + { + filename: fixture("simple-npmignore/x.js"), + code: "'simple-npmignore/x.js'", + }, + { + filename: fixture("multi-npmignore/x.js"), + code: "'multi-npmignore/x.js'", + }, + { + filename: fixture("simple-npmignore/lib/a.js"), + code: "'simple-npmignore/lib/a.js'", + }, + { + filename: fixture("multi-npmignore/lib/a.js"), + code: "'multi-npmignore/lib/a.js'", + }, + { + filename: fixture("issue115/lib/a.js"), + code: "'issue115/lib/a.js'", + }, - // empty name - "'stdin'", + // empty name + "'stdin'", - // convertPath option - { - filename: fixture("simple-files/a.js"), - code: "'simple-files/a.js'", - options: [{ convertPath: { "a.js": ["a.js", "lib/a.js"] } }], - }, - { - filename: fixture("multi-files/a.js"), - code: "'multi-files/a.js'", - options: [{ convertPath: { "a.js": ["a.js", "lib/a.js"] } }], - }, - { - filename: fixture("simple-npmignore/a.js"), - code: "'simple-npmignore/a.js'", - options: [{ convertPath: { "a.js": ["a.js", "lib/a.js"] } }], - }, - { - filename: fixture("multi-npmignore/a.js"), - code: "'multi-npmignore/a.js'", - options: [{ convertPath: { "a.js": ["a.js", "lib/a.js"] } }], - }, + // convertPath option + { + filename: fixture("simple-files/a.js"), + code: "'simple-files/a.js'", + options: [{ convertPath: { "a.js": ["a.js", "lib/a.js"] } }], + }, + { + filename: fixture("multi-files/a.js"), + code: "'multi-files/a.js'", + options: [{ convertPath: { "a.js": ["a.js", "lib/a.js"] } }], + }, + { + filename: fixture("simple-npmignore/a.js"), + code: "'simple-npmignore/a.js'", + options: [{ convertPath: { "a.js": ["a.js", "lib/a.js"] } }], + }, + { + filename: fixture("multi-npmignore/a.js"), + code: "'multi-npmignore/a.js'", + options: [{ convertPath: { "a.js": ["a.js", "lib/a.js"] } }], + }, + + // convertPath shared setting + { + filename: fixture("simple-files/a.js"), + code: "'simple-files/a.js'", + settings: { + node: { convertPath: { "a.js": ["a.js", "lib/a.js"] } }, + }, + }, + { + filename: fixture("multi-files/a.js"), + code: "'multi-files/a.js'", + settings: { + node: { convertPath: { "a.js": ["a.js", "lib/a.js"] } }, + }, + }, + { + filename: fixture("simple-npmignore/a.js"), + code: "'simple-npmignore/a.js'", + settings: { + node: { convertPath: { "a.js": ["a.js", "lib/a.js"] } }, + }, + }, + { + filename: fixture("multi-npmignore/a.js"), + code: "'multi-npmignore/a.js'", + settings: { + node: { convertPath: { "a.js": ["a.js", "lib/a.js"] } }, + }, + }, + ], + invalid: [ + // files field of `package.json` + { + filename: fixture("simple-files/a.js"), + code: "'simple-files/a.js'", + errors: [ + "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", + ], + }, + { + filename: fixture("multi-files/a.js"), + code: "'multi-files/a.js'", + errors: [ + "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", + ], + }, + { + filename: fixture("multi-files/b.js"), + code: "'multi-files/b.js'", + errors: [ + "npm ignores 'b.js'. Check 'files' field of 'package.json' or '.npmignore'.", + ], + }, - // convertPath shared setting - { - filename: fixture("simple-files/a.js"), - code: "'simple-files/a.js'", - settings: { - node: { convertPath: { "a.js": ["a.js", "lib/a.js"] } }, - }, - }, - { - filename: fixture("multi-files/a.js"), - code: "'multi-files/a.js'", - settings: { - node: { convertPath: { "a.js": ["a.js", "lib/a.js"] } }, - }, - }, - { - filename: fixture("simple-npmignore/a.js"), - code: "'simple-npmignore/a.js'", - settings: { - node: { convertPath: { "a.js": ["a.js", "lib/a.js"] } }, - }, - }, - { - filename: fixture("multi-npmignore/a.js"), - code: "'multi-npmignore/a.js'", - settings: { - node: { convertPath: { "a.js": ["a.js", "lib/a.js"] } }, - }, - }, - ], - invalid: [ - // files field of `package.json` - { - filename: fixture("simple-files/a.js"), - code: "'simple-files/a.js'", - errors: [ - "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", - ], - }, - { - filename: fixture("multi-files/a.js"), - code: "'multi-files/a.js'", - errors: [ - "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", - ], - }, - { - filename: fixture("multi-files/b.js"), - code: "'multi-files/b.js'", - errors: [ - "npm ignores 'b.js'. Check 'files' field of 'package.json' or '.npmignore'.", - ], - }, + // `.npmignore` + { + filename: fixture("simple-npmignore/a.js"), + code: "'simple-npmignore/a.js'", + errors: [ + "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", + ], + }, + { + filename: fixture("multi-npmignore/a.js"), + code: "'multi-npmignore/a.js'", + errors: [ + "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", + ], + }, - // `.npmignore` - { - filename: fixture("simple-npmignore/a.js"), - code: "'simple-npmignore/a.js'", - errors: [ - "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", - ], - }, - { - filename: fixture("multi-npmignore/a.js"), - code: "'multi-npmignore/a.js'", - errors: [ - "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", - ], - }, + // files field of `package.json` with convertPath + { + filename: fixture("simple-files/x.js"), + code: "'simple-files/x.js'", + options: [{ convertPath: { "x.js": ["x.js", "a.js"] } }], + errors: [ + "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", + ], + }, + { + filename: fixture("multi-files/x.js"), + code: "'multi-files/x.js'", + options: [{ convertPath: { "x.js": ["x.js", "a.js"] } }], + errors: [ + "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", + ], + }, + { + filename: fixture("multi-files/x.js"), + code: "'multi-files/x.js'", + options: [{ convertPath: { "x.js": ["x.js", "b.js"] } }], + errors: [ + "npm ignores 'b.js'. Check 'files' field of 'package.json' or '.npmignore'.", + ], + }, - // files field of `package.json` with convertPath - { - filename: fixture("simple-files/x.js"), - code: "'simple-files/x.js'", - options: [{ convertPath: { "x.js": ["x.js", "a.js"] } }], - errors: [ - "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", - ], - }, - { - filename: fixture("multi-files/x.js"), - code: "'multi-files/x.js'", - options: [{ convertPath: { "x.js": ["x.js", "a.js"] } }], - errors: [ - "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", - ], - }, - { - filename: fixture("multi-files/x.js"), - code: "'multi-files/x.js'", - options: [{ convertPath: { "x.js": ["x.js", "b.js"] } }], - errors: [ - "npm ignores 'b.js'. Check 'files' field of 'package.json' or '.npmignore'.", - ], - }, + // `.npmignore` with convertPath + { + filename: fixture("simple-npmignore/x.js"), + code: "'simple-npmignore/x.js'", + options: [{ convertPath: { "x.js": ["x.js", "a.js"] } }], + errors: [ + "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", + ], + }, + { + filename: fixture("multi-npmignore/x.js"), + code: "'multi-npmignore/x.js'", + options: [{ convertPath: { "x.js": ["x.js", "a.js"] } }], + errors: [ + "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", + ], + }, + { + filename: fixture("simple-npmignore/x.js"), + code: "'simple-npmignore/x.js'", + options: [ + { + convertPath: [ + { + include: ["x.js"], + replace: ["x.js", "a.js"], + }, + ], + }, + ], + errors: [ + "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", + ], + }, + { + filename: fixture("multi-npmignore/x.js"), + code: "'multi-npmignore/x.js'", + options: [ + { + convertPath: [ + { + include: ["x.js"], + replace: ["x.js", "a.js"], + }, + ], + }, + ], + errors: [ + "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", + ], + }, - // `.npmignore` with convertPath - { - filename: fixture("simple-npmignore/x.js"), - code: "'simple-npmignore/x.js'", - options: [{ convertPath: { "x.js": ["x.js", "a.js"] } }], - errors: [ - "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", - ], - }, - { - filename: fixture("multi-npmignore/x.js"), - code: "'multi-npmignore/x.js'", - options: [{ convertPath: { "x.js": ["x.js", "a.js"] } }], - errors: [ - "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", - ], - }, - { - filename: fixture("simple-npmignore/x.js"), - code: "'simple-npmignore/x.js'", - options: [ - { - convertPath: [ - { - include: ["x.js"], - replace: ["x.js", "a.js"], - }, - ], + // files field of `package.json` with convertPath (shared setting) + { + filename: fixture("simple-files/x.js"), + code: "'simple-files/x.js'", + errors: [ + "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", + ], + settings: { + node: { convertPath: { "x.js": ["x.js", "a.js"] } }, + }, + }, + { + filename: fixture("multi-files/x.js"), + code: "'multi-files/x.js'", + errors: [ + "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", + ], + settings: { + node: { convertPath: { "x.js": ["x.js", "a.js"] } }, }, - ], - errors: [ - "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", - ], - }, - { - filename: fixture("multi-npmignore/x.js"), - code: "'multi-npmignore/x.js'", - options: [ - { - convertPath: [ - { - include: ["x.js"], - replace: ["x.js", "a.js"], - }, - ], + }, + { + filename: fixture("multi-files/x.js"), + code: "'multi-files/x.js'", + errors: [ + "npm ignores 'b.js'. Check 'files' field of 'package.json' or '.npmignore'.", + ], + settings: { + node: { convertPath: { "x.js": ["x.js", "b.js"] } }, }, - ], - errors: [ - "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", - ], - }, - - // files field of `package.json` with convertPath (shared setting) - { - filename: fixture("simple-files/x.js"), - code: "'simple-files/x.js'", - errors: [ - "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", - ], - settings: { node: { convertPath: { "x.js": ["x.js", "a.js"] } } }, - }, - { - filename: fixture("multi-files/x.js"), - code: "'multi-files/x.js'", - errors: [ - "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", - ], - settings: { node: { convertPath: { "x.js": ["x.js", "a.js"] } } }, - }, - { - filename: fixture("multi-files/x.js"), - code: "'multi-files/x.js'", - errors: [ - "npm ignores 'b.js'. Check 'files' field of 'package.json' or '.npmignore'.", - ], - settings: { node: { convertPath: { "x.js": ["x.js", "b.js"] } } }, - }, + }, - // `.npmignore` with convertPath (shared setting) - { - filename: fixture("simple-npmignore/x.js"), - code: "'simple-npmignore/x.js'", - errors: [ - "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", - ], - settings: { node: { convertPath: { "x.js": ["x.js", "a.js"] } } }, - }, - { - filename: fixture("multi-npmignore/x.js"), - code: "'multi-npmignore/x.js'", - errors: [ - "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", - ], - settings: { node: { convertPath: { "x.js": ["x.js", "a.js"] } } }, - }, - ], -}) + // `.npmignore` with convertPath (shared setting) + { + filename: fixture("simple-npmignore/x.js"), + code: "'simple-npmignore/x.js'", + errors: [ + "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", + ], + settings: { + node: { convertPath: { "x.js": ["x.js", "a.js"] } }, + }, + }, + { + filename: fixture("multi-npmignore/x.js"), + code: "'multi-npmignore/x.js'", + errors: [ + "npm ignores 'a.js'. Check 'files' field of 'package.json' or '.npmignore'.", + ], + settings: { + node: { convertPath: { "x.js": ["x.js", "a.js"] } }, + }, + }, + ], + } +) diff --git a/tests/lib/rules/no-unpublished-require.js b/tests/lib/rules/no-unpublished-require.js index da3e0e1e..a4bf96c1 100644 --- a/tests/lib/rules/no-unpublished-require.js +++ b/tests/lib/rules/no-unpublished-require.js @@ -17,100 +17,82 @@ function fixture(name) { return path.resolve(__dirname, "../../fixtures/no-unpublished", name) } -const ruleTester = new RuleTester() +const ruleTester = new RuleTester({ env: { node: true, es6: true } }) ruleTester.run("no-unpublished-require", rule, { valid: [ { filename: fixture("1/test.js"), code: "require('fs');", - env: { node: true }, }, { filename: fixture("1/test.js"), code: "require('aaa');", - env: { node: true }, }, { filename: fixture("1/test.js"), code: "require('aaa/a/b/c');", - env: { node: true }, }, { filename: fixture("1/test.js"), code: "require('./a');", - env: { node: true }, }, { filename: fixture("1/test.js"), code: "require('./a.js');", - env: { node: true }, }, { filename: fixture("2/ignore1.js"), code: "require('./test');", - env: { node: true }, }, { filename: fixture("2/ignore1.js"), code: "require('bbb');", - env: { node: true }, }, { filename: fixture("2/ignore1.js"), code: "require('bbb/a/b/c');", - env: { node: true }, }, { filename: fixture("2/ignore1.js"), code: "require('./ignore2');", - env: { node: true }, }, { filename: fixture("3/test.js"), code: "require('./pub/a');", - env: { node: true }, }, { filename: fixture("3/test.js"), code: "require('./test2');", - env: { node: true }, }, { filename: fixture("3/test.js"), code: "require('aaa');", - env: { node: true }, }, { filename: fixture("3/test.js"), code: "require('bbb');", - env: { node: true }, }, { filename: fixture("3/pub/ignore1.js"), code: "require('bbb');", - env: { node: true }, }, { filename: fixture("3/pub/test.js"), code: "require('../package.json');", - env: { node: true }, }, { filename: fixture("3/src/pub/test.js"), code: "require('bbb');", - env: { node: true }, }, { filename: fixture("3/src/pub/test.js"), code: "require('bbb!foo?a=b&c=d');", - env: { node: true }, }, // `convertPath` option. { filename: fixture("3/src/test.jsx"), code: "require('./a');", - env: { node: true }, settings: { node: { convertPath: { @@ -131,12 +113,10 @@ ruleTester.run("no-unpublished-require", rule, { tryExtensions: [".js", ".jsx", ".json"], }, ], - env: { node: true }, }, { filename: fixture("3/src/test.jsx"), code: "require('../test');", - env: { node: true }, settings: { node: { convertPath: [ @@ -163,14 +143,12 @@ ruleTester.run("no-unpublished-require", rule, { ], }, ], - env: { node: true }, }, // Ignores it if not callee. { filename: fixture("1/test.js"), code: "require;", - env: { node: true }, }, // Ignores it if the global variable of `require` is not defined. @@ -182,28 +160,23 @@ ruleTester.run("no-unpublished-require", rule, { // Ignores it if the filename is unknown. { code: "require('no-exist-package-0');", - env: { node: true }, }, { code: "require('./b');", - env: { node: true }, }, // Ignores it if the target is not string. { filename: fixture("1/test.js"), code: "require();", - env: { node: true }, }, { filename: fixture("1/test.js"), code: "require(foo);", - env: { node: true }, }, { filename: fixture("1/test.js"), code: "require(777);", - env: { node: true }, }, { filename: fixture("1/test.js"), @@ -215,29 +188,24 @@ ruleTester.run("no-unpublished-require", rule, { { filename: "tests/fixtures/no-unpublished/2/test.js", code: "require('aaa');", - env: { node: true }, }, { filename: "tests/fixtures/no-unpublished/2/test.js", code: "require('./a');", - env: { node: true }, }, // Should work fine if the target is the package directory. { filename: fixture("issue48n/test.js"), code: "require('.');", - env: { node: true }, }, { filename: fixture("issue48n/test.js"), code: "require('./');", - env: { node: true }, }, { filename: fixture("issue48n/test/test.js"), code: "require('..');", - env: { node: true }, }, // https://github.com/eslint-community/eslint-plugin-n/issues/122 @@ -245,12 +213,10 @@ ruleTester.run("no-unpublished-require", rule, { { filename: fixture("issue99/test/bin.js"), code: "require('./index.js');", - env: { node: true }, }, { filename: fixture("issue99/test/bin.js"), code: "require('.');", - env: { node: true }, }, // allowModules option @@ -258,83 +224,70 @@ ruleTester.run("no-unpublished-require", rule, { filename: fixture("1/test.js"), code: "require('electron');", options: [{ allowModules: ["electron"] }], - env: { node: true }, }, // Auto-published files only apply to root package directory { filename: fixture("3/src/readme.js"), code: "require('bbb');", - env: { node: true }, }, // Negative patterns in files field. { filename: fixture("negative-in-files/lib/__test__/index.js"), code: "require('bbb');", - env: { node: true }, }, { filename: fixture("issue126/lib/test.js"), code: "require('bbb');", - env: { node: true }, }, // devDependency in a private package { filename: fixture("private-package/index.js"), code: "require('bbb');", - env: { node: true }, }, ], invalid: [ { filename: fixture("2/test.js"), code: "require('./ignore1.js');", - env: { node: true }, errors: ['"./ignore1.js" is not published.'], }, { filename: fixture("2/test.js"), code: "require('./ignore1');", - env: { node: true }, errors: ['"./ignore1" is not published.'], }, { filename: fixture("3/pub/test.js"), code: "require('bbb');", - env: { node: true }, errors: ['"bbb" is not published.'], }, { filename: fixture("3/pub/test.js"), code: "require('./ignore1');", - env: { node: true }, errors: ['"./ignore1" is not published.'], }, { filename: fixture("3/pub/test.js"), code: "require('./abc');", - env: { node: true }, errors: ['"./abc" is not published.'], }, { filename: fixture("3/pub/test.js"), code: "require('../test');", - env: { node: true }, errors: ['"../test" is not published.'], }, { filename: fixture("3/pub/test.js"), code: "require('../src/pub/a.js');", - env: { node: true }, errors: ['"../src/pub/a.js" is not published.'], }, { filename: fixture("1/test.js"), code: "require('../a.js');", - env: { node: true }, errors: ['"../a.js" is not published.'], }, @@ -342,7 +295,6 @@ ruleTester.run("no-unpublished-require", rule, { { filename: fixture("3/src/test.jsx"), code: "require('../test');", - env: { node: true }, errors: ['"../test" is not published.'], settings: { node: { @@ -362,13 +314,11 @@ ruleTester.run("no-unpublished-require", rule, { }, }, ], - env: { node: true }, errors: ['"../test" is not published.'], }, { filename: fixture("3/src/test.jsx"), code: "require('../test');", - env: { node: true }, errors: ['"../test" is not published.'], settings: { node: { @@ -394,7 +344,6 @@ ruleTester.run("no-unpublished-require", rule, { ], }, ], - env: { node: true }, errors: ['"../test" is not published.'], }, @@ -402,7 +351,6 @@ ruleTester.run("no-unpublished-require", rule, { { filename: "tests/fixtures/no-unpublished/2/test.js", code: "require('./ignore1');", - env: { node: true }, errors: ['"./ignore1" is not published.'], }, @@ -410,7 +358,6 @@ ruleTester.run("no-unpublished-require", rule, { { filename: fixture("1/test.js"), code: "require('../2/a.js');", - env: { node: true }, errors: ['"../2/a.js" is not published.'], }, ], diff --git a/tests/lib/rules/no-unsupported-features.js b/tests/lib/rules/no-unsupported-features.js index 10959462..ea139d3e 100644 --- a/tests/lib/rules/no-unsupported-features.js +++ b/tests/lib/rules/no-unsupported-features.js @@ -123,7 +123,7 @@ function fixture(name) { ) } -const ruleTester = new RuleTester() +const ruleTester = new RuleTester({ env: { node: true, es6: true } }) ruleTester.run( "no-unsupported-features", rule, diff --git a/tests/lib/rules/no-unsupported-features/node-builtins.js b/tests/lib/rules/no-unsupported-features/node-builtins.js index 3f690d61..910ab88c 100644 --- a/tests/lib/rules/no-unsupported-features/node-builtins.js +++ b/tests/lib/rules/no-unsupported-features/node-builtins.js @@ -27,18 +27,8 @@ function concat(patterns) { } new RuleTester({ - parserOptions: { - ecmaVersion: 2015, - sourceType: "module", - }, - globals: { - Buffer: false, - URL: false, - URLSearchParams: false, - console: false, - process: false, - require: false, - }, + parserOptions: { sourceType: "module" }, + env: { node: true, es6: true }, }).run( "no-unsupported-features/node-builtins", rule, diff --git a/tests/lib/rules/prefer-global/buffer.js b/tests/lib/rules/prefer-global/buffer.js index aadabb69..6a43622c 100644 --- a/tests/lib/rules/prefer-global/buffer.js +++ b/tests/lib/rules/prefer-global/buffer.js @@ -8,13 +8,7 @@ const RuleTester = require("eslint").RuleTester const rule = require("../../../../lib/rules/prefer-global/buffer") new RuleTester({ - parserOptions: { - ecmaVersion: 2015, - }, - globals: { - Buffer: false, - require: false, - }, + env: { node: true, es6: true }, }).run("prefer-global/buffer", rule, { valid: [ "var b = Buffer.alloc(10)", diff --git a/tests/lib/rules/prefer-global/console.js b/tests/lib/rules/prefer-global/console.js index 75c650e8..fcdb4b67 100644 --- a/tests/lib/rules/prefer-global/console.js +++ b/tests/lib/rules/prefer-global/console.js @@ -8,13 +8,7 @@ const RuleTester = require("eslint").RuleTester const rule = require("../../../../lib/rules/prefer-global/console") new RuleTester({ - parserOptions: { - ecmaVersion: 2015, - }, - globals: { - console: false, - require: false, - }, + env: { node: true, es6: true }, }).run("prefer-global/console", rule, { valid: [ "console.log(10)", diff --git a/tests/lib/rules/prefer-global/process.js b/tests/lib/rules/prefer-global/process.js index 54bb588a..8dbb0d51 100644 --- a/tests/lib/rules/prefer-global/process.js +++ b/tests/lib/rules/prefer-global/process.js @@ -8,13 +8,7 @@ const RuleTester = require("eslint").RuleTester const rule = require("../../../../lib/rules/prefer-global/process") new RuleTester({ - parserOptions: { - ecmaVersion: 2015, - }, - globals: { - process: false, - require: false, - }, + env: { node: true, es6: true }, }).run("prefer-global/process", rule, { valid: [ "process.exit(0)", diff --git a/tests/lib/rules/prefer-global/text-decoder.js b/tests/lib/rules/prefer-global/text-decoder.js index 23fe0281..bed954b5 100644 --- a/tests/lib/rules/prefer-global/text-decoder.js +++ b/tests/lib/rules/prefer-global/text-decoder.js @@ -8,13 +8,7 @@ const RuleTester = require("eslint").RuleTester const rule = require("../../../../lib/rules/prefer-global/text-decoder") new RuleTester({ - parserOptions: { - ecmaVersion: 2015, - }, - globals: { - TextDecoder: false, - require: false, - }, + env: { node: true, es6: true }, }).run("prefer-global/text-decoder", rule, { valid: [ "var b = new TextDecoder(s)", diff --git a/tests/lib/rules/prefer-global/text-encoder.js b/tests/lib/rules/prefer-global/text-encoder.js index d7293513..4e422ca9 100644 --- a/tests/lib/rules/prefer-global/text-encoder.js +++ b/tests/lib/rules/prefer-global/text-encoder.js @@ -8,13 +8,7 @@ const RuleTester = require("eslint").RuleTester const rule = require("../../../../lib/rules/prefer-global/text-encoder") new RuleTester({ - parserOptions: { - ecmaVersion: 2015, - }, - globals: { - TextEncoder: false, - require: false, - }, + env: { node: true, es6: true }, }).run("prefer-global/text-encoder", rule, { valid: [ "var b = new TextEncoder(s)", diff --git a/tests/lib/rules/prefer-global/url-search-params.js b/tests/lib/rules/prefer-global/url-search-params.js index 6da2ecac..23a08564 100644 --- a/tests/lib/rules/prefer-global/url-search-params.js +++ b/tests/lib/rules/prefer-global/url-search-params.js @@ -8,13 +8,7 @@ const RuleTester = require("eslint").RuleTester const rule = require("../../../../lib/rules/prefer-global/url-search-params") new RuleTester({ - parserOptions: { - ecmaVersion: 2015, - }, - globals: { - URLSearchParams: false, - require: false, - }, + env: { node: true, es6: true }, }).run("prefer-global/url-search-params", rule, { valid: [ "var b = new URLSearchParams(s)", diff --git a/tests/lib/rules/prefer-global/url.js b/tests/lib/rules/prefer-global/url.js index a55e0038..dd7a9af8 100644 --- a/tests/lib/rules/prefer-global/url.js +++ b/tests/lib/rules/prefer-global/url.js @@ -8,13 +8,7 @@ const RuleTester = require("eslint").RuleTester const rule = require("../../../../lib/rules/prefer-global/url") new RuleTester({ - parserOptions: { - ecmaVersion: 2015, - }, - globals: { - URL: false, - require: false, - }, + env: { node: true, es6: true }, }).run("prefer-global/url", rule, { valid: [ "var b = new URL(s)", diff --git a/tests/lib/rules/prefer-promises/dns.js b/tests/lib/rules/prefer-promises/dns.js index 281b1e74..c264559f 100644 --- a/tests/lib/rules/prefer-promises/dns.js +++ b/tests/lib/rules/prefer-promises/dns.js @@ -8,13 +8,8 @@ const RuleTester = require("eslint").RuleTester const rule = require("../../../../lib/rules/prefer-promises/dns") new RuleTester({ - parserOptions: { - ecmaVersion: 2015, - sourceType: "module", - }, - globals: { - require: false, - }, + parserOptions: { sourceType: "module" }, + env: { node: true, es6: true }, }).run("prefer-promises/dns", rule, { valid: [ "const dns = require('dns'); dns.lookupSync()", diff --git a/tests/lib/rules/prefer-promises/fs.js b/tests/lib/rules/prefer-promises/fs.js index 4bc9b60e..d9a3645e 100644 --- a/tests/lib/rules/prefer-promises/fs.js +++ b/tests/lib/rules/prefer-promises/fs.js @@ -8,13 +8,8 @@ const RuleTester = require("eslint").RuleTester const rule = require("../../../../lib/rules/prefer-promises/fs") new RuleTester({ - parserOptions: { - ecmaVersion: 2015, - sourceType: "module", - }, - globals: { - require: false, - }, + parserOptions: { sourceType: "module" }, + env: { node: true, es6: true }, }).run("prefer-promises/fs", rule, { valid: [ "const fs = require('fs'); fs.createReadStream()", diff --git a/tests/lib/rules/shebang.js b/tests/lib/rules/shebang.js index 3b2a9e9c..900a6d52 100644 --- a/tests/lib/rules/shebang.js +++ b/tests/lib/rules/shebang.js @@ -17,7 +17,7 @@ function fixture(name) { return path.resolve(__dirname, "../../fixtures/shebang", name) } -const ruleTester = new RuleTester() +const ruleTester = new RuleTester({ env: { node: true, es6: true } }) ruleTester.run("shebang", rule, { valid: [ {