Skip to content

Commit

Permalink
Require underscore for private methods (#23138)
Browse files Browse the repository at this point in the history
  • Loading branch information
MindFreeze authored Dec 4, 2024
1 parent 9396d5c commit d77dd53
Show file tree
Hide file tree
Showing 23 changed files with 30 additions and 51 deletions.
1 change: 0 additions & 1 deletion demo/src/custom-cards/cast-demo-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class CastDemoRow extends LitElement implements LovelaceRow {
this.requestUpdate();
});
mgr.castContext.addEventListener(
// eslint-disable-next-line no-undef
cast.framework.CastContextEventType.SESSION_STATE_CHANGED,
(ev) => {
// On Android, opening a new session always results in SESSION_RESUMED.
Expand Down
20 changes: 13 additions & 7 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,7 @@ export default [
"@typescript-eslint/no-shadow": ["error"],

"@typescript-eslint/naming-convention": [
"off",
{
selector: "default",
format: ["camelCase", "snake_case"],
leadingUnderscore: "allow",
trailingUnderscore: "allow",
},
"warn",
{
selector: ["variable"],
format: ["camelCase", "snake_case", "UPPER_CASE"],
Expand All @@ -131,6 +125,18 @@ export default [
selector: "typeLike",
format: ["PascalCase"],
},
{
selector: "method",
modifiers: ["public"],
format: ["camelCase"],
leadingUnderscore: "forbid",
},
{
selector: "method",
modifiers: ["private"],
format: ["camelCase"],
leadingUnderscore: "require",
},
],

"@typescript-eslint/no-unused-vars": "off",
Expand Down
1 change: 0 additions & 1 deletion gallery/src/pages/automation/editor-condition.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable lit/no-template-arrow */
import type { TemplateResult } from "lit";
import { LitElement, html, css } from "lit";
import { customElement, state } from "lit/decorators";
Expand Down
1 change: 0 additions & 1 deletion gallery/src/pages/components/ha-selector.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable lit/no-template-arrow */
import "@material/mwc-button";
import type { TemplateResult } from "lit";
import { css, html, LitElement } from "lit";
Expand Down
1 change: 0 additions & 1 deletion src/common/dom/fire_event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

declare global {
// eslint-disable-next-line
interface HASSDomEvents {}
}

Expand Down
2 changes: 0 additions & 2 deletions src/common/dom/scroll-to-target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ export default function scrollToTarget(element, target) {
const top = 0;
const scroller = target;
const easingFn = function easeOutQuad(t, b, c, d) {
/* eslint-disable no-param-reassign, space-infix-ops, no-mixed-operators */
t /= d;
return -c * t * (t - 2) + b;
/* eslint-enable no-param-reassign, space-infix-ops, no-mixed-operators */
};
const animationId = Math.random();
const duration = 200;
Expand Down
2 changes: 1 addition & 1 deletion src/components/ha-ansi-to-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class HaAnsiToHtml extends LitElement {

/* eslint-disable no-cond-assign */
let match;
// eslint-disable-next-line

while ((match = re.exec(line)) !== null) {
const j = match!.index;
const substring = line.substring(i, j);
Expand Down
1 change: 0 additions & 1 deletion src/components/ha-form/ha-form-string.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable lit/prefer-static-styles */
import { mdiEye, mdiEyeOff } from "@mdi/js";
import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
import { LitElement, css, html, nothing } from "lit";
Expand Down
1 change: 0 additions & 1 deletion src/components/ha-navigation-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ type NavigationItem = {

const DEFAULT_ITEMS: NavigationItem[] = [];

// eslint-disable-next-line lit/prefer-static-styles
const rowRenderer: ComboBoxLitRenderer<NavigationItem> = (item) => html`
<mwc-list-item graphic="icon" .twoline=${!!item.title}>
<ha-icon .icon=${item.icon} slot="graphic"></ha-icon>
Expand Down
2 changes: 0 additions & 2 deletions src/data/onboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export interface InstallationType {
| "Unknown";
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface OnboardingCoreConfigStepResponse {}

export interface OnboardingUserStepResponse {
Expand All @@ -21,7 +20,6 @@ export interface OnboardingIntegrationStepResponse {
auth_code: string;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface OnboardingAnalyticsStepResponse {}

export interface OnboardingResponses {
Expand Down
1 change: 0 additions & 1 deletion src/dialogs/restart/show-dialog-restart.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { fireEvent } from "../../common/dom/fire_event";

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface RestartDialogParams {}

export const loadRestartDialog = () => import("./dialog-restart");
Expand Down
2 changes: 1 addition & 1 deletion src/entrypoints/service-worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/triple-slash-reference */
// eslint-disable-next-line spaced-comment

/// <reference path="../types/service-worker.d.ts" />
/* eslint-env serviceworker */
import type { RouteHandler } from "workbox-core";
Expand Down
1 change: 0 additions & 1 deletion src/layouts/home-assistant-main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable lit/prefer-static-styles */
import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
import { css, html, LitElement } from "lit";
import { customElement, property, state } from "lit/decorators";
Expand Down
2 changes: 1 addition & 1 deletion src/panels/config/cloud/account/cloud-remote-pref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import "../../../../components/ha-radio";
import "../../../../components/ha-settings-row";
import "../../../../components/ha-switch";
import "../../../../components/ha-textfield";
// eslint-disable-next-line

import { formatDate } from "../../../../common/datetime/format_date";
import type { HaSwitch } from "../../../../components/ha-switch";
import type { CloudStatusLoggedIn } from "../../../../data/cloud";
Expand Down
2 changes: 1 addition & 1 deletion src/panels/lovelace/cards/hui-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class HuiCard extends ReactiveElement {
}
if (this._element.getLayoutOptions) {
// Disabled for now to avoid spamming the console, need to be re-enabled when hui-card performance are fixed
// eslint-disable-next-line no-console

// console.warn(
// `This card (${this.config?.type}) is using "getLayoutOptions" and it is deprecated, contact the developer to suggest to use "getGridOptions" instead`
// );
Expand Down
4 changes: 1 addition & 3 deletions src/panels/lovelace/cards/hui-empty-state-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ export class HuiEmptyStateCard extends LitElement implements LovelaceCard {
return 2;
}

public setConfig(_config: EmptyStateCardConfig): void {
// eslint-disable-next-line
}
public setConfig(_config: EmptyStateCardConfig): void {}

protected render() {
if (!this.hass) {
Expand Down
4 changes: 1 addition & 3 deletions src/panels/lovelace/cards/hui-starting-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ export class HuiStartingCard extends LitElement implements LovelaceCard {
return 2;
}

public setConfig(_config: LovelaceCardConfig): void {
// eslint-disable-next-line
}
public setConfig(_config: LovelaceCardConfig): void {}

protected updated(changedProperties: PropertyValues) {
super.updated(changedProperties);
Expand Down
3 changes: 1 addition & 2 deletions src/panels/lovelace/components/hui-marquee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ class HuiMarquee extends LitElement {
protected firstUpdated(changedProps) {
super.firstUpdated(changedProps);

// eslint-disable-next-line wc/no-self-class
this.addEventListener("mouseover", () => this.classList.add("hovering"), {
// Capture because we need to run before a parent sets active on us.
// Hovering will disable the overflow, allowing us to calc if we overflow.
capture: true,
});
// eslint-disable-next-line wc/no-self-class

this.addEventListener("mouseout", () => this.classList.remove("hovering"));
}

Expand Down
1 change: 0 additions & 1 deletion src/panels/lovelace/elements/hui-image-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export class HuiImageElement extends LitElement implements LovelaceElement {

this._config = { hold_action: { action: "more-info" }, ...config };

// eslint-disable-next-line wc/no-self-class
this.classList.toggle(
"clickable",
this._config.tap_action && this._config.tap_action.action !== "none"
Expand Down
1 change: 0 additions & 1 deletion src/panels/media-browser/browser-media-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export class BrowserMediaPlayer {
supported_features:
// eslint-disable-next-line no-bitwise
MediaPlayerEntityFeature.PLAY |
// eslint-disable-next-line no-bitwise
MediaPlayerEntityFeature.PAUSE |
MediaPlayerEntityFeature.VOLUME_SET,
};
Expand Down
21 changes: 5 additions & 16 deletions src/state/hass-base-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,18 @@ export class HassBaseEl extends LitElement {

protected initializeHass(_auth: Auth, _conn: Connection) {
// implemented in connection-mixin
// eslint-disable-next-line
}

// Exists so all methods can safely call super method
protected hassConnected() {
// eslint-disable-next-line
}
protected hassConnected() {}

protected hassReconnected() {
// eslint-disable-next-line
}
protected hassReconnected() {}

protected hassDisconnected() {
// eslint-disable-next-line
}
protected hassDisconnected() {}

protected panelUrlChanged(_newPanelUrl) {
// eslint-disable-next-line
}
protected panelUrlChanged(_newPanelUrl) {}

protected checkDataBaseMigration() {
// eslint-disable-next-line
}
protected checkDataBaseMigration() {}

protected hassChanged(hass, _oldHass) {
this.__provideHass.forEach((el) => {
Expand Down
2 changes: 2 additions & 0 deletions src/state/quick-bar-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ export default <T extends Constructor<HassElement>>(superClass: T) =>
a: (ev) => this._showVoiceCommandDialog(ev),
d: (ev) => this._showQuickBar(ev, QuickBarMode.Device),
// Those are fallbacks for non-latin keyboards that don't have e, c, m keys (qwerty-based shortcuts)
/* eslint-disable @typescript-eslint/naming-convention */
KeyE: (ev) => this._showQuickBar(ev),
KeyC: (ev) => this._showQuickBar(ev, QuickBarMode.Command),
KeyM: (ev) => this._createMyLink(ev),
KeyA: (ev) => this._showVoiceCommandDialog(ev),
KeyD: (ev) => this._showQuickBar(ev, QuickBarMode.Device),
/* eslint-enable @typescript-eslint/naming-convention */
});
}

Expand Down
5 changes: 3 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type { Themes } from "./data/ws-themes";
import type { ExternalMessaging } from "./external_app/external_messaging";

declare global {
/* eslint-disable no-var */
/* eslint-disable no-var, @typescript-eslint/naming-convention */
var __DEV__: boolean;
var __DEMO__: boolean;
var __BUILD__: "modern" | "legacy";
Expand All @@ -32,7 +32,7 @@ declare global {
var __BACKWARDS_COMPAT__: boolean;
var __SUPERVISOR__: boolean;
var __HASS_URL__: string;
/* eslint-enable no-var, no-redeclare */
/* eslint-enable no-var, @typescript-eslint/naming-convention */

interface Window {
// Custom panel entry point url
Expand Down Expand Up @@ -70,6 +70,7 @@ declare global {
// Intl.DurationFormat is not yet part of the TypeScript standard
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Intl {
// eslint-disable-next-line @typescript-eslint/naming-convention
const DurationFormat: DurationFormatConstructor;
}
}
Expand Down

0 comments on commit d77dd53

Please sign in to comment.