Skip to content

Commit

Permalink
Merge branch 'main' into rule-change
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed May 10, 2024
2 parents edab409 + d8f8161 commit 55fc1a7
Show file tree
Hide file tree
Showing 376 changed files with 10,062 additions and 2,353 deletions.
2 changes: 1 addition & 1 deletion .eslint-doc-generatorrc.js
Expand Up @@ -15,7 +15,7 @@ const config = {
'hasSuggestions',
'requiresTypeChecking',
],
urlConfigs: 'https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs',
urlConfigs: 'https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs-eslintconfigjs',
};

module.exports = config;
6 changes: 6 additions & 0 deletions .github/ISSUE_TEMPLATE/rule_proposal.yml
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
@@ -0,0 +1,4 @@
github: [sindresorhus, fisker]
open_collective: sindresorhus
buy_me_a_coffee: sindresorhus
custom: https://sindresorhus.com/donate
20 changes: 11 additions & 9 deletions .github/workflows/main.yml
Expand Up @@ -16,19 +16,20 @@ jobs:
matrix:
node-version:
- 20
- 16
- 18
os:
- ubuntu-latest
- windows-latest
include:
- os: ubuntu-latest
node-version: 18
# Even numbers of node-version
# include:
# - os: ubuntu-latest
# node-version: 18
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm install --legacy-peer-deps
- run: npx ava
lint-test:
runs-on: ${{ matrix.os }}
Expand All @@ -43,24 +44,25 @@ jobs:
with:
# Locked due to the difference of `zlib.gzipSync()` between Node.js versions
node-version: 20
- run: npm install
- run: npm install --legacy-peer-deps
- run: npm run lint
- run: npx del-cli test/snapshots --verbose
# Force update snapshots, https://github.com/avajs/ava/discussions/2754
- run: npx c8 ava --update-snapshots
env:
AVA_FORCE_CI: not-ci
- run: git diff --exit-code
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
files: coverage/lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
run-rules-on-codebase:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm install
- run: npm install --legacy-peer-deps
- run: npm run run-rules-on-codebase
integration:
name: Integration test (${{ matrix.group }})
Expand All @@ -83,5 +85,5 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm install
- run: npm install --legacy-peer-deps
- run: npm run integration -- --group ${{ matrix.group }}
4 changes: 2 additions & 2 deletions .github/workflows/smoke-test.yml
Expand Up @@ -12,9 +12,9 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- run: |
npm install
npm install --legacy-peer-deps
npm link
npm link eslint-plugin-unicorn
npm link eslint-plugin-unicorn --legacy-peer-deps
- uses: AriPerkkio/eslint-remote-tester-run-action@v4
with:
issue-title: "Results of weekly scheduled smoke test"
Expand Down
7 changes: 4 additions & 3 deletions .npmpackagejsonlintrc.json
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: 0 additions & 6 deletions configs/all.js

This file was deleted.

118 changes: 0 additions & 118 deletions configs/recommended.js

This file was deleted.

69 changes: 69 additions & 0 deletions docs/new-rule.md
Expand Up @@ -23,3 +23,72 @@ Use the [`astexplorer` site](https://astexplorer.net) with the `espree` parser a
- Open a pull request with a title in exactly the format `` Add `rule-name` rule ``, for example, `` Add `no-unused-properties` rule ``.
- The pull request description should include the issue it fixes, for example, `Fixes #123`.
- Run `npm run run-rules-on-codebase` to run the rules against codebase to ensure code in the repository are following your rule, _you can ignore this step until your PR is reviewed_.

## Implementation note

1. Try your best to provide an autofix if possible.
1. Try to provide a suggestion if an autofix is not possible.
1. Make sure the autofix doesn't change the runtime result.
1. Make sure the suggestion doesn't cause a syntax error.
1. Make sure that edge cases needing parentheses are considered in the fix function.

```js
const foo = 1;
foo.toString()
```

When changing `foo` to something else, make sure it works without `()`.

```js
// Good
(1).toString()

// Bad, will cause syntax error
1.toString()
```

1. Make sure that edge cases needing leading semicolons are considered in the fix function.

```js
foo
const bar = [1]
bar.forEach(number => {
console.log(number)
})
```

When changing `bar` to something that starts with `[` or `(`.

```js
// Good
foo
;[1].forEach(number => {
console.log(number)
})

// Bad
foo
[1].forEach(number => {
console.log(number)
})
```

1. If replacing a node that starts or ends with a symbol like `{`, make sure to add space before if the replacement starts with a letter.

The following is valid JavaScript code:

```js
for(const{foo}of[]);
```

When replacing `{foo}` with something that starts with a letter, space around is needed.

```js
// Good
for(const foo of[]);

// Bad
for(constfooof[]);
```

1. Try not to remove comments in the fix function.
2 changes: 1 addition & 1 deletion docs/rules/better-regex.md
@@ -1,6 +1,6 @@
# Improve regexes by making them shorter, consistent, and safer

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

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/catch-error-name.md
@@ -1,6 +1,6 @@
# Enforce a specific parameter name in catch clauses

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

Expand Down
4 changes: 2 additions & 2 deletions docs/rules/consistent-destructuring.md
@@ -1,8 +1,8 @@
# Use destructured variables over properties

🚫 This rule is _disabled_ in the ✅ `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs).
🚫 This rule is _disabled_ 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) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
🔧💡 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and 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` -->
Expand Down
42 changes: 42 additions & 0 deletions docs/rules/consistent-empty-array-spread.md
@@ -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' : ''),
];
```
2 changes: 1 addition & 1 deletion docs/rules/consistent-function-scoping.md
@@ -1,6 +1,6 @@
# Move function definitions to the highest possible scope

💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs).
💼 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` -->
Expand Down

0 comments on commit 55fc1a7

Please sign in to comment.