Skip to content

Commit

Permalink
refactor: use process.emitWarning()
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Jul 5, 2022
1 parent 1a723c1 commit 967ffb9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
16 changes: 8 additions & 8 deletions lib/rule-tester/rule-tester.js
Expand Up @@ -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"
);
}
}

Expand All @@ -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"
);
}
}

Expand Down
17 changes: 8 additions & 9 deletions tests/lib/rule-tester/rule-tester.js
Expand Up @@ -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"),
Expand Down Expand Up @@ -2233,7 +2232,7 @@ describe("RuleTester", () => {
let spy;

beforeEach(() => {
spy = sinon.spy(util, "deprecate");
spy = sinon.spy(process, "emitWarning");
});

afterEach(() => {
Expand Down Expand Up @@ -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"
);
});
Expand All @@ -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"
);
});
Expand All @@ -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"
);
});
Expand All @@ -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()`");
});
});

Expand Down

0 comments on commit 967ffb9

Please sign in to comment.