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

"npm run test" fails with an error about ./lib/rules/no-warning-comments #1546

Closed
gajus opened this issue Oct 11, 2021 · 8 comments · Fixed by #1548 or #1562
Closed

"npm run test" fails with an error about ./lib/rules/no-warning-comments #1546

gajus opened this issue Oct 11, 2021 · 8 comments · Fixed by #1548 or #1562
Labels

Comments

@gajus
Copy link

gajus commented Oct 11, 2021

$ git clone git@github.com:sindresorhus/eslint-plugin-unicorn.git test
$ cd test
$ npm install
$ npm run test
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Failed to load plugin 'unicorn' declared in 'BaseConfig » /Users/gajus/Documents/dev/gajus/test/node_modules/xo/config/plugins.cjs': Package subpath './lib/rules/no-warning-comments' is not defined by "exports" in /Users/gajus/Documents/dev/gajus/test/node_modules/eslint/package.json
Referenced from: /Users/gajus/Documents/dev/gajus/test/node_modules/xo/config/plugins.cjs
    at new NodeError (node:internal/errors:371:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:335:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:560:3)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:94:18)
    at Object.<anonymous> (/Users/gajus/Documents/dev/gajus/test/node_modules/eslint-plugin-unicorn/rules/expiring-todo-comments.js:5:18)

Tried using node v14 and node v16.

@gajus gajus added the bug label Oct 11, 2021
@gajus
Copy link
Author

gajus commented Oct 11, 2021

For what it is worth, I worked around this by locally removing exports from /Users/gajus/Documents/dev/gajus/test/node_modules/eslint/package.json.

@gajus
Copy link
Author

gajus commented Oct 12, 2021

@sindresorhus That commit does not address this issue. Getting the same error running the same commands on main branch.

@fisker
Copy link
Collaborator

fisker commented Oct 12, 2021

Ah, I misunderstood this issue, it fails because current version of xo don't support ESLint 8, we only need update eslint-plugin-unicorn on xo side to fix.

# `xo` can't work on ESLint 8

@gajus
Copy link
Author

gajus commented Oct 12, 2021

$ npm install eslint@7
$ npm run test

