Skip to content

Commit

Permalink
Merge c95fe32 into fce1e12
Browse files Browse the repository at this point in the history
  • Loading branch information
platinumazure committed Aug 25, 2021
2 parents fce1e12 + c95fe32 commit 25ef483
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@

// eslint-plugin-eslint-plugin
"eslint-plugin/meta-property-ordering": ["error", [
"type", "docs", "fixable", "messages", "schema", "deprecated", "replacedBy"
"type", "docs", "fixable", "hasSuggestions", "messages", "schema",
"deprecated", "replacedBy"
]],
"eslint-plugin/require-meta-docs-url": ["error", {
"pattern": "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/{{name}}.md"
Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ Each rule has emojis denoting:
| [assert-args](./docs/rules/assert-args.md) | enforce that the correct number of assert arguments are used || | |
| [literal-compare-order](./docs/rules/literal-compare-order.md) | enforce comparison assertions have arguments in the right order || 🔧 | |
| [no-arrow-tests](./docs/rules/no-arrow-tests.md) | disallow arrow functions as QUnit test/module callbacks || 🔧 | |
| [no-assert-equal](./docs/rules/no-assert-equal.md) | disallow the use of assert.equal | | | 💡 |
| [no-assert-equal-boolean](./docs/rules/no-assert-equal-boolean.md) | require use of boolean assertions || 🔧 | |
| [no-assert-logical-expression](./docs/rules/no-assert-logical-expression.md) | disallow binary logical expressions in assert arguments || | |
| [no-assert-ok](./docs/rules/no-assert-ok.md) | disallow the use of assert.ok/assert.notOk | | | |
| [no-async-in-loops](./docs/rules/no-async-in-loops.md) | disallow async calls in loops || | |
| [no-async-module-callbacks](./docs/rules/no-async-module-callbacks.md) | disallow async module callbacks || | |
| [no-async-test](./docs/rules/no-async-test.md) | disallow the use of asyncTest or QUnit.asyncTest || | |
Expand Down Expand Up @@ -72,6 +70,19 @@ Each rule has emojis denoting:

<!--RULES_TABLE_END-->

### Deprecated Rules

The following rules are deprecated:

<!--DEPRECATED_RULES_TABLE_START-->

| Name | Replaced By |
|:-----|:------------|
| [no-assert-equal](./docs/rules/no-assert-equal.md) | [no-loose-assertions](./docs/rules/no-loose-assertions.md)
| [no-assert-ok](./docs/rules/no-assert-ok.md) | [no-loose-assertions](./docs/rules/no-loose-assertions.md)

<!--DEPRECATED_RULES_TABLE_END-->

## Contributors

Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
Expand Down
2 changes: 2 additions & 0 deletions docs/rules/no-assert-equal.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Disallow the use of assert.equal (no-assert-equal)

**This rule has been deprecated.** Please see the project README for information about replacement rules.

💡 Some problems reported by this rule are manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).

The `assert.equal` assertion method in QUnit uses loose equality comparison. In a project which favors strict equality comparison, it is better to use `assert.strictEqual` for scalar values and either `assert.deepEqual` or `assert.propEqual` for more complex objects.
Expand Down
2 changes: 2 additions & 0 deletions docs/rules/no-assert-ok.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Disallow the use of assert.ok/assert.notOk (no-assert-ok)

**This rule has been deprecated.** Please see the project README for information about replacement rules.

`assert.ok` and `assert.notOk` pass for any truthy/falsy argument. As [many expressions evaluate to true/false in JavaScript](https://developer.mozilla.org/en-US/docs/Glossary/Truthy) the usage of `assert.ok` is potentially error prone. In general, it should be advisable to always test for exact values in tests which makes tests a lot more solid.

An example when using `assert.ok` can involuntarily go wrong:
Expand Down
4 changes: 3 additions & 1 deletion lib/rules/no-assert-equal.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = {
category: "Best Practices",
url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/master/docs/rules/no-assert-equal.md"
},
hasSuggestions: true,
messages: {
unexpectedGlobalEqual: "Unexpected equal. Use strictEqual, deepEqual, or propEqual.",
unexpectedAssertEqual: "Unexpected {{assertVar}}.equal. Use {{assertVar}}.strictEqual, {{assertVar}}.deepEqual, or {{assertVar}}.propEqual.",
Expand All @@ -32,7 +33,8 @@ module.exports = {
switchToStrictEqual: "Switch to strictEqual."
},
schema: [],
hasSuggestions: true
deprecated: true,
replacedBy: ["qunit/no-loose-assertions"]
},

create: function (context) {
Expand Down
4 changes: 3 additions & 1 deletion lib/rules/no-assert-ok.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ module.exports = {
[GLOBAL_ERROR_MESSAGE_ID]: "Unexpected {{assertion}}. Use strictEqual, deepEqual, or propEqual.",
[LOCAL_ERROR_MESSAGE_ID]: "Unexpected {{assertVar}}.{{assertion}}. Use {{assertVar}}.strictEqual, {{assertVar}}.deepEqual, or {{assertVar}}.propEqual."
},
schema: []
schema: [],
deprecated: true,
replacedBy: ["qunit/no-loose-assertions"]
},

create: utils.createAssertionCheck(assertions, ERROR_MESSAGE_CONFIG)
Expand Down
39 changes: 34 additions & 5 deletions scripts/update-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const { rules, configs } = require("../");

const pathReadme = path.resolve(__dirname, "../README.md");
const readmeContent = fs.readFileSync(pathReadme, "utf8");
const tablePlaceholder = /<!--RULES_TABLE_START-->[\S\s]*<!--RULES_TABLE_END-->/;
const rulesTablePlaceholder = /<!--RULES_TABLE_START-->[\S\s]*<!--RULES_TABLE_END-->/;
const deprecatedRulesTablePlaceholder = /<!--DEPRECATED_RULES_TABLE_START-->[\S\s]*<!--DEPRECATED_RULES_TABLE_END-->/;

// Config/preset/fixable emojis.
const EMOJI_RECOMMENDED = "✅";
Expand All @@ -15,6 +16,7 @@ const EMOJI_SUGGESTIONS = "💡";

// Generate rule table contents.
const rulesTableContent = Object.keys(rules)
.filter(ruleName => !rules[ruleName].meta.deprecated)
.sort()
.map((ruleName) => {
// Check which emojis to show for this rule.
Expand All @@ -28,10 +30,37 @@ const rulesTableContent = Object.keys(rules)
})
.join("\n");

// Generate deprecated rule table contents.
const deprecatedRulesTableContent = Object.keys(rules)
.filter(ruleName => rules[ruleName].meta.deprecated)
.sort()
.map((ruleName) => {
const url = `./docs/rules/${ruleName}.md`;
const link = `[${ruleName}](${url})`;

const replacedBy = rules[ruleName].meta.replacedBy || [];

const replacedByLinks = replacedBy
.map(replacementName => {
const simpleName = replacementName.replace(/^qunit\//, "");

const replaceUrl = `./docs/rules/${simpleName}.md`;
return `[${simpleName}](${replaceUrl})`;
});

return `| ${link} | ${replacedByLinks.join(", ")}`;
})
.join("\n");

fs.writeFileSync(
pathReadme,
readmeContent.replace(
tablePlaceholder,
`<!--RULES_TABLE_START-->\n\n| Name | Description | ${EMOJI_RECOMMENDED} | ${EMOJI_FIXABLE} | ${EMOJI_SUGGESTIONS} |\n|:--------|:--------|:---|:---|:---|\n${rulesTableContent}\n\n<!--RULES_TABLE_END-->`
)
readmeContent
.replace(
rulesTablePlaceholder,
`<!--RULES_TABLE_START-->\n\n| Name | Description | ${EMOJI_RECOMMENDED} | ${EMOJI_FIXABLE} | ${EMOJI_SUGGESTIONS} |\n|:--------|:--------|:---|:---|:---|\n${rulesTableContent}\n\n<!--RULES_TABLE_END-->`
)
.replace(
deprecatedRulesTablePlaceholder,
`<!--DEPRECATED_RULES_TABLE_START-->\n\n| Name | Replaced By |\n|:-----|:------------|\n${deprecatedRulesTableContent}\n\n<!--DEPRECATED_RULES_TABLE_END-->`
)
);
10 changes: 10 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const assert = require("chai").assert,
//------------------------------------------------------------------------------

const MESSAGES = {
deprecated: "**This rule has been deprecated.** Please see the project README for information about replacement rules.",
fixable: "🔧 The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.",
configRecommended: "✅ The `\"extends\": \"plugin:qunit/recommended\"` property in a configuration file enables this rule.",
hasSuggestions: "💡 Some problems reported by this rule are manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions)."
Expand Down Expand Up @@ -73,16 +74,25 @@ describe("index.js", function () {
// Decide which notices should be shown at the top of the doc.
const expectedNotices = [];
const unexpectedNotices = [];

if (rules[ruleName].meta.deprecated) {
expectedNotices.push("deprecated");
} else {
unexpectedNotices.push("deprecated");
}

if (configs.recommended.rules[`qunit/${ruleName}`]) {
expectedNotices.push("configRecommended");
} else {
unexpectedNotices.push("configRecommended");
}

if (rules[ruleName].meta.fixable) {
expectedNotices.push("fixable");
} else {
unexpectedNotices.push("fixable");
}

if (rules[ruleName].meta.hasSuggestions) {
expectedNotices.push("hasSuggestions");
} else {
Expand Down

0 comments on commit 25ef483

Please sign in to comment.