Skip to content

Commit 3c77c85

Browse files
chore: update dependencies + run prettier on codebase (#232)
* chore: update dependencies * chore: run Prettier on full codebase
1 parent e79c0e5 commit 3c77c85

9 files changed

+228
-14949
lines changed

.gitignore

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Output
1+
# Output
22
dist
33

44
# Logs
@@ -66,3 +66,8 @@ yarn-error.log
6666
.pnp.js
6767
# Yarn Integrity file
6868
.yarn-integrity
69+
70+
# these cause more harm than good
71+
# when working with contributors
72+
package-lock.json
73+
yarn.lock

commitlint.config.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
module.exports = { extends: ['@commitlint/config-conventional'] };
1+
module.exports = {
2+
extends: ['@commitlint/config-conventional'],
3+
};

lib/node-utils.ts

+32-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/experimental-utils';
1+
import {
2+
AST_NODE_TYPES,
3+
TSESTree,
4+
} from '@typescript-eslint/experimental-utils';
25
import { RuleContext } from '@typescript-eslint/experimental-utils/dist/ts-eslint';
36

47
export function isCallExpression(
@@ -84,7 +87,7 @@ export function findClosestCallExpressionNode(
8487
return node;
8588
}
8689

87-
if(!node.parent) return null
90+
if (!node.parent) return null;
8891

8992
return findClosestCallExpressionNode(node.parent);
9093
}
@@ -108,8 +111,10 @@ export function findClosestCallNode(
108111
}
109112
}
110113

