-
Notifications
You must be signed in to change notification settings - Fork 28
feat(valid-scripts): add valid-scripts rule (#839) #903
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
base: main
Are you sure you want to change the base?
Conversation
This change adds a new `valid-scripts` rule, which is also included in the `recommended` config.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #903 +/- ##
==========================================
+ Coverage 98.77% 98.83% +0.06%
==========================================
Files 21 22 +1
Lines 1222 1287 +65
Branches 142 151 +9
==========================================
+ Hits 1207 1272 +65
Misses 15 15 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😱 sorry for missing this for multiple weeks! This generally looks great to me - mostly small touchups. I think the only big point is whether we should validate that multiple keys aren't identical (IMO we should, but open to thoughts?).
🖤
emptyScript: | ||
'values contained in "scripts" object should not be empty', | ||
emptyScriptsField: '"scripts" field should not be empty.', | ||
incorrectTypeScript: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Praise] Haha, "TypeScript". I thought this was cute. 🙂
messageId: "incorrectTypeScript", | ||
node: node.value as unknown as ESTree.Node, | ||
}); | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Question] Why return;
? If multiple scripts are incorrect, we'd want to get reports on all of them I think.
E.g. here I'd expect the values of both script1
and script3
to have complaints:
"scripts": {
"script1": "",
"script2": "...",
"script3": "",
}
(here and the other return
)
{ | ||
code: `{ "scripts": { "test": undefined }}`, | ||
errors: [{ messageId: "incorrectTypeScript" }], | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Testing] No need, undefined
isn't valid JSON.
{ | |
code: `{ "scripts": { "test": undefined }}`, | |
errors: [{ messageId: "incorrectTypeScript" }], | |
}, |
I'm actually surprised this doesn't cause any "hey you have invalid stuff" complaint in the tester...
errors: [{ messageId: "incorrectTypeScript" }], | ||
}, | ||
], | ||
valid: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Testing] Some more valid cases to think of:
- No
"scripts"
key at all - Empty
"scripts"
- Just one value in
"scripts"
import { ruleTester } from "./ruleTester.js"; | ||
|
||
ruleTester.run("valid-scripts", rule, { | ||
invalid: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Testing] Some more invalid cases to think of:
- 1 incorrect value + 2 correct values
- 2 incorrect values
- duplicate values
- 2 incorrect values + 1 correct value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Feature] Fun fact, it is technically valid JSON to have duplicate keys:
"scripts": {
"this-is": "fine",
"this-is": "fine"
}
cc @michaelfaith to check me here, but IMO this should be reported on by valid-scripts
.
|
||
<!-- end auto-generated rule header --> | ||
|
||
This rule applies two validations to each property in `"scripts"` field: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Docs] Just nitpicking a little bit for clarity, WDYT?
This rule applies two validations to each property in `"scripts"` field: | |
This rule checks that if a `"scripts"` property exists, it is a non-empty object. | |
Additionally, for each of its script properties: |
This change adds a new
valid-scripts
rule, which is also included in therecommended
config.PR Checklist
status: accepting prs
Overview
This rule checks for
"scripts"
field to be an non-empty object.This rule checks that each property in
"scripts"
field:🖤