-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Don't set hass to undefined in lovelace cards. #21189
Conversation
Note Reviews pausedUse the following commands to manage reviews:
WalkthroughThe recent changes improve the configuration handling, loading, and property management across various Lovelace card components within the codebase. Key adjustments include added Changes
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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 as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
@coderabbitai pause |
@coderabbitai configuration |
CodeRabbit configurationlanguage: en-US
tone_instructions: ''
early_access: false
enable_free_tier: true
reviews:
profile: assertive
request_changes_workflow: false
high_level_summary: true
high_level_summary_placeholder: '@coderabbitai summary'
auto_title_placeholder: '@coderabbitai title'
poem: false
review_status: false
collapse_walkthrough: true
path_filters: []
path_instructions:
- path: '*/**(html|markdown|md)'
instructions: >-
- For instructional content in documentation, use a direct and
authoritative tone. Avoid expressions of politeness such as 'may' or
'please', and ensure the goal of the instruction is fronted.
- Apply the Microsoft Style Guide to ensure documentation maintains
clarity and conciseness.
- In step-by-step instructions, front the location phrase in the
instructional sentence.
- In step-by-step instructions, front the 'goal' in the instructional
sentence.
- In step-by-step instructions, if in doubt what to front, front the
'goal' before the location phrase in the instructional sentence.
- do not hyphenate terms like 'top-right' or 'bottom-left' with 'corner'
- path: '*/**(html|markdown|md)'
instructions: |-
- Use bold to mark UI strings.
- If "" are used to mark UI strings, replace them by bold.
- path: '*/**(html|markdown|md)'
instructions: >-
- Be brief in your replies and don't add fluff like "thank you for..."
and "Please let me know if"
- path: '*/**(html|markdown|md)'
instructions: '- Use sentence-style capitalization also in headings.'
abort_on_close: true
auto_review:
enabled: true
auto_incremental_review: true
ignore_title_keywords: []
labels: []
drafts: false
base_branches:
- master
- main
- rc
- next
- current
- dev
tools:
shellcheck:
enabled: true
ruff:
enabled: true
markdownlint:
enabled: true
github-checks:
enabled: true
timeout_ms: 90000
languagetool:
enabled: true
disabled_rules:
- EN_UNPAIRED_BRACKETS
- ENGLISH_WORD_REPEAT_BEGINNING_RULE
- REP_WANT_TO_VB
disabled_categories:
- TYPOGRAPHY
enabled_only: false
level: default
enabled_rules: []
enabled_categories: []
biome:
enabled: true
hadolint:
enabled: true
swiftlint:
enabled: true
phpstan:
enabled: true
level: '1'
golangci-lint:
enabled: true
yamllint:
enabled: true
gitleaks:
enabled: true
checkov:
enabled: true
ast-grep:
packages: []
rule_dirs: []
util_dirs: []
essential_rules: true
chat:
auto_reply: true
knowledge_base:
learnings:
scope: global
issues:
scope: global
jira:
project_keys: []
linear:
team_keys: []
|
5097df0
to
f0fb94b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Outside diff range comments (5)
src/panels/lovelace/cards/hui-card.ts (1)
Line range hint
131-162
: Complexity and error handling inupdate
method.The
update
method has a high complexity and multiple points where errors can occur. Consider refactoring to simplify the logic and improve error handling.- // Current implementation + // Suggested refactoring hereTools
Biome
[error] 91-91: Unexpected any. Specify a different type.
any disables many type checking rules. Its use should be avoided.
(lint/suspicious/noExplicitAny)
[error] 102-102: Forbidden non-null assertion.
(lint/style/noNonNullAssertion)
[error] 152-152: Unexpected any. Specify a different type.
any disables many type checking rules. Its use should be avoided.
(lint/suspicious/noExplicitAny)
[error] 131-131: Excessive complexity detected.
Please refactor this function to reduce its complexity score from 24 to the max allowed complexity 15.
(lint/complexity/noExcessiveCognitiveComplexity)
src/panels/lovelace/editor/card-editor/hui-card-layout-editor.ts (1)
Line range hint
185-210
: Address performance concerns with thedelete
operator.Using the
delete
operator can lead to performance issues. Consider using an undefined assignment instead to maintain performance while achieving the same functionality.- delete newConfig.layout_options; + newConfig.layout_options = undefined;src/panels/lovelace/sections/hui-section.ts (1)
Line range hint
172-172
: Consider replacing non-null assertions with safer checks.Using non-null assertions (
!
) can lead to runtime errors if the object is actually null. Consider using optional chaining (?.
) or adding necessary checks to ensure the object exists before accessing its properties.- this.hass! + this.hass?. // Repeat for all instancesAlso applies to: 193-193, 194-194, 195-195, 196-196, 197-197, 198-198, 261-261, 263-263
src/panels/lovelace/views/hui-view.ts (2)
Line range hint
93-93
: Avoid usingany
type for better type safety.Using
any
disables TypeScript's static type checking, which can lead to errors that are hard to detect. Consider specifying more explicit types.- processConfigEntities(config.badges as any); + processConfigEntities(config.badges as LovelaceBadgeConfig[]); // Adjust according to actual expected typeAlso applies to: 174-174, 186-186, 215-215, 340-340, 345-345
Line range hint
118-118
: Replace non-null assertions with optional chaining for safer code.Non-null assertions might lead to unexpected null reference errors. Using optional chaining (
?.
) is a safer alternative that handles potential null or undefined values gracefully.- this.hass! + this.hass?. // Repeat for all instancesAlso applies to: 262-262, 284-284, 285-285, 286-286, 287-287, 288-288, 289-289, 290-290, 291-291, 300-300, 326-326, 328-328
Proposed change
Multiple fix and improvements :
hass
ifundefined
(because it was the case beforehui-card
)Type of change
Example configuration
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed:
Summary by CodeRabbit
New Features
HuiCard
class with improved configuration handling and error management.load()
method across various card components for better initialization.Improvements
HuiStackCard
class to ensure controlled property assignments and addedload()
method calls.HuiCardLayoutEditor
,HuiSection
, andHUIView
to ensure elements are properly loaded before accessing properties.