-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathno-nth-methods.ts
38 lines (34 loc) · 1003 Bytes
/
no-nth-methods.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
import { getStringValue } from '../utils/ast.js'
import { createRule } from '../utils/createRule.js'
const methods = new Set(['first', 'last', 'nth'])
export default createRule({
create(context) {
return {
CallExpression(node) {
if (node.callee.type !== 'MemberExpression') return
const method = getStringValue(node.callee.property)
if (!methods.has(method)) return
context.report({
data: { method },
loc: {
end: node.loc!.end,
start: node.callee.property.loc!.start,
},
messageId: 'noNthMethod',
})
},
}
},
meta: {
docs: {
category: 'Best Practices',
description: 'Disallow usage of nth methods',
recommended: true,
url: 'https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-nth-methods.md',
},
messages: {
noNthMethod: 'Unexpected use of {{method}}()',
},
type: 'problem',
},
})