Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Replaced explanation of option object; corrected first example f… #13037

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions docs/rules/new-cap.md
Expand Up @@ -33,7 +33,7 @@ function foo(arg) {

## Options

This rule has an object option:
This rule has an object, `option`. This object can be used to define exceptions by property name, object name, or even both at the same time. Here are the properties one can define on the `option` object:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule has an object option

I think the previous version was correct. "object option" means that the option is an object. In some other rules options are strings, numbers, etc..

This object can be used to define exceptions by property name, object name, or even both at the same time. Here are the properties one can define on the option object

This might be confusing at this point because this rule doesn't apply only to member expressions (object.property). It also works with "simple" function/constructor calls where it's on an identifier, e.g., f() or new C().

Maybe we should revert this here, and provide a similar explanation in the ### capIsNewExceptionPattern section.


* `"newIsCap": true` (default) requires all `new` operators to be called with uppercase-started functions.
* `"newIsCap": false` allows `new` operators to be called with lowercase-started or uppercase-started functions.
Expand Down Expand Up @@ -135,14 +135,21 @@ 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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


```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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a blank line after ```, this produces the linting error.


```js
/*eslint new-cap: ["error", { "capIsNewExceptionPattern": "\.Bar$" }]*/

foo.Bar(); // Lint-Free!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need for // Lint-Free!, this is already an example of correct code.

Also, can we please add a similar example for newIsCapExceptionPattern?

```

### properties

Expand Down