Kai Cataldo 4ac9c7afe2
Upgrade to ESLint v7 (#11857)
* Upgrade to ESLint v7

* Upgrade eslint-plugin-import

* Update peer deps

* Remove max-len from ESLint config

* Update tests

* Only test babel-eslint-* packages in Node >=10

* Remove babel-eslint

* Fix linking in dev

* Add comment to Makefile

* Fix e2e tests

* Add --ignore-engines flag when installing in ESLint packages

* fix: convert tt.questionDot to Punctuator

* chore: update lockfile

Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
2020-07-29 19:11:48 -04:00

79 lines
2.4 KiB
JavaScript

import rule from "../../src/rules/no-undefined-identifier";
import RuleTester from "../../../babel-eslint-shared-fixtures/utils/RuleTester";
const error =
"Use path.scope.buildUndefinedNode() to create an undefined identifier directly.";
const ruleTester = new RuleTester({
parserOptions: { sourceType: "module" },
});
ruleTester.run("no-undefined-identifier", rule, {
valid: [
`_.identifier("undefined")`,
`_.Identifier("undefined")`,
`import * as t from "lib"; t.identifier("undefined");`,
`function f(_) { _.types.identifier("undefined"); }`,
`import * as t from "@babel/types"; t.identifier("not_undefined");`,
`path.scope.buildUndefinedNode();`,
],
invalid: [
{
code: `import { identifier } from "@babel/types"; identifier("undefined");`,
errors: [error],
},
{
code: `import { Identifier } from "@babel/types"; Identifier("undefined");`,
errors: [error],
},
{
code: `import * as t from "@babel/types"; t.identifier("undefined");`,
errors: [error],
},
{
code: `import * as t from "@babel/types"; var { identifier } = t; identifier("undefined");`,
errors: [error],
},
{
code: `import { identifier as id } from "@babel/types"; id("undefined");`,
errors: [error],
},
{
code: `import * as babel from "@babel/core"; babel.types.identifier("undefined");`,
errors: [error],
},
{
code: `import { types } from "@babel/core"; types.identifier("undefined");`,
errors: [error],
},
{
code: `import { types as t } from "@babel/core"; t.identifier("undefined");`,
errors: [error],
},
{
code: `export default function plugin(babel) { babel.types.identifier("undefined") }`,
errors: [error],
},
{
code: `export default function plugin({ types }) { types.identifier("undefined") }`,
errors: [error],
},
{
code: `export default function plugin({ types: t }) { t.identifier("undefined") }`,
errors: [error],
},
{
code: `export default ({ types }) => { types.identifier("undefined") }`,
errors: [error],
},
{
code: `module.exports = function plugin({ types }) { types.identifier("undefined") }`,
errors: [error],
},
{
code: `import { declare } from "@babel/helper-plugin-utils"; declare(({ types }) => { types.identifier("undefined") });`,
errors: [error],
},
],
});