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

[pull] main from sindresorhus:main #367

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
cc02a7f
`no-hex-escape`: Ignore `String.raw` (#2343)
fisker May 8, 2024
45bd444
`escape-case`: Ignore `String.raw` (#2342)
fisker May 8, 2024
342aafb
Add `no-invalid-fetch-options` rule (#2338)
fisker May 8, 2024
784db90
Pin `eslint-doc-generator` to v1.7.0 (#2344)
fisker May 9, 2024
b82542d
Add fisker to sponsors (#2348)
fisker May 9, 2024
e59d9ee
Add utility `getCallExpressionTokens` (#2345)
fisker May 9, 2024
aabcf1d
`template-indent`: Support member expression paths in `tags` and `fun…
fisker May 9, 2024
4f1400a
Add `prefer-string-raw` rule (#2339)
fisker May 9, 2024
f5a6cd7
Fix smoke test
fisker May 9, 2024
08dc329
Fix smoke test
fisker May 9, 2024
6fde3fe
Require rule proposal to include a proposed rule name (#2351)
sindresorhus May 10, 2024
8d7954c
Add `consistent-empty-array-spread` rule (#2349)
fisker May 10, 2024
cf2109a
53.0.0
sindresorhus May 10, 2024
d8f8161
Fix edge cases when add `new` to calls (#2352)
fisker May 10, 2024
94b6f5e
Add issue template for a rule change (#2279)
fregante May 10, 2024
175ea04
`prefer-string-raw`: Ignore strings in Enums (#2354)
fisker May 11, 2024
d2df181
Remove useless "recommended" properties (#2355)
DEVTomatoCake May 11, 2024
8105756
Update `@typescript-eslint/parse` to v8 (#2358)
fisker May 15, 2024
3a282ac
Add "bug" label to bug reports
fregante May 23, 2024
8957a03
Add `no-negation-in-equality-check` rule (#2353)
fisker May 24, 2024
a449af9
`prefer-array-find`: Change `checkFromLast` default value to `true` (…
fisker May 25, 2024
d812ad1
`prefer-includes`: Check `.lastIndexOf()` (#2368)
fisker May 25, 2024
2616ce3
Clean `run-rules-on-codebase` script (#2369)
fisker May 27, 2024
1490bb6
Tests: Update `eslint-remote-tester` to v4 (#2376)
AriPerkkio Jun 12, 2024
ac8536e
Add name to flat configs (#2377)
voxpelli Jun 14, 2024
10568ab
`prefer-array-some`: Check `Array#{findIndex,findLastIndex}()` (#2370)
fisker Jun 14, 2024
fce6ce3
54.0.0
sindresorhus Jun 14, 2024
37e00dd
`no-negation-in-equality-check`: Ignore boolean type casting (#2379)
fisker Jun 14, 2024
a45b24a
`prefer-node-protocol`: Ignore Bun modules (#2384)
SunsetTechuila Jun 21, 2024
8d28b6e
`no-single-promise-in-promise-methods`: Remove broken autofix for `Pr…
Clement398 Jun 22, 2024
68e0f13
Add TypeScript types (#2382)
hyoban Jun 23, 2024
1deb9bb
`prefer-node-protocol`: Fix docs (#2392)
benmccann Jun 26, 2024
3c33820
Add `no-length-as-slice-end` rule (#2400)
fisker Jul 12, 2024
cb7abc5
Get `globals` directly from `globals` package (#2395)
fisker Jul 12, 2024
f3ca6a0
Switch `run-rules-on-codebase` script to use ESLint CLI directly (#2402)
fisker Jul 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
name: Bug report
about: A rule isn't working as it should?
labels: bug
---

<!-- ✨ Thanks for reporting a bug! ➡️ Please don't ignore this template -->
Expand Down
55 changes: 55 additions & 0 deletions .github/ISSUE_TEMPLATE/rule_change.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Rule change
description: A rule could be improved or extended?
title: "`rule-name`: "
labels:
- change request
- evaluating
body:
- type: markdown
attributes:
value: |
Before opening a new issue:
- Look for existing [open or closed rule proposals](https://github.com/sindresorhus/eslint-plugin-unicorn/issues?q=is:issue+label%25enhancement)
- [Report a bug](https://github.com/sindresorhus/eslint-plugin-unicorn/issues/new?assignees=&labels=&projects=&template=bug_report.md) instead if it's a false positive
- type: textarea
validations:
required: true
attributes:
label: Description
description: Explain the improvement you would like to see.
- type: textarea
validations:
required: true
attributes:
label: Fail
description: Specify examples of code that should be detected.
value: |
```js
var replace = 'me';
```

```js
function foo() {
var replace = 'me';
return replace;
}
```
- type: textarea
validations:
required: true
attributes:
label: Pass
description: Specify examples of code that would be accepted in its place.
value: |
```js
const replace = 'me';
```

```js
function foo() {
return 'me';
}
```
- type: textarea
attributes:
label: Additional Info
6 changes: 6 additions & 0 deletions .github/ISSUE_TEMPLATE/rule_proposal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ body:
return 'me';
}
```
- type: input
validations:
required: true
attributes:
label: Proposed rule name
placeholder: no-invalid-rule-name
- type: textarea
attributes:
label: Additional Info
Expand Down
4 changes: 4 additions & 0 deletions .github/funding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github: [sindresorhus, fisker]
open_collective: sindresorhus
buy_me_a_coffee: sindresorhus
custom: https://sindresorhus.com/donate
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install --legacy-peer-deps
- run: npm install
- run: npx ava
lint-test:
runs-on: ${{ matrix.os }}
Expand All @@ -44,7 +44,7 @@ jobs:
with:
# Locked due to the difference of `zlib.gzipSync()` between Node.js versions
node-version: 20
- run: npm install --legacy-peer-deps
- run: npm install
- run: npm run lint
- run: npx del-cli test/snapshots --verbose
# Force update snapshots, https://github.com/avajs/ava/discussions/2754
Expand All @@ -62,7 +62,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm install --legacy-peer-deps
- run: npm install
- run: npm run run-rules-on-codebase
integration:
name: Integration test (${{ matrix.group }})
Expand All @@ -85,5 +85,5 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm install --legacy-peer-deps
- run: npm install
- run: npm run integration -- --group ${{ matrix.group }}
13 changes: 5 additions & 8 deletions .github/workflows/smoke-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- run: |
npm install
npm link
npm link eslint-plugin-unicorn
- uses: AriPerkkio/eslint-remote-tester-run-action@v4
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm install
- uses: AriPerkkio/eslint-remote-tester-run-action@v5
with:
issue-title: "Results of weekly scheduled smoke test"
eslint-remote-tester-config: test/smoke/eslint-remote-tester.config.js
eslint-remote-tester-config: test/smoke/eslint-remote-tester.config.mjs
7 changes: 4 additions & 3 deletions .npmpackagejsonlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
"prefer-alphabetical-optionalDependencies": "error",
"prefer-alphabetical-bundledDependencies": "error",
"prefer-alphabetical-scripts": "error",
"prefer-caret-version-dependencies": [
"prefer-caret-version-dependencies": "error",
"prefer-caret-version-devDependencies": [
"error",
{
"exceptions": [
"eslint-plugin-unicorn"
"eslint-plugin-internal-rules",
"eslint-doc-generator"
]
}
],
"prefer-caret-version-devDependencies": "error",
"prefer-scripts": [
"error",
[
Expand Down
6 changes: 2 additions & 4 deletions configs/flat-config-base.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
'use strict';
const eslintrc = require('@eslint/eslintrc');

const {globals} = eslintrc.Legacy.environments.get('es2024');
const globals = require('globals');

module.exports = {
languageOptions: {
globals,
globals: globals.builtin,
},
};
42 changes: 42 additions & 0 deletions docs/rules/consistent-empty-array-spread.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Prefer consistent types when spreading a ternary in an array literal

💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs-eslintconfigjs).

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

<!-- end auto-generated rule header -->
<!-- Do not manually modify this header. Run: `npm run fix:eslint-docs` -->

When spreading a ternary in an array, we can use both `[]` and `''` as fallbacks, but it's better to have consistent types in both branches.

## Fail

```js
const array = [
a,
...(foo ? [b, c] : ''),
];
```

```js
const array = [
a,
...(foo ? 'bc' : []),
];
```

## Pass

```js
const array = [
a,
...(foo ? [b, c] : []),
];
```

```js
const array = [
a,
...(foo ? 'bc' : ''),
];
```
44 changes: 44 additions & 0 deletions docs/rules/no-invalid-fetch-options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Disallow invalid options in `fetch()` and `new Request()`

💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs-eslintconfigjs).

<!-- end auto-generated rule header -->
<!-- Do not manually modify this header. Run: `npm run fix:eslint-docs` -->

[`fetch()`](https://developer.mozilla.org/en-US/docs/Web/API/fetch) throws a `TypeError` when the method is `GET` or `HEAD` and a body is provided.

## Fail

```js
const response = await fetch('/', {body: 'foo=bar'});
```

```js
const request = new Request('/', {body: 'foo=bar'});
```

```js
const response = await fetch('/', {method: 'GET', body: 'foo=bar'});
```

```js
const request = new Request('/', {method: 'GET', body: 'foo=bar'});
```

## Pass

```js
const response = await fetch('/', {method: 'HEAD'});
```

```js
const request = new Request('/', {method: 'HEAD'});
```

```js
const response = await fetch('/', {method: 'POST', body: 'foo=bar'});
```

```js
const request = new Request('/', {method: 'POST', body: 'foo=bar'});
```
30 changes: 30 additions & 0 deletions docs/rules/no-length-as-slice-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Disallow using `.length` as the `end` argument of `{Array,String,TypedArray}#slice()`

💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs-eslintconfigjs).

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

<!-- end auto-generated rule header -->
<!-- Do not manually modify this header. Run: `npm run fix:eslint-docs` -->

When calling `{String,Array,TypedArray}#slice(start, end)`, omitting the `end` argument defaults it to the object's `.length`. Passing it explicitly is unnecessary.

## Fail

```js
const foo = string.slice(1, string.length);
```

```js
const foo = array.slice(1, array.length);
```

## Pass

```js
const foo = string.slice(1);
```

```js
const foo = bar.slice(1, baz.length);
```
30 changes: 30 additions & 0 deletions docs/rules/no-negation-in-equality-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Disallow negated expression in equality check

💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs-eslintconfigjs).

💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).

<!-- end auto-generated rule header -->
<!-- Do not manually modify this header. Run: `npm run fix:eslint-docs` -->

Using a negated expression in equality check is most likely a mistake.

## Fail

```js
if (!foo === bar) {}
```

```js
if (!foo !== bar) {}
```

## Pass

```js
if (foo !== bar) {}
```

```js
if (!(foo === bar)) {}
```
25 changes: 13 additions & 12 deletions docs/rules/prefer-array-find.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@ This rule is fixable unless default values are used in declaration or assignment
const item = array.filter(x => isUnicorn(x))[0];
```

```js
const item = array.filter(x => isUnicorn(x)).at(-1);
```

```js
const item = array.filter(x => isUnicorn(x)).shift();
```

```js
const item = array.filter(x => isUnicorn(x)).pop();
```

```js
const [item] = array.filter(x => isUnicorn(x));
```
Expand Down Expand Up @@ -50,25 +58,18 @@ Type: `object`
### checkFromLast

Type: `boolean`\
Default: `false`
Default: `true`

Pass `checkFromLast: true` to check cases searching from last.
Pass `checkFromLast: false` to disable check cases searching from last.

#### Fail
#### Pass

```js
// eslint unicorn/prefer-array-find: ["error", {"checkFromLast": true}]
// eslint unicorn/prefer-array-find: ["error", {"checkFromLast": false}]
const item = array.filter(x => isUnicorn(x)).at(-1);
```

```js
// eslint unicorn/prefer-array-find: ["error", {"checkFromLast": true}]
// eslint unicorn/prefer-array-find: ["error", {"checkFromLast": false}]
const item = array.filter(x => isUnicorn(x)).pop();
```

#### Pass

```js
// eslint unicorn/prefer-array-find: ["error", {"checkFromLast": true}]
const item = array.findLast(x => isUnicorn(x));
```
Loading