diff --git a/.eslintrc.json b/.eslintrc.json index 985f1da4fd..54c0a23818 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -60,7 +60,6 @@ "no-restricted-globals": [2, "event"], "prefer-promise-reject-errors": "off", "no-unsafe-optional-chaining": "warn", - "prefer-regex-literals": ["warn"], "import/prefer-default-export": "off", "import/no-default-export": "off", "import/no-unresolved": "off", diff --git a/demo/src/stubs/history.ts b/demo/src/stubs/history.ts index 5b96b77ddf..0daccb4d80 100644 --- a/demo/src/stubs/history.ts +++ b/demo/src/stubs/history.ts @@ -66,7 +66,7 @@ const incrementalUnits = ["clients", "queries", "ads"]; export const mockHistory = (mockHass: MockHomeAssistant) => { mockHass.mockAPI( - new RegExp("history/period/.+"), + /history\/period\/.+/, (hass, _method, path, _parameters) => { const params = parseQuery(path.split("?")[1]); const entities = params.filter_entity_id.split(","); diff --git a/src/common/string/has-template.ts b/src/common/string/has-template.ts index c86d7f6e8e..189f10f635 100644 --- a/src/common/string/has-template.ts +++ b/src/common/string/has-template.ts @@ -1,4 +1,4 @@ -const isTemplateRegex = new RegExp("{%|{{"); +const isTemplateRegex = /{%|{{/; export const isTemplate = (value: string): boolean => isTemplateRegex.test(value); diff --git a/src/entrypoints/service_worker.ts b/src/entrypoints/service_worker.ts index d44ce684ba..da8fbd8471 100644 --- a/src/entrypoints/service_worker.ts +++ b/src/entrypoints/service_worker.ts @@ -13,10 +13,8 @@ import { StaleWhileRevalidate, } from "workbox-strategies"; -const noFallBackRegEx = new RegExp( - "/(api|static|auth|frontend_latest|frontend_es5|local)/.*" -); - +const noFallBackRegEx = + /\/(api|static|auth|frontend_latest|frontend_es5|local)\/.*/; // Clean up caches from older workboxes and old service workers. // Will help with cleaning up Workbox v4 stuff cleanupOutdatedCaches(); @@ -33,22 +31,22 @@ function initRouting() { // Cache static content (including translations) on first access. registerRoute( - new RegExp("/(static|frontend_latest|frontend_es5)/.+"), + /\/(static|frontend_latest|frontend_es5)\/.+/, new CacheFirst({ matchOptions: { ignoreSearch: true } }) ); // Get api from network. - registerRoute(new RegExp("/(api|auth)/.*"), new NetworkOnly()); + registerRoute(/\/(api|auth)\/.*/, new NetworkOnly()); // Get manifest, service worker, onboarding from network. registerRoute( - new RegExp("/(service_worker.js|manifest.json|onboarding.html)"), + /\/(service_worker.js|manifest.json|onboarding.html)/, new NetworkOnly() ); // For the root "/" we ignore search registerRoute( - new RegExp(/\/(\?.*)?$/), + /\/(\?.*)?$/, new StaleWhileRevalidate({ matchOptions: { ignoreSearch: true } }) ); @@ -57,7 +55,7 @@ function initRouting() { // First access might bring stale data from cache, but a single refresh will bring updated // file. registerRoute( - new RegExp(/\/.*/), + /\/.*/, new StaleWhileRevalidate({ cacheName: "file-cache", plugins: [ diff --git a/src/fake_data/provide_hass.ts b/src/fake_data/provide_hass.ts index 2c717528ee..5263dadcaf 100644 --- a/src/fake_data/provide_hass.ts +++ b/src/fake_data/provide_hass.ts @@ -116,7 +116,7 @@ export const provideHass = ( } mockAPI( - new RegExp("states/.+"), + /states\/.+/, ( // @ts-ignore method,