-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(require-files): add require-files rule (#887)
<!-- π 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
1 parent
036a033
commit 4de33de
Showing
4 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] }`], | ||
}); |