diff --git a/eslint/babel-eslint-plugin/tests/rules/new-cap.js b/eslint/babel-eslint-plugin/tests/rules/new-cap.js index 5fe53cbe39..d03adde071 100644 --- a/eslint/babel-eslint-plugin/tests/rules/new-cap.js +++ b/eslint/babel-eslint-plugin/tests/rules/new-cap.js @@ -37,36 +37,46 @@ ruleTester.run('babel/new-cap', rule, { "var x = Symbol('symbol')", "var x = _();", "var x = $();", - { code: "var x = Foo(42)", options: [{"capIsNew": false}] }, - { code: "var x = bar.Foo(42)", options: [{"capIsNew": false}] }, + { code: "var x = Foo(42)", options: [{ capIsNew: false }] }, + { code: "var x = bar.Foo(42)", options: [{ capIsNew: false }] }, + { code: "var x = Foo.bar(42)", options: [{ capIsNew: false }] }, "var x = bar[Foo](42)", - {code: "var x = bar['Foo'](42)", options: [{"capIsNew": false}] }, + { code: "var x = bar['Foo'](42)", options: [{ capIsNew: false }] }, "var x = Foo.bar(42)", - { code: "var x = new foo(42)", options: [{"newIsCap": false}] }, + { code: "var x = new foo(42)", options: [{ newIsCap: false }] }, "var o = { 1: function() {} }; o[1]();", "var o = { 1: function() {} }; new o[1]();", { code: "var x = Foo(42);", options: [{ capIsNew: true, capIsNewExceptions: ["Foo"] }] }, + { code: "var x = Foo(42);", options: [{ capIsNewExceptionPattern: "^Foo" }] }, { code: "var x = new foo(42);", options: [{ newIsCap: true, newIsCapExceptions: ["foo"] }] }, + { code: "var x = new foo(42);", options: [{ newIsCapExceptionPattern: "^foo" }] }, { code: "var x = Object(42);", options: [{ capIsNewExceptions: ["Foo"] }] }, { code: "var x = Foo.Bar(42);", options: [{ capIsNewExceptions: ["Bar"] }] }, { code: "var x = Foo.Bar(42);", options: [{ capIsNewExceptions: ["Foo.Bar"] }] }, + + { code: "var x = Foo.Bar(42);", options: [{ capIsNewExceptionPattern: "^Foo\\.." }] }, { code: "var x = new foo.bar(42);", options: [{ newIsCapExceptions: ["bar"] }] }, { code: "var x = new foo.bar(42);", options: [{ newIsCapExceptions: ["foo.bar"] }] }, + { code: "var x = new foo.bar(42);", options: [{ newIsCapExceptionPattern: "^foo\\.." }] }, + { code: "var x = new foo.bar(42);", options: [{ properties: false }] }, + { code: "var x = Foo.bar(42);", options: [{ properties: false }] }, + { code: "var x = foo.Bar(42);", options: [{ capIsNew: false, properties: false }] }, + // Babel-specific test cases. { code: "@MyDecorator(123) class MyClass{}", parser: "babel-eslint" }, ], invalid: [ - { code: "var x = new c();", errors: [{ message: "A constructor name should not start with a lowercase letter.", type: "NewExpression"}] }, - { code: "var x = new φ;", errors: [{ message: "A constructor name should not start with a lowercase letter.", type: "NewExpression"}] }, - { code: "var x = new a.b.c;", errors: [{ message: "A constructor name should not start with a lowercase letter.", type: "NewExpression"}] }, - { code: "var x = new a.b['c'];", errors: [{ message: "A constructor name should not start with a lowercase letter.", type: "NewExpression"}] }, - { code: "var b = Foo();", errors: [{ message: "A function with a name starting with an uppercase letter should only be used as a constructor.", type: "CallExpression"}] }, - { code: "var b = a.Foo();", errors: [{ message: "A function with a name starting with an uppercase letter should only be used as a constructor.", type: "CallExpression"}] }, - { code: "var b = a['Foo']();", errors: [{ message: "A function with a name starting with an uppercase letter should only be used as a constructor.", type: "CallExpression"}] }, - { code: "var b = a.Date.UTC();", errors: [{ message: "A function with a name starting with an uppercase letter should only be used as a constructor.", type: "CallExpression"}] }, - { code: "var b = UTC();", errors: [{ message: "A function with a name starting with an uppercase letter should only be used as a constructor.", type: "CallExpression"}] }, + { code: "var x = new c();", errors: [{ message: "A constructor name should not start with a lowercase letter.", type: "NewExpression" }] }, + { code: "var x = new φ;", errors: [{ message: "A constructor name should not start with a lowercase letter.", type: "NewExpression" }] }, + { code: "var x = new a.b.c;", errors: [{ message: "A constructor name should not start with a lowercase letter.", type: "NewExpression" }] }, + { code: "var x = new a.b['c'];", errors: [{ message: "A constructor name should not start with a lowercase letter.", type: "NewExpression" }] }, + { code: "var b = Foo();", errors: [{ message: "A function with a name starting with an uppercase letter should only be used as a constructor.", type: "CallExpression" }] }, + { code: "var b = a.Foo();", errors: [{ message: "A function with a name starting with an uppercase letter should only be used as a constructor.", type: "CallExpression" }] }, + { code: "var b = a['Foo']();", errors: [{ message: "A function with a name starting with an uppercase letter should only be used as a constructor.", type: "CallExpression" }] }, + { code: "var b = a.Date.UTC();", errors: [{ message: "A function with a name starting with an uppercase letter should only be used as a constructor.", type: "CallExpression" }] }, + { code: "var b = UTC();", errors: [{ message: "A function with a name starting with an uppercase letter should only be used as a constructor.", type: "CallExpression" }] }, { code: "var a = B.C();", errors: [ @@ -125,13 +135,25 @@ ruleTester.run('babel/new-cap', rule, { { code: "var x = Foo.Bar(42);", - options: [{capIsNewExceptions: ["Foo"]}], - errors: [{type: "CallExpression", message: "A function with a name starting with an uppercase letter should only be used as a constructor."}] + options: [{ capIsNewExceptions: ["Foo"] }], + errors: [{ type: "CallExpression", message: "A function with a name starting with an uppercase letter should only be used as a constructor." }] + }, + { + code: "var x = Bar.Foo(42);", + + options: [{ capIsNewExceptionPattern: "^Foo\\.." }], + errors: [{ type: "CallExpression", message: "A function with a name starting with an uppercase letter should only be used as a constructor." }] }, { code: "var x = new foo.bar(42);", - options: [{newIsCapExceptions: ["foo"]}], - errors: [{type: "NewExpression", message: "A constructor name should not start with a lowercase letter."}] + options: [{ newIsCapExceptions: ["foo"] }], + errors: [{ type: "NewExpression", message: "A constructor name should not start with a lowercase letter." }] + }, + { + code: "var x = new bar.foo(42);", + + options: [{ newIsCapExceptionPattern: "^foo\\.." }], + errors: [{ type: "NewExpression", message: "A constructor name should not start with a lowercase letter." }] } ] });