Prefer regex literals over constructors (#15553)

This commit is contained in:
Steve Repsher 2023-02-23 08:06:35 -05:00 committed by GitHub
parent ab231eec4f
commit 03e3f161f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 13 deletions

View File

@ -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",

View File

@ -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<HistoryQueryParams>(path.split("?")[1]);
const entities = params.filter_entity_id.split(",");

View File

@ -1,4 +1,4 @@
const isTemplateRegex = new RegExp("{%|{{");
const isTemplateRegex = /{%|{{/;
export const isTemplate = (value: string): boolean =>
isTemplateRegex.test(value);

View File

@ -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: [

View File

@ -116,7 +116,7 @@ export const provideHass = (
}
mockAPI(
new RegExp("states/.+"),
/states\/.+/,
(
// @ts-ignore
method,