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 failures on CI #21986

Merged
merged 1 commit into from
Sep 23, 2024
Merged

Fix lint failures on CI #21986

merged 1 commit into from
Sep 23, 2024

Conversation

silamon
Copy link
Contributor

@silamon silamon commented Sep 15, 2024

Proposed change

Lint failures are appearing on some pull requests since #21940. This only appears when cache is being refreshed for now.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue or discussion:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

Summary by CodeRabbit

  • New Features

    • Enhanced performance and reactivity of the Matter device and Z-Wave JS node addition dialogs by transitioning to the Lit framework.
    • Improved initialization of components with updated lifecycle methods for better functionality.
  • Bug Fixes

    • Ensured proper setup and initialization of web components through updated class definitions.

Copy link
Contributor

coderabbitai bot commented Sep 15, 2024

Walkthrough

Walkthrough

The changes involve refactoring two classes, MatterAddDevice and DialogZWaveJSAddNode, to extend LitElement instead of HTMLElement. This transition incorporates the Lit framework for building web components, enhancing their performance and reactivity. Both classes now properly initialize their parent class through the connectedCallback method, ensuring that necessary setup from LitElement is executed while maintaining their original functionality related to device addition dialogs.

Changes

File Path Change Summary
src/panels/config/integrations/integration-panels/matter/matter-add-device.ts
src/panels/config/integrations/integration-panels/zwave_js/zwave_js-add-node.ts
Changed class definitions from extending HTMLElement to LitElement and added super.connectedCallback(); in the connectedCallback method.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MatterAddDevice
    participant DialogZWaveJSAddNode

    User->>MatterAddDevice: Open Add Device Dialog
    MatterAddDevice->>MatterAddDevice: connectedCallback()
    MatterAddDevice->>User: Display Dialog

    User->>DialogZWaveJSAddNode: Open Add Node Dialog
    DialogZWaveJSAddNode->>DialogZWaveJSAddNode: connectedCallback()
    DialogZWaveJSAddNode->>User: Display Dialog
Loading

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4608e59 and 63ff35d.

Files selected for processing (2)
  • src/panels/config/integrations/integration-panels/matter/matter-add-device.ts (1 hunks)
  • src/panels/config/integrations/integration-panels/zwave_js/zwave_js-add-node.ts (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/panels/config/integrations/integration-panels/matter/matter-add-device.ts
  • src/panels/config/integrations/integration-panels/zwave_js/zwave_js-add-node.ts

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

import { customElement } from "lit/decorators";
import { navigate } from "../../../../../common/navigate";
import { HomeAssistant } from "../../../../../types";
import { showMatterAddDeviceDialog } from "./show-dialog-add-matter-device";

@customElement("matter-add-device")
export class MatterAddDevice extends HTMLElement {
export class MatterAddDevice extends LitElement {
Copy link
Member

Choose a reason for hiding this comment

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

Why should this extend LitElement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure why it's HTMLElement, but the linting introduced in #21940 forces us to use LitElement. We should revert that one if this is inappropiate.

Copy link
Member

Choose a reason for hiding this comment

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

It is because the customElement decorator is used, that was added in that release of es-lit, which I don't agree with that but ok...

This is HTMLElement because it is not needed to be a LitElement, because it doesnt use Lit (LitElement extends ReactiveElement) or properties it need to be updated from (ReactiveElement extends HTMLElement)

We can either remove the customElement decorator, and register the element manually:

customElements.define("matter-add-device", MatterAddDevice);

Or ignore the linting issue.

import { customElement } from "lit/decorators";
import { navigate } from "../../../../../common/navigate";
import { HomeAssistant } from "../../../../../types";
import { showZWaveJSAddNodeDialog } from "./show-dialog-zwave_js-add-node";

@customElement("zwave_js-add-node")
export class DialogZWaveJSAddNode extends HTMLElement {
export class DialogZWaveJSAddNode extends LitElement {
Copy link
Member

Choose a reason for hiding this comment

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

Why should this extend LitElement?

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range and nitpick comments (1)
src/panels/config/integrations/integration-panels/matter/matter-add-device.ts (1)

Line range hint 1-24: Consider transitioning to LitElement as discussed

Based on the past review comments and the PR objectives, there was a discussion about transitioning this component to extend LitElement instead of HTMLElement. This change hasn't been implemented yet, and it might be the root cause of the lint failures mentioned in the PR summary.

Consider refactoring the class to extend LitElement:

-import { customElement } from "lit/decorators";
+import { LitElement, html } from "lit";
+import { customElement } from "lit/decorators";
 import { navigate } from "../../../../../common/navigate";
 import { HomeAssistant } from "../../../../../types";
 import { showMatterAddDeviceDialog } from "./show-dialog-add-matter-device";

 @customElement("matter-add-device")
-export class MatterAddDevice extends HTMLElement {
+export class MatterAddDevice extends LitElement {
   public hass!: HomeAssistant;

   connectedCallback() {
     super.connectedCallback();
     showMatterAddDeviceDialog(this);
     navigate(`/config/devices`, {
       replace: true,
     });
   }
+
+  render() {
+    return html``;
+  }
 }

 declare global {
   interface HTMLElementTagNameMap {
     "matter-add-device": MatterAddDevice;
   }
 }

This refactoring addresses the discussion in the past comments and might resolve the lint failures mentioned in the PR objectives.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b7cf3e2 and 4608e59.

Files selected for processing (2)
  • src/panels/config/integrations/integration-panels/matter/matter-add-device.ts (1 hunks)
  • src/panels/config/integrations/integration-panels/zwave_js/zwave_js-add-node.ts (1 hunks)
Additional comments not posted (1)
src/panels/config/integrations/integration-panels/matter/matter-add-device.ts (1)

11-11: Verify the necessity of super.connectedCallback()

The addition of super.connectedCallback() is correct for HTMLElement. However, given the past comments and the PR objectives, we need to verify if this change addresses the lint failures mentioned in the PR summary.

Let's check if there are any lint rules related to super.connectedCallback():

@@ -10,6 +10,7 @@ export class DialogZWaveJSAddNode extends HTMLElement {
public configEntryId!: string;

connectedCallback() {
super.connectedCallback();
Copy link
Contributor

Choose a reason for hiding this comment

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

Inconsistent use of super.connectedCallback()

The addition of super.connectedCallback() is inconsistent with the class extending HTMLElement. HTMLElement doesn't have a connectedCallback method to call.

This change suggests that the class should be extending LitElement instead of HTMLElement, which aligns with the past review comment asking why this should extend LitElement.

Consider updating the class declaration to extend LitElement:

- export class DialogZWaveJSAddNode extends HTMLElement {
+ export class DialogZWaveJSAddNode extends LitElement {

If you make this change, ensure you also:

  1. Import LitElement from the appropriate Lit package.
  2. Update any necessary TypeScript declarations or imports.
  3. Refactor the class to properly use Lit's reactive properties and rendering if needed.

Committable suggestion was skipped due to low confidence.

@bramkragten bramkragten enabled auto-merge (squash) September 23, 2024 15:45
@bramkragten bramkragten merged commit be02a88 into home-assistant:dev Sep 23, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants