Skip to content

Commit

Permalink
Merge branch 'main'
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaKGoldberg committed Jul 10, 2023
2 parents c8bb00d + a8c824a commit bccf851
Show file tree
Hide file tree
Showing 18 changed files with 1,035 additions and 751 deletions.
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"rulesets",
"serializers",
"Sourcegraph",
"stringification",
"superset",
"thenables",
"transpiled",
Expand Down
30 changes: 10 additions & 20 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,65 +24,55 @@ Thanks goes to these wonderful people:
<tr>
<td align="center"><a href="https://github.com/MichaelDeBoey"><img src="https://avatars.githubusercontent.com/u/6643991?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Michaël De Boey</b></sub></a></td>
<td align="center"><a href="https://github.com/soda0289"><img src="https://avatars.githubusercontent.com/u/2373964?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Reyad Attiyat</b></sub></a></td>
<td align="center"><a href="https://github.com/sosukesuzuki"><img src="https://avatars.githubusercontent.com/u/14838850?v=4&size=100" width="100px;" alt=""/><br /><sub><b>SUZUKI Sosuke</b></sub></a></td>
<td align="center"><a href="https://github.com/G-Rath"><img src="https://avatars.githubusercontent.com/u/3151613?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Gareth Jones</b></sub></a></td>
<td align="center"><a href="https://github.com/Josh-Cena"><img src="https://avatars.githubusercontent.com/u/55398995?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Joshua Chen</b></sub></a></td>
<td align="center"><a href="https://github.com/weirdpattern"><img src="https://avatars.githubusercontent.com/u/19519411?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Patricio Trevino</b></sub></a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/weirdpattern"><img src="https://avatars.githubusercontent.com/u/19519411?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Patricio Trevino</b></sub></a></td>
<td align="center"><a href="https://github.com/yeonjuan"><img src="https://avatars.githubusercontent.com/u/41323220?v=4&size=100" width="100px;" alt=""/><br /><sub><b>YeonJuan</b></sub></a></td>
<td align="center"><a href="https://github.com/nzakas"><img src="https://avatars.githubusercontent.com/u/38546?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Nicholas C. Zakas</b></sub></a></td>
<td align="center"><a href="https://github.com/j-f1"><img src="https://avatars.githubusercontent.com/u/25517624?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Jed Fox</b></sub></a></td>
<td align="center"><a href="https://github.com/rafaelss95"><img src="https://avatars.githubusercontent.com/u/11965907?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Rafael Santana</b></sub></a></td>
<td align="center"><a href="https://github.com/uniqueiniquity"><img src="https://avatars.githubusercontent.com/u/9092011?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Ben Lichtman</b></sub></a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/uniqueiniquity"><img src="https://avatars.githubusercontent.com/u/9092011?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Ben Lichtman</b></sub></a></td>
<td align="center"><a href="https://github.com/phaux"><img src="https://avatars.githubusercontent.com/u/1270987?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Nikita</b></sub></a></td>
<td align="center"><a href="https://github.com/lonyele"><img src="https://avatars.githubusercontent.com/u/15892571?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Taeheon Kim</b></sub></a></td>
<td align="center"><a href="https://github.com/scottohara"><img src="https://avatars.githubusercontent.com/u/289327?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Scott O'Hara</b></sub></a></td>
<td align="center"><a href="https://github.com/Retsam"><img src="https://avatars.githubusercontent.com/u/2281166?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Retsam</b></sub></a></td>
<td align="center"><a href="https://github.com/kaicataldo"><img src="https://avatars.githubusercontent.com/u/7041728?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Kai Cataldo</b></sub></a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/kaicataldo"><img src="https://avatars.githubusercontent.com/u/7041728?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Kai Cataldo</b></sub></a></td>
<td align="center"><a href="https://github.com/Pajn"><img src="https://avatars.githubusercontent.com/u/817422?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Rasmus Eneman</b></sub></a></td>
<td align="center"><a href="https://github.com/RebeccaStevens"><img src="https://avatars.githubusercontent.com/u/7224206?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Rebecca Stevens</b></sub></a></td>
<td align="center"><a href="https://github.com/mysticatea"><img src="https://avatars.githubusercontent.com/u/1937871?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Toru Nagashima</b></sub></a></td>
<td align="center"><a href="https://github.com/ota-meshi"><img src="https://avatars.githubusercontent.com/u/16508807?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Yosuke Ota</b></sub></a></td>
<td align="center"><a href="https://github.com/JounQin"><img src="https://avatars.githubusercontent.com/u/8336744?v=4&size=100" width="100px;" alt=""/><br /><sub><b>JounQin</b></sub></a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/JounQin"><img src="https://avatars.githubusercontent.com/u/8336744?v=4&size=100" width="100px;" alt=""/><br /><sub><b>JounQin</b></sub></a></td>
<td align="center"><a href="https://github.com/azz"><img src="https://avatars.githubusercontent.com/u/1297597?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Lucas Azzola</b></sub></a></td>
<td align="center"><a href="https://github.com/omril1"><img src="https://avatars.githubusercontent.com/u/18642549?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Omri Luzon</b></sub></a></td>
<td align="center"><a href="https://github.com/SimenB"><img src="https://avatars.githubusercontent.com/u/1404810?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Simen Bekkhus</b></sub></a></td>
<td align="center"><a href="https://github.com/dannyfritz"><img src="https://avatars.githubusercontent.com/u/315788?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Danny Fritz</b></sub></a></td>
<td align="center"><a href="https://github.com/ikatyang"><img src="https://avatars.githubusercontent.com/u/8341033?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Ika</b></sub></a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/ikatyang"><img src="https://avatars.githubusercontent.com/u/8341033?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Ika</b></sub></a></td>
<td align="center"><a href="https://github.com/macklinu"><img src="https://avatars.githubusercontent.com/u/2344137?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Mackie Underdown</b></sub></a></td>
<td align="center"><a href="https://github.com/sviat9440"><img src="https://avatars.githubusercontent.com/u/13107421?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Sviatoslav Zaytsev</b></sub></a></td>
<td align="center"><a href="https://github.com/bmish"><img src="https://avatars.githubusercontent.com/u/698306?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Bryan Mishkin</b></sub></a></td>
<td align="center"><a href="https://github.com/lukyth"><img src="https://avatars.githubusercontent.com/u/7040242?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Kanitkorn Sujautra</b></sub></a></td>
<td align="center"><a href="https://github.com/islandryu"><img src="https://avatars.githubusercontent.com/u/65934663?v=4&size=100" width="100px;" alt=""/><br /><sub><b>SHIMA RYUHEI</b></sub></a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/islandryu"><img src="https://avatars.githubusercontent.com/u/65934663?v=4&size=100" width="100px;" alt=""/><br /><sub><b>SHIMA RYUHEI</b></sub></a></td>
<td align="center"><a href="https://github.com/Zzzen"><img src="https://avatars.githubusercontent.com/u/6630042?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Zzzen</b></sub></a></td>
<td align="center"><a href="https://github.com/anikethsaha"><img src="https://avatars.githubusercontent.com/u/26347874?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Anix</b></sub></a></td>
<td align="center"><a href="https://github.com/cparros"><img src="https://avatars.githubusercontent.com/u/65684072?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Cparros</b></sub></a></td>
<td align="center"><a href="https://github.com/ldrick"><img src="https://avatars.githubusercontent.com/u/3674067?v=4&size=100" width="100px;" alt=""/><br /><sub><b>ldrick</b></sub></a></td>
<td align="center"><a href="https://github.com/kmin-jeong"><img src="https://avatars.githubusercontent.com/u/53456037?v=4&size=100" width="100px;" alt=""/><br /><sub><b>kmin-jeong</b></sub></a></td>
<td align="center"><a href="https://github.com/octogonz"><img src="https://avatars.githubusercontent.com/u/4673363?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Pete Gonzalez</b></sub></a></td>
<td align="center"><a href="https://github.com/gavinbarron"><img src="https://avatars.githubusercontent.com/u/7122716?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Gavin Barron</b></sub></a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/platinumazure"><img src="https://avatars.githubusercontent.com/u/284282?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Kevin Partington</b></sub></a></td>
<td align="center"><a href="https://github.com/mightyiam"><img src="https://avatars.githubusercontent.com/u/635591?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Shahar "Dawn" Or</b></sub></a></td>
<td align="center"><a href="https://github.com/koooge"><img src="https://avatars.githubusercontent.com/u/7419215?v=4&size=100" width="100px;" alt=""/><br /><sub><b>koooge</b></sub></a></td>
<td align="center"><a href="https://github.com/thomasmichaelwallace"><img src="https://avatars.githubusercontent.com/u/1954845?v=4&size=100" width="100px;" alt=""/><br /><sub><b>thomas michael wallace</b></sub></a></td>
<td align="center"><a href="https://github.com/juank1809"><img src="https://avatars.githubusercontent.com/u/82288753?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Juan García</b></sub></a></td>
<td align="center"><a href="https://github.com/sfavello"><img src="https://avatars.githubusercontent.com/u/90116354?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Sylvia Favello</b></sub></a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/djcsdy"><img src="https://avatars.githubusercontent.com/u/310800?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Daniel Cassidy</b></sub></a></td>
<td align="center"><a href="https://github.com/dimitropoulos"><img src="https://avatars.githubusercontent.com/u/15232461?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Dimitri Mitropoulos</b></sub></a></td>
<td align="center"><a href="https://github.com/43081j"><img src="https://avatars.githubusercontent.com/u/5677153?v=4&size=100" width="100px;" alt=""/><br /><sub><b>James Garbutt</b></sub></a></td>
<td align="center"><a href="https://github.com/jonathanrdelgado"><img src="https://avatars.githubusercontent.com/u/1841149?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Jonathan Delgado</b></sub></a></td>
<td align="center"><a href="https://github.com/tadhgmister"><img src="https://avatars.githubusercontent.com/u/18615763?v=4&size=100" width="100px;" alt=""/><br /><sub><b>Tadhg McDonald-Jensen</b></sub></a></td>
</table>

