Skip to content

Commit 9d88510

Browse files
removed chains refrences
1 parent 64a314b commit 9d88510

File tree

4 files changed

+7
-108
lines changed

4 files changed

+7
-108
lines changed

Diff for: src/rules/collection-method-value.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = {
4141
);
4242
}
4343

44-
function isPureLodashCollectionMethod(method) {
44+
function isPureRemedaCollectionMethod(method) {
4545
return isCollectionMethod(method) && !isAliasOfMethod("remove", method);
4646
}
4747

@@ -59,7 +59,7 @@ module.exports = {
5959
context,
6060
(node, iteratee, { method, callType }) => {
6161
if (
62-
isPureLodashCollectionMethod(method) &&
62+
isPureRemedaCollectionMethod(method) &&
6363
!parentUsesValue(node, callType)
6464
) {
6565
context.report({

Diff for: src/util/LodashContext.js

-45
Original file line numberDiff line numberDiff line change
@@ -114,51 +114,6 @@ module.exports = class {
114114
);
115115
}
116116

117-
/**
118-
* Returns whether the node is an implicit chain start, _()...
119-
* @param node
120-
* @returns {boolean|undefined}
121-
*/
122-
isImplicitChainStart(node) {
123-
return (
124-
(this.pragma && node.callee.name === this.pragma) ||
125-
(this.isImportedRemeda(node.callee) && node.callee.name !== "chain")
126-
);
127-
}
128-
129-
/**
130-
* Returns whether the node is an explicit chain start, _.chain()...
131-
* @param node
132-
* @returns {boolean|undefined}
133-
*/
134-
isExplicitChainStart(node) {
135-
return this.isLodashCall(node) && getMethodName(node) === "chain";
136-
}
137-
138-
/**
139-
* Returns whether the node is chain start imported as member, chain()... import { chain } from 'lodash'
140-
* @param node
141-
* @returns {boolean|undefined}
142-
*/
143-
isImportedChainStart(node) {
144-
return node.callee.name === "chain" && this.isImportedRemeda(node.callee);
145-
}
146-
147-
/**
148-
* Returns whether the node is a Lodash chain start, implicit or explicit
149-
* @param node
150-
* @returns {*|boolean|boolean|undefined}
151-
*/
152-
isLodashChainStart(node) {
153-
return (
154-
node &&
155-
node.type === "CallExpression" &&
156-
(this.isImplicitChainStart(node) ||
157-
this.isExplicitChainStart(node) ||
158-
this.isImportedChainStart(node))
159-
);
160-
}
161-
162117
/**
163118
*
164119
* @returns {string|undefined} the current Remeda pragma

Diff for: src/util/lodashUtil.js

+5-47
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,7 @@ function getIsTypeMethod(name) {
5454
function getRemedaMethodCallExpVisitor(lodashContext, reporter) {
5555
return function (node) {
5656
let iterateeIndex;
57-
if (lodashContext.isLodashChainStart(node)) {
58-
let prevNode = node;
59-
node = node.parent.parent;
60-
while (
61-
astUtil.getCaller(node) === prevNode &&
62-
astUtil.isMethodCall(node) &&
63-
!isChainBreaker(node)
64-
) {
65-
const method = astUtil.getMethodName(node);
66-
iterateeIndex = methodDataUtil.getIterateeIndex(method);
67-
reporter(node, node.arguments[iterateeIndex - 1], {
68-
callType: "chained",
69-
method,
70-
lodashContext,
71-
});
72-
prevNode = node;
73-
node = node.parent.parent;
74-
}
75-
} else if (lodashContext.isLodashCall(node)) {
57+
if (lodashContext.isLodashCall(node)) {
7658
const method = astUtil.getMethodName(node);
7759
iterateeIndex = methodDataUtil.getIterateeIndex(method);
7860
reporter(node, node.arguments[iterateeIndex], {
@@ -94,16 +76,16 @@ function getRemedaMethodCallExpVisitor(lodashContext, reporter) {
9476
};
9577
}
9678

97-
function isLodashCallToMethod(node, method, lodashContext) {
79+
function isRemedaCallToMethod(node, method, lodashContext) {
9880
return lodashContext.isLodashCall(node) && isCallToMethod(node, method);
9981
}
10082

101-
function isCallToLodashMethod(node, method, lodashContext) {
83+
function isCallToRemedaMethod(node, method, lodashContext) {
10284
if (!node || node.type !== "CallExpression") {
10385
return false;
10486
}
10587
return (
106-
isLodashCallToMethod(node, method, lodashContext) ||
88+
isRemedaCallToMethod(node, method, lodashContext) ||
10789
methodDataUtil.isAliasOfMethod(
10890
method,
10991
lodashContext.getImportedRemedaMethod(node),
@@ -135,31 +117,7 @@ module.exports = {
135117
isCallToMethod,
136118
getIsTypeMethod,
137119
getRemedaMethodCallExpVisitor,
138-
isCallToLodashMethod,
120+
isCallToLodashMethod: isCallToRemedaMethod,
139121
getRemedaMethodVisitors,
140122
getLodashContext,
141123
};
142-
143-
/**
144-
@callback LodashReporter
145-
@param {Object} node
146-
@param {Object} iteratee
147-
@param {Object?} options
148-
*/
149-
150-
/**
151-
@callback NodeTypeVisitor
152-
@param {Object} node
153-
*/
154-
155-
/**
156-
* @typedef {Object} ShorthandChecks
157-
* @property {function} canUseShorthand
158-
* @property {function} usesShorthand
159-
*/
160-
161-
/**
162-
* @typedef {object} ShorthandMessages
163-
* @property {string} always
164-
* @property {string} never
165-
*/

Diff for: tests/lib/util/LodashContext.js

-14
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,6 @@ describe("LodashContext", () => {
188188
}),
189189
);
190190
});
191-
it("should not consider Object.prototype methods as Remeda", (done) => {
192-
visitWithContext(
193-
'const {toString} = require("remeda"); const x = toString(y)',
194-
undefined,
195-
(lodashContext) => ({
196-
CallExpression(node) {
197-
if (node.callee.name === "toString") {
198-
assert(!lodashContext.isLodashChainStart(node));
199-
done();
200-
}
201-
},
202-
}),
203-
);
204-
});
205191
});
206192
});
207193
describe("isImportedRemeda", () => {

0 commit comments

Comments
 (0)