Skip to content

Commit feb75fa

Browse files
committedMar 9, 2024
refactor: remove usage of _.forEach
1 parent fbac97d commit feb75fa

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed
 

‎src/format-path.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import _ from 'lodash';
3333
export function formatPath(paths) {
3434
let str = '';
3535

36-
_.forEach(paths, (p) => {
36+
paths.forEach((p) => {
3737
if (_.isNumber(p)) {
3838
str += `[${p}]`;
3939
} else if (!str) {

‎src/license-plugin-option.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function validateOptions(options) {
140140

141141
const messages = [];
142142

143-
_.forEach(errors, (e) => {
143+
errors.forEach((e) => {
144144
if (e.type === 'object.allowUnknown') {
145145
warn(`Unknown property: "${formatPath(e.path)}", allowed options are: ${_.keys(SCHEMA).join(', ')}.`);
146146
} else {

‎src/license-plugin.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ class LicensePlugin {
220220
}
221221

222222
// Update the cache
223-
_.forEach(scannedDirs, (scannedDir) => {
223+
scannedDirs.forEach((scannedDir) => {
224224
this._cache[scannedDir] = pkg;
225225
});
226226
}
@@ -234,7 +234,7 @@ class LicensePlugin {
234234
scanDependencies(dependencies) {
235235
this.debug(`Scanning: ${dependencies}`);
236236

237-
_.forEach(dependencies, (dependency) => {
237+
dependencies.forEach((dependency) => {
238238
this.scanDependency(dependency);
239239
});
240240
}
@@ -455,7 +455,7 @@ class LicensePlugin {
455455
* @return {void}
456456
*/
457457
_scanLicenseViolations(outputDependencies, allow) {
458-
_.forEach(outputDependencies, (dependency) => {
458+
outputDependencies.forEach((dependency) => {
459459
this._scanLicenseViolation(dependency, allow);
460460
});
461461
}
@@ -541,7 +541,7 @@ class LicensePlugin {
541541
* @return {void}
542542
*/
543543
_exportThirdParties(outputDependencies, outputs) {
544-
_.forEach(_.castArray(outputs), (output) => {
544+
_.castArray(outputs).forEach((output) => {
545545
this._exportThirdPartiesToOutput(outputDependencies, output);
546546
});
547547
}

‎src/person.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class Person {
5757
}
5858
}
5959

60-
_.forEach(['name', 'email', 'url'], (prop) => {
60+
['name', 'email', 'url'].forEach((prop) => {
6161
if (_.has(o, prop)) {
6262
o[prop] = _.trim(o[prop]);
6363
}

‎src/schema-validator.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ function doItemValidation(value, schema, path) {
6868
function validateObject(obj, schema, current) {
6969
const errors = [];
7070

71-
_.forEach(obj, (value, k) => {
71+
if (!obj) {
72+
return errors;
73+
}
74+
75+
Object.keys(obj).forEach((k) => {
76+
const value = obj[k];
7277
if (value == null) {
7378
return;
7479
}

0 commit comments

Comments
 (0)
Please sign in to comment.