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

Switch to flat config format #609

Merged
merged 37 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5d73594
revert to config file using new flat config format
spaceninja Nov 12, 2024
d78c4d2
2.0.0-alpha.0
spaceninja Nov 12, 2024
6b9ad00
fix package name
spaceninja Nov 12, 2024
cc971da
2.0.0-alpha.1
spaceninja Nov 12, 2024
c713ff3
update readme
spaceninja Nov 12, 2024
cdeaa87
add globals
spaceninja Nov 12, 2024
8843460
add node plugin
spaceninja Nov 12, 2024
1645f31
2.0.0-alpha.2
spaceninja Nov 12, 2024
a090c20
trying something
spaceninja Nov 12, 2024
2b83141
2.0.0-alpha.3
spaceninja Nov 12, 2024
53120db
add more plugins
spaceninja Nov 12, 2024
2ad1513
2.0.0-alpha.4
spaceninja Nov 12, 2024
4b72441
disable stylistic rules
spaceninja Nov 13, 2024
e614455
2.0.0-alpha.5
spaceninja Nov 13, 2024
fc93e72
add rules
spaceninja Nov 13, 2024
91f3865
update globals
spaceninja Nov 13, 2024
314c440
2.0.0-alpha.6
spaceninja Nov 13, 2024
6c23c09
updated stylistic rules
spaceninja Nov 13, 2024
8e773f9
2.0.0-alpha.7
spaceninja Nov 13, 2024
2880934
add custom rule
spaceninja Nov 13, 2024
1c016e4
2.0.0-alpha.8
spaceninja Nov 13, 2024
3c9772d
better match existing config
spaceninja Nov 13, 2024
766d0cc
2.0.0-alpha.9
spaceninja Nov 13, 2024
002312b
add TS configs
spaceninja Nov 13, 2024
8810dcd
2.0.0-alpha.10
spaceninja Nov 13, 2024
a98d1ea
simplify TS config
spaceninja Nov 14, 2024
4bc9206
2.0.0-alpha.11
spaceninja Nov 14, 2024
4d6c334
standardize import naming
spaceninja Nov 14, 2024
e85ae09
update docs
spaceninja Nov 14, 2024
26d9fce
update ci name
spaceninja Nov 14, 2024
044acf5
better comment
spaceninja Nov 14, 2024
ca13b87
reduce diff
spaceninja Nov 14, 2024
71a7178
oops
spaceninja Nov 14, 2024
53b12b5
move to right directory
spaceninja Nov 14, 2024
d073f2b
2.0.0-alpha.12
spaceninja Nov 14, 2024
ca58850
restore changelog, bump version
spaceninja Nov 14, 2024
0b353c6
24.0.0-alpha.13
spaceninja Nov 14, 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
8 changes: 0 additions & 8 deletions .changeset/README.md

This file was deleted.

13 changes: 0 additions & 13 deletions .changeset/config.json

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/sweet-mugs-shake.md

This file was deleted.

9 changes: 7 additions & 2 deletions .editorconfig
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the updates to the editorconfig. 👍🏽

Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
root = true

[*]
indent_style = space
indent_style = tab
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
trim_trailing_whitespace = false

# YAML files cannot have tabs
# @see https://yaml.org/faq.html
[*.yml]
indent_style = space
3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

27 changes: 9 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,17 @@ concurrency:
cancel-in-progress: true

jobs:
lint:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 18
uses: actions/setup-node@v3
- name: Check out repository code
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18
- name: Cache node modules
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-build-${{ env.cache-name }}-
${{ runner.OS }}-build-
${{ runner.OS }}-
node-version: 'lts/*'
cache: 'npm'
- name: Install Dependencies
run: npm ci && npm link && npm link @cloudfour/eslint-plugin
- name: Run Build
run: npm run build
run: npm ci
- name: Run Lint
run: npm run check-lint
run: npm run lint:check
36 changes: 0 additions & 36 deletions .github/workflows/release.yml

This file was deleted.

