JamieMason / eslint-plugin-prefer-arrow-functions

Auto-fix plain Functions into Arrow Functions, in all cases where conversion would result in the same behaviour
https://www.npmjs.com/package/eslint-plugin-prefer-arrow-functions
MIT License
43 stars 11 forks source link

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

Open andersk opened 3 weeks ago

andersk commented 3 weeks ago

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