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

ava/no-import-test-files triggers for scoped packages #253

Closed
freaktechnik opened this issue Jun 1, 2019 · 7 comments · Fixed by #255
Closed

ava/no-import-test-files triggers for scoped packages #253

freaktechnik opened this issue Jun 1, 2019 · 7 comments · Fixed by #255

Comments

@freaktechnik
Copy link
Contributor

Using the recommended config of the plugin, import Octokit from '@octokit/rest'; inside a file called _stubs.js, so an ava helper file, triggers the rule ava/no-import-test-files with the message "Test files should not be imported" for the whole line.

Example: https://travis-ci.org/mozillach/gh-projects-content-queue/jobs/540192593#L477

freaktechnik added a commit to mozillach/gh-projects-content-queue that referenced this issue Jun 1, 2019
@GMartigny
Copy link
Contributor

You file _stubs.js is considered a test file because it's under the test directory. The best thing you can do is to put all non-test files related to test under a helper directory.
Alternatively, you can change your AVA settings on helper files.

@freaktechnik
Copy link
Contributor Author

freaktechnik commented Jun 1, 2019

That is not what the rule error is saying though. It's saying I'm importing a test file, which is not what's happening. Plus according to the changelog _ still makes a file a helper file.

@freaktechnik
Copy link
Contributor Author

From a quick glance at the rule, I'd suspect this is because @octokit/rest does not match https://github.com/avajs/eslint-plugin-ava/blob/master/rules/no-import-test-files.js#L5, since @ is not in \w.

@GMartigny
Copy link
Contributor

@ not matching makes it considered as an internal module, but it should not be considered a test file anyway.

@freaktechnik
Copy link
Contributor Author

Well, given how the helper seems to work it will just assume that there is a folder called @octokit, and a file called rest would be a test.

@novemberborn
Copy link
Member

@ not matching makes it considered as an internal module, but it should not be considered a test file anyway.

Unfortunately we resolve the path relative to the file being linted, and when that's done with a scoped package we end up with a relative path inside the test directory: test/@octokit/rest.

I'll PR up a fix soon.

novemberborn added a commit that referenced this issue Jun 2, 2019
Only attempt to classify imports that are file paths. Fixes #253.
@novemberborn
Copy link
Member

This should be fixed by #255.

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

Successfully merging a pull request may close this issue.

3 participants