-
Notifications
You must be signed in to change notification settings - Fork 49
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
Add support for ava.config.js
#192
Conversation
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.
Thanks for the PR @HenriBeck!
Config loading is a little more involved, I've left some inline comments.
Would be good to have tests as well.
util.js
Outdated
@@ -33,7 +34,15 @@ exports.getAvaConfig = filepath => { | |||
|
|||
try { | |||
const packageContent = JSON.parse(fs.readFileSync(filepath, 'utf8')); | |||
return (packageContent && packageContent.ava) || defaultResult; | |||
|
|||
if (packageContent && packageContent.ava) { |
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.
Strictly speaking AVA ignores "ava": {}
in favor of an ava.config.js
file. We should do the same here.
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.
From the docs:
To use an ava.config.js file:
It must be in the same directory as your package.json
Your package.json must not contain an ava property (or, if it does, it must be an empty object)
I thought it would prefer the ava object from 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.
No it throws an exception if it finds config in package.json
(that is, the "ava"
key contains a non-empty object) as well as an ava.config.js
file. Therefore if you find an empty object here, you need to check for ava.config.js
as well. But it may not exist, and that should be OK.
I'm not sure what we should do here when both configurations are provided. If we throw an exception how does ESLint surface that?
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.
When you throw an error in ESLint, it just ends the process. So I think throwing an error isn't an option here.
util.js
Outdated
const fileOptions = path.parse(filepath); | ||
const avaConfig = esmRequire(path.join(fileOptions.dir, 'ava.config.js')); | ||
|
||
return avaConfig.default; |
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.
The config file may export a factory method that's invoked with an options argument. For here, that should be {projectDir: fileOptions.dir}
.
We'll need to ignore MODULE_NOT_FOUND
errors and return defaultResult
instead.
Signed-off-by: Henri Beck <[email protected]>
@novemberborn I added support for the function. |
util.js
Outdated
@@ -33,7 +34,15 @@ exports.getAvaConfig = filepath => { | |||
|
|||
try { | |||
const packageContent = JSON.parse(fs.readFileSync(filepath, 'utf8')); | |||
return (packageContent && packageContent.ava) || defaultResult; | |||
|
|||
if (packageContent && packageContent.ava) { |
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.
No it throws an exception if it finds config in package.json
(that is, the "ava"
key contains a non-empty object) as well as an ava.config.js
file. Therefore if you find an empty object here, you need to check for ava.config.js
as well. But it may not exist, and that should be OK.
I'm not sure what we should do here when both configurations are provided. If we throw an exception how does ESLint surface that?
util.js
Outdated
@@ -2,6 +2,7 @@ | |||
const fs = require('fs'); | |||
const path = require('path'); | |||
const pkg = require('./package'); | |||
const esmRequire = require('esm')(module); |
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.
To be in sync with AVA itself, you need to set {cjs: false, mode: 'all'}
options.
ava.config.js
I've fixed the merge conflicts and brought the logic in line with AVA itself. I've also added some tests and updated the relevant rule documentation. @HenriBeck are you happy with these changes? @sindresorhus any thoughts? Would be good to merge and ship so we're compatible with both the latest AVA and ESLint. |
Yeah, I think it's the right thing to return the default config when there is no config/invalid config because throwing an error would completely abort eslint. A rule could be added which would validate the config maybe. |
Thanks. I'm waiting for a new
Yea, see #199. |
Looks great :) |
Co-authored-by: Mark Wubben <[email protected]> Adds support for checking the `ava.config.js` when there is no `ava` config inside `package.json`. This uses the `esm` module for parsing the config file. Fixes #191
Co-authored-by: Mark Wubben <[email protected]> Adds support for checking the `ava.config.js` when there is no `ava` config inside `package.json`. This uses the `esm` module for parsing the config file. Fixes #191
Adds support for checking the `ava.config.js` when there is no `ava` config inside `package.json`. This uses the `esm` module for parsing the config file. Fixes #191 Co-authored-by: Mark Wubben <[email protected]>
Must be similar to avajs#192
Adds support for checking the
ava.config.js
when there is noava
config insidepackage.json
.This uses the
esm
module for parsing the config file.Fixes #191