Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Add test that deprecated rules display a deprecated notice #14989

Merged
merged 5 commits into from Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 23 additions & 4 deletions Makefile.js
Expand Up @@ -816,6 +816,20 @@ target.checkRuleFiles = function() {
return idNewAtBeginningOfTitleRegExp.test(docText) || idOldAtEndOfTitleRegExp.test(docText);
}

/**
* Check if deprecated information is in rule code and READNE.md.
* @returns {boolean} true if present
* @private
*/
function hasDeprecatedInfo() {
const ruleCode = cat(filename);
const deprecatedTagRegExp = /@deprecated in ESLint/u;
const docText = cat(docFilename);
const deprecatedInfoRegExp = /This rule was .+deprecated.+in ESLint/u;
bmish marked this conversation as resolved.
Show resolved Hide resolved

return deprecatedTagRegExp.test(ruleCode) && deprecatedInfoRegExp.test(docText);
}

// check for docs
if (!test("-f", docFilename)) {
console.error("Missing documentation for rule %s", basename);
Expand All @@ -842,12 +856,17 @@ target.checkRuleFiles = function() {
if (!ruleDef) {
console.error(`Missing rule from index (./lib/rules/index.js): ${basename}. If you just added a new rule then add an entry for it in this file.`);
errors++;
}
} else {

// check deprecated
if (ruleDef.meta.deprecated && !hasDeprecatedInfo()) {
console.error(`Missing deprecated information in ${basename} rule code or README.md. Please write @deprecated tag in code or 「This rule was deprecated in ESLint ...」 in README.md.`);
errors++;
}

// check eslint:recommended
const recommended = require("./conf/eslint-recommended");
// check eslint:recommended
const recommended = require("./conf/eslint-recommended");

if (ruleDef) {
if (ruleDef.meta.docs.recommended) {
if (recommended.rules[basename] !== "error") {
console.error(`Missing rule from eslint:recommended (./conf/eslint-recommended.js): ${basename}. If you just made a rule recommended then add an entry for it in this file.`);
Expand Down
1 change: 1 addition & 0 deletions docs/rules/indent-legacy.md
@@ -1,5 +1,6 @@
# enforce consistent indentation (indent-legacy)

This rule was **deprecated** in ESLint v4.0.0.
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have blank line after:

Suggested change
This rule was **deprecated** in ESLint v4.0.0.
This rule was **deprecated** in ESLint v4.0.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 48b21c2

ESLint 4.0.0 introduced a rewrite of the [`indent`](/docs/rules/indent) rule, which now reports more errors than it did in previous versions. To ease the process of migrating to 4.0.0, the `indent-legacy` rule was introduced as a snapshot of the `indent` rule from ESLint 3.x. If your build is failing after the upgrade to 4.0.0, you can disable `indent` and enable `indent-legacy` as a quick fix. Eventually, you should switch back to the `indent` rule to get bugfixes and improvements in future versions.

---
Expand Down