From 29f59e4f897c512825a2b24d84ef6a6c85c74869 Mon Sep 17 00:00:00 2001 From: Viet Ngoc Date: Mon, 4 Nov 2024 06:33:16 +0100 Subject: [PATCH] refactor: Remove unnecessary imports and update dependencies --- .eslintignore | 5 ++-- eslint.config.mjs | 10 ++++---- package.json | 4 ++-- src/components/moon-data.ts | 8 +++---- src/components/moon-horizon.ts | 8 ++++--- src/components/moon-phase-calendar.ts | 9 ++++--- src/editor.ts | 14 +++++------ src/lunar-phase-card.ts | 34 +++++++++++++-------------- src/utils/helpers.ts | 1 + src/utils/loader.ts | 2 +- src/utils/moon.ts | 5 ++-- 11 files changed, 48 insertions(+), 52 deletions(-) diff --git a/.eslintignore b/.eslintignore index b3eb27e..f06235c 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,2 @@ -src/localize/*.ts -src/localize/*.js -scripts/*.js \ No newline at end of file +node_modules +dist diff --git a/eslint.config.mjs b/eslint.config.mjs index f6fbe10..d69f7fe 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -4,6 +4,7 @@ import perfectionist from 'eslint-plugin-perfectionist'; export default [ { + files: ['src/**/*.ts'], languageOptions: { parser: tsParser, parserOptions: { @@ -23,16 +24,16 @@ export default [ type: 'alphabetical', order: 'asc', ignoreCase: true, - internalPattern: ['~/**'], + internalPattern: ['~/**', '^~/.*'], newlinesBetween: 'always', maxLineLength: undefined, groups: [ + ['external', 'builtin'], + ['parent-type', 'sibling-type', 'index-type'], + ['parent', 'sibling', 'index'], 'type', - ['builtin', 'external'], 'internal-type', 'internal', - ['parent-type', 'sibling-type', 'index-type'], - ['parent', 'sibling', 'index'], 'object', 'unknown', ], @@ -41,6 +42,5 @@ export default [ }, ], }, - ignores: ['rollup.config.*'], }, ]; diff --git a/package.json b/package.json index b9d4659..a66996d 100644 --- a/package.json +++ b/package.json @@ -73,10 +73,10 @@ "scripts": { "dev": "rollup -c --watch --bundleConfigAsCjs", "build": "npm run lint && npm run rollup", - "lint": "eslint src/**/*.ts --no-warn-ignored", + "lint": "eslint src/**/*.ts ", "rollup": "rollup -c", "update-lang": "node scripts/update-languages", "import-lang": "node scripts/generate-lang-imports.js", "local-copy": "cp dist/lunar-phase-card.js /Volumes/config/www/dashboard-resources/lunar-phase-card.js" } -} +} \ No newline at end of file diff --git a/src/components/moon-data.ts b/src/components/moon-data.ts index 3106639..1c9aab3 100644 --- a/src/components/moon-data.ts +++ b/src/components/moon-data.ts @@ -1,14 +1,12 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ import { LitElement, html, TemplateResult, CSSResultGroup, PropertyValues, unsafeCSS } from 'lit'; import { customElement, state } from 'lit/decorators.js'; - import Swiper from 'swiper'; import { Pagination } from 'swiper/modules'; -import { MoonData, MoonDataItem } from '../types'; -import { Moon } from '../utils/moon'; +import swiperStyleCss from 'swiper/swiper-bundle.css'; import mainStyles from '../css/style.css'; -import swiperStyleCss from 'swiper/swiper-bundle.css'; +import { MoonData, MoonDataItem } from '../types'; +import { Moon } from '../utils/moon'; @customElement('lunar-base-data') export class LunarBaseData extends LitElement { diff --git a/src/components/moon-horizon.ts b/src/components/moon-horizon.ts index ba2fb2c..c4a52be 100644 --- a/src/components/moon-horizon.ts +++ b/src/components/moon-horizon.ts @@ -1,6 +1,9 @@ +import { formatTime, formatDateTime, HomeAssistant } from 'custom-card-helpers'; import { LitElement, html, CSSResultGroup, TemplateResult, css } from 'lit'; import { customElement, state, property } from 'lit/decorators.js'; -import { formatTime, formatDateTime, HomeAssistant } from 'custom-card-helpers'; + +import type { ChartDataset } from 'chart.js/auto'; + // Chart.js import { Chart, @@ -12,12 +15,11 @@ import { ScaleChartOptions, } from 'chart.js/auto'; import annotationPlugin from 'chartjs-plugin-annotation'; -import type { ChartDataset } from 'chart.js/auto'; Chart.register(annotationPlugin); +import { LunarPhaseCard } from '../lunar-phase-card'; // Local imports import { Moon } from '../utils/moon'; -import { LunarPhaseCard } from '../lunar-phase-card'; // Styles import styles from '../css/style.css'; diff --git a/src/components/moon-phase-calendar.ts b/src/components/moon-phase-calendar.ts index e9587bc..43a31c5 100644 --- a/src/components/moon-phase-calendar.ts +++ b/src/components/moon-phase-calendar.ts @@ -1,16 +1,15 @@ -import { LitElement, html, TemplateResult, CSSResultGroup, css } from 'lit'; -import { customElement, state, property } from 'lit/decorators.js'; - import { Calendar } from '@fullcalendar/core'; +import allLocales from '@fullcalendar/core/locales-all'; import dayGridPlugin from '@fullcalendar/daygrid'; import interactionPlugin from '@fullcalendar/interaction'; -import allLocales from '@fullcalendar/core/locales-all'; +import { LitElement, html, TemplateResult, CSSResultGroup, css } from 'lit'; +import { customElement, state, property } from 'lit/decorators.js'; +import { LunarPhaseCard } from '../lunar-phase-card'; import { Moon } from '../utils/moon'; // styles import styles from '../css/style.css'; -import { LunarPhaseCard } from '../lunar-phase-card'; @customElement('moon-phase-calendar') export class MoonPhaseCalendar extends LitElement { diff --git a/src/editor.ts b/src/editor.ts index a60c733..b7f2359 100644 --- a/src/editor.ts +++ b/src/editor.ts @@ -1,19 +1,17 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ +/* @typescript-eslint/no-explicit-any */ import { LitElement, html, TemplateResult, css, CSSResultGroup, PropertyValues } from 'lit'; import { customElement, property, state } from 'lit/decorators.js'; // Custom card helpers import { fireEvent, LovelaceCardEditor } from 'custom-card-helpers'; -import { HomeAssistantExtended as HomeAssistant, LunarPhaseCardConfig, FontCustomStyles, defaultConfig } from './types'; - -import { languageOptions, localize } from './localize/localize'; -import { loadHaComponents, fetchLatestReleaseTag, stickyPreview } from './utils/loader'; -import { compareVersions } from './utils/helpers'; -import { deepMerge, InitializeDefaultConfig } from './utils/ha-helper'; - import { CARD_VERSION, FONTCOLORS, FONTSTYLES, FONTSIZES } from './const'; import editorcss from './css/editor.css'; +import { languageOptions, localize } from './localize/localize'; +import { HomeAssistantExtended as HomeAssistant, LunarPhaseCardConfig, FontCustomStyles, defaultConfig } from './types'; +import { deepMerge, InitializeDefaultConfig } from './utils/ha-helper'; +import { compareVersions } from './utils/helpers'; +import { loadHaComponents, fetchLatestReleaseTag, stickyPreview } from './utils/loader'; @customElement('lunar-phase-card-editor') export class LunarPhaseCardEditor extends LitElement implements LovelaceCardEditor { diff --git a/src/lunar-phase-card.ts b/src/lunar-phase-card.ts index 81ee55f..e56138c 100644 --- a/src/lunar-phase-card.ts +++ b/src/lunar-phase-card.ts @@ -1,21 +1,3 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import { LitElement, html, TemplateResult, PropertyValues, CSSResultGroup, nothing } from 'lit'; -import { customElement, property, query, state } from 'lit/decorators.js'; -import { classMap } from 'lit/directives/class-map.js'; -import { LovelaceCardEditor, formatDate, FrontendLocaleData } from 'custom-card-helpers'; -import { HomeAssistantExtended as HomeAssistant, LunarPhaseCardConfig, defaultConfig } from './types'; -import { BASE_REFRESH_INTERVAL, BACKGROUND, CurrentPage } from './const'; -import { localize } from './localize/localize'; -import { getDefaultConfig } from './utils/helpers'; - -import { Moon } from './utils/moon'; -import './components/moon-data'; -import './components/moon-horizon'; -import './components/moon-phase-calendar'; -import { LunarBaseData } from './components/moon-data'; -import { MoonHorizon } from './components/moon-horizon'; - -import style from './css/style.css'; import { mdiCalendarMonthOutline, mdiCalendarSearch, @@ -24,6 +6,22 @@ import { mdiChevronRight, mdiRestore, } from '@mdi/js'; +import { LovelaceCardEditor, formatDate, FrontendLocaleData } from 'custom-card-helpers'; +import { LitElement, html, TemplateResult, PropertyValues, CSSResultGroup, nothing } from 'lit'; +import { customElement, property, query, state } from 'lit/decorators.js'; +import { classMap } from 'lit/directives/class-map.js'; + +import { LunarBaseData } from './components/moon-data'; +import { MoonHorizon } from './components/moon-horizon'; +import { BASE_REFRESH_INTERVAL, BACKGROUND, CurrentPage } from './const'; +import style from './css/style.css'; +import './components/moon-data'; +import './components/moon-horizon'; +import './components/moon-phase-calendar'; +import { localize } from './localize/localize'; +import { HomeAssistantExtended as HomeAssistant, LunarPhaseCardConfig, defaultConfig } from './types'; +import { getDefaultConfig } from './utils/helpers'; +import { Moon } from './utils/moon'; @customElement('lunar-phase-card') export class LunarPhaseCard extends LitElement { diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 4909621..88ddc4a 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -1,4 +1,5 @@ import { FrontendLocaleData, TimeFormat, HomeAssistant } from 'custom-card-helpers'; + import { BASE_BACKGROUND_URL } from '../const'; import { MOON_IMAGES } from './moon-pic'; diff --git a/src/utils/loader.ts b/src/utils/loader.ts index 896ffca..f0fb90d 100644 --- a/src/utils/loader.ts +++ b/src/utils/loader.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { REPOSITORY, BASE_BACKGROUND_URL } from '../const'; +import { REPOSITORY } from '../const'; // Hack to load ha-components needed for editor export const loadHaComponents = () => { diff --git a/src/utils/moon.ts b/src/utils/moon.ts index 906a5ca..fb44e89 100644 --- a/src/utils/moon.ts +++ b/src/utils/moon.ts @@ -1,9 +1,10 @@ import * as SunCalc from '@noim/suncalc3'; +import { FrontendLocaleData, formatNumber } from 'custom-card-helpers'; + import { localize } from '../localize/localize'; import { LunarPhaseCardConfig, MoonData, MoonDataItem, MoonImage, Location } from '../types'; -import { formatRelativeTime, formatedTime, convertKmToMiles } from './helpers'; import { MOON_IMAGES } from '../utils/moon-pic'; -import { FrontendLocaleData, formatNumber } from 'custom-card-helpers'; +import { formatRelativeTime, formatedTime, convertKmToMiles } from './helpers'; export class Moon { readonly _date: Date;