From 967ffb9fe1a7af3a36b1d38717e4688be802d3e6 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Tue, 5 Jul 2022 18:16:56 +0530 Subject: [PATCH] refactor: use process.emitWarning() --- lib/rule-tester/rule-tester.js | 16 ++++++++-------- tests/lib/rule-tester/rule-tester.js | 17 ++++++++--------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/rule-tester/rule-tester.js b/lib/rule-tester/rule-tester.js index 1355e0458df..80bbef2a921 100644 --- a/lib/rule-tester/rule-tester.js +++ b/lib/rule-tester/rule-tester.js @@ -313,10 +313,10 @@ function getCommentsDeprecation() { function emitLegacyRuleAPIWarning(ruleName) { if (!emitLegacyRuleAPIWarning[`warned-${ruleName}`]) { emitLegacyRuleAPIWarning[`warned-${ruleName}`] = true; - util.deprecate( - () => {}, - `"${ruleName}" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/developer-guide/working-with-rules` - )(); + process.emitWarning( + `"${ruleName}" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/developer-guide/working-with-rules`, + "DeprecationWarning" + ); } } @@ -328,10 +328,10 @@ function emitLegacyRuleAPIWarning(ruleName) { function emitMissingSchemaWarning(ruleName) { if (!emitMissingSchemaWarning[`warned-${ruleName}`]) { emitMissingSchemaWarning[`warned-${ruleName}`] = true; - util.deprecate( - () => {}, - `"${ruleName}" rule has options but is missing the "meta.schema" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas` - )(); + process.emitWarning( + `"${ruleName}" rule has options but is missing the "meta.schema" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas`, + "DeprecationWarning" + ); } } diff --git a/tests/lib/rule-tester/rule-tester.js b/tests/lib/rule-tester/rule-tester.js index 5dddb43abad..dc7e5c08b65 100644 --- a/tests/lib/rule-tester/rule-tester.js +++ b/tests/lib/rule-tester/rule-tester.js @@ -9,7 +9,6 @@ //------------------------------------------------------------------------------ const sinon = require("sinon"), EventEmitter = require("events"), - util = require("util"), { RuleTester } = require("../../../lib/rule-tester"), assert = require("chai").assert, nodeAssert = require("assert"), @@ -2233,7 +2232,7 @@ describe("RuleTester", () => { let spy; beforeEach(() => { - spy = sinon.spy(util, "deprecate"); + spy = sinon.spy(process, "emitWarning"); }); afterEach(() => { @@ -2262,9 +2261,9 @@ describe("RuleTester", () => { ] }); - assert.strictEqual(spy.callCount, 1, "calls `util.deprecate()` once"); + assert.strictEqual(spy.callCount, 1, "calls `process.emitWarning()` once"); assert.strictEqual( - spy.getCall(0).args[1], + spy.getCall(0).args[0], "\"function-style-rule\" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/developer-guide/working-with-rules" ); }); @@ -2287,9 +2286,9 @@ describe("RuleTester", () => { ] }); - assert.strictEqual(spy.callCount, 1, "calls `util.deprecate` once"); + assert.strictEqual(spy.callCount, 1, "calls `process.emitWarning()` once"); assert.strictEqual( - spy.getCall(0).args[1], + spy.getCall(0).args[0], "\"rule-with-no-meta\" rule has options but is missing the \"meta.schema\" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas" ); }); @@ -2315,9 +2314,9 @@ describe("RuleTester", () => { ] }); - assert.strictEqual(spy.callCount, 1, "calls `util.deprecate` once"); + assert.strictEqual(spy.callCount, 1, "calls `process.emitWarning()` once"); assert.strictEqual( - spy.getCall(0).args[1], + spy.getCall(0).args[0], "\"rule-with-no-schema\" rule has options but is missing the \"meta.schema\" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas" ); }); @@ -2342,7 +2341,7 @@ describe("RuleTester", () => { invalid: [{ code: "var foo = bar;", errors: 1 }] }); - assert.strictEqual(spy.callCount, 0, "never calls `util.deprecate`"); + assert.strictEqual(spy.callCount, 0, "never calls `process.emitWarning()`"); }); });