Skip to content

Commit

Permalink
Merge pull request #739 from streamich/formatting
Browse files Browse the repository at this point in the history
Formatting
  • Loading branch information
streamich authored Nov 2, 2024
2 parents b2e8875 + e19a44f commit 14e17f4
Show file tree
Hide file tree
Showing 340 changed files with 940 additions and 803 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- run: yarn install --frozen-lockfile
- run: yarn build:all
- run: yarn lint
- run: yarn prettier:check
- run: yarn format
- run: yarn test:cli:pointer
- run: yarn test:cli:patch
- run: yarn test:cli:pack
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: yarn
- run: yarn install --frozen-lockfile
- run: yarn prettier:check
- run: yarn format
- run: yarn lint
- run: yarn test:ci --ci
- run: yarn build:all
Expand Down
43 changes: 43 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.3/schema.json",
"organizeImports": {
"enabled": true
},
"formatter": {
"indentStyle": "space",
"lineWidth": 120
},
"javascript": {
"formatter": {
"quoteStyle": "single",
"trailingCommas": "all",
"bracketSpacing": false
}
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"style": {
"noNonNullAssertion": "off",
"useNodejsImportProtocol": "off",
"useTemplate": "off",
"noInferrableTypes": "off",
"noUselessElse": "off",
"noParameterAssign": "off",
"noCommaOperator": "off",
"useSingleVarDeclarator": "off",
"useLiteralEnumMembers": "off"
},
"suspicious": {
"noExplicitAny": "off",
"useIsArray": "off",
"noAssignInExpressions": "off"
},
"complexity": {
"noStaticOnlyClass": "off",
"useOptionalChain": "off"
}
}
}
}
20 changes: 5 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,10 @@
"lib/"
],
"scripts": {
"prettier": "npx [email protected] --write .",
"prettier:check": "npx [email protected] --check .",
"lint": "yarn tslint",
"lint:fix": "yarn tslint --fix",
"tslint": "tslint 'src/**/*.{js,jsx,ts,tsx}' -t verbose --project .",
"format": "biome format ./src",
"format:fix": "biome format --write ./src",
"lint": "biome lint ./src",
"lint:fix": "biome lint --apply ./src",
"clean": "npx [email protected] lib es6 es2019 es2020 esm typedocs coverage gh-pages yarn-error.log src/**/__bench__/node_modules src/**/__bench__/yarn-error.log",
"build:es2020": "tsc --project tsconfig.build.json --module commonjs --target es2020 --outDir lib",
"build:all": "npx [email protected] \"yarn build:es2020\"",
Expand Down Expand Up @@ -137,6 +136,7 @@
"tree-dump": "^1.0.2"
},
"devDependencies": {
"@biomejs/biome": "^1.9.4",
"@types/benchmark": "^2.1.5",
"@types/jest": "^29.5.12",
"@types/react": "^18.3.11",
Expand Down Expand Up @@ -179,16 +179,6 @@
],
"testRegex": ".*/(__tests__|__jest__|demo)/.*\\.(test|spec)\\.ts$"
},
"prettier": {
"arrowParens": "always",
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": false
},
"config": {
"commitizen": {
"changelog": {
Expand Down
3 changes: 0 additions & 3 deletions src/__bench__/data/json-object-many-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module.exports = {
'-6666666': -6666666,
62343423432: 62343423432,
0.123: 0.123,
'0.0': 0.0,
'-123.3434343': -123.3434343,
127: 127,
128: 128,
Expand All @@ -21,8 +20,6 @@ module.exports = {
257: 257,
258: 258,
1000: 1000,
1000: 1000,
1000: 1000,
'-222222': -222222,
'-22222': -22222,
a: 'a',
Expand Down
2 changes: 1 addition & 1 deletion src/__bench__/data/text-editing-traces/collect-trace.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs');
const zlib = require('zlib');

const filename = `/Users/mini/vscodelogs/actions_14_05_2023_olcXlNJx.json`;
const filename = '/Users/mini/vscodelogs/actions_14_05_2023_olcXlNJx.json';
const targetDocFileName = '/Users/mini/dev/json-joy-blog/blog-post-1.md';
const data = fs.readFileSync(filename, 'utf8');
const lines = data.split('\n');
Expand Down
5 changes: 4 additions & 1 deletion src/__bench__/payloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export const payloads = [
export const payloadsWithCombined = [
...(payloads.length > 1
? (() => {
const combined = payloads.reduce((acc, payload) => [...acc, payload.data], [] as unknown[]);
const combined = payloads.reduce((acc, payload) => {
acc.push(payload.data);
return acc;
}, [] as unknown[]);
return [
{
data: combined,
Expand Down
5 changes: 4 additions & 1 deletion src/__tests__/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ export const until = async (check: () => boolean, pollInterval: number = 1) => {
do {
if (check()) return;
await tick(pollInterval);
} while (true);
} while (
// biome-ignore lint: constant condition is intentional
true
);
};
18 changes: 9 additions & 9 deletions src/json-cli/json-pack-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import {spawnSync} from 'child_process';
import {
testSuites,
TestCaseNil,
TestCaseBool,
TestCaseString,
TestCaseNumber,
TestCaseArray,
TestCaseMap,
type TestCaseNil,
type TestCaseBool,
type TestCaseString,
type TestCaseNumber,
type TestCaseArray,
type TestCaseMap,
} from './test/msgpack-test-suite';

const bin = String(process.argv[2]);
Expand All @@ -19,7 +19,7 @@ if (!bin) {
}

console.log('');
console.log(`Running json-pack tests.`);
console.log('Running json-pack tests.');
console.log('');

let cntCorrect = 0;
Expand Down Expand Up @@ -54,11 +54,11 @@ for (const name in testSuites) {
const result = new Uint8Array(stdout.length);
for (let i = 0; i < result.length; i++) result[i] = stdout[i];
EXPECTED: for (const exp of testCase.msgpack) {
const expected = new Uint8Array(exp.split('-').map((a) => parseInt(a, 16)));
const expected = new Uint8Array(exp.split('-').map((a) => Number.parseInt(a, 16)));
if (expected.length !== result.length) continue;
for (let i = 0; i < expected.length; i++) if (expected[i] !== result[i]) continue EXPECTED;
isCorrect = true;
break EXPECTED;
break;
}
if (isCorrect) {
cntCorrect++;
Expand Down
14 changes: 7 additions & 7 deletions src/json-cli/json-patch-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ if (!bin) {
let cntCorrect = 0;
let cntFailed = 0;

testSuites.forEach((suite) => {
for (const suite of testSuites) {
console.log('');
console.log(suite.name);
console.log('');

suite.tests.forEach((test: any) => {
if (test.disabled) return;
for (const test of suite.tests) {
if (test.disabled) break;
const testName = test.comment || test.error || JSON.stringify(test.patch);
if (test.expected !== undefined) {
test.patch.forEach(validateOperation);
test.patch.forEach(validateOperation as any);
let isCorrect = false;
let result;
let result: unknown;
try {
const input = JSON.stringify(test.doc);
const {stdout} = spawnSync(bin, [JSON.stringify(test.patch)], {input});
Expand Down Expand Up @@ -69,8 +69,8 @@ testSuites.forEach((suite) => {
}

if (cntFailed) process.exit(1);
});
});
}
}

console.log('');
console.log(`Successful = ${cntCorrect}, Failed = ${cntFailed}, Total = ${cntCorrect + cntFailed}`);
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/json-pointer-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (!bin) {
}

console.log('');
console.log(`Running JSON Pointer tests.`);
console.log('Running JSON Pointer tests.');
console.log('');

let cntCorrect = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/test/op.add.tests.json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestCase} from './types';
import type {TestCase} from './types';

const testCases: TestCase[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/test/op.contains.tests.json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestCase} from './types';
import type {TestCase} from './types';

const testCases: TestCase[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/test/op.copy.tests.json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestCase} from './types';
import type {TestCase} from './types';

const testCases: TestCase[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/test/op.defined.tests.json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestCase} from './types';
import type {TestCase} from './types';

const testCases: TestCase[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/test/op.ends.tests.json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestCase} from './types';
import type {TestCase} from './types';

const testCases: TestCase[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/test/op.extend.tests.json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestCase} from './types';
import type {TestCase} from './types';

const testCases: TestCase[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/test/op.flip.tests.json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestCase} from './types';
import type {TestCase} from './types';

const testCases: TestCase[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/test/op.in.tests.json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestCase} from './types';
import type {TestCase} from './types';

const testCases: TestCase[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/test/op.inc.tests.json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestCase} from './types';
import type {TestCase} from './types';

const testCases: TestCase[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/test/op.less.tests.json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestCase} from './types';
import type {TestCase} from './types';

const testCases: TestCase[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/test/op.merge.tests.json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestCase} from './types';
import type {TestCase} from './types';

const testCases: TestCase[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/test/op.more.tests.json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestCase} from './types';
import type {TestCase} from './types';

const testCases: TestCase[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/test/op.move.tests.json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestCase} from './types';
import type {TestCase} from './types';

const testCases: TestCase[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/test/op.remove.tests.json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestCase} from './types';
import type {TestCase} from './types';

const testCases: TestCase[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/test/op.replace.tests.json.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {clone as deepClone} from '@jsonjoy.com/util/lib/json-clone/clone';
import {TestCase} from './types';
import type {TestCase} from './types';

const values: [string, unknown][] = [
['"null"', null],
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/test/op.split.tests.json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestCase} from './types';
import type {TestCase} from './types';

const testCases: TestCase[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/test/op.starts.tests.json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestCase} from './types';
import type {TestCase} from './types';

const testCases: TestCase[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/test/op.str_del.tests.json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestCase} from './types';
import type {TestCase} from './types';

const testCases: TestCase[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/test/op.str_ins.tests.json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestCase} from './types';
import type {TestCase} from './types';

const testCases: TestCase[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/test/op.test.tests.json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestCase} from './types';
import type {TestCase} from './types';

const testCases: TestCase[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/test/op.type.tests.json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestCase} from './types';
import type {TestCase} from './types';

const testCases: TestCase[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/test/op.undefined.tests.json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestCase} from './types';
import type {TestCase} from './types';

const testCases: TestCase[] = [
{
Expand Down
4 changes: 2 additions & 2 deletions src/json-cli/test/spec.json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestCase} from './types';
import type {TestCase} from './types';

const testCases: TestCase[] = [
{
Expand Down Expand Up @@ -168,7 +168,7 @@ const testCases: TestCase[] = [
},
patch: [
// @ts-ignore
{op: 'add', path: '/baz', value: 'qux', op: 'remove'},
{path: '/baz', value: 'qux', op: 'remove'},
],
error: "operation has two 'op' members",
disabled: true,
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/test/suites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import op_starts_tests_json from './op.starts.tests.json';
import op_type_tests_json from './op.type.tests.json';
import op_undefined_tests_json from './op.undefined.tests.json';
import spec_json from './spec.json';
import {TestSuite} from './types';
import type {TestSuite} from './types';

export const testSuites: TestSuite[] = [
// JSON Patch
Expand Down
2 changes: 1 addition & 1 deletion src/json-cli/test/tests.json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestCase} from './types';
import type {TestCase} from './types';

const testCases: TestCase[] = [
{
Expand Down
Loading

0 comments on commit 14e17f4

Please sign in to comment.