From 278813a6e759f6b5512ac64c7530c9c51732e692 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sun, 27 Jun 2021 00:31:45 +0530 Subject: [PATCH] Docs: fix and add more examples for new-cap rule (fixes #12874) (#14725) * Docs: fix and add more examples for `new-cap` rule * Docs: update * Docs: update * Docs: update * Docs: Update docs/rules/new-cap.md Co-authored-by: Milos Djermanovic Co-authored-by: Milos Djermanovic --- docs/rules/new-cap.md | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/docs/rules/new-cap.md b/docs/rules/new-cap.md index 22ac57729dc..ef8c61508c6 100644 --- a/docs/rules/new-cap.md +++ b/docs/rules/new-cap.md @@ -112,15 +112,24 @@ var emitter = new events(); ### newIsCapExceptionPattern -Examples of additional **correct** code for this rule with the `{ "newIsCapExceptionPattern": "^person\.." }` option: +Examples of additional **correct** code for this rule with the `{ "newIsCapExceptionPattern": "^person\\.." }` option: ```js -/*eslint new-cap: ["error", { "newIsCapExceptionPattern": "^person\.." }]*/ +/*eslint new-cap: ["error", { "newIsCapExceptionPattern": "^person\\.." }]*/ var friend = new person.acquaintance(); + var bestFriend = new person.friend(); ``` +Examples of additional **correct** code for this rule with the `{ "newIsCapExceptionPattern": "\\.bar$" }` option: + +```js +/*eslint new-cap: ["error", { "newIsCapExceptionPattern": "\\.bar$" }]*/ + +var friend = new person.bar(); +``` + ### capIsNewExceptions Examples of additional **correct** code for this rule with the `{ "capIsNewExceptions": ["Person"] }` option: @@ -135,15 +144,35 @@ function foo(arg) { ### capIsNewExceptionPattern -Examples of additional **correct** code for this rule with the `{ "capIsNewExceptionPattern": "^Person\.." }` option: +Examples of additional **correct** code for this rule with the `{ "capIsNewExceptionPattern": "^person\\.." }` option: ```js -/*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^Person\.." }]*/ +/*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^person\\.." }]*/ var friend = person.Acquaintance(); var bestFriend = person.Friend(); ``` +Examples of additional **correct** code for this rule with the `{ "capIsNewExceptionPattern": "\\.Bar$" }` option: + +```js +/*eslint new-cap: ["error", { "capIsNewExceptionPattern": "\\.Bar$" }]*/ + +foo.Bar(); +``` + +Examples of additional **correct** code for this rule with the `{ "capIsNewExceptionPattern": "^Foo" }` option: + +```js +/*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^Foo" }]*/ + +var x = Foo(42); + +var y = Foobar(42); + +var z = Foo.Bar(42); +``` + ### properties Examples of **incorrect** code for this rule with the default `{ "properties": true }` option: