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

Enforce rules based on "engines" field in package.json #281

Merged
merged 14 commits into from
Jan 20, 2018

Conversation

pvdlg
Copy link
Contributor

@pvdlg pvdlg commented Jan 7, 2018

This allow to enable specific rules/rules configuration based on the range defined in engines field in package.json or the nodeVersion option.

If nodeVersion is set to false 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 above
  • prefer-rest-params for Node 6 and above
  • prefer-spread for Node 5 and above
  • prefer-destructuring for Node 6 and above

Should 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 in engines.node or nodeEngine. 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

@pvdlg pvdlg force-pushed the node-engines-rules branch 2 times, most recently from cb75e3f to c8058c9 Compare January 7, 2018 18:47
@sindresorhus
Copy link
Member

Maybe we can make that automatic if the users have AVA in their dependencies?

Yeah, let's do that.

@pvdlg
Copy link
Contributor Author

pvdlg commented Jan 8, 2018

AVA doesn't seems to expose an API to read its config to figure out the files option.

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

@pvdlg
Copy link
Contributor Author

pvdlg commented Jan 10, 2018

I added the default list of AVA files. Let me know you'd prefer something else.

'prefer-destructuring': {
'6.0.0': ['error', {array: true, object: true}, {enforceForRenamedProperties: true}]
}
};
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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

Copy link
Member

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

Copy link
Contributor Author

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
Copy link
Member

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`.
Copy link
Member

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 your package.json.

How about this?

@sindresorhus
Copy link
Member

Do I have a convenient way to determine where are the AVA test files for the current user?

The list you added works if the user just runs AVA with $ ava, but they could be running it with $ ava foo.js and we wouldn't detect it. Those file patterns might also match users of other test frameworks which doesn't compile like AVA does, so I think this approach is a no-go.

Another approach would be to just run a simple regex for require('ava') or from 'ava'; at the top of the file.

@sindresorhus
Copy link
Member

That should be solved once mysticatea/eslint-plugin-node@846e677 get released. We could enable the rule then.

👍

@pvdlg
Copy link
Contributor Author

pvdlg commented Jan 14, 2018

The list you added works if the user just runs AVA with $ ava, but they could be running it with $ ava foo.js and we wouldn't detect it. Those file patterns might also match users of other test frameworks which doesn't compile like AVA does, so I think this approach is a no-go.
Another approach would be to just run a simple regex for require('ava') or from 'ava'; at the top of the file.

Ok make sense. Should implement this way then?

@pvdlg
Copy link
Contributor Author

pvdlg commented Jan 14, 2018

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.
That would prevent users to toggles rules or to use overrides in the case of AVA files.

@sindresorhus
Copy link
Member

Yeah, let's leave it out for now.

@pvdlg
Copy link
Contributor Author

pvdlg commented Jan 14, 2018

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?

@sindresorhus
Copy link
Member

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.

@pvdlg
Copy link
Contributor Author

pvdlg commented Jan 20, 2018

Ok revert is done. I pushed the previous code to the ava-default-ignore branch.

@sindresorhus sindresorhus merged commit 0d18368 into xojs:master Jan 20, 2018
@sindresorhus
Copy link
Member

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 :)

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

Successfully merging this pull request may close these issues.

None yet

2 participants