Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sindresorhus/eslint-plugin-unicorn
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v45.0.2
Choose a base ref
...
head repository: sindresorhus/eslint-plugin-unicorn
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v46.0.0
Choose a head ref
  • 13 commits
  • 35 files changed
  • 7 contributors

Commits on Dec 16, 2022

  1. Verified

    This commit was signed with the committer’s verified signature.
    thaJeztah Sebastiaan van Stijn
    Copy the full SHA
    9df6b86 View commit details

Commits on Jan 3, 2023

  1. Verified

    This commit was signed with the committer’s verified signature.
    thaJeztah Sebastiaan van Stijn
    Copy the full SHA
    fe61924 View commit details

Commits on Feb 1, 2023

  1. Verified

    This commit was signed with the committer’s verified signature.
    thaJeztah Sebastiaan van Stijn
    Copy the full SHA
    ca5c62a View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    thaJeztah Sebastiaan van Stijn
    Copy the full SHA
    4ada50e View commit details
  3. no-empty-file: Support .jsx and .tsx extensions (#2002)

    Co-authored-by: fisker Cheung <lionkay@gmail.com>
    Felix-kln and fisker authored Feb 1, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    thaJeztah Sebastiaan van Stijn
    Copy the full SHA
    ba1a00e View commit details
  4. Verified

    This commit was signed with the committer’s verified signature.
    thaJeztah Sebastiaan van Stijn
    Copy the full SHA
    fcd8934 View commit details

Commits on Feb 2, 2023

  1. prefer-negative-index: Check .toSpliced() and .with() (#2031)

    Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
    fisker and sindresorhus authored Feb 2, 2023
    Copy the full SHA
    7ed738a View commit details
  2. Copy the full SHA
    00883a8 View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    thaJeztah Sebastiaan van Stijn
    Copy the full SHA
    fea5b42 View commit details
  4. Verified

    This commit was signed with the committer’s verified signature.
    thaJeztah Sebastiaan van Stijn
    Copy the full SHA
    55469e5 View commit details
  5. Refactor tests (#2036)

    fisker authored Feb 2, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    thaJeztah Sebastiaan van Stijn
    Copy the full SHA
    27e23e5 View commit details

Commits on Feb 4, 2023

  1. Copy the full SHA
    2a9c840 View commit details

Commits on Mar 3, 2023

  1. 46.0.0

    sindresorhus committed Mar 3, 2023
    Copy the full SHA
    5fcdf0f View commit details
21 changes: 21 additions & 0 deletions .eslint-doc-generatorrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint unicorn/prevent-abbreviations:"off" -- https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2015 */

/** @type {import('eslint-doc-generator').GenerateOptions} */
const config = {
ignoreConfig: ['all'],
ignoreDeprecatedRules: true,
ruleDocTitleFormat: 'desc',
ruleListColumns: [
'name',
'description',
'configsError',
// Omit `configsOff` since we don't intend to convey meaning by setting rules to `off` in the `recommended` config.
'configsWarn',
'fixable',
'hasSuggestions',
'requiresTypeChecking',
],
urlConfigs: 'https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs',
};

module.exports = config;
22 changes: 20 additions & 2 deletions docs/rules/prefer-negative-index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Prefer negative index over `.length - index` for `{String,Array,TypedArray}#{slice,at}()` and `Array#splice()`
# Prefer negative index over `.length - index` when possible

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

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

Prefer negative index over calculating from `.length` for [`String#slice()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice), [`Array#slice()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice), [`TypedArray#slice()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice), [`String#at()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at), [`Array#at()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at), [`TypedArray#at()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/at), and [`Array#splice()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)
Prefer negative index over calculating from `.length` for:

- [`String#slice()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice)
- [`Array#slice()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
- [`TypedArray#slice()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice)
- [`String#at()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at)
- [`Array#at()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
- [`TypedArray#at()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/at)
- [`Array#splice()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)
- [`Array#toSpliced()`](https://github.com/tc39/proposal-change-array-by-copy#overview)
- [`Array#with()`](https://github.com/tc39/proposal-change-array-by-copy#overview)
- [`TypedArray#with()`](https://github.com/tc39/proposal-change-array-by-copy#overview)

<!--
TODO: Use MDN links when available
- [`Array#toSpliced()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSpliced)
- [`Array#with()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/with)
- [`TypedArray#with()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/with)
-->

## Fail

14 changes: 13 additions & 1 deletion docs/rules/prefer-spread.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Prefer the spread operator over `Array.from(…)`, `Array#concat(…)`, `Array#slice()` and `String#split('')`
# Prefer the spread operator over `Array.from(…)`, `Array#concat(…)`, `Array#{slice,toSpliced}()` and `String#split('')`

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

@@ -25,6 +25,10 @@ Enforces the use of [the spread operator (`...`)](https://developer.mozilla.org/

Variables named `arrayBuffer`, `blob`, `buffer`, `file`, and `this` are ignored.

- `Array#toSpliced()`

Shallow copy an `Array`.

- `String#split('')`

Split a string into an array of characters.
@@ -47,6 +51,14 @@ const array = array1.concat(array2);
const copy = array.slice();
```

```js
const copy = array.slice(0);
```

```js
const copy = array.toSpliced();
```

```js
const characters = string.split('');
```
17 changes: 6 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-unicorn",
"version": "45.0.2",
"version": "46.0.0",
"description": "More than 100 powerful ESLint rules",
"license": "MIT",
"repository": "sindresorhus/eslint-plugin-unicorn",
@@ -16,7 +16,7 @@
"scripts": {
"create-rule": "node ./scripts/create-rule.mjs && npm run fix:eslint-docs",
"fix": "run-p --continue-on-error fix:*",
"fix:eslint-docs": "eslint-doc-generator --ignore-deprecated-rules --ignore-config all --rule-doc-title-format desc --url-configs \"https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs\"",
"fix:eslint-docs": "eslint-doc-generator",
"fix:js": "npm run lint:js -- --fix",
"fix:md": "npm run lint:md -- --fix",
"integration": "node ./test/integration/test.mjs",
@@ -79,7 +79,7 @@
"eslint-plugin-eslint-plugin": "^5.0.6",
"eslint-plugin-internal-rules": "file:./scripts/internal-rules/",
"eslint-remote-tester": "^3.0.0",
"eslint-remote-tester-repositories": "^0.0.7",
"eslint-remote-tester-repositories": "^1.0.0",
"execa": "^6.1.0",
"listr": "^0.14.3",
"lodash-es": "^4.17.21",
@@ -109,6 +109,9 @@
]
},
"xo": {
"extends": [
"plugin:internal-rules/all"
],
"ignores": [
".cache-eslint-remote-tester",
"eslint-remote-tester-results",
@@ -160,14 +163,6 @@
"eslint-plugin/require-meta-has-suggestions": "off",
"eslint-plugin/require-meta-schema": "off"
}
},
{
"files": [
"rules/**/*.js"
],
"extends": [
"plugin:internal-rules/all"
]
}
]
},
Loading