Skip to content
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

chore(types): solidify type annotations, add tsc checks #56

Merged
merged 7 commits into from
Aug 3, 2024

Conversation

argl
Copy link
Contributor

@argl argl commented Aug 2, 2024

Description

Set type verification to "strict" and fixes any tsc related issues, hardening the types and assorted checks.

(MP-1401)

@argl argl marked this pull request as ready for review August 2, 2024 13:11
@argl argl requested review from mdn-bot and a team as code owners August 2, 2024 13:11
Copy link
Member

@LeoMcA LeoMcA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question: in the places you've used getFirstHttpHeader do we know what user agents should be doing by-spec if they receive more than one header? Should they be ignoring other headers, should they be merging headers, should they be raising an error?

Otherwise a few little nits, but looks good!

"moduleResolution": "nodenext"
}
"moduleResolution": "nodenext",
"strict": true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with strict true, we can remove noImplicitAny above (as it defaults to true when strict is true)

.split(",") // NodeJS joins multiple headers with a comma
.map((scpString) => scpString.replace(/[\r\n]/g, "").trim())
: [""]
scpString ? scpString.replaceAll(/[\r\n]/g, "").trim() : [""]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can scpString (typo of cspString?) be undefined? Typescript doesn't think so. And isn't it already a flat array? Could this simply be:

const cleanCspList = cspList.map((cspString) => cspString.replaceAll(/[\r\n]/g, "").trim())`

Comment on lines 77 to 84
let policy = output.data
.split(",")
.filter((e) => valid.includes(e.toLowerCase().trim()))
.reverse()[0]
?.toLowerCase()
.trim();
? output.data
.split(",")
.filter((e) => valid.includes(e.toLowerCase().trim()))
.reverse()[0]
?.toLowerCase()
.trim()
: "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might it be a bit neater to do?
let policy = output.data?.split(",").etc(...) ?? "";

@argl
Copy link
Contributor Author

argl commented Aug 3, 2024

Most docs I found on duplicate headers say that behaviour is undefined ("...agents MAY combine it to a comma-separated list..."), with some exceptions like cookie and CSP headers. I could not find a general answer to that, but I am ready to be proven wrong.

@argl argl changed the title Mp 1401 tsc type verification chore(types): solidify type annotations, add tsc checks Aug 3, 2024
@argl argl merged commit fa09305 into main Aug 3, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants