Skip to content

Commit 70dcc97

Browse files
authored
Replace getKeyName with utility from eslint-utils (#1732)
1 parent d944282 commit 70dcc97

File tree

6 files changed

+16
-57
lines changed

6 files changed

+16
-57
lines changed

rules/no-document-cookie.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
const getKeyName = require('./utils/get-key-name.js');
2+
const {getPropertyName} = require('eslint-utils');
33

44
const MESSAGE_ID = 'no-document-cookie';
55
const messages = {
@@ -17,7 +17,7 @@ const selector = [
1717
/** @param {import('eslint').Rule.RuleContext} context */
1818
const create = context => ({
1919
[selector](node) {
20-
if (getKeyName(node, context.getScope()) !== 'cookie') {
20+
if (getPropertyName(node, context.getScope()) !== 'cookie') {
2121
return;
2222
}
2323

rules/no-thenable.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
2-
const {getStaticValue} = require('eslint-utils');
2+
const {getStaticValue, getPropertyName} = require('eslint-utils');
33
const {methodCallSelector} = require('./selectors/index.js');
4-
const getKeyName = require('./utils/get-key-name.js');
54

65
const MESSAGE_ID_OBJECT = 'no-thenable-object';
76
const MESSAGE_ID_EXPORT = 'no-thenable-export';
@@ -25,7 +24,7 @@ const cases = [
2524
// `{get [computedKey]() {}}`,
2625
{
2726
selector: 'ObjectExpression > Property.properties > .key',
28-
test: (node, context) => getKeyName(node.parent, context.getScope()) === 'then',
27+
test: (node, context) => getPropertyName(node.parent, context.getScope()) === 'then',
2928
messageId: MESSAGE_ID_OBJECT,
3029
},
3130
// `class Foo {then}`,
@@ -34,14 +33,14 @@ const cases = [
3433
// `class Foo {static get then() {}}`,
3534
{
3635
selector: ':matches(PropertyDefinition, MethodDefinition) > .key',
37-
test: (node, context) => getKeyName(node.parent, context.getScope()) === 'then',
36+
test: (node, context) => getPropertyName(node.parent, context.getScope()) === 'then',
3837
messageId: MESSAGE_ID_CLASS,
3938
},
4039
// `foo.then = …`
4140
// `foo[computedKey] = …`
4241
{
4342
selector: 'AssignmentExpression > MemberExpression.left > .property',
44-
test: (node, context) => getKeyName(node.parent, context.getScope()) === 'then',
43+
test: (node, context) => getPropertyName(node.parent, context.getScope()) === 'then',
4544
messageId: MESSAGE_ID_OBJECT,
4645
},
4746
// `Object.defineProperty(foo, 'then', …)`

rules/prefer-json-parse-buffer.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'use strict';
2-
const {findVariable, getStaticValue} = require('eslint-utils');
2+
const {findVariable, getStaticValue, getPropertyName} = require('eslint-utils');
33
const {methodCallSelector} = require('./selectors/index.js');
44
const {removeArgument} = require('./fix/index.js');
5-
const getKeyName = require('./utils/get-key-name.js');
65

76
const MESSAGE_ID = 'prefer-json-parse-buffer';
87
const messages = {
@@ -80,7 +79,7 @@ function isUtf8Encoding(node, scope) {
8079
node.type === 'ObjectExpression'
8180
&& node.properties.length === 1
8281
&& node.properties[0].type === 'Property'
83-
&& getKeyName(node.properties[0], scope) === 'encoding'
82+
&& getPropertyName(node.properties[0], scope) === 'encoding'
8483
&& isUtf8EncodingStringNode(node.properties[0].value, scope)
8584
) {
8685
return true;
@@ -126,7 +125,7 @@ const create = context => ({
126125
return;
127126
}
128127

129-
const method = getKeyName(node.callee, scope);
128+
const method = getPropertyName(node.callee, scope);
130129
if (method !== 'readFile' && method !== 'readFileSync') {
131130
return;
132131
}

rules/prefer-prototype-methods.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
2+
const {getPropertyName} = require('eslint-utils');
23
const {
34
methodCallSelector,
45
emptyObjectSelector,
56
emptyArraySelector,
67
matches,
78
} = require('./selectors/index.js');
8-
const getKeyName = require('./utils/get-key-name.js');
99
const {fixSpaceAroundKeyword} = require('./fix/index.js');
1010

1111
const messages = {
@@ -41,7 +41,7 @@ function create(context) {
4141
return {
4242
[selector](node) {
4343
const constructorName = node.object.type === 'ArrayExpression' ? 'Array' : 'Object';
44-
const methodName = getKeyName(node, context.getScope());
44+
const methodName = getPropertyName(node, context.getScope());
4545

4646
return {
4747
node,

rules/prefer-reflect-apply.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
2+
const {getPropertyName} = require('eslint-utils');
23
const isLiteralValue = require('./utils/is-literal-value.js');
3-
const getKeyName = require('./utils/get-key-name.js');
44
const {not, methodCallSelector} = require('./selectors/index.js');
55

66
const MESSAGE_ID = 'prefer-reflect-apply';
@@ -31,7 +31,7 @@ const getReflectApplyCall = (sourceCode, target, receiver, argumentsList) => (
3131

3232
const fixDirectApplyCall = (node, sourceCode) => {
3333
if (
34-
getKeyName(node.callee) === 'apply'
34+
getPropertyName(node.callee) === 'apply'
3535
&& node.arguments.length === 2
3636
&& isApplySignature(node.arguments[0], node.arguments[1])
3737
) {
@@ -46,9 +46,9 @@ const fixDirectApplyCall = (node, sourceCode) => {
4646

4747
const fixFunctionPrototypeCall = (node, sourceCode) => {
4848
if (
49-
getKeyName(node.callee) === 'call'
50-
&& getKeyName(node.callee.object) === 'apply'
51-
&& getKeyName(node.callee.object.object) === 'prototype'
49+
getPropertyName(node.callee) === 'call'
50+
&& getPropertyName(node.callee.object) === 'apply'
51+
&& getPropertyName(node.callee.object.object) === 'prototype'
5252
&& node.callee.object.object.object
5353
&& node.callee.object.object.object.type === 'Identifier'
5454
&& node.callee.object.object.object.name === 'Function'

rules/utils/get-key-name.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)