Skip to content

Commit

Permalink
bugfix: fixed crash for dep not found
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaPontrandolfo committed Sep 15, 2024
1 parent da465eb commit c80c387
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 33 deletions.
7 changes: 7 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ const sheriffOptions = {
export default defineFlatConfig([
...sheriff(sheriffOptions),
eslintPlugin.configs["flat/recommended"],
{
rules: {
"func-style": 0,
"import/no-default-export": 0,
"@typescript-eslint/explicit-module-boundary-types": 0,
},
},
]);
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ESLint } from "eslint";
import _ from "lodash";
import { last } from "lodash";
import packageJson from "../package.json";
import { rules } from "./rules";

Expand All @@ -11,7 +11,7 @@ const plugin = {
processors: {},
} satisfies ESLint.Plugin;

const pluginShortName = _.last(plugin.meta.name.split("-")) as string;
const pluginShortName = last(plugin.meta.name.split("-")) as string;

Object.assign(plugin.configs, {
recommended: {
Expand Down
4 changes: 2 additions & 2 deletions src/rules/collection-method-value.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* @fileoverview Rule to enforce usage of collection method values
* @file Rule to enforce usage of collection method values.
*/

import includes from "lodash/includes";
import { includes } from "lodash";
import astUtil from "../util/astUtil";
import { getDocsUrl } from "../util/getDocsUrl";
import {
Expand Down
9 changes: 4 additions & 5 deletions src/rules/collection-return.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assign from "lodash/assign";
import { assign } from "lodash";
import astUtil from "../util/astUtil";
import { getDocsUrl } from "../util/getDocsUrl";
import { isCollectionMethod } from "../util/methodDataUtil";
Expand All @@ -7,10 +7,6 @@ import {
getRemedaMethodCallExpVisitor,
} from "../util/remedaUtil";

/**
* @fileoverview Rule to check that iteratees for all collection functions except forEach return a value;
*/

interface FuncInfo {
upper: FuncInfo;
codePath: any;
Expand All @@ -25,6 +21,9 @@ const meta = {
},
} as const;

/**
* Rule to check that iteratees for all collection functions except forEach return a value;.
*/
function create(context) {
const funcInfos = new Map();
let currFuncInfo: FuncInfo;
Expand Down
5 changes: 2 additions & 3 deletions src/rules/prefer-map.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/**
* @fileoverview Rule to check if a call to R.forEach should be a call to R.map
* Rule to check if a call to R.forEach should be a call to R.map.
*/

import get from "lodash/get";
import includes from "lodash/includes";
import { get, includes } from "lodash";
import astUtil from "../util/astUtil";
import { getDocsUrl } from "../util/getDocsUrl";
import { getRemedaMethodVisitors } from "../util/remedaUtil";
Expand Down
4 changes: 2 additions & 2 deletions src/rules/prefer-remeda-typecheck.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* @fileoverview Rule to check if there's a method in the chain start that can be in the chain
* @file Rule to check if there's a method in the chain start that can be in the chain.
*/

import some from "lodash/some";
import { some } from "lodash";
import { getDocsUrl } from "../util/getDocsUrl";
import { getIsTypeMethod } from "../util/remedaUtil";

Expand Down
4 changes: 2 additions & 2 deletions src/util/importUtil.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import get from "lodash/get";
import { get } from "lodash";

function getNameFromCjsRequire(init) {
if (
Expand All @@ -17,4 +17,4 @@ const getMethodImportFromName = (str: string) => {
return match && match[2];
};

export { getNameFromCjsRequire, isFullRemedaImport, getMethodImportFromName };
export { getMethodImportFromName, getNameFromCjsRequire, isFullRemedaImport };
13 changes: 7 additions & 6 deletions src/util/methodDataUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ function methodSupportsShorthand(method: string, shorthandType?: string) {
function getIterateeIndex(method: string) {
const methodData = methodDataCatalog[method];

if (has(methodData, "iterateeIndex")) {
return methodData.iterateeIndex;
}
//@ts-expect-error
if (methodData.iteratee) {
return 1;
if (methodData) {
if (has(methodData, "iterateeIndex")) {
return methodData.iterateeIndex;
}
if (methodData.iteratee) {
return 1;
}
}

return -1;
Expand Down
15 changes: 7 additions & 8 deletions src/util/remedaUtil.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { capitalize,includes } from "lodash";
import { capitalize, includes } from "lodash";
import type { RemedaMethodVisitors } from "../types";
import astUtil from "./astUtil";
import * as methodDataUtil from "./methodDataUtil";
Expand All @@ -16,7 +16,7 @@ function isCallToMethod(node, method) {
}

/**
* Gets the 'isX' method for a specified type, e.g. isObject
* Gets the 'isX' method for a specified type, e.g. IsObject.
*
* @param name
* @returns
Expand All @@ -40,7 +40,7 @@ function getIsTypeMethod(name) {
}

/**
* Gets the context's Remeda settings and a function and returns a visitor that calls the function for every Remeda or chain call
* Gets the context's Remeda settings and a function and returns a visitor that calls the function for every Remeda or chain call.
*
* @param remedaContext
* @param reporter
Expand Down Expand Up @@ -103,19 +103,18 @@ function getRemedaMethodVisitors(context, remedaCallExpVisitor) {
}

/**
*
* @param context
* @returns a RemedaContext for a given context
* @returns A RemedaContext for a given context.
*/
function getRemedaContext(context) {
return new RemedaContext(context);
}

export {
isCallToMethod,
getIsTypeMethod,
getRemedaContext,
getRemedaMethodCallExpVisitor,
isCallToRemedaMethod,
getRemedaMethodVisitors,
getRemedaContext,
isCallToMethod,
isCallToRemedaMethod,
};
4 changes: 1 addition & 3 deletions src/util/ruleUtil.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import assignWith from "lodash/assignWith";
import mapValues from "lodash/mapValues";
import over from "lodash/over";
import { assignWith, mapValues, over } from "lodash";

function combineVisitorObjects(...objects) {
const accumForAllVisitors = assignWith(
Expand Down

0 comments on commit c80c387

Please sign in to comment.