This repository was archived by the owner on May 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathno-restricted-syntax.js
More file actions
69 lines (67 loc) · 2.76 KB
/
no-restricted-syntax.js
File metadata and controls
69 lines (67 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
module.exports = [
// NOTE: If you add more rules, add the tests to no-restricted-syntax.test.ts
{
selector:
"TSTypeReference[typeName.name='Record'][typeParameters.params.0.type=TSStringKeyword][typeParameters.params.1.type=TSUnknownKeyword]",
message: "Use `UnknownRecord` from 'type-fest' instead of `Record<string, unknown>`",
},
{
selector: "CallExpression[callee.property.name='allSettled']",
message:
'For safety and convenience, use this instead: import { allSettled } from "@/utils/promiseUtils";',
},
{
message:
"Bootstrap columns should not be used if there's a single column. Use a plain `div` or drop the wrapper altogether if not needed. You might also consider using one of the classes 'max-550', 'max-750', or 'max-950' to limit the width of the body.",
selector:
"JSXElement[openingElement.name.name='Row'] > JSXText:first-child + JSXElement:nth-last-child(2)",
},
{
message:
"Use the `uuid` module instead because crypto.randomUUID is not available in http: contexts",
selector: 'MemberExpression > Identifier[name="randomUUID"]',
},
{
message: "Use `jest.mocked(fn)` instead of `fn as jest.Mock`.",
selector: "TSAsExpression TSQualifiedName[right.name='Mock']",
},
{
message: "Use `jest.mocked(fn)` instead of `fn as jest.MockedFunction`.",
selector: "TSAsExpression TSQualifiedName[right.name='MockedFunction']",
},
{
message:
"Unless the code is using .then(), calling `.mockResolvedValue(undefined)` is the same as leaving it out",
selector:
"CallExpression[callee.property.name='mockResolvedValue'][arguments.0.name='undefined'][arguments.0.type='Identifier']",
},
{
message: "Use this instead: import cx from 'classnames'",
selector:
"ImportDeclaration[source.value=classnames] ImportDefaultSpecifier[local.name!=/cx/]",
},
{
message:
"Instead of `<div onClick/>`, use <UnstyledButton/> (`button` element) or <ClickableElement/> (accessible `div` element)",
selector:
"JSXOpeningElement[name.name='div'][attributes.0.name.name='onClick']",
},
{
message:
"Prefer importing `getSelectionRange()` helper or check `selection.rangeCount` first: https://github.com/pixiebrix/pixiebrix-extension/pull/7989",
selector: "CallExpression[callee.property.name='getRangeAt']",
},
{
message:
"Use the chrome.* APIs (browser.* is now only used for for messaging)",
selector:
"MemberExpression[object.object.name='browser']:not(:has(Identifier[name=/runtime|tabs/]):has(Identifier[name=/Message/]))",
},
{
message:
"Use the browser.* APIs for messaging (chrome.* for everything else)",
selector:
"MemberExpression[object.object.name='chrome']:has(Identifier[name=/runtime|tabs/]):has(Identifier[name=/Message/])",
},
// NOTE: If you add more rules, add the tests to no-restricted-syntax.test.ts
];