Skip to content

Commit

Permalink
Updated from latest linter recommendations (#1418)
Browse files Browse the repository at this point in the history
* chore(dev-deps): update linter & rules

* fix: duplicate import

* fix: remove union with undefined

* fix(internal): disable lint rules

* chore(dev-deps): update linter & rules

* fix: explicit return type

* refactor: prefer for const over reduce

* test: fix ambigous import

* test(bench): disable sonar

* docs: add changesets

* refactor: remove unused variable

* feat: add INVALID_ARGUMENT to error in  assertParsableStrictIsoDateZ

* refactor(internal): clarify code

* chore: fix vitest plugin

* chore(dev-deps): latest linter

* chore: align lint-staged config

* refactor(internal): improve cache existence operations

* chore: latest linter

* chore(lint): enable projectService

* refactor!: getUuidVersion now returns null instead of false

* refactor: remove undefined from optional

* fix(internal): remove dead code

* fix: remove todo

* docs: changeset

* chore(dev-deps): latest linter

* refactor: remove undefined from optional

* feat: next canary

* feat: next canary

* docs: update readme
  • Loading branch information
belgattitude authored Sep 9, 2024
1 parent 95e5490 commit 366520a
Show file tree
Hide file tree
Showing 67 changed files with 2,262 additions and 697 deletions.
5 changes: 5 additions & 0 deletions .changeset/angry-tips-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@httpx/dsn-parser": patch
---

Fix types: remove 'undefined' from params unions (exactOptionalPropertyTypes)
5 changes: 5 additions & 0 deletions .changeset/fair-shrimps-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@httpx/assert": minor
---

Add INVALID_ARGUMENT reason to assertParsableStrictIsoDateZ
11 changes: 11 additions & 0 deletions .changeset/late-boxes-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@httpx/plain-object": patch
"@httpx/dsn-parser": patch
"@httpx/exception": patch
"@httpx/memo-intl": patch
"@httpx/json-api": patch
"@httpx/assert": patch
"@httpx/treeu": patch
---

Internal refactor based on linter updates
5 changes: 5 additions & 0 deletions .changeset/plenty-ligers-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@httpx/plain-object": patch
---

Fix duplicate imports for assertPlainObject
5 changes: 5 additions & 0 deletions .changeset/pretty-nails-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@httpx/assert": minor
---

BC getUuidVersion returns null instead of false when the uuid isn't correct
5 changes: 5 additions & 0 deletions .changeset/quick-squids-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@httpx/dsn-parser": patch
---

Internal: replace RegExp.match by RegExp.exec (prefer-regexp-exec)
5 changes: 5 additions & 0 deletions .changeset/stale-cups-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@httpx/dsn-parser": patch
---

Internal refactor to remove Array.reduce and prefer for const
5 changes: 5 additions & 0 deletions .changeset/stupid-parrots-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@httpx/json-api": patch
---

Make static methods readonly
5 changes: 5 additions & 0 deletions .changeset/warm-coats-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@httpx/memo-intl": patch
---

Internal refactor to simplify cache conditions
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"react-dom": "18.3.1"
},
"devDependencies": {
"@belgattitude/eslint-config-bases": "5.17.0",
"@belgattitude/eslint-config-bases": "6.0.0-canary.9",
"eslint": "8.57.0",
"eslint-config-next": "14.2.8",
"eslint-plugin-tailwindcss": "3.17.4",
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs-app/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = {
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
projectService: true,
tsconfigRootDir: __dirname,
},
root: true,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/nextjs-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"zod": "3.23.8"
},
"devDependencies": {
"@belgattitude/eslint-config-bases": "5.17.0",
"@belgattitude/eslint-config-bases": "6.0.0-canary.9",
"@types/node": "22.5.4",
"@types/react": "18.3.5",
"@types/react-dom": "18.3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { twMerge } from 'tailwind-merge';
const providerValue = {
// Will add as a pass through preset based on PrimeOne Design
// @link https://primereact.org/tailwind/#unstyledmode
// @todo choose whether we're ready to go full unstyled
unstyled: false,
pt: {},
ptOptions: {
Expand Down
2 changes: 1 addition & 1 deletion integrations/prisma-exception/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = {
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
projectService: true,
tsconfigRootDir: __dirname,
},
root: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,13 @@ const {
*/
const rules = {
'**/*.{js,jsx,ts,tsx}': (filenames) => {
return [
getEslintFixCmd({
cache: true,
cwd: __dirname,
files: filenames,
// when autofixing staged-files a good tip is to disable react-hooks/exhaustive-deps, cause
fix: true,
maxWarnings: 25,
// a change here can potentially break things without proper visibility.
rules: ['react-hooks/exhaustive-deps: off'],
}),
];
return getEslintFixCmd({
cache: true,
cwd: __dirname,
files: filenames,
fix: true,
maxWarnings: 25,
});
},
'**/*.{json,md,mdx,css,html,yml,yaml,scss}': (filenames) => {
return [`prettier --write ${concatFilesForPrettier(filenames)}`];
Expand Down
10 changes: 5 additions & 5 deletions integrations/prisma-exception/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@
},
"devDependencies": {
"@arethetypeswrong/cli": "0.16.1",
"@belgattitude/eslint-config-bases": "5.17.0",
"@size-limit/file": "11.1.4",
"@size-limit/webpack": "11.1.4",
"@size-limit/webpack-why": "11.1.4",
"@belgattitude/eslint-config-bases": "6.0.0-canary.9",
"@size-limit/file": "11.1.5",
"@size-limit/webpack": "11.1.5",
"@size-limit/webpack-why": "11.1.5",
"@types/node": "22.5.4",
"@vitest/coverage-istanbul": "2.0.5",
"@vitest/ui": "2.0.5",
Expand All @@ -85,7 +85,7 @@
"npm-run-all2": "6.2.2",
"publint": "0.2.10",
"rimraf": "6.0.1",
"size-limit": "11.1.4",
"size-limit": "11.1.5",
"tsup": "8.2.4",
"typedoc": "0.26.7",
"typedoc-plugin-markdown": "4.2.7",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@
],
"packageManager": "[email protected]",
"devDependencies": {
"@belgattitude/eslint-config-bases": "5.17.0",
"@belgattitude/eslint-config-bases": "6.0.0-canary.9",
"@changesets/changelog-github": "0.5.0",
"@changesets/cli": "2.27.8",
"@commitlint/cli": "19.4.1",
"@commitlint/config-conventional": "19.4.1",
"@types/shell-quote": "1.7.5",
"@typescript-eslint/parser": "8.4.0",
"cross-env": "7.0.3",
"eslint": "8.57.0",
"gh-pages": "6.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/assert/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module.exports = {
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
projectService: true,
tsconfigRootDir: __dirname,
},
root: true,
Expand Down
4 changes: 2 additions & 2 deletions packages/assert/bench/comparative.bench.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import-x/no-unresolved */
import { Type } from '@sinclair/typebox';
import { Value } from '@sinclair/typebox/value';
import * as v from 'valibot';
Expand All @@ -23,8 +24,7 @@ const valibotSchema = v.record(v.string(), v.unknown());
const typeboxSchema = Type.Record(Type.String(), Type.Unknown());

describe(`Compare calling ${realLifeScenarios.length}x isPlainObject with mixed types values`, async () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// eslint-disable-next-line @typescript-eslint/ban-ts-comment,import-x/no-unresolved,@typescript-eslint/no-unsafe-assignment
// @ts-ignore to apply benchmarks assert must be built
const httpxIsPlainObject: (_v) => boolean = await import('@httpx/assert')
.then((mod) => mod.isPlainObject)
Expand Down
8 changes: 4 additions & 4 deletions packages/assert/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@
},
"devDependencies": {
"@arethetypeswrong/cli": "0.16.1",
"@belgattitude/eslint-config-bases": "5.17.0",
"@belgattitude/eslint-config-bases": "6.0.0-canary.9",
"@codspeed/vitest-plugin": "3.1.1",
"@edge-runtime/vm": "4.0.3",
"@sinclair/typebox": "0.33.9",
"@sindresorhus/is": "7.0.1",
"@size-limit/file": "11.1.4",
"@size-limit/webpack": "11.1.4",
"@size-limit/file": "11.1.5",
"@size-limit/webpack": "11.1.5",
"@types/lodash-es": "4.17.12",
"@vitest/coverage-istanbul": "2.0.5",
"@vitest/ui": "2.0.5",
Expand All @@ -92,7 +92,7 @@
"publint": "0.2.10",
"rimraf": "6.0.1",
"rollup": "4.21.2",
"size-limit": "11.1.4",
"size-limit": "11.1.5",
"tinybench": "2.9.0",
"tsup": "8.2.4",
"type-fest": "4.26.1",
Expand Down
3 changes: 0 additions & 3 deletions packages/assert/src/__tests__/object.types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ describe('object types tests', () => {
// when removing the nullable (undefined) from the union
expectTypeOf(invalidKeyIsUnknown).toBeUnknown();

const unknownPo2 = unknownPo;
unknownPo2.key;

assertType<PlainObject>(unknownPo);
assertType<Record<string, unknown>>(unknownPo);
expectTypeOf(unknownPo.key).not.toBeString();
Expand Down
6 changes: 3 additions & 3 deletions packages/assert/src/__tests__/string.assert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ describe('string assertions tests', () => {
'2023-02-29T23:37:31.653z', // no 29th feb in 2023
],
[
'Value is expected to be a string containing a strict iso date, got: Date',
'Value is expected to be a string containing a strict iso date (INVALID_ARGUMENT), got: Date',
new Date(),
],
[
'Value is expected to be a string containing a strict iso date, got: null',
'Value is expected to be a string containing a strict iso date (INVALID_ARGUMENT), got: null',
null,
],
[
'Value is expected to be a string containing a strict iso date, got: NaN',
'Value is expected to be a string containing a strict iso date (INVALID_ARGUMENT), got: NaN',
Number.NaN,
],
])('should throw with message %s when value is %s', (msg, v) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/assert/src/__tests__/uuid.utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { getUuidVersion } from '../uuid.helpers';
describe('uuid utils tests', () => {
describe('getUuidVersion', () => {
it.each([
[false, false as unknown as string],
[false, new Date() as unknown as string],
[null, false as unknown as string],
[null, new Date() as unknown as string],
[1, uuidsTestData.v1],
[3, uuidsTestData.v3],
[4, uuidsTestData.v4],
Expand Down
7 changes: 2 additions & 5 deletions packages/assert/src/messages/errorMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ export const formatErrMsg = (
}
): string => {
const { pfx = true } = options ?? {};
return `${
pfx
? `${errPfx} ${vowelsAndH.has((msg?.[0] ?? '').toLowerCase()) ? 'an' : 'a'} `
: ''
}${msg}, got: ${getTypeInfo(v)}`;
const aOrAn = vowelsAndH.has((msg?.[0] ?? '').toLowerCase()) ? 'an' : 'a';
return `${pfx ? `${errPfx} ${aOrAn} ` : ''}${msg}, got: ${getTypeInfo(v)}`;
};
10 changes: 3 additions & 7 deletions packages/assert/src/messages/getTypeInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ export const getTypeInfo = (v: unknown): string => {
break;
}
default:
v = typeof v;
}
return type;
};
const vowels = new Set(['a', 'e', 'i', 'o', 'u', 'y']);
const vowelsAndH = new Set(['a', 'e', 'i', 'o', 'u', 'y', 'h']);
export const formatErrMsg = (
msg: string,
v: unknown,
Expand All @@ -60,9 +59,6 @@ export const formatErrMsg = (
}
): string => {
const { pfx = true } = options ?? {};
return `${
pfx
? `${errPfx} ${vowels.has((msg?.[0] ?? '').toLowerCase()) ? 'an' : 'a'} `
: ''
}${msg}, got: ${getTypeInfo(v)}`;
const aOrAn = vowelsAndH.has((msg?.[0] ?? '').toLowerCase()) ? 'an' : 'a';
return `${pfx ? `${errPfx} ${aOrAn} ` : ''}${msg}, got: ${getTypeInfo(v)}`;
};
16 changes: 8 additions & 8 deletions packages/assert/src/string.asserts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,14 @@ export function assertParsableStrictIsoDateZ(
v: unknown,
msgOrErrorFactory?: MsgOrErrorFactory
): asserts v is ParsableStrictIsoDateZ {
let check: 'INVALID_FORMAT' | 'INVALID_DATE' | true | null = null;
let check:
| 'INVALID_FORMAT'
| 'INVALID_DATE'
| 'INVALID_ARGUMENT'
| true
| undefined = undefined;
if (typeof v !== 'string') {
check = null;
check = 'INVALID_ARGUMENT';
} else if (v.length === 24 && isoDateTimeZRegexp.test(v)) {
try {
check =
Expand All @@ -83,12 +88,7 @@ export function assertParsableStrictIsoDateZ(
if (check !== true) {
throw createAssertException(
msgOrErrorFactory,
formatErrMsg(
`string containing a strict iso date${
check === null ? '' : ` (${check})`
}`,
v
)
formatErrMsg(`string containing a strict iso date (${check})`, v)
);
}
}
1 change: 1 addition & 0 deletions packages/assert/src/types/internal.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export type MsgOrErrorFactory = string | (() => Error);
*/
export type Simplify<T> = {
[KeyType in keyof T]: T[KeyType];
// eslint-disable-next-line sonarjs/no-useless-intersection
} & NonNullable<unknown>;
2 changes: 1 addition & 1 deletion packages/assert/src/utils/createAssertException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
export const createAssertException = (
msgOrErrorFactory?: string | (() => Error),
fallbackMsg?: string
) => {
): TypeError | Error => {
if (
typeof msgOrErrorFactory === 'string' ||
msgOrErrorFactory === undefined
Expand Down
2 changes: 1 addition & 1 deletion packages/assert/src/uuid.asserts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function assertUuid(
v: unknown,
msgOrErrorFactory?: MsgOrErrorFactory | undefined,
options?: {
version?: UuidVersion | undefined;
version?: UuidVersion;
}
): asserts v is Uuid {
const { version } = options ?? {};
Expand Down
6 changes: 3 additions & 3 deletions packages/assert/src/uuid.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { uuidSupportedVersions } from './uuid.utils';
/**
* Adapted from https://github.com/uuidjs/uuid/blob/main/src/version.js
*/
export const getUuidVersion = (uuid: string): UuidVersion | false => {
export const getUuidVersion = (uuid: string): UuidVersion | null => {
if (typeof uuid !== 'string') {
return false;
return null;
}
const v = Number.parseInt(uuid.slice(14, 15), 16);
if (uuidSupportedVersions.has(v)) {
return v as UuidVersion;
}
return false;
return null;
};
1 change: 1 addition & 0 deletions packages/assert/src/uuid.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Taken from https://github.com/uuidjs/uuid/blob/main/src/regex.js
*/
export const uuidRegexp =
// eslint-disable-next-line sonarjs/regex-complexity
/^(?:[\da-f]{8}-[\da-f]{4}-[1-5][\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}|0{8}-(?:0{4}-){3}0{12})$/i;

export const uuidSupportedVersions = new Set([1, 3, 4, 5, 7]);
2 changes: 1 addition & 1 deletion packages/dsn-parser/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports = {
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
projectService: true,
tsconfigRootDir: __dirname,
},
root: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/dsn-parser/.size-limit.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = [
name: 'Only parseDsn (ESM)',
path: ['dist/index.mjs'],
import: "{ parseDsn }",
limit: '780B',
limit: '785B',
},
{
name: 'Everything (CJS)',
Expand Down
Loading

0 comments on commit 366520a

Please sign in to comment.