Skip to content
This repository was archived by the owner on May 1, 2025. It is now read-only.

Commit 4bbd9e7

Browse files
authored
Import rules from monorepo (#326)
1 parent 526bb4d commit 4bbd9e7

File tree

5 files changed

+63
-1
lines changed

5 files changed

+63
-1
lines changed

no-restricted-syntax.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ module.exports = [
4747
selector:
4848
"JSXOpeningElement[name.name='div'][attributes.0.name.name='onClick']",
4949
},
50+
{
51+
message:
52+
"Prefer importing `getSelectionRange()` helper or check `selection.rangeCount` first: https://github.com/pixiebrix/pixiebrix-extension/pull/7989",
53+
selector: "CallExpression[callee.property.name='getRangeAt']",
54+
},
55+
{
56+
message:
57+
"Use the chrome.* APIs (browser.* is now only used for for messaging)",
58+
selector:
59+
"MemberExpression[object.object.name='browser']:not(:has(Identifier[name=/runtime|tabs/]):has(Identifier[name=/Message/]))",
60+
},
61+
{
62+
message:
63+
"Use the browser.* APIs for messaging (chrome.* for everything else)",
64+
selector:
65+
"MemberExpression[object.object.name='chrome']:has(Identifier[name=/runtime|tabs/]):has(Identifier[name=/Message/])",
66+
},
5067

5168
// NOTE: If you add more rules, add the tests to no-restricted-syntax.test.ts
5269
];

no-restricted-syntax.test.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
/* eslint-disable unicorn/no-useless-undefined */
66
/* eslint-disable @typescript-eslint/no-unsafe-call */
77
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
8+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
89

910
// eslint-disable-next-line no-restricted-syntax
1011
import classnames from "classnames";
11-
import cx from "classnames";
12+
import cx from "classnames"; // Ok
1213

1314
// eslint-disable-next-line no-restricted-syntax
1415
export const id = crypto.randomUUID();
@@ -24,3 +25,32 @@ export const mockPromise = jest.fn().mockResolvedValue(undefined);
2425

2526
// eslint-disable-next-line no-restricted-syntax
2627
export type MyObject = Record<string, unknown>;
28+
29+
const selection = getSelection(); // Ok
30+
// eslint-disable-next-line no-restricted-syntax
31+
export const range = selection?.getRangeAt(0).startContainer;
32+
export const string = selection?.toString(); // Ok
33+
34+
// eslint-disable-next-line no-restricted-syntax -- necessary to define rule
35+
browser.runtime.getURL("options.html");
36+
chrome.runtime.getURL("options.html"); // Ok
37+
38+
// eslint-disable-next-line no-restricted-syntax -- necessary to define rule
39+
browser.tabs.query({ active: true });
40+
chrome.tabs.query({ active: true }); // Ok
41+
42+
// eslint-disable-next-line no-restricted-syntax -- necessary to define rule
43+
browser.scripting.getRegisteredContentScripts();
44+
chrome.scripting.getRegisteredContentScripts(); // Ok
45+
46+
// eslint-disable-next-line no-restricted-syntax -- necessary to define rule
47+
chrome.runtime.sendMessage("good soup");
48+
browser.runtime.sendMessage("good soup"); // Ok
49+
50+
// eslint-disable-next-line no-restricted-syntax -- necessary to define rule
51+
chrome.tabs.sendMessage(1, "u e e a i");
52+
browser.tabs.sendMessage(1, "u e e a i"); // Ok
53+
54+
// eslint-disable-next-line no-restricted-syntax -- necessary to define rule
55+
chrome.runtime.onMessage.addListener(() => undefined);
56+
browser.runtime.onMessage.addListener(() => undefined); // Ok

plugins/import.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,12 @@ module.exports = {
4848
},
4949
],
5050
};
51+
52+
// `npm run lint:fast` will skip the (slow) import/* rules
53+
// Useful if you're trying to iterate fixes over other rules
54+
if (process.env.ESLINT_NO_IMPORTS) {
55+
const importRules = Object.keys(require("eslint-plugin-import").rules);
56+
for (const ruleName of importRules) {
57+
module.exports.rules[`import/${ruleName}`] = "off";
58+
}
59+
}

plugins/typescript.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ module.exports = {
3131
}
3232
),
3333

34+
// TODO: Remove after https://github.com/xojs/eslint-config-xo-typescript/pull/92
35+
"@typescript-eslint/no-unsafe-member-access": "error",
36+
3437
// Reason: https://github.com/pixiebrix/pixiebrix-extension/pull/7703
3538
"@typescript-eslint/restrict-template-expressions": [
3639
"error",

tests.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ module.exports = {
3232
"@typescript-eslint/no-non-null-assertion": "off",
3333
"react/jsx-key": "off",
3434

35+
// Conflicts with Redux' .concat()
36+
"unicorn/prefer-spread": "off",
37+
3538
// Common and required usage in tests
3639
"unicorn/no-useless-undefined": "off",
3740

0 commit comments

Comments
 (0)