ava icon indicating copy to clipboard operation
ava copied to clipboard

Eslint fails on node-no-missing-require and node/no-unpublished-require

Open NickColley opened this issue 3 years ago • 1 comments

const test = require("ava");

test("should be true", async (assert) => {
  assert.true(true);
});

With eslint node/recommended I get:

error  "ava" is not found (node/no-missing-require)
error  "ava" is not published (node/no-unpublished-require)

Is there something missing from my configuration or ava's published package.json?

NickColley avatar Aug 18 '22 12:08 NickColley

Hey @NickColley you'll probably need to adjust the allowModules plugin setting to exclude ava. I had to do a similar thing for eslint-plugin-import (see https://github.com/mysticatea/eslint-plugin-node/issues/314). Most of eslint plugins do not play well yet with exports maps (which ava 4.x uses)

jonathansamines avatar Aug 29 '22 16:08 jonathansamines

I ran into the no-unpublished-require rule as well and the docs explain it pretty good: https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/no-unpublished-require.md#-rule-details

In my case it was triggered because ava is a devDependency but I didn't make use of files and the test files weren't added to .npmignore yet so they would have actually been published to npm.

Windvis avatar Oct 13 '22 12:10 Windvis

I wonder given my repository has "private" set to true so it can never be published if these rules could automatically relax?

Here's the config I ended up going with:

{
  "eslintConfig": {
    "rules": {
      "node/no-unpublished-import": "off",
      "node/no-missing-import": [
        "error",
        {
          "allowModules": [
            "ava"
          ]
        }
      ]
    }
  }
}

NickColley avatar Oct 22 '22 21:10 NickColley

@NickColley I had the same thoughts and that's indeed a popular request in the eslint-plugin-node repo: https://github.com/mysticatea/eslint-plugin-node/issues/77 Sadly that projects is kind of unmaintained at the moment.

I did however create a PR in the community fork but that still needs to be reviewed.

Windvis avatar Oct 23 '22 07:10 Windvis

Seems like this is already discussed then, thank you for your time.

NickColley avatar Oct 23 '22 08:10 NickColley