Skip to content

feat(require-keywords): add require-keywords rule #884

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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-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. | ✅ | | | |
| [sort-collections](docs/rules/sort-collections.md) | Dependencies, scripts, and configuration values must be declared in alphabetical order. | ✅ | 🔧 | | |
Expand Down
25 changes: 25 additions & 0 deletions docs/rules/require-keywords.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# require-keywords

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

This rule checks for the existence of the `"keywords"` 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",
"keywords": ["eslint"]
}
```
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],
["keywords", false],
["name", true],
["version", true],
// TODO: More to come!
Expand Down
47 changes: 47 additions & 0 deletions src/tests/rules/require-keywords.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-keywords", rules["require-keywords"], {
invalid: [
{
code: "{}",
errors: [
{
data: { property: "keywords" },
line: 1,
messageId: "missing",
},
],
},
{
code: `{
"version": "1.0.0"
}
`,
errors: [
{
data: { property: "keywords" },
line: 1,
messageId: "missing",
},
],
},
{
code: `{
"author": "Jessica Moss",
"bin": {
"keywords": ["test"]
}
}
`,
errors: [
{
data: { property: "keywords" },
line: 1,
messageId: "missing",
},
],
},
],
valid: [`{ "keywords": ["test"] }`],
});
Loading