Repository: eslint/eslint
File: tests/lib/rule-tester/flat-rule-tester.js (JavaScript)

Code before:

        it("should fail if a rule produces two suggestions with the same description", () => {
            assert.throws(() => {
                ruleTester.run("suggestions-missing-hasSuggestions-property", require("../../fixtures/testers/rule-tester/suggestions").withDuplicateDescriptions, {
                    valid: [],
                    invalid: [
                        { code: "var foo = bar;", output: "5", errors: 1 }
                    ]
                });
            }, "Suggestion message 'Rename 'foo' to 'bar'' reported from suggestion 1 was previously reported by suggestion 0. Suggestion messages should be unique within an error.");
        });

        it("should fail if a rule produces two suggestions with the same messageId without data", () => {
            assert.throws(() => {
                ruleTester.run("suggestions-missing-hasSuggestions-property", require("../../fixtures/testers/rule-tester/suggestions").withDuplicateMessageIdsNoData, {
                    valid: [],
                    invalid: [
                        { code: "var foo = bar;", output: "5", errors: 1 }
                    ]
                });
            }, "Suggestion message 'Rename identifier' reported from suggestion 1 was previously reported by suggestion 0. Suggestion messages should be unique within an error.");
        });

        it("should fail if a rule produces two suggestions with the same messageId without data", () => {
            assert.throws(() => {
                ruleTester.run("suggestions-missing-hasSuggestions-property", require("../../fixtures/testers/rule-tester/suggestions").withDuplicateMessageIdsWithData, {
                    valid: [],
                    invalid: [
                        { code: "var foo = bar;", output: "5", errors: 1 }
                    ]
                });
            }, "Suggestion message 'Rename identifier 'foo' to 'bar'' reported from suggestion 1 was previously reported by suggestion 0. Suggestion messages should be unique within an error.");
        });

        it("should throw an error if a rule that doesn't have `meta.hasSuggestions` enabled produces suggestions", () => {
            assert.throws(() => {
                ruleTester.run("suggestions-missing-hasSuggestions-property", require("../../fixtures/testers/rule-tester/suggestions").withoutHasSuggestionsProperty, {
                    valid: [],
                    invalid: [
                        { code: "var foo = bar;", output: "5", errors: 1 }
                    ]
                });
            }, "Rules with suggestions must set the `meta.hasSuggestions` property to `true`.");
        });
    });

    /**
     * Asserts that a particular value will be emitted from an EventEmitter.
     * @param {EventEmitter} emitter The emitter that should emit a value
     * @param {string} emitType The type of emission to listen for
     * @param {any} expectedValue The value that should be emitted

Review comment (refactor):
```suggestion
                ruleTester.run("suggestions-with-duplicate-messageids-with-data", require("../../fixtures/testers/rule-tester/suggestions").withDuplicateMessageIdsWithData, {
```

Code after:

        it("should fail if a rule produces two suggestions with the same description", () => {
            assert.throws(() => {
                ruleTester.run("suggestions-with-duplicate-descriptions", require("../../fixtures/testers/rule-tester/suggestions").withDuplicateDescriptions, {
                    valid: [],
                    invalid: [
                        { code: "var foo = bar;", errors: 1 }
                    ]
                });
            }, "Suggestion message 'Rename 'foo' to 'bar'' reported from suggestion 1 was previously reported by suggestion 0. Suggestion messages should be unique within an error.");
        });

        it("should fail if a rule produces two suggestions with the same messageId without data", () => {
            assert.throws(() => {
                ruleTester.run("suggestions-with-duplicate-messageids-no-data", require("../../fixtures/testers/rule-tester/suggestions").withDuplicateMessageIdsNoData, {
                    valid: [],
                    invalid: [
                        { code: "var foo = bar;", errors: 1 }
                    ]
                });
            }, "Suggestion message 'Rename identifier' reported from suggestion 1 was previously reported by suggestion 0. Suggestion messages should be unique within an error.");
        });

        it("should fail if a rule produces two suggestions with the same messageId with data", () => {
            assert.throws(() => {
                ruleTester.run("suggestions-with-duplicate-messageids-with-data", require("../../fixtures/testers/rule-tester/suggestions").withDuplicateMessageIdsWithData, {
                    valid: [],
                    invalid: [
                        { code: "var foo = bar;", errors: 1 }
                    ]
                });
            }, "Suggestion message 'Rename identifier 'foo' to 'bar'' reported from suggestion 1 was previously reported by suggestion 0. Suggestion messages should be unique within an error.");
        });

        it("should throw an error if a rule that doesn't have `meta.hasSuggestions` enabled produces suggestions", () => {
            assert.throws(() => {
                ruleTester.run("suggestions-missing-hasSuggestions-property", require("../../fixtures/testers/rule-tester/suggestions").withoutHasSuggestionsProperty, {
                    valid: [],
                    invalid: [
                        { code: "var foo = bar;", output: "5", errors: 1 }
                    ]
                });
            }, "Rules with suggestions must set the `meta.hasSuggestions` property to `true`.");
        });
    });

    /**
     * Asserts that a particular value will be emitted from an EventEmitter.
     * @param {EventEmitter} emitter The emitter that should emit a value
     * @param {string} emitType The type of emission to listen for
     * @param {any} expectedValue The value that should be emitted