Skip to content

Commit

Permalink
Add deprecation notices to RuleTester/FlatRuleTester
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas committed Sep 6, 2023
1 parent 929dd4d commit d350fa9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/rule-tester/rule-tester.js
Expand Up @@ -391,6 +391,21 @@ function emitDeprecatedContextMethodWarning(ruleName, methodName) {
}
}

/**
* Emit a deprecation warning if rule uses CodePath#currentSegments.
* @param {string} ruleName Name of the rule.
* @returns {void}
*/
function emitCodePathCurrentSegmentsWarning(ruleName) {
if (!emitCodePathCurrentSegmentsWarning[`warned-${ruleName}`]) {
emitCodePathCurrentSegmentsWarning[`warned-${ruleName}`] = true;
process.emitWarning(
`"${ruleName}" rule uses CodePath#currentSegments and will stop working in ESLint v9. Please read the documentation for how to update your code: https://eslint.org/docs/latest/extend/code-path-analysis#usage-examples`,
"DeprecationWarning"
);
}
}

//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------
Expand Down
26 changes: 26 additions & 0 deletions tests/lib/rule-tester/rule-tester.js
Expand Up @@ -2581,6 +2581,32 @@ describe("RuleTester", () => {

});

it("should emit a deprecation warning when CodePath#currentSegments is accessed", () => {

const useCurrentSegmentsRule = {
create: () => ({
onCodePathStart(codePath) {
codePath.currentSegments.forEach(() => {});
}
})
};

ruleTester.run("use-current-segments", useCurrentSegmentsRule, {
valid: ["foo"],
invalid: []
});

assert.strictEqual(processStub.callCount, 1, "calls `process.emitWarning()` once");
assert.deepStrictEqual(
processStub.getCall(0).args,
[
"\"use-current-segments\" rule uses CodePath#currentSegments and will stop working in ESLint v9. Please read the documentation for how to update your code: https://eslint.org/docs/latest/extend/code-path-analysis#usage-examples",
"DeprecationWarning"
]
);

});

});

/**
Expand Down

0 comments on commit d350fa9

Please sign in to comment.