<!-- markdownlint-restore -->
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"clean": "lerna clean -y && nx run-many --target=clean",
"format": "prettier --write .",
"generate-breaking-changes": "nx run eslint-plugin:generate-breaking-changes",
"generate-configs": "nx run eslint-plugin:generate-configs",
"generate-configs": "nx run eslint-plugin:generate:configs",
"generate-contributors": "nx run repo-tools:generate-contributors",
"generate-sponsors": "nx run repo-tools:generate-sponsors",
"generate-website-dts": "nx run website:generate-website-dts",
Expand Down
23 changes: 23 additions & 0 deletions packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,29 @@ a ?? (b && c && d);

**_NOTE:_** Errors for this specific case will be presented as suggestions (see below), instead of fixes. This is because it is not always safe to automatically convert `||` to `??` within a mixed logical expression, as we cannot tell the intended precedence of the operator. Note that by design, `??` requires parentheses when used with `&&` or `||` in the same expression.

### `ignorePrimitives`

If you would like to ignore certain primitive types that can be falsy then you may pass an object containing a boolean value for each primitive:

- `string: true`, ignores `null` or `undefined` unions with `string` (default: false).
- `number: true`, ignores `null` or `undefined` unions with `number` (default: false).
- `bigint: true`, ignores `null` or `undefined` unions with `bigint` (default: false).
- `boolean: true`, ignores `null` or `undefined` unions with `boolean` (default: false).

