question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[6.0.0-alpha.1] `RuleTester` fails tests if `parser` property is a package name

See original GitHub issue

From https://github.com/benmosher/eslint-plugin-import/issues/1362 From https://travis-ci.org/benmosher/eslint-plugin-import/jobs/533124402

Tell us about your environment

  • ESLint Version: 6.0.0-alpha.1
  • Node Version: 10.15.3
  • npm Version: 6.4.1

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

n/a

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.

Use RuleTester with parser option with babel-eslint. (e.g., eslint-plugin-import:/tests/src/rules/default.js#L31)

What did you expect to happen?

No errors.

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

The test failed with “Parsers provided as strings to RuleTester must be absolute paths.”

Are you willing to submit a pull request to fix this bug?

Yes.


I think that RuleTester should allow package names (maybe it loads it relative to CWD).

Also, the Migration Guide must describe this change.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mysticateacommented, May 21, 2019

Thank you for the explanation.

But, my position is different. Because to use file paths for parser config is a pretty rare case (probably only we are). For 99.99% of users, parser is packages such as babel-eslint, vue-eslint-parser, @typescript-eslint/parser. and etc. Not a file path. Therefore, disallowing a package name would be a surprising behavior.

I think that good design is “people can do the most popular use case easily, and can do rare cases with detailed way.” I believe we should allow a package name and show a understandable error message for rare cases (E.g., '${parser}' was not found on '${cwd}'. Make sure the package to be installed or use an absolute path with 'require.resolve()'.). The current behavior seems to enforce annoying to users by afraid of pretty rare cases.

1reaction
not-an-aardvarkcommented, May 16, 2019

The current behavior is intentional because it’s not clear where packages should be loaded from with RuleTester. I suppose the CWD works, but it could be confusing because projects using RuleTester might be dependencies of the user’s project, so they can’t guarantee that their dependencies will be loadable from the CWD. It seems like it would be safer to require an absolute path so that users use require.resolve to avoid the ambiguity.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unit tests for managed package fail in target org after install
It's only when the tests are run again after installation that the errors occur. One specific error: System.QueryException: No such column ' ...
Read more >
eslint | Yarn - Package Manager
ESLint uses Espree for JavaScript parsing. ESLint uses an AST to evaluate patterns in code. ESLint is completely pluggable, every single rule is...
Read more >
JUnit Parser ignore errors in tests (#23992) - GitLab.org
We are using WmTestSuite as the testing tool and it always generates Error and not Failures. As Gitlab only shows Failures, test results...
Read more >
Testing custom linting rules - Practical Abstract Syntax Trees
const { RuleTester } = require("eslint");. The rule tester uses the default ESLint configuration (not the one provided by ...
Read more >
eslint: Versions | Openbase
Openbase helps you choose packages with reviews, metrics & categories. ... d0f4cb4 docs: use shorthand property name in example (#16180) (Kevin Elliott).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found