still produces errors

 prefer-switch.mjs › Invalid #23
         1 | function unicorn() {
         2 | 	if (foo === 1) {
         3 | 		if (true) {
         4 | 			throw error;
         5 | 		} else {
         6 | 			return false;
         7 | 		}
         8 | 	}
         9 | 	else if (foo === 2) {
        10 | 		if (true) {
        11 | 			throw error;
        12 | 		}
        13 | 	// no else, need break
        14 | 	}
        15 | 	else if (foo === 3) {
        16 | 		if (a) {
        17 | 			return a;
        18 | 		} else if (b) {
        19 | 			return b;
        20 | 		} else if (c) {
        21 | 			return c;
        22 | 		} else if (d) {
  no-keyword-prefix.mjs › invalid: var { newFoo = 1 } = foo;

  Error thrown in test:

  AssertionError {
    actual: 0,
    code: 'ERR_ASSERTION',
    expected: 1,
    generatedMessage: false,
    operator: 'strictEqual',
    message: 'Should have 1 error but had 0: []',
  }

  › testInvalidTemplate (node_modules/eslint/lib/rule-tester/rule-tester.js:724:24)
  › node_modules/eslint/lib/rule-tester/rule-tester.js:958:29
  › node_modules/eslint-ava-rule-tester/index.js:28:9



  no-keyword-prefix.mjs › invalid: function foo({ newBar = 'default value' }) {};

  Error thrown in test:

  AssertionError {
    actual: 0,
    code: 'ERR_ASSERTION',
    expected: 1,
    generatedMessage: false,
    operator: 'strictEqual',
    message: 'Should have 1 error but had 0: []',
  }

  › testInvalidTemplate (node_modules/eslint/lib/rule-tester/rule-tester.js:724:24)
  › node_modules/eslint/lib/rule-tester/rule-tester.js:958:29
  › node_modules/eslint-ava-rule-tester/index.js:28:9



  no-keyword-prefix.mjs › invalid: const newFoo = 0; function foo({ newBar = newFoo}) {}

  Error thrown in test:

  AssertionError {
    actual: 1,
    code: 'ERR_ASSERTION',
    expected: 2,
    generatedMessage: false,
    operator: 'strictEqual',
    message: `Should have 2 errors but had 1: [␊
      {␊
        ruleId: 'no-keyword-prefix',␊
        severity: 1,␊
        message: 'Do not prefix identifiers with keyword \`new\`.',␊
        line: 1,␊
        column: 7,␊
        nodeType: 'Identifier',␊
        messageId: 'noKeywordPrefix',␊
        endLine: 1,␊
        endColumn: 13␊
      }␊
    ]`,
  }

  › ]
  › testInvalidTemplate (node_modules/eslint/lib/rule-tester/rule-tester.js:724:24)
  › node_modules/eslint/lib/rule-tester/rule-tester.js:958:29
  › node_modules/eslint-ava-rule-tester/index.js:28:9



  no-keyword-prefix.mjs › invalid: const { newFoo = false } = foo;

  Error thrown in test:

  AssertionError {
    actual: 0,
    code: 'ERR_ASSERTION',
    expected: 1,
    generatedMessage: false,
    operator: 'strictEqual',
    message: 'Should have 1 error but had 0: []',
  }

  › testInvalidTemplate (node_modules/eslint/lib/rule-tester/rule-tester.js:724:24)
  › node_modules/eslint/lib/rule-tester/rule-tester.js:958:29
  › node_modules/eslint-ava-rule-tester/index.js:28:9



  no-keyword-prefix.mjs › invalid: const { newFoo = newBar } = foo;

  Error thrown in test:

  AssertionError {
    actual: 0,
    code: 'ERR_ASSERTION',
    expected: 1,
    generatedMessage: false,
    operator: 'strictEqual',
    message: 'Should have 1 error but had 0: []',
  }

  › testInvalidTemplate (node_modules/eslint/lib/rule-tester/rule-tester.js:724:24)
  › node_modules/eslint/lib/rule-tester/rule-tester.js:958:29
  › node_modules/eslint-ava-rule-tester/index.js:28:9



  no-array-for-each.mjs › Invalid #69
        1 | [{children, index: 1}].forEach((children, index) => process(children, index))

  Output

  Difference:

    `␊
  -   1 | for (const [index, children] of [{children, index: 1}].entries())  process(children, index)␊
  + > 1 | [{children, index: 1}].forEach((children, index) => process(children, index))␊
  +     |                        ^^^^^^^ Use \`for…of\` instead of \`Array#forEach(…)\`.␊
    `

  › file://test/utils/snapshot-rule-tester.mjs:177:9



  no-array-for-each.mjs › Invalid #70
        1 | [{children: 1, index}].forEach((children, index) => process(children, index))

  Output

  Difference:

    `␊
  -   1 | for (const [index, children] of [{children: 1, index}].entries())  process(children, index)␊
  + > 1 | [{children: 1, index}].forEach((children, index) => process(children, index))␊
  +     |                        ^^^^^^^ Use \`for…of\` instead of \`Array#forEach(…)\`.␊
    `

  › file://test/utils/snapshot-rule-tester.mjs:177:9



  prefer-dom-node-text-content.mjs › Invalid #7
        1 | const {innerText = "default text"} = node;

  Invalid case should has at least one error.

  Value is deeply equal:

  []

  › file://test/utils/snapshot-rule-tester.mjs:159:8



  prefer-dom-node-text-content.mjs › Invalid #11
        1 | ({innerText = "default text"} = node);

  Invalid case should has at least one error.

  Value is deeply equal:

  []

  › file://test/utils/snapshot-rule-tester.mjs:159:8



  prefer-module.mjs › Invalid #3
        1 | const foo = { __dirname};

  Invalid case should has at least one error.

  Value is deeply equal:

  []

  › file://test/utils/snapshot-rule-tester.mjs:159:8



  prefer-module.mjs › Invalid #4
        1 | const foo = {__filename, };

  Invalid case should has at least one error.

  Value is deeply equal:

  []

  › file://test/utils/snapshot-rule-tester.mjs:159:8



  prefer-number-properties.mjs › invalid: const foo = {NaN};

  Error thrown in test:

  AssertionError {
    actual: 0,
    code: 'ERR_ASSERTION',
    expected: 1,
    generatedMessage: false,
    operator: 'strictEqual',
    message: 'Should have 1 error but had 0: []',
  }

  › testInvalidTemplate (node_modules/eslint/lib/rule-tester/rule-tester.js:724:24)
  › node_modules/eslint/lib/rule-tester/rule-tester.js:958:29
  › node_modules/eslint-ava-rule-tester/index.js:28:9



  prefer-number-properties.mjs › Invalid #10
        1 | const foo = {Infinity};

  Invalid case should has at least one error.

  Value is deeply equal:

  []

  › file://test/utils/snapshot-rule-tester.mjs:159:8

  ─

@fisker
Copy link
Collaborator

fisker commented Oct 12, 2021

The lint(xo) needs eslint7, the test(ava) needs eslint8, before we fix this, you'll have to use npx ava to run test locally.

@fisker
Copy link
Collaborator

fisker commented Oct 12, 2021

Or just remove xo && from this line,

"test": "xo && nyc ava",
, it's fine.

@gajus
Copy link
Author

gajus commented Oct 20, 2021

This remains a blocker.

@fisker
Copy link
Collaborator

fisker commented Oct 29, 2021

Fixed by #1562

@fisker fisker closed this as completed Oct 29, 2021
@fisker fisker mentioned this issue Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants