Skip to content

Commit

Permalink
chore: onboard eslint-doc-generator (#66)
Browse files Browse the repository at this point in the history
Fixes #36.

Adds a `rules` export to `src/index.ts` -> `lib/index.js` in the
process.
  • Loading branch information
JoshuaKGoldberg authored Nov 8, 2023
1 parent 4fe92e0 commit ffbd3ab
Show file tree
Hide file tree
Showing 9 changed files with 1,343 additions and 311 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/lint-eslint-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
jobs:
tsc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/prepare
- run: npm run tsc
- run: npm run lint:eslint-docs

name: Lint ESLint Docs

on:
pull_request: ~
push:
branches:
- main
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,18 @@ module.exports = {

## Supported Rules

- [`package-json/order-properties`](docs/rules/order-properties.md): Require top-level properties to be in a conventional order (`"name"`first, etc.).
- [`package-json/sort-collections`](docs/rules/sort-collections.md): Keep sub-collections like `"dependencies"` and `"scripts"` in alphabetical order.
- [`package-json/valid-package-def`](docs/rules/valid-package-def.md): Validate `package.json` files against the NPM specification.
- [`package-json/valid-local-dependency`](docs/rules/valid-local-dependency.md): Validates the casing for `file:` and `link:` dependencies in the `package.json` files.
<!-- begin auto-generated rules list -->

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

| Name                   | Description | 🔧 |
| :------------------------------------------------------------- | :-------------------------------------------------------------------------------------- | :- |
| [order-properties](docs/rules/order-properties.md) | Package properties must be declared in standard order | 🔧 |
| [sort-collections](docs/rules/sort-collections.md) | Dependencies, scripts, and configuration values must be declared in alphabetical order. | 🔧 |
| [valid-local-dependency](docs/rules/valid-local-dependency.md) | Checks existence of local dependencies in the package.json | |
| [valid-package-def](docs/rules/valid-package-def.md) | Enforce that package.json has all properties required by NPM spec | |

<!-- end auto-generated rules list -->

These rules only run on `package.json` files; they will ignore all other files being linted. They lint `package.json` files at project root, and in any subfolder of the project, making this plugin great for monorepos.

Expand Down
6 changes: 5 additions & 1 deletion docs/rules/order-properties.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Package properties must be declared in standard order (order-properties)
# Package properties must be declared in standard order (`package-json/order-properties`)

🔧 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 -->

A conventional order exists for `package.json` top-level properties. NPM does
not enforce this order, but for consistency and readability, this rule can
Expand Down
6 changes: 5 additions & 1 deletion docs/rules/sort-collections.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Dependencies, scripts, and configuration values must be declared in alphabetical order. (sort-collections)
# Dependencies, scripts, and configuration values must be declared in alphabetical order (`package-json/sort-collections`)

🔧 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 -->

Whenever NPM changes package dependencies through `npm install`, it lexically sorts (that is, alphabetizes by package name) all dependencies in `package.json`. Nevertheless, sometimes a developer will manually update `package.json` and leave dependencies out of order, leading to "noise" in changesets when a later change re-sorts the packages. This rule aims to keep the dependency collections sorted in every commit.

Expand Down
8 changes: 3 additions & 5 deletions docs/rules/valid-local-dependency.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Ensures that local dependencies specified in a package.json exist
# Checks existence of local dependencies in the package.json (`package-json/valid-local-dependency`)

<!-- end auto-generated rule header -->

## Rule Details

Expand All @@ -19,7 +21,3 @@ Examples of **correct** code for this rule:
"some-package": "link:../folder",
}
```

### Options

This rule has no options.
8 changes: 3 additions & 5 deletions docs/rules/valid-package-def.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Enforce that package.json has all properties required by NPM spec (valid-package-def)
# Enforce that package.json has all properties required by NPM spec (`package-json/valid-package-def`)

<!-- end auto-generated rule header -->

NPM issues warnings after install if the `package.json` has a missing or
invalid required property. This rule uses [`package-json-validator`][pjv] to
Expand Down Expand Up @@ -43,10 +45,6 @@ Examples of **correct** code for this rule:
}
```

### Options

This rule has no options.

## When Not To Use It

NPM may complain, but it works perfectly with many package files that do not
Expand Down
Loading

0 comments on commit ffbd3ab

Please sign in to comment.