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 · May be fixed by ali8889/emerald-wallet#4, Dizzydaizys/yarn#9 or DmytroSkrypnyk/test_bootstrap#6
Closed

Comments

@betaorbust
Copy link
Contributor

@betaorbust betaorbust commented Jan 25, 2018

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 eslint bot added the triage label Jan 25, 2018
@platinumazure

This comment has been minimized.

Copy link
Member

@platinumazure platinumazure commented Jan 25, 2018

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

@betaorbust

This comment has been minimized.

Copy link
Contributor Author

@betaorbust betaorbust commented Jan 25, 2018

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
platinumazure added a commit that referenced this issue Jan 25, 2018
@eslint eslint bot locked and limited conversation to collaborators Jul 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.