111-
export function isObjectExpression(node: TSESTree.Expression): node is TSESTree.ObjectExpression {
112-
return node?.type === AST_NODE_TYPES.ObjectExpression
114+
export function isObjectExpression(
115+
node: TSESTree.Expression
116+
): node is TSESTree.ObjectExpression {
117+
return node?.type === AST_NODE_TYPES.ObjectExpression;
113118
}
114119

115120
export function hasThenProperty(node: TSESTree.Node) {
@@ -126,16 +131,24 @@ export function isAwaitExpression(
126131
return node && node.type === AST_NODE_TYPES.AwaitExpression;
127132
}
128133

129-
export function isArrowFunctionExpression(node: TSESTree.Node): node is TSESTree.ArrowFunctionExpression {
130-
return node && node.type === AST_NODE_TYPES.ArrowFunctionExpression
134+
export function isArrowFunctionExpression(
135+
node: TSESTree.Node
136+
): node is TSESTree.ArrowFunctionExpression {
137+
return node && node.type === AST_NODE_TYPES.ArrowFunctionExpression;
131138
}
132139

133-
export function isReturnStatement(node: TSESTree.Node): node is TSESTree.ReturnStatement {
134-
return node && node.type === AST_NODE_TYPES.ReturnStatement
140+
export function isReturnStatement(
141+
node: TSESTree.Node
142+
): node is TSESTree.ReturnStatement {
143+
return node && node.type === AST_NODE_TYPES.ReturnStatement;
135144
}
136145

137146
export function isAwaited(node: TSESTree.Node) {
138-
return isAwaitExpression(node) || isArrowFunctionExpression(node) || isReturnStatement(node)
147+
return (
148+
isAwaitExpression(node) ||
149+
isArrowFunctionExpression(node) ||
150+
isReturnStatement(node)
151+
);
139152
}
140153

141154
export function isPromiseResolved(node: TSESTree.Node) {
@@ -150,6 +163,13 @@ export function isPromiseResolved(node: TSESTree.Node) {
150163
return hasThenProperty(parent);
151164
}
152165

153-
export function getVariableReferences(context: RuleContext<string, []>, node: TSESTree.Node) {
154-
return (isVariableDeclarator(node) && context.getDeclaredVariables(node)[0].references.slice(1)) || [];
155-
}
166+
export function getVariableReferences(
167+
context: RuleContext<string, []>,
168+
node: TSESTree.Node
169+
) {
170+
return (
171+
(isVariableDeclarator(node) &&
172+
context.getDeclaredVariables(node)[0].references.slice(1)) ||
173+
[]
174+
);
175+
}

lib/rules/no-debug.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ import {
1414

1515
export const RULE_NAME = 'no-debug';
1616
export type MessageIds = 'noDebug';
17-
type Options = [
18-
{ renderFunctions?: string[]; }
19-
];
17+
type Options = [{ renderFunctions?: string[] }];
2018

2119
function isRenderVariableDeclarator(
2220
node: TSESTree.VariableDeclarator,

lib/rules/prefer-screen-queries.ts

+39-18
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,23 @@ export const RULE_NAME = 'prefer-screen-queries';
1313
export type MessageIds = 'preferScreenQueries';
1414
type Options = [];
1515

16-
const ALLOWED_RENDER_PROPERTIES_FOR_DESTRUCTURING = ['container', 'baseElement']
16+
const ALLOWED_RENDER_PROPERTIES_FOR_DESTRUCTURING = [
17+
'container',
18+
'baseElement',
19+
];
1720
const ALL_QUERIES_COMBINATIONS_REGEXP = ALL_QUERIES_COMBINATIONS.join('|');
1821

1922
function usesContainerOrBaseElement(node: TSESTree.CallExpression) {
20-
const secondArgument = node.arguments[1]
21-
return isObjectExpression(secondArgument) && secondArgument.properties.some((property) => isProperty(property) && isIdentifier(property.key) && ALLOWED_RENDER_PROPERTIES_FOR_DESTRUCTURING.includes(property.key.name))
23+
const secondArgument = node.arguments[1];
24+
return (
25+
isObjectExpression(secondArgument) &&
26+
secondArgument.properties.some(
27+
property =>
28+
isProperty(property) &&
29+
isIdentifier(property.key) &&
30+
ALLOWED_RENDER_PROPERTIES_FOR_DESTRUCTURING.includes(property.key.name)
31+
)
32+
);
2233
}
2334

2435
export default ESLintUtils.RuleCreator(getDocsUrl)<Options, MessageIds>({
@@ -53,33 +64,43 @@ export default ESLintUtils.RuleCreator(getDocsUrl)<Options, MessageIds>({
5364
const queriesRegex = new RegExp(ALL_QUERIES_COMBINATIONS_REGEXP);
5465
const queriesDestructuredInWithinDeclaration: string[] = [];
5566
// use an array as within might be used more than once in a test
56-
const withinDeclaredVariables : string[] = []
67+
const withinDeclaredVariables: string[] = [];
5768

5869
return {
5970
VariableDeclarator(node) {
6071
if (!isCallExpression(node.init) || !isIdentifier(node.init.callee)) {
61-
return
72+
return;
6273
}
63-
const isWithinFunction = node.init.callee.name === 'within';
74+
const isWithinFunction = node.init.callee.name === 'within';
6475
// TODO add the custom render option #198
65-
const usesRenderOptions = node.init.callee.name === 'render' && usesContainerOrBaseElement(node.init);
76+
const usesRenderOptions =
77+
node.init.callee.name === 'render' &&
78+
usesContainerOrBaseElement(node.init);
6679

6780
if (!isWithinFunction && !usesRenderOptions) {
68-
return
81+
return;
6982
}
7083

7184
if (isObjectPattern(node.id)) {
7285
// save the destructured query methods
7386
const identifiers = node.id.properties
74-
.filter(property => isProperty(property) && isIdentifier(property.key) && queriesRegex.test(property.key.name))
75-
.map((property: TSESTree.Property) => (property.key as TSESTree.Identifier).name);
87+
.filter(
88+
property =>
89+
isProperty(property) &&
90+
isIdentifier(property.key) &&
91+
queriesRegex.test(property.key.name)
92+
)
93+
.map(
94+
(property: TSESTree.Property) =>
95+
(property.key as TSESTree.Identifier).name
96+
);
7697

7798
queriesDestructuredInWithinDeclaration.push(...identifiers);
78-
return
99+
return;
79100
}
80101

81102
if (isIdentifier(node.id)) {
82-
withinDeclaredVariables.push(node.id.name)
103+
withinDeclaredVariables.push(node.id.name);
83104
}
84105
},
85106
[`CallExpression > Identifier[name=/^${ALL_QUERIES_COMBINATIONS_REGEXP}$/]`](
@@ -96,18 +117,18 @@ export default ESLintUtils.RuleCreator(getDocsUrl)<Options, MessageIds>({
96117
[`MemberExpression > Identifier[name=/^${ALL_QUERIES_COMBINATIONS_REGEXP}$/]`](
97118
node: TSESTree.Identifier
98119
) {
99-
100120
function isIdentifierAllowed(name: string) {
101-
return ['screen', ...withinDeclaredVariables].includes(name)
121+
return ['screen', ...withinDeclaredVariables].includes(name);
102122
}
103123

104124
if (
105125
isIdentifier(node) &&
106126
isMemberExpression(node.parent) &&
107127
isCallExpression(node.parent.object) &&
108-
isIdentifier(node.parent.object.callee) &&
109-
node.parent.object.callee.name !== 'within' &&
110-
node.parent.object.callee.name === 'render' && !usesContainerOrBaseElement(node.parent.object)
128+
isIdentifier(node.parent.object.callee) &&
129+
node.parent.object.callee.name !== 'within' &&
130+
node.parent.object.callee.name === 'render' &&
131+
!usesContainerOrBaseElement(node.parent.object)
111132
) {
112133
reportInvalidUsage(node);
113134
return;
@@ -123,4 +144,4 @@ export default ESLintUtils.RuleCreator(getDocsUrl)<Options, MessageIds>({
123144
},
124145
};
125146
},
126-
});
147+
});

0 commit comments

Comments
 (0)