Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

ESLint use-magic-construct throwing error #52

Open
MagicLegend opened this issue May 24, 2021 · 0 comments
Open

ESLint use-magic-construct throwing error #52

MagicLegend opened this issue May 24, 2021 · 0 comments

Comments

@MagicLegend
Copy link

MagicLegend commented May 24, 2021

Describe the bug

In a specific scenario we have in our PWA v3 instance the linter bugs out and dies. This is preventing us linting the entire project in one go.

Did you try recovering your dependencies?

They are coming from our PWA v3 installation.

Environment

Node 15.5.1
NPM 7.4.0
Other versions are locked in package-lock.json in the example repo.

Steps to reproduce

Repo that should show the issue:
https://github.com/MagicLegend/spwa-eslint-issue

  1. Run npm run eslint:1
  2. Observe error thrown

Expected behavior

Linter throwing use-magic-construct rule.

Actual behavior

± % npm run eslint:1
                                                                                                                                                                                                                                                                              
> [email protected] eslint:1                                                                                                                                                                                                                                            
> eslint --cache --resolve-plugins-relative-to . --ignore-pattern *.test.* ./src/Test.handler.js
                                                                                                                                       
Warning: React version was set to "detect" in eslint-plugin-react settings, but the "react" package is not installed. Assuming latest React version for linting.
                                                                   
Oops! Something went wrong! :(
                                                                   
ESLint: 7.27.0                             
                                                                   
TypeError: Cannot read property 'name' of null
Occurred while linting /home/magiclegend/Documents/tmp/spwa-eslint-issue/src/Test.handler.js:13
    at MethodDefinition (/home/magiclegend/Documents/tmp/spwa-eslint-issue/node_modules/@scandipwa/eslint-plugin-scandipwa-guidelines/lib/rules/use-magic-construct.js:22:47)                                                                                                 
    at /home/magiclegend/Documents/tmp/spwa-eslint-issue/node_modules/eslint/lib/linter/safe-emitter.js:45:58                                                                                                                                                                 
    at Array.forEach (<anonymous>)
    at Object.emit (/home/magiclegend/Documents/tmp/spwa-eslint-issue/node_modules/eslint/lib/linter/safe-emitter.js:45:38)                                                                                                                                                   
    at NodeEventGenerator.applySelector (/home/magiclegend/Documents/tmp/spwa-eslint-issue/node_modules/eslint/lib/linter/node-event-generator.js:293:26)                                                                                                                    
    at NodeEventGenerator.applySelectors (/home/magiclegend/Documents/tmp/spwa-eslint-issue/node_modules/eslint/lib/linter/node-event-generator.js:322:22)
    at NodeEventGenerator.enterNode (/home/magiclegend/Documents/tmp/spwa-eslint-issue/node_modules/eslint/lib/linter/node-event-generator.js:336:14)                                                                                                                         
    at CodePathAnalyzer.enterNode (/home/magiclegend/Documents/tmp/spwa-eslint-issue/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:711:23)                                                                                                         
    at /home/magiclegend/Documents/tmp/spwa-eslint-issue/node_modules/eslint/lib/linter/linter.js:954:32
    at Array.forEach (<anonymous>) 

Reproducible demo

https://github.com/MagicLegend/spwa-eslint-issue

Note that I've also gotten it to throw this when there is no Namespace:

± % eslint --resolve-plugins-relative-to . <path_to_specific_handler>.handler.js
Warning: React version was set to "detect" in eslint-plugin-react settings, but the "react" package is not installed. Assuming latest React version for linting.

Oops! Something went wrong! :(

ESLint: 7.26.0

TypeError [ERR_INVALID_ARG_TYPE]: The "from" argument must be of type string. Received undefined
    at new NodeError (node:internal/errors:278:15)
    at validateString (node:internal/validators:123:11)
    at Object.relative (node:path:1095:5)
    at generateNamespace (/home/magiclegend/Documents/puma-docker/src/node_modules/@scandipwa/eslint-plugin-scandipwa-guidelines/lib/rules/use-namespace.js:169:31)
    at ExportNamedDeclaration > ClassDeclaration,CallExpression[callee.type='MemberExpression'][callee.object.name!=/.+Dispatcher/]:matches([callee.property.name='then'], [callee.property.name='catch']) > ArrowFunctionExpression,ExportNamedDeclaration > VariableDeclaration > VariableDeclarator > ArrowFunctionExpression (/home/magiclegend/Documents/puma-docker/src/node_modules/@scandipwa/eslint-plugin-scandipwa-guidelines/lib/rules/use-namespace.js:218:31)
    at /home/magiclegend/.nvm/versions/node/v15.5.1/lib/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/home/magiclegend/.nvm/versions/node/v15.5.1/lib/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/home/magiclegend/.nvm/versions/node/v15.5.1/lib/node_modules/eslint/lib/linter/node-event-generator.js:256:26)
    at NodeEventGenerator.applySelectors (/home/magiclegend/.nvm/versions/node/v15.5.1/lib/node_modules/eslint/lib/linter/node-event-generator.js:285:22)

When reverting @scandipwa/eslint-plugin-scandipwa-guidelines back to ^1.10 this no longer throws.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant