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

fix(lint/noUnreachableSuper): handle complex CFG #97

Merged
merged 1 commit into from
Sep 4, 2023

Conversation

Conaclos
Copy link
Member

@Conaclos Conaclos commented Aug 30, 2023

Summary

Fix rome#4616.

I take the opportunity to fix an unnoticed bug: the rule assimilated super calls such as super.method() to a super call super().

I think that the new implementation is simpler and more robust.

i discovered some cases statically undecidable. For instance the following example:

class A {
    constructor(a) {
        if (a) { throw new Error(); }
    }
}

class B extends A {
    constructor() {
        try {
            super(true);
            f();
        } catch { super(false); }
    }
}

As a workaround, I decided to assume that the try block has both a super() call and no super() call when an exception is caught. Thus, the rule reports duplicate super() in the previous example.

We could also ignore catch blocks. Any thought?

EDIT: TypeScript uses the same workaround.


Note: I have just noticed that I had a wrong assumption about throw expressions. Biome CFG wrapped every throw expression in a return instruction, including throw in a try catch block. I expected a jump for this special case... Not sure if this should be fixed in the rule implementation or on the CFG?

I think this issue requires more thoughts and should be fixed in another PR.

Test Plan

New tests included.

@Conaclos Conaclos temporarily deployed to Website deployment August 30, 2023 23:00 — with GitHub Actions Inactive
@Conaclos Conaclos requested a review from ematipico August 30, 2023 23:00
@github-actions github-actions bot added A-Linter Area: linter A-Website Area: website L-JavaScript Language: JavaScript and super languages A-Changelog Area: changelog labels Aug 30, 2023
@Conaclos Conaclos force-pushed the conaclos/lint/noUnreachableSuper/rome4616 branch from 8dce8e0 to a720e75 Compare August 30, 2023 23:01
@Conaclos Conaclos temporarily deployed to Website deployment August 30, 2023 23:01 — with GitHub Actions Inactive
@Conaclos Conaclos force-pushed the conaclos/lint/noUnreachableSuper/rome4616 branch from a720e75 to 698cde3 Compare August 30, 2023 23:03
@Conaclos Conaclos temporarily deployed to Website deployment August 30, 2023 23:03 — with GitHub Actions Inactive
@Conaclos Conaclos force-pushed the conaclos/lint/noUnreachableSuper/rome4616 branch from 698cde3 to 523c15b Compare August 31, 2023 10:22
@Conaclos Conaclos temporarily deployed to Website deployment August 31, 2023 10:23 — with GitHub Actions Inactive
@Conaclos
Copy link
Member Author

Conaclos commented Sep 3, 2023

noUnreachableSuper and noInvalidConstructorSuper have covering cases. They both report classes that should call super(). One difference is that noInvalidConstructorSUper also checks that a class which extends a non-constructor should not call super().

To avoid double reports, I suggest removing the common check from noUnreachableSuper. Another solution is merging the two rules into noUnreachableSuper.

@ematipico
Copy link
Member

Note: I have just noticed that I had a wrong assumption about throw expressions. Biome CFG wrapped every throw expression in a return instruction, including throw in a try catch block. I expected a jump for this special case... Not sure if this should be fixed in the rule implementation or on the CFG?

It's possible it's a bug

@Conaclos
Copy link
Member Author

Conaclos commented Sep 4, 2023

@ematipico
Have you some thoughts about my remark

@ematipico
Copy link
Member

noUnreachableSuper and noInvalidConstructorSuper have covering cases. They both report classes that should call super(). One difference is that noInvalidConstructorSUper also checks that a class which extends a non-constructor should not call super().

To avoid double reports, I suggest removing the common check from noUnreachableSuper. Another solution is merging the two rules into noUnreachableSuper.

I believe they should be two different rules, they have clearly two different purposes and they don't necessarily overlap. It's totally reasonable to have two rules that report on the same TextRange.

@Conaclos Conaclos force-pushed the conaclos/lint/noUnreachableSuper/rome4616 branch 2 times, most recently from e532ebb to 059ebaf Compare September 4, 2023 15:49
@Conaclos Conaclos temporarily deployed to Website deployment September 4, 2023 15:49 — with GitHub Actions Inactive
@Conaclos Conaclos merged commit 9f0b9aa into main Sep 4, 2023
@Conaclos Conaclos deleted the conaclos/lint/noUnreachableSuper/rome4616 branch September 4, 2023 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Changelog Area: changelog A-Linter Area: linter A-Website Area: website L-JavaScript Language: JavaScript and super languages
Projects
None yet
2 participants