avajs / eslint-plugin-ava

ESLint rules for AVA
https://avajs.dev
MIT License
230 stars 49 forks source link

`prefer-t-regex` fails with `t.is()` with a single argument #347

Open ehmicky opened 2 years ago

ehmicky commented 2 years ago

When t.is() is passed 0 or 1 argument instead of 2, prefer-t-regex crashes.

This is related to https://github.com/avajs/eslint-plugin-ava/issues/346, but that other issue seems to be more focused on graceful failures in general.

Steps to reproduce

test.js:

import test from 'ava'

test('example', t => {
  t.is(true)
}) 

.eslintrc.yml:

parserOptions:
  sourceType: module
  ecmaVersion: 2022
plugins: [ava]
rules:
  ava/prefer-t-regex: 2
$ eslint test.js 

Oops! Something went wrong! :(

ESLint: 8.22.0

TypeError: Cannot read properties of undefined (reading 'regex')
Occurred while linting /home/ehmicky/Desktop/test.js:4
Rule: "ava/prefer-t-regex"
    at isRegExp (/home/ehmicky/Desktop/node_modules/eslint-plugin-ava/rules/prefer-t-regex.js:83:14)
    at equalityHandler (/home/ehmicky/Desktop/node_modules/eslint-plugin-ava/rules/prefer-t-regex.js:138:32)
    at /home/ehmicky/Desktop/node_modules/eslint-plugin-ava/rules/prefer-t-regex.js:195:5
    at /home/ehmicky/Desktop/node_modules/enhance-visitors/index.js:25:12
    at /home/ehmicky/Desktop/node_modules/enhance-visitors/index.js:15:7
    at ruleErrorHandler (/home/ehmicky/Desktop/node_modules/eslint/lib/linter/linter.js:1114:28)
    at /home/ehmicky/Desktop/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/home/ehmicky/Desktop/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/home/ehmicky/Desktop/node_modules/eslint/lib/linter/node-event-generator.js:297:26)

ESLint: 8.22.0 eslint-plugin-ava: 13.2.0 Ava: 4.3.1

fregante commented 2 months ago

Duplicate of https://github.com/avajs/eslint-plugin-ava/issues/346