Skip to content

Extended diagnostics in compiler #42966

Closed

Description

@dgp1130

Which @angular/* package(s) are relevant/releated to the feature request?

compiler-cli

Description

The compiler should have some capability for "extended template diagnostics", meaning diagnostics applied after type checking. Currently, the compiler doesn't really have any warnings, and only ever fails for fatal issues that directly prevent compilation (with some minor exceptions). These extended diagnostics will allow warnings to be easily authored to check for smaller mistakes like getting two-way binding syntax backwards ([foo])="bar" or having extraneous operators like using foo ?? 'bar' when foo is not nullable.

For scoping, we just need a private flag in the compiler for now. This will be enough for the CLI and language service to plug in and surface these diagnostics.

Proposed solution

A new private flag in the compiler which enables "extended template diagnostic" checks that give warning/information diagnostics about user templates which aren't strictly fatal errors. This issue is mostly about building the required infrastructure, but we should include one or two simple checks to validate the system.

Alternatives considered

N/A

Activity

  1. added
    feature
    area: compiler
    on Jul 26, 2021
  2. modified the milestone: Backlog on Jul 26, 2021
  3. dgp1130 commented on Jul 26, 2021

    @dgp1130
    ContributorAuthor
  4. angular-robot commented on Jul 27, 2021

    @angular-robot
    Contributor

    This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.

    You can find more details about the feature request process in our documentation.

  5. itea-dev commented on Jul 27, 2021

    @itea-dev
    Contributor

    @eneajaho @ahnpnl

    A suggestion for you... Use thumbs up (👍) for voting.

  6. 296 remaining items

  7. angular-robot commented on Sep 5, 2021

    @angular-robot
    Contributor

    Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

    Find more details about Angular's feature request process in our documentation.

  8. dgp1130 commented on Sep 9, 2021

    @dgp1130
    ContributorAuthor

    Most of the implementation here is done (thanks @danieltre23!). We're current working through some of the surrounding integrations that need to be done. The three main tasks left before we can do an initial MVP release are:

    • Determining what kind of configuration we want to support and implementing it.
    • Determining how the CLI should integrate with extended template checks.
    • Decide what extended checks we want to include to justify the public launch. We currently check for invalid banana in box and a useless nullish coalescing, is that enough for the initial release or should we include more?

    Some initial ideas of additional checks we could add:

    • No negated async pipes
    • Verify that all UI text nodes have an i18n attribute.
    • a11y attribute validator
    • Non-nullable optional chaining
      • foo?.bar is useless if foo is not nullable.
    • Catching foo | date: "format" ?? 'test'
      • The ?? applies to "format", which isn't what the user wanted.
      • Does the existing nullish coalescing check already catch this case? My intuition is yes?
        • Edit: Yes it does., but we could have a clearer error message here.
    • Other Codelyzer checks.

    We'll need to decide how much to do for the initial release and what we want to defer for later.

  9. dgp1130 commented on Sep 10, 2021

    @dgp1130
    ContributorAuthor

    Some more possible ideas: #42690

  10. angular-robot commented on Sep 25, 2021

    @angular-robot
    Contributor

    Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

    We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

    You can find more details about the feature request process in our documentation.

  11. dgp1130 commented on Sep 27, 2021

    @dgp1130
    ContributorAuthor

    Just discussed the configuration support we'll need for MVP. Our current plan is to support:

    • Enabling / disabling all extended template checks via a single option.
    • Suppressing individual checks by name (error codes already have "names", we just need to plumb this through and expose them publicly).
    • Promoting warnings to errors by name.
    • Promoting all warnings to errors via a single option.
    • Document all this and the specific checks for each.

    This will be managed in the tsconfig.json so editors, language service, and the like will see and use these options. The Angular CLI already supports compiling with a specific tsconfig.json in the browser builder, so users could create multiple targets with different configurations if they want to be more specific (such as warnings in local dev but errors on CI).

    This should be enough for an MVP of the feature that can be officially launched. I also have #43582 out to make ngc-wrapped pass the build if only warnings are emitted, as well as #43572 to fix a minor bug in the nullish coalescing not nullable check. We'll also need to confirm that the CLI doesn't fail when given only warnings, but that should be an easy fix if not.

    Tracking google3 launch of this feature in http://b/199443160.

  12. angular-robot commented on Sep 28, 2021

    @angular-robot
    Contributor

    Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

    We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

    You can find more details about the feature request process in our documentation.

  13. dgp1130 commented on Oct 11, 2021

    @dgp1130
    ContributorAuthor

    One more idea for an extended template diagnostic, warn on != or == in an *ngIf conditional. Devs should almost always prefer !== or === due to simpler behavior on type mismatches, and related lint checks for JS/TS code is pretty common. Doing the same for extended template diagnostics would be an easy win.

  14. dgp1130 commented on Dec 7, 2021

    @dgp1130
    ContributorAuthor

    #44391 has the main implementation of the configuration. Once that lands a simple flag flip should be sufficient to enable the feature.

    The one other task left to do is make some documentation on the implemented diagnostics. Long term, we'd like to make something similar to https://angular.io/errors. For now, we'll start with just a single page that talks about these diagnostics and lists out the two we're starting with (invalidBananaInBox and nullishCoalescingNotNullable), how they work, why they are bad practice, and what users can do about them.

  15. JoostK commented on Jan 27, 2022

    @JoostK
    Member

    This is now available in 13.2, for anyone interested here's the docs.

  16. dgp1130 commented on Jan 28, 2022

    @dgp1130
    ContributorAuthor
  17. DaSchTour commented on Feb 1, 2022

    @DaSchTour

    I wonder what is the difference between diagnostics checks and @angular-eslint/eslint-plugin-template? I think it would be better to have one solution and not create different in worst case incompatible solutions.
    Linter would also have the benefit of beeing visible while without angular runing and also having fixers.

  18. dgp1130 commented on Feb 2, 2022

    @dgp1130
    ContributorAuthor

    @DaSchTour, see #44712 (comment) for a bit more background.

    Extended diagnostics are intended to work with angular-eslint and provide a hook for surfacing critical diagnostics to the user earlier to save debugging and implementation time. Linters offer a much broader set of checks than extended diagnostics are intended to support.

    To address your two specific comments, extended diagnostics are visible in the Angular language service and should appear in your IDE. I also just opened an issue about supporting fixers (#44941), which is something we experimented with a while back and are hoping to implement in the future.

  19. angular-automatic-lock-bot commented on Mar 5, 2022

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: compilerfeaturefeature: under consideration

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions