mirror of
https://github.com/hanzoai/eslint.git
synced 2026-10-30 19:38:10 +00:00
* chore: remove formatting-related lint rules internally * chore: formatted files with Prettier via trunk fmt * rm .prettierrc.json * chore: correct comment directives and formatting * Apply introduced fmt changes post-merge * Also disable MD010 and MD030 in preparation for 19355 * Also disable MD013 in preparation for 19355 * Updated tools/update-rule-type-headers.js to print tabs * Fix introduced issues from the main merge * Manually format conf/*.json * Switch conf/*.json files back to two spaces, per prettier config * chore: empty commit to hopefully unblock GitHub
75 lines
1.8 KiB
JavaScript
75 lines
1.8 KiB
JavaScript
/**
|
|
* @fileoverview Tests for the no-new-native-nonconstructor rule
|
|
* @author Sosuke Suzuki
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Requirements
|
|
//------------------------------------------------------------------------------
|
|
|
|
const rule = require("../../../lib/rules/no-new-native-nonconstructor"),
|
|
RuleTester = require("../../../lib/rule-tester/rule-tester");
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Tests
|
|
//------------------------------------------------------------------------------
|
|
|
|
const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2022 } });
|
|
|
|
ruleTester.run("no-new-native-nonconstructor", rule, {
|
|
valid: [
|
|
// Symbol
|
|
"var foo = Symbol('foo');",
|
|
"function bar(Symbol) { var baz = new Symbol('baz');}",
|
|
"function Symbol() {} new Symbol();",
|
|
"new foo(Symbol);",
|
|
"new foo(bar, Symbol);",
|
|
|
|
// BigInt
|
|
"var foo = BigInt(9007199254740991);",
|
|
"function bar(BigInt) { var baz = new BigInt(9007199254740991);}",
|
|
"function BigInt() {} new BigInt();",
|
|
"new foo(BigInt);",
|
|
"new foo(bar, BigInt);",
|
|
],
|
|
invalid: [
|
|
// Symbol
|
|
{
|
|
code: "var foo = new Symbol('foo');",
|
|
errors: [
|
|
{
|
|
message: "`Symbol` cannot be called as a constructor.",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "function bar() { return function Symbol() {}; } var baz = new Symbol('baz');",
|
|
errors: [
|
|
{
|
|
message: "`Symbol` cannot be called as a constructor.",
|
|
},
|
|
],
|
|
},
|
|
|
|
// BigInt
|
|
{
|
|
code: "var foo = new BigInt(9007199254740991);",
|
|
errors: [
|
|
{
|
|
message: "`BigInt` cannot be called as a constructor.",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "function bar() { return function BigInt() {}; } var baz = new BigInt(9007199254740991);",
|
|
errors: [
|
|
{
|
|
message: "`BigInt` cannot be called as a constructor.",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|