5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
node_modules
/dist/*.js
.vscode/
/fixtures/repos
/tmp-eslint-config
.vscode
3 changes: 0 additions & 3 deletions .npmrc

This file was deleted.

1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/*
3 changes: 0 additions & 3 deletions .prettierignore

This file was deleted.

28 changes: 14 additions & 14 deletions .renovaterc.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"extends": ["config:base", ":automergeMinor"],
"reviewers": ["team:dev"],
"dependencyDashboard": true,
"stabilityDays": 4,
"packageRules": [
{
"matchDepTypes": ["dependencies"],
"rangeStrategy": "bump"
},
{
"matchPackagePatterns": ["eslint"],
"automerge": false
}
]
"extends": ["config:base", ":automergeMinor"],
"reviewers": ["team:dev"],
"dependencyDashboard": true,
"stabilityDays": 4,
"packageRules": [
{
"matchDepTypes": ["dependencies"],
"rangeStrategy": "bump"
},
{
"matchPackagePatterns": ["eslint"],
"automerge": false
}
]
}
25 changes: 16 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @cloudfour/eslint-plugin

## Unreleased

### Breaking Changes

- Changed from a "super plugin" to a flat config file.
- Changed package name from `@cloudfour/eslint-plugin` to `@cloudfour/eslint-config`.

## 23.0.0

### Major Changes
Expand Down Expand Up @@ -471,22 +478,22 @@

```js
function a() {
if (_) {
a();
b();
c();
}
if (_) {
a();
b();
c();
}
}
```

into:

```js
function a() {
if (!_) return;
a();
b();
c();
if (!_) return;
a();
b();
c();
}
```

Expand Down
32 changes: 2 additions & 30 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,5 @@
# Contributing Guide

## Running @cloudfour/eslint-plugin on itself
## Release Process

In order to run `npm run lint` on this project, it needs to have a symlink to itself in `node_modules`, so that ESLint can find it. To set up this symlink, run `npm link` and then `npm link @cloudfour/eslint-plugin`. Then you should be able to run `npm run lint`.

## Pull Requests

If you are submitting a pull request that includes changes that will affect places where this ESLint config is installed, add a Changeset file to describe the outward-facing changes:
Copy link
Member Author

Choose a reason for hiding this comment

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

Changesets is nice, but a bit of a maintenance burden. I opted to rip it out and just use a standard release process like we do for our Stylelint config.


- On your feature branch, run `npx changeset`.

- First it will ask you what [kind of change it is](https://semver.org/#summary):

- **Major changes** include
- Enabling rules
- Removing rules
- Bugfixes to rules that are likely to error on more code than before
- Removing support for Node or ESLint or TypeScript versions
- **Minor changes** include
- Creating rules that are not enabled by default
- Adding support for Node or ESLint or TypeScript versions
- Bugfixes to rules that are not likely to error on more code than before
- **Patch releases** include
- Bugfixes/refactorings that will not change the functionality

Dependency updates can fall into any of the three categories, consider how the dependency change will affect consumers of this ESLint config.

- Next it will ask you to describe your changes. This message will appear in the Changelog. You can press enter before you type anything to edit the message in your editor.

## Releasing

- [Changesets Action](https://github.com/changesets/action) will create and maintain release PR's whenever changes are pushed to main. Merge the "Publish Next Version" PR to release all unreleased changes on `main`. All of the changes will get combined into a single release. Changesets will handle updating the changelog, pushing git tags, and publishing to npm.
[How to publish an updated version](https://cloudfour.com/thinks/how-to-publish-an-updated-version-of-an-npm-package/)
78 changes: 23 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,75 +1,43 @@
# @cloudfour/eslint-plugin
# @cloudfour/eslint-config
Copy link
Member Author

Choose a reason for hiding this comment

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

Fun bit of history here — This repo is called eslint-config and originally, the node package was called @cloudfour/eslint-config with a version number of 0.X.

One of Caleb's first tasks was bumping the version number to 1.0.0.

Then he converted it to a super-plugin, and changed the package name to @cloudfour/eslint-plugin and bumped the version number to 2.0.0.

Since then, we've released 20+ versions, bumping whenever a dependency released a major version.

Now, I'm converting it back to the config, and reclaiming the @cloudfour/eslint-config package name — which is still at 1.0.0, making this release 2.0.0!

Copy link
Member Author

Choose a reason for hiding this comment

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

After further consideration, I've restored the changelog and set the version number to 24. No sense throwing out our history just because the package name changed again.


[![NPM version](https://img.shields.io/npm/v/@cloudfour/eslint-plugin.svg)](https://www.npmjs.com/package/@cloudfour/eslint-plugin) [![Build Status](https://github.com/cloudfour/eslint-config/workflows/CI/badge.svg)](https://github.com/cloudfour/eslint-config/actions?query=workflow%3ACI) [![Renovate](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com)
[![NPM version](https://img.shields.io/npm/v/@cloudfour/eslint-config.svg)](https://www.npmjs.com/package/@cloudfour/eslint-config) [![Build Status](https://github.com/cloudfour/eslint-config/workflows/CI/badge.svg)](https://github.com/cloudfour/eslint-config/actions?query=workflow%3ACI) [![Renovate](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com)

Cloud Four's ESLint configuration. This exports itself as a "super-plugin" because of a [limitation of ESLint](https://github.com/eslint/eslint/issues/3458).
Cloud Four's ESLint configuration.

The way this works is that it requires all of the plugin dependencies, and exports them from this plugin under a prefix.

The plugins that this exposes are:
This config extends the following plugins:

- [`n`](https://github.com/weiran-zsd/eslint-plugin-node) (maintained fork of original [`eslint-plugin-node`](https://github.com/mysticatea/eslint-plugin-node))
- [`import`](https://github.com/benmosher/eslint-plugin-import)
- [`standard`](https://github.com/standard/eslint-plugin-standard)
- [`promise`](https://github.com/xjamundx/eslint-plugin-promise)
- [`unicorn`](https://github.com/sindresorhus/eslint-plugin-unicorn)
- [`jsdoc`](https://github.com/gajus/eslint-plugin-jsdoc)
- [`unicorn`](https://github.com/sindresorhus/eslint-plugin-unicorn)
- [`standard`](https://github.com/standard/eslint-config-standard)
- [`@typescript-eslint`](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin)

To override settings for any of these plugins, you must prefix the configuration
with `cloudfour/`, because the plugins are exposed through this "super-plugin".

```json
{
"extends": ["plugin:@cloudfour/recommended"],
"rules": {
"@cloudfour/promise/no-native": "off"
}
}
```

In addition to the `recommended` configuration, `@cloudfour/eslint-plugin` also re-exports typescript-eslint's [`disable-type-checked` configuration](https://typescript-eslint.io/linting/configs/#disable-type-checked). This configuration disables any rules that depend on typescript-eslint's typescript integration.

## Installation
It also adds the following custom rules:

```sh
npm install --save-dev @cloudfour/eslint-plugin eslint prettier
```
- [`prefer-early-return`](./rules/prefer-early-return/)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm kind of surprised this isn't part of one of the plugins we extend. This is a great rule


## Usage

Add this to your `package.json`:

```json
"scripts": {
"check-lint": "eslint . && prettier --check .",
"lint": "eslint --fix . && prettier --write ."
},
"eslintConfig": {
"extends": "plugin:@cloudfour/recommended"
},
"prettier": {
"singleQuote": true
}
```

### Check for Lint Errors
This package exports [a flat ESLint configuration](https://eslint.org/docs/latest/use/configure/configuration-files-new).

```sh
npm run check-lint
```bash
npm install --save-dev eslint @cloudfour/eslint-config
```

### Fix Lint Errors
Example `eslint.config.js`:

This command will attempt to automatically fix lint errors. Note that not all lint errors can be fixed this way, so be prepeared to fix any remaining errors by hand.
```js
import cloudFourConfig from '@cloudfour/eslint-config';

```sh
npm run lint
export default [
...cloudFourConfig,
{
rules: {
// your overrides here
...
}
},
];
```

### Troubleshooting Note

This config relies on using a version of eslint installed locally to your project. If you also have eslint installed globally, it's possible to run into conflicts. To avoid any problems, either:

- Just use the `npm run check-lint` and `npm run lint` scripts, which will run the local version of eslint.
- Or, if you prefer to run eslint by hand, use [npx](https://www.npmjs.com/package/npx), which will run the local version of eslint. eg, `npx eslint '**/*.js'`
Loading