-
-
Notifications
You must be signed in to change notification settings - Fork 285
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
Enforce rules based on "engines" field in package.json #281
Conversation
cb75e3f
to
c8058c9
Compare
Yeah, let's do that. |
AVA doesn't seems to expose an API to read its config to figure out the Do I have a convenient way to determine where are the AVA test files for the current user? If no I can use the default that would be the list here |
I added the default list of AVA files. Let me know you'd prefer something else. |
lib/options-manager.js
Outdated
'prefer-destructuring': { | ||
'6.0.0': ['error', {array: true, object: true}, {enforceForRenamedProperties: true}] | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Id didn't include it becasue it's deprecated. See https://eslint.org/docs/rules/prefer-reflect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I didn't realize. We can eventually fix that: sindresorhus/eslint-plugin-unicorn#142
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a bunch of rules to add from eslint-plugin-unicorn
and some of them should apply only for specific Node.js version. But that might be better to do that in a different PR.
main.js
Outdated
@@ -21,6 +22,7 @@ const cli = meow(` | |||
--space Use space indent instead of tabs [Default: 2] | |||
--no-semicolon Prevent use of semicolons | |||
--prettier Conform to Prettier code style | |||
--node-version Range of Node version to support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Node
=> Node.js
readme.md
Outdated
@@ -27,6 +27,7 @@ Uses [ESLint](http://eslint.org) underneath, so issues regarding rules should be | |||
- No need to specify file paths to lint as it lints all JS files except for [commonly ignored paths](#ignores). | |||
- [Config overrides per files/globs.](#config-overrides) | |||
- Includes many useful ESLint plugins, like [`unicorn`](https://github.com/sindresorhus/eslint-plugin-unicorn), [`import`](https://github.com/benmosher/eslint-plugin-import), [`ava`](https://github.com/avajs/eslint-plugin-ava), [`node`](https://github.com/mysticatea/eslint-plugin-node) and more. | |||
- Automatically enable or disable rules based on the [engines](https://docs.npmjs.com/files/package.json#engines) of your `package.json`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Automatically toggles rules based on the
engines
field in yourpackage.json
.
How about this?
The list you added works if the user just runs AVA with Another approach would be to just run a simple regex for |
👍 |
6091205
to
b5c5ebb
Compare
Ok make sense. Should implement this way then? |
Actually thinking about the AVA files path issue, I wonder if it's a good idea to use a regex to detect if AVA is imported. |
Yeah, let's leave it out for now. |
I'm confused, do you mean leaving the default AVA paths that I set in the PR, or removing them? Like should I revert a78e02e or keep it? |
Revert, but put it in a separate branch so we can continue it later. It's not a priority now, but I would like to solve it at some point. |
19549e1
to
dccf3d8
Compare
Ok revert is done. I pushed the previous code to the ava-default-ignore branch. |
This looks excellent. Thanks so much for working on this @pvdlg. I'm really happy about being able to use newer rules without having to manually configure them :) |
This allow to enable specific rules/rules configuration based on the range defined in
engines
field inpackage.json
or thenodeVersion
option.If
nodeVersion
is set tofalse
then the old behavior is resumed: no Node version specific rules are enabled.The following rules are enable:
promise/prefer-await-to-then
for Node 8 and aboveprefer-rest-params
for Node 6 and aboveprefer-spread
for Node 5 and aboveprefer-destructuring
for Node 6 and aboveShould I add more?
We could later add node/no-unsupported-features by passing the value
opts.nodeEngine
in the version option.Unfortunately for now the
version
option of the rule accept only a specific version and not the range defined inengines.node
ornodeEngine
. That should be solved once mysticatea/eslint-plugin-node@846e677 get released. We could enable the rule then.I also added a "Tips" for overriding the test when using AVA. Maybe we can make that automatic if the users have AVA in their dependencies?
Fix #266