Incorrect code for `ignorePrimitives: { string: true }`, and correct code for `ignorePrimitives: { string: false }`:

```ts
const foo: string | undefined = 'bar';
foo || 'a string';
```

Correct code for `ignorePrimitives: { string: true }`:

```ts
const foo: string | undefined = 'bar';
foo ?? 'a string';
```

## When Not To Use It

If you are not using TypeScript 3.7 (or greater), then you will not be able to use this rule, as the operator is not supported.
Expand Down
18 changes: 15 additions & 3 deletions packages/eslint-plugin/docs/rules/restrict-template-expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ description: 'Enforce template literal expressions to be of `string` type.'
>
> See **https://typescript-eslint.io/rules/restrict-template-expressions** for documentation.
JavaScript will call `toString()` on an object when it is converted to a string, such as when `+` adding to a string or in `${}` template literals.
The default Object `.toString()` returns `"[object Object]"`, which is often not what was intended.
This rule reports on values used in a template literal string that aren't primitives and don't define a more useful `.toString()` method.
JavaScript automatically [converts an object to a string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#string_coercion) in a string context, such as when concatenating it with a string using `+` or embedding it in a template literal using `${}`.
The default `toString()` method of objects returns `"[object Object]"`, which is often not what was intended.
This rule reports on values used in a template literal string that aren't strings, numbers, or BigInts, optionally allowing other data types that provide useful stringification results.

:::note

This rule intentionally does not allow objects with a custom `toString()` method to be used in template literals, because the stringification result may not be user-friendly.

For example, arrays have a custom [`toString()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString) method, which only calls `join()` internally, which joins the array elements with commas. This means that (1) array elements are not necessarily stringified to useful results (2) the commas don't have spaces after them, making the result not user-friendly. The best way to format arrays is to use [`Intl.ListFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat), which even supports adding the "and" conjunction where necessary.
You must explicitly call `object.toString()` if you want to use this object in a template literal.
The [`no-base-to-string`](./no-base-to-string.md) rule can be used to guard this case against producing `"[object Object]"` by accident.

:::

## Examples

Expand Down Expand Up @@ -47,6 +57,8 @@ const msg1 = `arg = ${arg}`;
const msg2 = `arg = ${arg || 'zero'}`;
```

This option controls both numbers and BigInts.

### `allowBoolean`

Examples of additional **correct** code for this rule with `{ allowBoolean: true }`:
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin/src/configs/strict-type-checked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export = {
'@typescript-eslint/prefer-as-const': 'error',
'@typescript-eslint/prefer-includes': 'error',
'@typescript-eslint/prefer-literal-enum-member': 'error',
'@typescript-eslint/prefer-nullish-coalescing': 'error',
'@typescript-eslint/prefer-reduce-type-parameter': 'error',
'@typescript-eslint/prefer-return-this-type': 'error',
'@typescript-eslint/prefer-ts-expect-error': 'error',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export = {
'@typescript-eslint/prefer-for-of': 'error',
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/prefer-namespace-keyword': 'error',
'@typescript-eslint/prefer-nullish-coalescing': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/prefer-string-starts-ends-with': 'error',
},
Expand Down
Loading

0 comments on commit bccf851

Please sign in to comment.