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

context.options not getting the values #339

Closed
rahgurung opened this issue Jul 11, 2019 · 5 comments
Closed

context.options not getting the values #339

rahgurung opened this issue Jul 11, 2019 · 5 comments
Labels

Comments

@rahgurung
Copy link

rahgurung commented Jul 11, 2019

While developing the rule, in index.js when I do

'unicorn/myrule': ['error', {name: 'hello'}]

and in rules/myrule.js I just did a simple console.log(context.options[0]) and it is coming undefined all the time when I wrote a simple test and ran it using
npx ava test/myrule.js.

Am I doing something wrong to pass options?

PS: console.log('hello') works fine.

@futpib
Copy link
Collaborator

futpib commented Jul 11, 2019

Try this:

-'unicorn/myrule': 'error', [ {name: 'hello'}]
+'unicorn/myrule': ['error', {name: 'hello'}]

@rahgurung
Copy link
Author

@futpib my fault, it was already that way. :( doesn't work.

@rahgurung
Copy link
Author

rahgurung commented Jul 11, 2019

I will edit it to my version.

@futpib
Copy link
Collaborator

futpib commented Jul 11, 2019

index.js is a definition of a ESLint plugin. When you run tests, your rule does not get passed the options from index.js. Instead it is passed options from the test definition (or none, if none specified in the test definition).

Here is an example of a test with custom options:

{
code: 'try {} catch (_error) {}',
output: 'try {} catch (error) {}',
errors: [
{
ruleId: 'catch-error-name',
message: 'The catch parameter should be named `error`.'
}
],
options: [
{
caughtErrorsIgnorePattern: '^skip'
}
]
}

@rahgurung
Copy link
Author

That's exactly what I was missing, thanks.:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants