Skip to content

Commit

Permalink
feat(require-files): add require-files rule (#887)
Browse files Browse the repository at this point in the history
<!-- πŸ‘‹ Hi, thanks for sending a PR to eslint-plugin-package-json! πŸ’–.
Please fill out all fields below and make sure each item is true and [x]
checked.
Otherwise we may not be able to review your PR. -->

## PR Checklist

-   [x] Addresses an existing open issue: fixes #803 
- [x] That issue was marked as [`status: accepting
prs`](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
- [x] Steps in
[CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/blob/main/.github/CONTRIBUTING.md)
were taken

## Overview

<!-- Description of what is changed and how the code change does that.
-->

Add `require-files` rule
  • Loading branch information
chouchouji authored Feb 10, 2025
1 parent 036a033 commit 4de33de
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ The default settings don't conflict, and Prettier plugins can quickly fix up ord
| [order-properties](docs/rules/order-properties.md) | Package properties must be declared in standard order | βœ… | πŸ”§ | | |
| [repository-shorthand](docs/rules/repository-shorthand.md) | Enforce either object or shorthand declaration for repository. | βœ… | πŸ”§ | | |
| [require-author](docs/rules/require-author.md) | Requires the `author` property to be present. | | | | |
| [require-files](docs/rules/require-files.md) | Requires the `files` property to be present. | | | | |
| [require-keywords](docs/rules/require-keywords.md) | Requires the `keywords` property to be present. | | | | |
| [require-name](docs/rules/require-name.md) | Requires the `name` property to be present. | βœ… | | | |
| [require-version](docs/rules/require-version.md) | Requires the `version` property to be present. | βœ… | | | |
Expand Down
25 changes: 25 additions & 0 deletions docs/rules/require-files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# require-files

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

This rule checks for the existence of the `"files"` property in a package.json,
and reports a violation if it doesn't exist.

Example of **incorrect** code for this rule:

```json
{
"name": "thee-silver-mt-zion",
"version": "13.0.0"
}
```

Example of **correct** code for this rule:

```json
{
"name": "thee-silver-mt-zion",
"version": "13.0.0",
"files": ["lib"]
}
```
1 change: 1 addition & 0 deletions src/rules/require-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { createRequirePropertyRule } from "../utils/createRequirePropertyRule.js
// in the format [propertyName, isRecommended]
const properties = [
["author", false],
["files", false],
["keywords", false],
["name", true],
["version", true],
Expand Down
47 changes: 47 additions & 0 deletions src/tests/rules/require-files.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { rules } from "../../rules/require-properties.js";
import { ruleTester } from "./ruleTester.js";

ruleTester.run("require-files", rules["require-files"], {
invalid: [
{
code: "{}",
errors: [
{
data: { property: "files" },
line: 1,
messageId: "missing",
},
],
},
{
code: `{
"version": "1.0.0"
}
`,
errors: [
{
data: { property: "files" },
line: 1,
messageId: "missing",
},
],
},
{
code: `{
"author": "Jessica Moss",
"bin": {
"files": ["lib"]
}
}
`,
errors: [
{
data: { property: "files" },
line: 1,
messageId: "missing",
},
],
},
],
valid: [`{ "files": ["lib"] }`],
});

0 comments on commit 4de33de

Please sign in to comment.