Skip to content

Add no-ignored-test-files rule (fixes #51) #56

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

Merged
merged 1 commit into from
Apr 4, 2016

Conversation

jfmengels
Copy link
Contributor

Add no-ignored-test-files rule (fixes #51)

I would like to add more checks to see whether the test is in the AVA glob (with an option to de-/activate or set a custom glob), but I haven't found (yet, haven't searched much for now) a library that simply tells me whether a file matches a glob, and I don't know if we can reliably get the cwd from ESLint (or the editor running ESLint).
This can be added later to the rule though. I might take a look at it later, or someone could take a look too if interested.

@jfmengels jfmengels force-pushed the no-ignored-test-files branch from ea68124 to a547b54 Compare March 30, 2016 22:14
@novemberborn
Copy link
Member

I would like to add more checks to see whether the test is in the AVA glob (with an option to de-/activate or set a custom glob), but I haven't found (yet, haven't searched much for now) a library that simply tells me whether a file matches a glob

The watcher does this, see https://github.com/sindresorhus/ava/blob/005b656b9950ab3fa1e2bd9af326d5b39540e71b/lib/watcher.js#L333:L379. It uses https://www.npmjs.com/package/multimatch.

@jfmengels
Copy link
Contributor Author

From what I could test, in Atom's ESLint plugin (the Atom plugin that runs ESLint I mean), process.cwd() returns the current file's folder everytime, not the root of the project, and ESLint's context.getFilename() returns the file's absolute path. Meaning it becomes pretty hard to figure out the project's root folder.

So it means two things:

  • Globbing becomes pretty hard, because even the default glob is relative to the folder Ava is run from.
  • Anybody who uses eslint-plugin-ava (at least in Atom) will have this rule ringing loudly for every file if his project, dev folder, or any higher-up folder is named fixtures/helpers.

The second is obviously pretty rare (I'd think at least), but it can be problematic for some users. Let me know what you guys think about this.

@novemberborn
Copy link
Member

@jfmengels could use https://www.npmjs.com/package/pkg-up until you find a package that depends on AVA?

@jfmengels
Copy link
Contributor Author

@novemberborn Sounded good, so I tried it and it works well. I disabled the rule altogether progammatically when no package.json is found (debatable, but probably pretty rare anyway. The rule is not worth much without it, nor all that reliable).

The result is pretty rad IMO!
screenshot from 2016-04-02 20-08-10

Haven't squashed the commits so that I could revert back to previous impl, as someone might find it unacceptable to depend on a package.json file. I'll squash and merge when people are happy with this.

ignoredFolder = 'helpers';
}

if (ignoredFolder) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use multimatch here as well? Copy excludePatterns without the leading ! and you should be good to go.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! Will do that (won't put node_modules though as ESLint ignores them already)

@novemberborn
Copy link
Member

Do people put test factories in their helpers? That might be a legitimate ava import. Though you could disable the rule in that case or customize the pattern.


Very cool @jfmengels!

@jfmengels
Copy link
Contributor Author

@novemberborn @jamestalmage had the same comment #51 (comment), and I agree that you should then simply disable the rule. There was an interesting proposition avajs/ava#695 for test macros which would be better. We only lint an error if you import AVA and create a test, but we could then make an exception if you're defining a macro

@jfmengels jfmengels force-pushed the no-ignored-test-files branch from b25192e to a4b65ae Compare April 3, 2016 14:38
@jfmengels
Copy link
Contributor Author

Updated :)

@novemberborn
Copy link
Member

We only lint an error if you import AVA and create a test, but we could then make an exception if you're defining a macro

That sounds good.

@@ -0,0 +1,92 @@
# Ensure no tests are written in ignored files

When searching for tests, AVA ignores files contained in folders named `fixtures` or `helpers`. By default, it will search in `test.js test-*.js test/**/*.js`, which you can override by specifying a path when launching AVA or in the [AVA configuration in the `package.json` file] ](https://github.com/sindresorhus/ava#configuration).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention node_modules here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, ESLint ignores node_modules anyway. I don't really mind adding it, but for consistency we'd have to add it to every rule. I think that users of Node or ESLint know that node_modules/ should not be touched.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but you're describing AVA's behavior here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. I've added the mention about node_modules, and to clarify, a message saying that they won't be linted due to ESLint.

@novemberborn
Copy link
Member

Nothing further from me 👯

@jfmengels jfmengels force-pushed the no-ignored-test-files branch 2 times, most recently from e1ff1d3 to 46dca09 Compare April 4, 2016 10:25
@sindresorhus
Copy link
Member

LGTM

@jfmengels
Copy link
Contributor Author

Cool, I'll squash and merge then.

@jfmengels jfmengels force-pushed the no-ignored-test-files branch from 46dca09 to b0da32c Compare April 4, 2016 19:57
@jamestalmage
Copy link
Contributor

@jfmengels - FYI - GH has a new "Squash and Merge" feature built in. Just click the merge button and you will see a drop down that gives you that option.

Ideally you would use that, even for 1 commit PR's. It avoids creating an extra merge commit.

If there are multiple commits that you want to keep separate, the old merge method is fine.

@jfmengels
Copy link
Contributor Author

Aah. Yeah I knew about it, but I thought it was something that you needed to activate as I didn't see it. But it only shows when you click the merge button once apparently ^^'

(Hoping for a rebase button to come soon)

@jfmengels jfmengels merged commit ecc990b into master Apr 4, 2016
@jfmengels jfmengels deleted the no-ignored-test-files branch April 4, 2016 20:11
@jamestalmage
Copy link
Contributor

You usually only need to rebase if there is a merge conflict (in which case you probably want to do some edits / testing locally). I guess it could be useful for selectively squashing (i.e. ending up with less commits, but still more than one), and for editing commit messages. But that is a rare enough need I'm not clamoring for it. I would much rather see improvements to issue management first.

@jfmengels
Copy link
Contributor Author

I mean merge rebase in the sense of no merge commits. I like straight lines.

@sindresorhus
Copy link
Member

I mean merge rebase in the sense of no merge commits. I like straight lines.

That's exactly what the squash button does, but you seems you used the old merge button.

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 this pull request may close these issues.

Check parent directory name
4 participants