-
Notifications
You must be signed in to change notification settings - Fork 498
/
Copy pathno-it-screenshot-only-or-repeat.ts
47 lines (40 loc) · 1.57 KB
/
no-it-screenshot-only-or-repeat.ts
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
// Copyright 2023 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {createRule} from './utils/ruleCreator.ts';
type MessageIds = `itScreenshot-${'only'|'repeat'}`;
const BANNED_IT_EXTENSIONS = new Set(['only', 'repeat']);
export default createRule<[], MessageIds>({
name: 'no-it-screenshot-only-or-repeat',
meta: {
type: 'problem',
docs: {
description: 'ensure no itScreenshot.only or itScreenshot.repeat calls',
category: 'Possible Errors',
},
messages: {
'itScreenshot-only': 'Focused screenshot tests are not allowed.',
'itScreenshot-repeat': 'Repeated screenshot tests are not allowed.',
},
schema: [], // no options
},
defaultOptions: [],
create: function(context) {
return {
CallExpression(node): void {
if (node.callee.type !== 'MemberExpression' || node.callee.object.type !== 'Identifier' ||
node.callee.object.name !== 'itScreenshot' || node.callee.property.type !== 'Identifier') {
return;
}
const calleePropertyName = node.callee.property.name;
if (!BANNED_IT_EXTENSIONS.has(calleePropertyName)) {
return;
}
// Construct the message ID dynamically and assert its type
const errorMessageId = `itScreenshot-${calleePropertyName}` as MessageIds;
// Report the specific property (.only or .repeat) as the error location
context.report({node: node.callee.property, messageId: errorMessageId});
},
};
},
});