Skip to content

Commit

Permalink
Prevent and fix restricted imports between src/background, src/conten…
Browse files Browse the repository at this point in the history
…t and src/common (#313)
  • Loading branch information
david-tejada authored Sep 18, 2024
1 parent 88b04fe commit b6202fe
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 9 deletions.
65 changes: 64 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,70 @@
"@typescript-eslint/ban-types": "off",
"no-redeclare": "off",
"@typescript-eslint/no-redeclare": "off"
}
},
"overrides": [
{
"files": [
"src/background/**"
],
"rules": {
"no-restricted-imports": [
"error",
{
"patterns": [
{
"group": [
"**/content/**"
],
"message": "Modules within /src/background can't import from /src/content"
}
]
}
]
}
},
{
"files": [
"src/content/**"
],
"rules": {
"no-restricted-imports": [
"error",
{
"patterns": [
{
"group": [
"**/background/**"
],
"message": "Modules within /src/content can't import from /src/background"
}
]
}
]
}
},
{
"files": [
"src/common/**"
],
"rules": {
"no-restricted-imports": [
"error",
{
"patterns": [
{
"group": [
"**/background/**",
"**/content/**"
],
"message": "Modules within /src/content can't import from /src/background or /src/content"
}
]
}
]
}
}
]
},
"prettier": {
"trailingComma": "es5",
Expand Down
2 changes: 1 addition & 1 deletion src/background/hints/hintsAllocator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import browser from "webextension-polyfill";
import { getKeysToExclude } from "../../common/getKeysToExclude";
import { retrieve, store } from "../../common/storage";
import { HintsStack } from "../../typings/StorageSchema";
import { letterHints, numberHints } from "../utils/allHints";
import { letterHints, numberHints } from "../../common/allHints";
import { navigationOccurred } from "./preloadTabs";

async function getEmptyStack(tabId: number): Promise<HintsStack> {
Expand Down
2 changes: 1 addition & 1 deletion src/background/misc/tabMarkers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import browser from "webextension-polyfill";
import { Mutex } from "async-mutex";
import { retrieve, store } from "../../common/storage";
import { TabMarkers } from "../../typings/StorageSchema";
import { letterHints } from "../utils/allHints";
import { letterHints } from "../../common/allHints";
import { sendRequestToContent } from "../messaging/sendRequestToContent";

const mutex = new Mutex();
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/common/defaultStorage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { letterHints } from "../background/utils/allHints";
import { StorageSchema } from "../typings/StorageSchema";
import { letterHints } from "./allHints";
import { defaultSettings } from "./settings";

export const defaultStorage: StorageSchema = {
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/common/transformSettings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from "zod";
import { isValidSelector } from "../content/utils/selectorUtils";
import { isValidRegExp } from "../content/utils/textUtils";
import { CustomSelector, StorageSchema } from "../typings/StorageSchema";
import { isValidSelector } from "./selectorUtils";
import { isValidRegExp } from "./textUtils";

type CustomsSelectorsLegacyEntry = [
string,
Expand Down
2 changes: 1 addition & 1 deletion src/content/hints/computeCustomSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
getSpecificityValue,
isValidSelector,
selectorToArray,
} from "../utils/selectorUtils";
} from "../../common/selectorUtils";
import { SelectorAlternative } from "../../typings/SelectorAlternative";

function getChildNumber(target: Element) {
Expand Down
4 changes: 2 additions & 2 deletions src/settings/CustomHintsSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { faBan, faPlus, faTrash } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { CustomSelector } from "../typings/StorageSchema";
import "./CustomHintsSetting.css";
import { isValidSelector } from "../content/utils/selectorUtils";
import { isValidRegExp } from "../content/utils/textUtils";
import { isValidSelector } from "../common/selectorUtils";
import { isValidRegExp } from "../common/textUtils";

type CustomHintsSettingProp = {
value: CustomSelector[];
Expand Down

0 comments on commit b6202fe

Please sign in to comment.