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

function f() { return; } leads to TypeError: Cannot read properties of null (reading 'type') #38

Open
andersk opened this issue Jun 7, 2024 · 0 comments · May be fixed by #40
Open

Comments

@andersk
Copy link

andersk commented Jun 7, 2024

Linting a function with an empty return statement:

function f() { return; }

produces this crash:

Oops! Something went wrong! :(

ESLint: 8.57.0

TypeError: Cannot read properties of null (reading 'type')
Occurred while linting /tmp/test/test.js:1
Rule: "prefer-arrow-functions/prefer-arrow-functions"
    at getBodySource (/tmp/test/node_modules/.pnpm/eslint-plugin-prefer-arrow-functions@3.3.2_eslint@8.57.0/node_modules/eslint-plugin-prefer-arrow-functions/dist/prefer-arrow-functions.js:59:36)
    at getFunctionDescriptor (/tmp/test/node_modules/.pnpm/eslint-plugin-prefer-arrow-functions@3.3.2_eslint@8.57.0/node_modules/eslint-plugin-prefer-arrow-functions/dist/prefer-arrow-functions.js:156:23)
    at writeArrowConstant (/tmp/test/node_modules/.pnpm/eslint-plugin-prefer-arrow-functions@3.3.2_eslint@8.57.0/node_modules/eslint-plugin-prefer-arrow-functions/dist/prefer-arrow-functions.js:151:22)
    at Object.fix (/tmp/test/node_modules/.pnpm/eslint-plugin-prefer-arrow-functions@3.3.2_eslint@8.57.0/node_modules/eslint-plugin-prefer-arrow-functions/dist/prefer-arrow-functions.js:277:60)
    at normalizeFixes (/tmp/test/node_modules/.pnpm/eslint@8.57.0/node_modules/eslint/lib/linter/report-translator.js:194:28)
    at /tmp/test/node_modules/.pnpm/eslint@8.57.0/node_modules/eslint/lib/linter/report-translator.js:365:49
    at Object.report (/tmp/test/node_modules/.pnpm/eslint@8.57.0/node_modules/eslint/lib/linter/linter.js:1047:41)
    at FunctionDeclaration[parent.type!="ExportDefaultDeclaration"] (/tmp/test/node_modules/.pnpm/eslint-plugin-prefer-arrow-functions@3.3.2_eslint@8.57.0/node_modules/eslint-plugin-prefer-arrow-functions/dist/prefer-arrow-functions.js:275:29)
    at ruleErrorHandler (/tmp/test/node_modules/.pnpm/eslint@8.57.0/node_modules/eslint/lib/linter/linter.js:1076:28)
    at /tmp/test/node_modules/.pnpm/eslint@8.57.0/node_modules/eslint/lib/linter/safe-emitter.js:45:58
andersk added a commit to andersk/eslint-plugin-prefer-arrow-functions that referenced this issue Jun 7, 2024
Fixes JamieMason#38.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
@andersk andersk linked a pull request Jun 7, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant