Skip to content

Commit

Permalink
feat: init
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Feb 21, 2024
0 parents commit f8e2cf3
Show file tree
Hide file tree
Showing 26 changed files with 5,329 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release

on:
push:
branches: master

jobs:
release:
name: Release
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc

- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8
run_install: true

- name: Release
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: pnpm dlx semantic-release
37 changes: 37 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Test

on:
push:
branches: [develop]
pull_request:
branches: [master, develop]

jobs:
test:
name: Test
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc

- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8
run_install: true

- name: Lint
run: pnpm lint

- name: Build
run: pnpm build

- name: Test
run: pnpm test
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# macOS
.DS_Store

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Dependency directories
node_modules/

# Output of 'npm pack'
/*.tgz

# dotenv environment variables file
.env
.env.test

# Distribution
dist

# yarn zero-installs
**/.yarn/*
!**/.yarn/cache
!**/.yarn/releases

# Cache
.eslintcache
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.11.0
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
150 changes: 150 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# 📌 eslint-plugin-fix-later

This plugin automatically suppresses ESLint errors with "fix later" comments, turning them into warnings for future resolution.

<br>

<table>
<tr>
<th align="center">
Before
</th>
<th align="center">
After auto-fix
</th>
</tr>
<tr>
<td>

```js
console.log()
```
<p align="center">

**Error** `no-console Unexpected console statement`
</p>
</td>
<td>

```js
// eslint-disable-next-line no-console -- Fix later
console.log()
```
<p align="center">

⚠️ **Warning** `[REMINDER] Fix later`
</p>
</td>
</tr>
</table>

<br>

> [!TIP]
> Use the `git blame` feature documented below to tag the author in the "fix later" comment.

## Why?

In large projects with many developers, ESLint helps keep code consistent and high-quality. But, updating the ESLint config with new rules can be challenging when it surfaces many new errors. This would be too much for one dev to fix, and potentially risky if it's outside of their familiarity.

This plugin solves this by temporarily suppressing these errors into "fix later" warnings, allowing the right dev to address them when ready. This keeps the project moving forward without sacrificing code quality.

## Install
```
pnpm i -D eslint-plugin-fix-later
```

## Setup

In your ESLint config:

```json5
{
plugins: [
// ...
'fix-later',
],
rules: {
// ...
'fix-later/fix-later': ['warn', {
// Options...
}]
}
}
```

### Recommended workflow

1. **Activate this plugin**

Set up the `fix-later` rule to emit a _warning_ (as opposed to `errors`).

2. **Automate linting on commit**

Use [simple-git-hooks](https://github.com/toplenboren/simple-git-hooks) & [lint-staged](https://github.com/lint-staged/lint-staged) to auto-lint changed files when committing

3. **Disallow linting warnings on commit**

Configure your commit hook to reject warnings: `eslint --max-warnings=0`

This encourages devs working in the file to address outstanding warnings if they can. If not, they can commit with `--no-verify`.

4. **Disallow linting errors on CI**

On CI, run ESLint with warnings allowed: `eslint .`

This approach prevents errors from slipping through while accommodating "fix later" notes.

## Options

### includeWarnings

Type: `boolean`

Default: `false`

Whether to suppress warnings in addition to errors.

### insertDisableComment

Type: `'above-line' | 'end-of-line'`

Default: `'end-of-line'`

Whether to put the `eslint-disable` comment on the same line or on the line above.

### commentTemplate

Type: string

Default: `'// {{ eslint-disable }} -- Fix later'`

The template for the `eslint-disable` comment. The `{{ eslint-disable }}` handlebar is required to interpolate the `eslint-disable` type into.

#### Git blame

You can also `git blame` the errorneous code and leave a TODO for the author:
```
// {{ eslint-disable }} -- Please fix: {{ blame.author }} <{{ blame.author-mail }}>
```

Which will create the following comment:
```
// eslint-disable-line -- Please fix: John Doe <[email protected]>
```

All properties from `git blame` are available:

```json5
{
"author": "John Doe",
"author-mail": "[email protected]",
"author-time": "1708498454",
"author-tz": "+0100",
"committer": "John Doe",
"committer-mail": "<[email protected]>",
"committer-time": "1708498454",
"committer-tz": "+0100"
}
```
53 changes: 53 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "eslint-plugin-fix-later",
"version": "0.0.0-semantic-release",
"description": "ESLint plugin to suppresses ESLint errors as warnings for future resolution",
"keywords": [
"eslint",
"plugin",
"fix",
"later",
"suppress",
"errors",
"warnings"
],
"license": "MIT",
"repository": "privatenumber/eslint-plugin-fix-later",
"author": {
"name": "Hiroki Osame",
"email": "[email protected]"
},
"files": [
"dist"
],
"main": "./dist/index.cjs",
"exports": "./dist/index.cjs",
"scripts": {
"test": "tsx tests",
"dev": "tsx watch tests",
"build": "pkgroll",
"lint": "lint . --ignore-pattern README.md",
"prepack": "pnpm build && clean-pkg-json"
},
"peerDependencies": {
"eslint": "^7.0.0"
},
"devDependencies": {
"@pvtnbr/eslint-config": "^1.0.3",
"@types/eslint": "^8.56.2",
"@types/node": "^20.11.19",
"clean-pkg-json": "^1.2.0",
"dot-prop": "^8.0.2",
"eslint": "^8.56.0",
"execa": "^8.0.1",
"fs-fixture": "^1.2.0",
"manten": "^1.2.0",
"outdent": "^0.8.0",
"pkgroll": "^2.0.1",
"tsx": "^4.7.1",
"typescript": "^5.3.3"
},
"eslintConfig": {
"extends": "@pvtnbr/eslint-config"
}
}
Loading

0 comments on commit f8e2cf3

Please sign in to comment.