Skip to content

Commit

Permalink
Merge pull request #105 from MatheusBaldi/MatheusBaldi/update-eslint-…
Browse files Browse the repository at this point in the history
…config-file

chore: update @silvermine/eslint-config
  • Loading branch information
onebytegone authored Jan 23, 2025
2 parents 97c4e90 + abcd9e0 commit 03a368b
Show file tree
Hide file tree
Showing 30 changed files with 1,716 additions and 751 deletions.
5 changes: 0 additions & 5 deletions .eslintrc.json

This file was deleted.

15 changes: 15 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const config = require('@silvermine/eslint-config'),
node = require('@silvermine/eslint-config/partials/node'),
nodeTests = require('@silvermine/eslint-config/partials/node-tests');

module.exports = [
...config,
{
files: [ 'tests/**.ts' ],
...nodeTests,
},
{
files: [ '**/*.ts', '**/*.js' ],
...node,
},
];
2,282 changes: 1,622 additions & 660 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"devDependencies": {
"@silvermine/chai-strictly-equal": "1.1.1",
"@silvermine/eslint-config": "github:silvermine/eslint-config-silvermine#aa8ecacb12ab778078fd195d3b15f09ecac76c11",
"@silvermine/eslint-config": "github:silvermine/eslint-config-silvermine#634db8f6cfb2314070ba59339faf86f089c8e65d",
"@silvermine/standardization": "2.0.0",
"@silvermine/typescript-config": "git+https://github.com/silvermine/typescript-config#23213e33077089e723629dead5342abe6f3b3c8c",
"@types/chai": "4.3.19",
Expand Down
12 changes: 5 additions & 7 deletions src/types/KeyValueStringObject.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { isObject } from '../utils/is-object';
import { isArray } from '../utils/is-array';
import { isArguments } from '../utils/is-arguments';
import { isArrayOfStrings } from '../utils/is-array-of-strings';
import { isString } from '../utils/is-string';
import { isStringUnknownMap } from './StringUnknownMap';

/**
* `KeyValueStringObject`s have `string`s as keys and one of:
Expand Down Expand Up @@ -32,15 +30,15 @@ export interface KeyValueStringObject { [k: string]: (string | string[] | KeyVal
*
* @returns `true` if `o` is a `KeyValueStringObject`
*/
export function isKeyValueStringObject(o: any): o is KeyValueStringObject {
export function isKeyValueStringObject(o: unknown): o is KeyValueStringObject {
// Arrays and the array-like `arguments` variable are objects, so they would not be
// caught by an `isObject` check
if (!isObject(o) || isArray(o) || isArguments(o)) {
if (!isStringUnknownMap(o)) {
return false;
}

for (let k of Object.keys(o)) {
let v: any = (o as any)[k];
for (const k of Object.keys(o)) {
const v: unknown = o[k];

if (!isString(v) && !isArrayOfStrings(v) && !isKeyValueStringObject(v)) {
return false;
Expand Down
12 changes: 5 additions & 7 deletions src/types/StringArrayOfStringsMap.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { isArguments } from '../utils/is-arguments';
import { isArrayOfStrings } from '../utils/is-array-of-strings';
import { isObject } from '../utils/is-object';
import { isArray } from '../utils/is-array';
import { isStringUnknownMap } from './StringUnknownMap';

/**
* `StringArrayOfStringsMap`s have `string`s as keys and `string[]` as values. For
Expand All @@ -21,15 +19,15 @@ export interface StringArrayOfStringsMap { [s: string]: string[] }
*
* @returns `true` if `o` is a `StringArrayOfStringsMap`
*/
export function isStringArrayOfStringsMap(o: any): o is StringArrayOfStringsMap {
export function isStringArrayOfStringsMap(o: unknown): o is StringArrayOfStringsMap {
// Arrays and the array-like `arguments` variable are objects, so they would not be
// caught by an `isObject` check
if (!isObject(o) || isArray(o) || isArguments(o)) {
if (!isStringUnknownMap(o)) {
return false;
}

for (let k of Object.keys(o)) {
if (!isArrayOfStrings((o as any)[k])) {
for (const k of Object.keys(o)) {
if (!isArrayOfStrings(o[k])) {
return false;
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/types/StringMap.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { isObject } from '../utils/is-object';
import { isArray } from '../utils/is-array';
import { isArguments } from '../utils/is-arguments';
import { isString } from '../utils/is-string';
import { isStringUnknownMap } from './StringUnknownMap';

/**
* `StringMap`s have `string`s as keys and `string`s as values. For example:
Expand All @@ -19,15 +17,15 @@ export interface StringMap { [s: string]: string }
*
* @returns `true` if `o` is a `StringMap`
*/
export function isStringMap(o: any): o is StringMap {
export function isStringMap(o: unknown): o is StringMap {
// Arrays and the array-like `arguments` variable are objects, so they would not be
// caught by an `isObject` check
if (!isObject(o) || isArray(o) || isArguments(o)) {
if (!isStringUnknownMap(o)) {
return false;
}

for (let k of Object.keys(o)) {
if (!isString((o as any)[k])) {
for (const k of Object.keys(o)) {
if (!isString(o[k])) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/StringUnknownMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ export interface StringUnknownMap { [s: string]: unknown }
*
* @returns `true` if `o` is a `StringUnknownMap`
*/
export function isStringUnknownMap(o: any): o is StringUnknownMap {
export function isStringUnknownMap(o: unknown): o is StringUnknownMap {
return isObject(o) && !isArray(o) && !isArguments(o);
}
2 changes: 1 addition & 1 deletion src/utils/get-tag-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
* @see https://github.com/jashkenas/underscore/blob/d5fe0fd4060f13b40608cb9d92eda6d857e8752c/underscore.js#L1326
* @see https://github.com/lodash/lodash/blob/750067f42d3aa5f927604ece2c6df0ff2b2e9d72/isNumber.js#L31
*/
export function getTagString(o: any): string {
export function getTagString(o: unknown): string {
return Object.prototype.toString.call(o);
}
3 changes: 3 additions & 0 deletions src/utils/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function toKey(value: unknown): string | symbol {
const IS_DEEP_PROP_REGEX = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
IS_PLAIN_PROP_REGEX = /^\w*$/;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function isKey(value: any, object: any): boolean {
if (Array.isArray(value)) {
return false;
Expand Down Expand Up @@ -93,6 +94,7 @@ function stringToPath(str: string): string[] {
return result;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function createPathArray(value: any, object: any): string[] {
if (Array.isArray(value)) {
return value;
Expand Down Expand Up @@ -139,6 +141,7 @@ function get<TResult = unknown>(
resultObj: unknown = obj;

while (resultObj !== null && resultObj !== undefined && index < length) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
resultObj = (resultObj as any)[toKey(pathArray[index])];

index += 1;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/is-array-of-strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function isArrayOfStrings(values: unknown): values is string[] {
return false;
}

for (let v of values) {
for (const v of values) {
if (!isString(v)) {
return false;
}
Expand Down
8 changes: 6 additions & 2 deletions src/utils/is-empty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ import { isUndefined } from './is-undefined';
*
* @returns `true` if `o` is empty
*/
export function isEmpty(o: any): boolean {
export function isEmpty(o: unknown): boolean {
if (o === null || isUndefined(o)) {
return true;
}
if (isArray(o) || isString(o) || isArguments(o)) {
return o.length === 0;
}
return Object.keys(o).length === 0;
// Non-object arguments passed into Object.keys are coerced into objects (the only
// exception being undefined or null, which is handled above). Therefore, it's ok to
// assume the input is an object because it will be once passed through. See also:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys#using_object.keys_on_primitives
return Object.keys(o as object).length === 0;
}
6 changes: 3 additions & 3 deletions src/utils/is-map-with-values-of-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { isStringUnknownMap } from '../types/StringUnknownMap';
* @returns `true` if `o` is a map with `string` keys and values that pass the provided
* type guard.
*/
export function isMapWithValuesOfType<T>(guard: (x: any) => x is T, o: any): o is Record<string, T> {
export function isMapWithValuesOfType<T>(guard: (x: unknown) => x is T, o: unknown): o is Record<string, T> {
if (!isStringUnknownMap(o)) {
return false;
}

for (let k of Object.keys(o)) {
if (!guard((o as any)[k])) {
for (const k of Object.keys(o)) {
if (!guard(o[k])) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/is-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @returns `true` if `o` is an `object`
*/
export function isObject(o: unknown): o is object {
let type = typeof o;
const type = typeof o;

return o !== null && (type === 'object' || type === 'function');
}
2 changes: 1 addition & 1 deletion src/utils/is-promise-like.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import { isObject } from './is-object';
* @returns `true` if `o` is `Promise`-like (i.e. has a `then` function)
*/
export function isPromiseLike(o: unknown): o is PromiseLike<unknown> {
return isPromise(o) || (isObject(o) && typeof (o as any).then === 'function');
return isPromise(o) || (isObject(o) && typeof (o as PromiseLike<unknown>).then === 'function');
}
19 changes: 8 additions & 11 deletions src/utils/make-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const DEFAULT_SETTINGS: ToolboxTemplateSettings = {
interpolate: /<%=([\s\S]+?)%>/g,
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function getValue(path: string, data: any): unknown {
return get(data, (path || '').trim(), '');
}
Expand All @@ -16,7 +17,7 @@ export interface ToolboxTemplateSettings {
}

export interface ToolboxTemplateFunction {
(data: Record<string, any>): string;
(data: Record<string, unknown>): string;
}

/**
Expand Down Expand Up @@ -51,23 +52,19 @@ export interface ToolboxTemplateFunction {
export function makeTemplate(text: string, userSettings?: ToolboxTemplateSettings): (data: unknown) => string {
type TemplateFunction = (data: unknown) => unknown;

let parts: (TemplateFunction | string)[] = [],
index = 0,
settings = Object.assign({}, DEFAULT_SETTINGS, userSettings || {}),
regExpPattern, matcher;
let index = 0;

regExpPattern = [
settings.escape.source,
settings.interpolate.source,
];
matcher = new RegExp(regExpPattern.join('|') + '|$', 'g');
const parts: (TemplateFunction | string)[] = [],
settings = Object.assign({}, DEFAULT_SETTINGS, userSettings || {}),
regExpPattern = [ settings.escape.source, settings.interpolate.source ],
matcher = new RegExp(regExpPattern.join('|') + '|$', 'g');

text.replace(matcher, (match, escape, interpolate, offset) => {
parts.push(text.slice(index, offset));
index = offset + match.length;

if (escape) {
parts.push((data: any) => {
parts.push((data: unknown) => {
return escapeHTML(getValue(escape, data));
});
} else if (interpolate) {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/uniq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const iterateeUniq = <T, U>(arr: T[], iteratee: (value: T, i: number, arr: T[])
seen: U[] = [];

for (let i = 0, length = arr.length; i < length; i++) {
let value = arr[i],
computed = iteratee(value, i, arr);
const value = arr[i],
computed = iteratee(value, i, arr);

if (seen.indexOf(computed) === -1) {
seen.push(computed);
Expand All @@ -21,7 +21,7 @@ const sortedUniq = <T, U>(arr: T[]): T[] => {
let lastSeen: T | U | undefined;

for (let i = 0, length = arr.length; i < length; i++) {
let value = arr[i];
const value = arr[i];

if (i === 0 || lastSeen !== value) {
result.push(value);
Expand Down
7 changes: 3 additions & 4 deletions tests/types/PropsWithType.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { expect } from 'chai';
import { PropsWithType } from '../../src/index';
import { isUndefined } from 'util';
import { isUndefined, PropsWithType } from '../../src/index';

describe('PropsWithType', () => {

Expand All @@ -21,7 +20,7 @@ describe('PropsWithType', () => {
return from[field];
}

let obj: TestType = { prop: 'test', anotherProp: 1, additionalProp: 2 };
const obj: TestType = { prop: 'test', anotherProp: 1, additionalProp: 2 };

expect(getNumber(obj, 'anotherProp')).to.strictlyEqual(1);
expect(getNumber(obj, 'additionalProp')).to.strictlyEqual(2);
Expand All @@ -42,7 +41,7 @@ describe('PropsWithType', () => {
return isUndefined(val) ? 0 : val;
}

let obj: TestType = { prop: 'test', anotherProp: 1, additionalProp: 2 };
const obj: TestType = { prop: 'test', anotherProp: 1, additionalProp: 2 };

expect(getNumber(obj, 'anotherProp')).to.strictlyEqual(1);
expect(getNumber(obj, 'additionalProp')).to.strictlyEqual(2);
Expand Down
1 change: 1 addition & 0 deletions tests/types/RequireDefined.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
describe('RequireDefined', () => {

// eslint-disable-next-line no-empty-function
it('is tested by the hasDefined tests', () => {});

});
6 changes: 3 additions & 3 deletions tests/types/Writable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ describe('Writable', () => {
// eslint-disable-next-line @typescript-eslint/no-type-alias
type ReadOnlyStringMap = Readonly<StringMap>;

let obj: ReadOnlyStringMap = { a: 'test' },
writable: Writable<ReadOnlyStringMap>;
const obj: ReadOnlyStringMap = { a: 'test' };

expect(obj.a).to.strictlyEqual('test');

writable = obj;
const writable: Writable<ReadOnlyStringMap> = obj;

writable.a = 'changed';

expect(writable.a).to.strictlyEqual('changed');
Expand Down
10 changes: 6 additions & 4 deletions tests/utils/delay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { delay, isPromiseLike } from '../../src';
describe('delay', () => {

it('delays before returning a value', async () => {
let after: string | null = null,
promise = delay(10, 'this-is-my-test-value');
const promise = delay(10, 'this-is-my-test-value');

let after: string | null = null;

promise.then((v) => { after = v; });

Expand All @@ -23,8 +24,9 @@ describe('delay', () => {
});

it('returns undefined when no value supplied', async () => {
let after: string | undefined = 'initial-value',
promise = delay(10);
let after: string | undefined = 'initial-value';

const promise = delay(10);

promise.then((v) => { after = v; });

Expand Down
10 changes: 5 additions & 5 deletions tests/utils/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ describe('get', () => {

it('returns undefined for keys that don\'t exist', () => {
expect(get(testObj, 'DNE')).to.strictlyEqual(undefined);
expect(get(100 as unknown as {}, 'DNE')).to.strictlyEqual(undefined);
expect(get([] as unknown as {}, 'DNE')).to.strictlyEqual(undefined);
expect(get(true as unknown as {}, 'DNE')).to.strictlyEqual(undefined);
expect(get(100 as unknown as object, 'DNE')).to.strictlyEqual(undefined);
expect(get([] as unknown as object, 'DNE')).to.strictlyEqual(undefined);
expect(get(true as unknown as object, 'DNE')).to.strictlyEqual(undefined);
expect(get({}, 'DNE')).to.strictlyEqual(undefined);
});

it('returns undefined when the object parameter is null or undefined', () => {
expect(get(undefined as unknown as {}, 'DNE')).to.strictlyEqual(undefined);
expect(get(null as unknown as {}, 'DNE')).to.strictlyEqual(undefined);
expect(get(undefined as unknown as object, 'DNE')).to.strictlyEqual(undefined);
expect(get(null as unknown as object, 'DNE')).to.strictlyEqual(undefined);
});

it('returns the default value for undefined values', () => {
Expand Down
Loading

0 comments on commit 03a368b

Please sign in to comment.