Skip to content
Permalink
Browse files
Chore: Add test that deprecated rules display a deprecated notice (#1…
…4989)

* Chore: Add tests for check deprecated rule

* Chore: Fix lint and refactor

* Chore: Fix RegExp

* Chore: Add space

* Chore: Add blank
  • Loading branch information
wafuwafu13 committed Aug 31, 2021
1 parent 88b4e3d commit b4232d47f88611c68a6c0f915b092b68845ecbaf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
@@ -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;

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

// check for docs
if (!test("-f", docFilename)) {
console.error("Missing documentation for rule %s", basename);
@@ -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.`);
@@ -1,5 +1,7 @@
# enforce consistent indentation (indent-legacy)

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

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.

---

0 comments on commit b4232d4

Please sign in to comment.