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

messageId doc examples throw during testing. #9889

Closed
betaorbust opened this issue Jan 25, 2018 · 2 comments · Fixed by Urigo/tortilla#62, #9892, mono-js/mono-notifications#5, mono-js/mono-push#5 or terrajs/lib-starter#5
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion documentation Relates to ESLint's documentation

Comments

@betaorbust
Copy link
Contributor

Tell us about your environment

  • ESLint Version: 4.15+
  • Node Version: 8.9.3
  • npm Version: 5.5.1

What parser (default, Babel-ESLint, etc.) are you using?
default

Please show your full configuration:
N/A

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
Ran the code provided in the messageId section of the Working with Rules page.
Recreated below:

lib/rules/no-foo.js

'use strict';
module.exports = {
    meta: {
        messages: {
            avoidName: "Avoid using variables named '{{ name }}'"
        }
    },
    create(context) {
        return {
            Identifier(node) {
                if (node.name === "foo") {
                    context.report({
                        node,
                        messageId: "avoidName",
                        data: {
                            name: "foo",
                        }
                    });
                }
            }
        };
    }
};

tests/lib/rules/no-foo.js
Updated require path which was var rule = require('../../../lib/rules/no-insecure-random'); which seems unrelated to this example.

'use strict';
// In your tests:
var rule = require('../../../lib/rules/no-foo');
var RuleTester = require('eslint').RuleTester;

var ruleTester = new RuleTester();
ruleTester.run('my-rule', rule, {
  valid: ['bar', 'baz'],

  invalid: [
    {
      code: 'foo',
      errors: [
        {
          messageId: 'foo',
        }
      ]
    }
  ]
});

What did you expect to happen?
It should work out of the box more or less.

What actually happened? Please include the actual, raw output from ESLint.

 1 failing

  1) my-rule invalid foo:
     AssertionError [ERR_ASSERTION]: Invalid messageId 'foo'. Expected one of ['avoidName'].
      at testInvalidTemplate (node_modules\eslint\lib\testers\rule-tester.js:508:40)
      at Context.RuleTester.it (node_modules\eslint\lib\testers\rule-tester.js:581:25)
@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Jan 25, 2018
@platinumazure platinumazure added documentation Relates to ESLint's documentation accepted There is consensus among the team that this change meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Jan 25, 2018
@platinumazure
Copy link
Member

Hi @betaorbust, thanks for the issue! I agree 100%, those docs need tweaking. Would you like to submit a pull request?

@betaorbust
Copy link
Contributor Author

Unfortunately, while putting together my PR for this, I ran into a much bigger problem in how the messageId feature currently works.

See #9890 for more details.

j-f1 added a commit to j-f1/forked-eslint that referenced this issue Jan 25, 2018
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jul 26, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Jul 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.