Skip to content

Commit

Permalink
refactor(utils): replace with lodash (#1694)
Browse files Browse the repository at this point in the history
  • Loading branch information
bd82 authored Nov 4, 2021
1 parent 719598c commit 2dce611
Show file tree
Hide file tree
Showing 62 changed files with 471 additions and 1,210 deletions.
5 changes: 3 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = {
parserOptions: {
// The `ecmaVersion` should align to the supported features of our target runtimes (browsers / nodejs / others)
// Consult with: https://kangax.github.io/compat-table/es2016plus/
ecmaVersion: 2017
ecmaVersion: 2018
},
rules: {
// conflicts with some prettier settings in UMD sources.
Expand All @@ -38,7 +38,7 @@ module.exports = {
{
// For sub-packages using TypeScript (libraries/VSCode Exts) && TypeScript definitions (d.ts)
files: ["*.ts"],
plugins: ["@typescript-eslint"],
plugins: ["@typescript-eslint", "lodash"],
parser: "@typescript-eslint/parser",
parserOptions: {
// project: ["./tsconfig.base.json", "./tsconfig.json"],
Expand All @@ -48,6 +48,7 @@ module.exports = {
// "plugin:@typescript-eslint/recommended-requiring-type-checking",
],
rules: {
"lodash/import-scope": ["error", "method"],
"@typescript-eslint/no-use-before-define": [
"error",
// These can be safely used before they are defined due to function hoisting in EcmaScript
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"@typescript-eslint/eslint-plugin": "5.1.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-eslint-comments": "3.2.0",
"eslint-plugin-lodash": "7.3.0",
"source-map-support": "0.5.20",
"@istanbuljs/schema": "0.1.3"
}
Expand Down
4 changes: 3 additions & 1 deletion packages/chevrotain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@
"dependencies": {
"@chevrotain/types": "^9.1.0",
"@chevrotain/utils": "^9.1.0",
"regexp-to-ast": "0.5.0"
"regexp-to-ast": "0.5.0",
"lodash": "4.17.21"
},
"devDependencies": {
"@types/lodash": "4.14.176",
"@types/sinon-chai": "3.2.5",
"error-stack-parser": "2.0.6",
"esbuild": "0.13.8",
Expand Down
24 changes: 11 additions & 13 deletions packages/chevrotain/src/parse/cst/cst_visitor.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import {
compact,
contains,
forEach,
isArray,
isEmpty,
isFunction,
isUndefined,
keys,
map
} from "@chevrotain/utils"
import isEmpty from "lodash/isEmpty"
import compact from "lodash/compact"
import isArray from "lodash/isArray"
import map from "lodash/map"
import forEach from "lodash/forEach"
import keys from "lodash/keys"
import isFunction from "lodash/isFunction"
import isUndefined from "lodash/isUndefined"
import includes from "lodash/includes"
import { defineNameProp } from "../../lang/lang_extensions"
import { CstNode, ICstVisitor } from "@chevrotain/types"

Expand Down Expand Up @@ -159,8 +157,8 @@ export function validateRedundantMethods(
for (const prop in visitorInstance) {
if (
isFunction((visitorInstance as any)[prop]) &&
!contains(VALID_PROP_NAMES, prop) &&
!contains(ruleNames, prop)
!includes(VALID_PROP_NAMES, prop) &&
!includes(ruleNames, prop)
) {
errors.push({
msg:
Expand Down
7 changes: 4 additions & 3 deletions packages/chevrotain/src/parse/errors_public.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { hasTokenLabel, tokenLabel } from "../scan/tokens_public"
import * as utils from "@chevrotain/utils"
import { first, map, reduce } from "@chevrotain/utils"
import first from "lodash/first"
import map from "lodash/map"
import reduce from "lodash/reduce"
import {
Alternation,
NonTerminal,
Expand Down Expand Up @@ -281,7 +282,7 @@ export const defaultGrammarValidatorErrorProvider: IGrammarValidatorErrorMessage
leftRecursionPath: Rule[]
}): string {
const ruleName = options.topLevelRule.name
const pathNames = utils.map(
const pathNames = map(
options.leftRecursionPath,
(currRule) => currRule.name
)
Expand Down
4 changes: 2 additions & 2 deletions packages/chevrotain/src/parse/exceptions_public.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { contains } from "@chevrotain/utils"
import includes from "lodash/includes"
import {
IToken,
IRecognitionException,
Expand All @@ -22,7 +22,7 @@ Object.freeze(RECOGNITION_EXCEPTION_NAMES)
// hacks to bypass no support for custom Errors in javascript/typescript
export function isRecognitionException(error: Error) {
// can't do instanceof on hacked custom js exceptions
return contains(RECOGNITION_EXCEPTION_NAMES, error.name)
return includes(RECOGNITION_EXCEPTION_NAMES, error.name)
}

abstract class RecognitionException
Expand Down
Loading

0 comments on commit 2dce611

Please sign in to comment.