Skip to content

Commit

Permalink
Replace getKeyName with utility from eslint-utils (#1732)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Feb 17, 2022
1 parent d944282 commit 70dcc97
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 57 deletions.
4 changes: 2 additions & 2 deletions rules/no-document-cookie.js
@@ -1,5 +1,5 @@
'use strict';
const getKeyName = require('./utils/get-key-name.js');
const {getPropertyName} = require('eslint-utils');

const MESSAGE_ID = 'no-document-cookie';
const messages = {
Expand All @@ -17,7 +17,7 @@ const selector = [
/** @param {import('eslint').Rule.RuleContext} context */
const create = context => ({
[selector](node) {
if (getKeyName(node, context.getScope()) !== 'cookie') {
if (getPropertyName(node, context.getScope()) !== 'cookie') {
return;
}

Expand Down
9 changes: 4 additions & 5 deletions rules/no-thenable.js
@@ -1,7 +1,6 @@
'use strict';
const {getStaticValue} = require('eslint-utils');
const {getStaticValue, getPropertyName} = require('eslint-utils');
const {methodCallSelector} = require('./selectors/index.js');
const getKeyName = require('./utils/get-key-name.js');

const MESSAGE_ID_OBJECT = 'no-thenable-object';
const MESSAGE_ID_EXPORT = 'no-thenable-export';
Expand All @@ -25,7 +24,7 @@ const cases = [
// `{get [computedKey]() {}}`,
{
selector: 'ObjectExpression > Property.properties > .key',
test: (node, context) => getKeyName(node.parent, context.getScope()) === 'then',
test: (node, context) => getPropertyName(node.parent, context.getScope()) === 'then',
messageId: MESSAGE_ID_OBJECT,
},
// `class Foo {then}`,
Expand All @@ -34,14 +33,14 @@ const cases = [
// `class Foo {static get then() {}}`,
{
selector: ':matches(PropertyDefinition, MethodDefinition) > .key',
test: (node, context) => getKeyName(node.parent, context.getScope()) === 'then',
test: (node, context) => getPropertyName(node.parent, context.getScope()) === 'then',
messageId: MESSAGE_ID_CLASS,
},
// `foo.then = …`
// `foo[computedKey] = …`
{
selector: 'AssignmentExpression > MemberExpression.left > .property',
test: (node, context) => getKeyName(node.parent, context.getScope()) === 'then',
test: (node, context) => getPropertyName(node.parent, context.getScope()) === 'then',
messageId: MESSAGE_ID_OBJECT,
},
// `Object.defineProperty(foo, 'then', …)`
Expand Down
7 changes: 3 additions & 4 deletions rules/prefer-json-parse-buffer.js
@@ -1,8 +1,7 @@
'use strict';
const {findVariable, getStaticValue} = require('eslint-utils');
const {findVariable, getStaticValue, getPropertyName} = require('eslint-utils');
const {methodCallSelector} = require('./selectors/index.js');
const {removeArgument} = require('./fix/index.js');
const getKeyName = require('./utils/get-key-name.js');

const MESSAGE_ID = 'prefer-json-parse-buffer';
const messages = {
Expand Down Expand Up @@ -80,7 +79,7 @@ function isUtf8Encoding(node, scope) {
node.type === 'ObjectExpression'
&& node.properties.length === 1
&& node.properties[0].type === 'Property'
&& getKeyName(node.properties[0], scope) === 'encoding'
&& getPropertyName(node.properties[0], scope) === 'encoding'
&& isUtf8EncodingStringNode(node.properties[0].value, scope)
) {
return true;
Expand Down Expand Up @@ -126,7 +125,7 @@ const create = context => ({
return;
}

const method = getKeyName(node.callee, scope);
const method = getPropertyName(node.callee, scope);
if (method !== 'readFile' && method !== 'readFileSync') {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions rules/prefer-prototype-methods.js
@@ -1,11 +1,11 @@
'use strict';
const {getPropertyName} = require('eslint-utils');
const {
methodCallSelector,
emptyObjectSelector,
emptyArraySelector,
matches,
} = require('./selectors/index.js');
const getKeyName = require('./utils/get-key-name.js');
const {fixSpaceAroundKeyword} = require('./fix/index.js');

const messages = {
Expand Down Expand Up @@ -41,7 +41,7 @@ function create(context) {
return {
[selector](node) {
const constructorName = node.object.type === 'ArrayExpression' ? 'Array' : 'Object';
const methodName = getKeyName(node, context.getScope());
const methodName = getPropertyName(node, context.getScope());

return {
node,
Expand Down
10 changes: 5 additions & 5 deletions rules/prefer-reflect-apply.js
@@ -1,6 +1,6 @@
'use strict';
const {getPropertyName} = require('eslint-utils');
const isLiteralValue = require('./utils/is-literal-value.js');
const getKeyName = require('./utils/get-key-name.js');
const {not, methodCallSelector} = require('./selectors/index.js');

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

const fixDirectApplyCall = (node, sourceCode) => {
if (
getKeyName(node.callee) === 'apply'
getPropertyName(node.callee) === 'apply'
&& node.arguments.length === 2
&& isApplySignature(node.arguments[0], node.arguments[1])
) {
Expand All @@ -46,9 +46,9 @@ const fixDirectApplyCall = (node, sourceCode) => {

const fixFunctionPrototypeCall = (node, sourceCode) => {
if (
getKeyName(node.callee) === 'call'
&& getKeyName(node.callee.object) === 'apply'
&& getKeyName(node.callee.object.object) === 'prototype'
getPropertyName(node.callee) === 'call'
&& getPropertyName(node.callee.object) === 'apply'
&& getPropertyName(node.callee.object.object) === 'prototype'
&& node.callee.object.object.object
&& node.callee.object.object.object.type === 'Identifier'
&& node.callee.object.object.object.name === 'Function'
Expand Down
39 changes: 0 additions & 39 deletions rules/utils/get-key-name.js

This file was deleted.

0 comments on commit 70dcc97

Please sign in to comment.