Skip to content

Commit 3ecdbaa

Browse files
committed
core(lint): Add custom no-focused-tests and no-skipped-tests rules
1 parent c24f6d0 commit 3ecdbaa

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

packages/eslint-config-sdk/src/base.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ module.exports = {
184184
'@sentry-internal/sdk/no-optional-chaining': 'off',
185185
'@sentry-internal/sdk/no-nullish-coalescing': 'off',
186186
'@typescript-eslint/no-floating-promises': 'off',
187+
'@sentry-internal/sdk/no-focused-tests': 'error',
188+
'@sentry-internal/sdk/no-skipped-tests': 'error',
187189
},
188190
},
189191
{

packages/eslint-plugin-sdk/src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@ module.exports = {
1515
'no-eq-empty': require('./rules/no-eq-empty'),
1616
'no-class-field-initializers': require('./rules/no-class-field-initializers'),
1717
'no-regexp-constructor': require('./rules/no-regexp-constructor'),
18+
'no-focused-tests': require('./rules/no-focused-tests'),
19+
'no-skipped-tests': require('./rules/no-skipped-tests'),
1820
},
1921
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
/**
4+
* This rule was created to flag usages of the `.only` function in vitest and jest tests.
5+
* Usually, we don't want to commit focused tests as this causes other tests to be skipped.
6+
*/
7+
module.exports = {
8+
meta: {
9+
docs: {
10+
description: "Do not focus tests via `.only` to ensure we don't commit accidentally skip the other tests.",
11+
},
12+
schema: [],
13+
},
14+
create: function (context) {
15+
return {
16+
CallExpression(node) {
17+
if (
18+
node.callee.type === 'MemberExpression' &&
19+
node.callee.object.type === 'Identifier' &&
20+
['test', 'it', 'describe'].includes(node.callee.object.name) &&
21+
node.callee.property.type === 'Identifier' &&
22+
node.callee.property.name === 'only'
23+
) {
24+
context.report({
25+
node,
26+
message: "Do not focus tests via `.only` to ensure we don't commit accidentally skip the other tests.",
27+
});
28+
}
29+
},
30+
};
31+
},
32+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
/**
4+
* This rule was created to flag usages of the `.skip` function in vitest and jest tests.
5+
* Usually, we don't want to commit skipped tests as this causes other tests to be skipped.
6+
* Sometimes, skipping is valid (e.g. flaky tests), in which case, we can simply eslint-disable the rule.
7+
*/
8+
module.exports = {
9+
meta: {
10+
docs: {
11+
description: "Do not skip tests via `.skip` to ensure we don't commit accidentally skipped tests.",
12+
},
13+
schema: [],
14+
},
15+
create: function (context) {
16+
return {
17+
CallExpression(node) {
18+
if (
19+
node.callee.type === 'MemberExpression' &&
20+
node.callee.object.type === 'Identifier' &&
21+
['test', 'it', 'describe'].includes(node.callee.object.name) &&
22+
node.callee.property.type === 'Identifier' &&
23+
node.callee.property.name === 'skip'
24+
) {
25+
context.report({
26+
node,
27+
message: "Do not skip tests via `.skip` to ensure we don't commit accidentally skipped tests.",
28+
});
29+
}
30+
},
31+
};
32+
},
33+
};

0 commit comments

Comments
 (0)