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

style(typescript): enable strict except noImplicitAny and strictNullChecks #7559

Merged
merged 16 commits into from
Nov 24, 2022

Conversation

nschonni
Copy link
Collaborator

Summary

ESLint is checking a bunch more on the TS files, but there are still some things that the compiler is suppressing. With just strict there were 800+ issues, but with the other 2 options it's down to 76

Problem

Solution

Either the remaining issues could be suppressed inline or addressed before landing this


Screenshots

Before

After


How did you test this change?

@caugner
Copy link
Contributor

caugner commented Nov 15, 2022

Great initiative, we definitely want this!

However, it's probably more realistic to enable strict one after another in the subfolders' tsconfig.json.

@nschonni
Copy link
Collaborator Author

I just tried updating some of the sub-configs with

{
  "extends": "../tsconfig.json",
  "include": ["."],
  "compilerOptions": {
    "strict": true
  }
}

But it doesn't seem to have any affect

@github-actions github-actions bot added flaw-system issues and feature requests related to the flaws system macros tracking issues related to kumascript macros markdown markdown related issues and pull requests labels Nov 16, 2022
Copy link
Contributor

@caugner caugner left a comment

Choose a reason for hiding this comment

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

Note that I'm fixing/ignoring the other warnings in #7601.

subpages(path, depth, self) {
return this.page.subpagesExpand(path, depth, self);
subpages(this: KumaThis, path, depth, self) {
return (this.page as any).subpagesExpand(path, depth, self);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know why this.page doesn't work, possibly because this.page refers to what this would be without specifying this: KumaThis. 🤷

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is the this.page.subpagesExpanded needed vs this.subpagesExpanded

Copy link
Contributor

Choose a reason for hiding this comment

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

Haven't tried, but it looks like all those methods get called using Function.call() with the environment ("KumaThis") as argThis.

Copy link
Collaborator

Choose a reason for hiding this comment

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

this.page.XXX is needed because this is not the page when this function is called, as per the above statement. TypeScript doesn't like this since we're essentially overwriting the variable with a new value, hence the need to cast to any here.

@@ -164,7 +173,7 @@ const web = {
flawAttribute = ` data-flaw-src="${util.htmlEscape(flaw.macroSource)}"`;
}
// Let's get a potentially localized title for when the document is missing.
const titleWhenMissing = this.mdn.getLocalString(
const titleWhenMissing = (this.mdn as any).getLocalString(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is similar to the previous issue, except that this.web.getJSONData() works here (although this.web is the self-reference here) whereas this.mdn.getLocalString() doesn't. 😕

// If the path ends with a slash, remove it.
if (path.substr(-1, 1) === "/") {
path = path.slice(0, -1);
}

const pages = this.page.subpages(path, depth, self);
const pages = (this.page as any).subpages(path, depth, self);
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

tool/cli.ts Outdated Show resolved Hide resolved
tool/sync-translated-content.ts Show resolved Hide resolved
@caugner caugner changed the title chore: enable Strict in TSConfig style(typescript): enable strict, but without noImplicitAny/strictNullChecks Nov 16, 2022
@caugner caugner changed the title style(typescript): enable strict, but without noImplicitAny/strictNullChecks style(typescript): enable strict except noImplicitAny and strictNullChecks Nov 16, 2022
build/flaws/index.ts Outdated Show resolved Hide resolved
build/index.ts Outdated Show resolved Hide resolved
@caugner
Copy link
Contributor

caugner commented Nov 18, 2022

I triggered a dev build to make sure this doesn't break anything: https://github.com/mdn/yari/actions/runs/3497657664

@github-actions
Copy link
Contributor

Dev build for fc0cdc9 was deployed to: https://pr7559.content.dev.mdn.mozit.cloud/

@caugner
Copy link
Contributor

caugner commented Nov 18, 2022

Dev build for fc0cdc9 was deployed to: https://pr7559.content.dev.mdn.mozit.cloud/

LGTM

Now covered by `strict`
@nschonni
Copy link
Collaborator Author

Pushed one change, that shouldn't change the testing. https://www.typescriptlang.org/tsconfig/#strictBindCallApply is not already turned on by strict so I just cleaned it out of the config

@caugner caugner merged commit 13a2ed0 into mdn:main Nov 24, 2022
@nschonni nschonni deleted the tsconfig-strict branch November 24, 2022 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flaw-system issues and feature requests related to the flaws system macros tracking issues related to kumascript macros markdown markdown related issues and pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants