Skip to content

no-manual-cleanup does not like require(modulaName) #125

Closed
@kentcdodds

Description

@kentcdodds

I've got code like this:

require(moduleName)

and no-manual-cleanup does this:

TypeError: Cannot read property 'match' of undefined
Occurred while linting /Users/kentcdodds/code/kcd-scripts/src/utils.js:39
    at VariableDeclarator (/Users/kentcdodds/code/kcd-scripts/node_modules/eslint-plugin-testing-library/rules/no-manual-cleanup.js:71:73)
    at /Users/kentcdodds/code/kcd-scripts/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/kentcdodds/code/kcd-scripts/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/Users/kentcdodds/code/kcd-scripts/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors (/Users/kentcdodds/code/kcd-scripts/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
    at NodeEventGenerator.enterNode (/Users/kentcdodds/code/kcd-scripts/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode (/Users/kentcdodds/code/kcd-scripts/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:634:23)
    at /Users/kentcdodds/code/kcd-scripts/node_modules/eslint/lib/linter/linter.js:936:32
    at Array.forEach (<anonymous>)

This is because of this code:

const value = node.source.value as string;
const testingLibraryWithCleanup = value.match(CLEANUP_LIBRARY_REGEX);

It should check whether value exists before calling match :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions