Skip to content

Commit

Permalink
wip: code formatting nits continued
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Sep 17, 2023
1 parent 0b28b7f commit b5c5931
Show file tree
Hide file tree
Showing 421 changed files with 7,362 additions and 9,013 deletions.
5 changes: 3 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
"rules": {
"prettier/prettier": "error",
// Overridden
"no-eval": "off",
"camelcase": ["error", { "properties": "never", "allow": [ "W[0-9]+_"] }],
"import/extensions": "off",
"no-eval": "off",
"no-self-compare": "off",
"one-var": ["error", "never"],
// @TODO: Fix the following rules progressively.
"arrow-body-style": "warn",
"prefer-arrow-callback": "warn",
Expand All @@ -46,7 +48,6 @@
"guard-for-in": "off",
"import/prefer-default-export": "off",
"prefer-rest-params": "off",
"one-var": "off",
"prefer-spread": "off",
"no-lonely-if": "off",
"no-prototype-builtins": "off",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"sideEffects": false,
"scripts": {
"prepare": "husky install",
"lint": "eslint ./src/**/*.ts ./test/**/*.ts"
"lint": "eslint ./src/**/*.ts"
},
"devDependencies": {
"@commitlint/cli": "17.7.1",
Expand Down
2 changes: 1 addition & 1 deletion src/.internal/cloneBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function cloneBuffer(buffer, isDeep) {
return buffer.slice()
}
const length = buffer.length
const result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length)
const result = allocUnsafe ? allocUnsafe(length) : buffer.constructor.alloc(length)

buffer.copy(result)
return result
Expand Down
5 changes: 3 additions & 2 deletions src/after.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
* forEach(saves, type => asyncSave({ 'type': type, 'complete': done }))
* // => Logs 'done saving!' after the two async saves have completed.
*/
function after(n, func) {
function after(n, func: Function) {
if (typeof func !== 'function') {
throw new TypeError('Expected a function');
}
n = n || 0;
return function (...args) {
// eslint-disable-next-line consistent-return
return function (this: any, ...args: any[]) {
if (--n < 1) {
return func.apply(this, args);
}
Expand Down
2 changes: 1 addition & 1 deletion src/clamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* clamp(10, -5, 5)
* // => 5
*/
function clamp(number, lower, upper) {
function clamp(number: number, lower: number, upper: number) {
number = +number;
lower = +lower;
upper = +upper;
Expand Down
8 changes: 4 additions & 4 deletions src/cond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ import map from './map.js';
* func({ 'a': '1', 'b': '2' })
* // => 'no match'
*/
function cond(pairs) {
function cond(pairs: any[]) {
const length = pairs == null ? 0 : pairs.length;

pairs = !length
? []
: map(pairs, (pair) => {
: map(pairs, (pair: any[]) => {
if (typeof pair[1] !== 'function') {
throw new TypeError('Expected a function');
}
return [pair[0], pair[1]];
});

return (...args) => {
// eslint-disable-next-line consistent-return
return function (this: any, ...args: any[]) {
for (const pair of pairs) {
if (pair[0].apply(this, args)) {
return pair[1].apply(this, args);
Expand Down
8 changes: 6 additions & 2 deletions src/debounce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ import root from './.internal/root.js';
* const status = debounced.pending() ? "Pending..." : "Ready"
*/
function debounce(func, wait, options) {
let lastArgs, lastThis, maxWait, result, timerId, lastCallTime;

let lastArgs;
let lastThis;
let maxWait;
let result;
let timerId;
let lastCallTime;
let lastInvokeTime = 0;
let leading = false;
let maxing = false;
Expand Down
1 change: 1 addition & 0 deletions src/deburr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const rsCombo = `[${rsComboRange}]`;
* Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
* [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
*/
// eslint-disable-next-line no-misleading-character-class
const reComboMark = RegExp(rsCombo, 'g');

/**
Expand Down
3 changes: 2 additions & 1 deletion src/defer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
* defer(text => console.log(text), 'deferred')
* // => Logs 'deferred' after one millisecond.
*/
function defer(func, ...args) {
function defer(func: Function, ...args: any[]) {
if (typeof func !== 'function') {
throw new TypeError('Expected a function');
}
// eslint-disable-next-line @typescript-eslint/no-implied-eval
return setTimeout(func, 1, ...args);
}

Expand Down
3 changes: 2 additions & 1 deletion src/delay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
* delay(text => console.log(text), 1000, 'later')
* // => Logs 'later' after one second.
*/
function delay(func, wait, ...args) {
function delay(func: Function, wait: number, ...args: any[]) {
if (typeof func !== 'function') {
throw new TypeError('Expected a function');
}
// eslint-disable-next-line @typescript-eslint/no-implied-eval
return setTimeout(func, +wait || 0, ...args);
}

Expand Down
1 change: 1 addition & 0 deletions src/each.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// eslint-disable-next-line no-restricted-exports
export { default } from './forEach.js';
1 change: 1 addition & 0 deletions src/eachRight.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// eslint-disable-next-line no-restricted-exports
export { default } from './forEachRight.js';
14 changes: 7 additions & 7 deletions src/findKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@
* // => 'barney' (iteration order is not guaranteed)
*/
function findKey(object, predicate) {
let result;
if (object == null) {
return result;
return undefined;
}
Object.keys(object).some((key) => {
const keys = Object.keys(object);
for (let i = 0, { length } = keys; i < length; i += 1) {
const key = keys[i];
const value = object[key];
if (predicate(value, key, object)) {
result = key;
return true;
return key;
}
});
return result;
}
return undefined;
}

export default findKey;
1 change: 1 addition & 0 deletions src/first.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// eslint-disable-next-line no-restricted-exports
export { default } from './head.js';
18 changes: 9 additions & 9 deletions src/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
* addSquare(1, 2)
* // => 9
*/
function flow(...funcs) {
function flow(...funcs: Function[]) {
const length = funcs.length;
let index = length;
while (index--) {
if (typeof funcs[index] !== 'function') {
let i = length;
while (i--) {
if (typeof funcs[i] !== 'function') {
throw new TypeError('Expected a function');
}
}
return function (...args) {
let index = 0;
let result = length ? funcs[index].apply(this, args) : args[0];
while (++index < length) {
result = funcs[index].call(this, result);
return function (this: any, ...args: any[]) {
let j = 0;
let result = length ? funcs[j].apply(this, args) : args[0];
while (++j < length) {
result = funcs[j].call(this, result);
}
return result;
};
Expand Down
2 changes: 1 addition & 1 deletion src/isBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const nativeIsBuffer = root?.Buffer?.isBuffer;
* @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
* @example
*
* isBuffer(new Buffer(2))
* isBuffer(Buffer.alloc(2))
* // => true
*
* isBuffer(new Uint8Array(2))
Expand Down
7 changes: 5 additions & 2 deletions src/keyBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ import reduce from './reduce.js';
* keyBy(array, ({ code }) => String.fromCharCode(code))
* // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
*/
function keyBy(collection, iteratee) {
function keyBy(collection: any, iteratee: Function) {
return reduce(
collection,
(result, value, key) => (baseAssignValue(result, iteratee(value), value), result),
(result: object, value: any) => {
baseAssignValue(result, iteratee(value), value);
return result;
},
{},
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/nth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ import isIndex from './.internal/isIndex.js';
* nth(array, -2)
* // => 'c'
*/
function nth(array, n) {
function nth(array: any[], n: number) {
const length = array == null ? 0 : array.length;
if (!length) {
return;
}
n += n < 0 ? length : 0;
// eslint-disable-next-line consistent-return
return isIndex(n, length) ? array[n] : undefined;
}

Expand Down
5 changes: 4 additions & 1 deletion src/partition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import reduce from './reduce.js';
function partition(collection, predicate) {
return reduce(
collection,
(result, value, key) => (result[predicate(value) ? 0 : 1].push(value), result),
(result, value) => {
result[predicate(value) ? 0 : 1].push(value);
return result;
},
[[], []],
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ function transform(object, iteratee, accumulator) {
accumulator = {};
}
}
(isArrLike ? arrayEach : baseForOwn)(object, (value, index, object) =>
iteratee(accumulator, value, index, object),
(isArrLike ? arrayEach : baseForOwn)(object, (value, index, _object) =>
iteratee(accumulator, value, index, _object),
);
return accumulator;
}
Expand Down
2 changes: 1 addition & 1 deletion src/trim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import stringToArray from './.internal/stringToArray.js';
* trim('-_-abc-_-', '_-')
* // => 'abc'
*/
function trim(string, chars) {
function trim(string: string, chars: string) {
if (string && chars === undefined) {
return string.trim();
}
Expand Down
2 changes: 1 addition & 1 deletion src/union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import isArrayLikeObject from './isArrayLikeObject.js';
* union([2, 3], [1, 2])
* // => [2, 3, 1]
*/
function union(...arrays) {
function union(...arrays: any[]) {
return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
}

Expand Down
1 change: 1 addition & 0 deletions src/unzip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function unzip(array) {
return [];
}
let length = 0;
// eslint-disable-next-line consistent-return
array = filter(array, (group) => {
if (isArrayLikeObject(group)) {
length = Math.max(group.length, length);
Expand Down
1 change: 1 addition & 0 deletions src/words.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const hasUnicodeWord = RegExp.prototype.test.bind(
);

/** Used to match words composed of alphanumeric characters. */
// eslint-disable-next-line no-control-regex
const reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;

function asciiWords(string) {
Expand Down

0 comments on commit b5c5931

Please sign in to comment.