Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
lint: format (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
AliMD authored Sep 19, 2023
2 parents b1b2f5a + ae8b25c commit e225301
Show file tree
Hide file tree
Showing 38 changed files with 320 additions and 382 deletions.
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/1-bug-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ Note: Please search to see if an issue already exists for the bug you encountere
-->

### Current Behavior

<!-- A concise description of what you're experiencing. -->

### Expected Behavior

<!-- A concise description of what you expected to happen. -->

### Steps To Reproduce

<!--
Example: steps to reproduce the behavior:
1. In this environment...
Expand All @@ -26,6 +29,7 @@ Example: steps to reproduce the behavior:
-->

### Environment

<!--
Example:
- OS: Ubuntu 20.04
Expand All @@ -34,6 +38,7 @@ Example:
-->

### Anything else

<!--
Links? References? Anything that will give us more context about the issue that you are encountering!
-->
20 changes: 9 additions & 11 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

version: 2
updates:
-
package-ecosystem: github-actions
- package-ecosystem: github-actions
directory: /
open-pull-requests-limit: 20
reviewers:
Expand All @@ -17,10 +16,9 @@ updates:
groups:
github-actions:
patterns:
- "*"
- '*'

-
package-ecosystem: npm
- package-ecosystem: npm
directory: /
versioning-strategy: increase
open-pull-requests-limit: 20
Expand All @@ -35,15 +33,15 @@ updates:
- maintenance
groups:
production-dependencies:
dependency-type: "production"
dependency-type: 'production'
development-dependencies:
dependency-type: "development"
dependency-type: 'development'
exclude-patterns:
- "*lint*"
- '*lint*'
lint-dependencies:
patterns:
- "*lint*"
- '*lint*'
alwatr-dependencies:
patterns:
- "@alwatr/*"
- "fract"
- '@alwatr/*'
- 'fract'
10 changes: 2 additions & 8 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
"cSpell.words": [],
"typescript.tsdk": "node_modules/typescript/lib",
"git.autoStash": true,
"git.branchProtection": [
"main",
"next"
],
"githubPullRequests.ignoredPullRequestBranches": [
"main",
"next"
]
"git.branchProtection": ["main", "next"],
"githubPullRequests.ignoredPullRequestBranches": ["main", "next"]
}
1 change: 0 additions & 1 deletion demo/crypto/rand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ const hashGenerator = new AlwatrHashGenerator(secretGeneratorPreConfig);
for (let i = 0; i <= 10; i++) {
console.log('hash: %s', hashGenerator.randomSelfValidate());
}

6 changes: 4 additions & 2 deletions demo/es-bench/bench.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
if (globalThis.process && (globalThis.process?.env.NODE_ENV !== 'production' || typeof globalThis.gc !== 'function')) {
console.warn('Please run node in production with `--expose-gc` for benchmark\nNODE_ENV=production node --expose-gc demo/...');
console.warn(
'Please run node in production with `--expose-gc` for benchmark\nNODE_ENV=production node --expose-gc demo/...',
);
}

export const bench = (name: string, func: () => void, count = 1_000_000): void => {
Expand All @@ -19,7 +21,7 @@ export const bench = (name: string, func: () => void, count = 1_000_000): void =
console.log(
`run ${name} ${runPerSec.toLocaleString()}/s with ${
globalThis.process?.memoryUsage.rss !== undefined ? memoryUsage.toLocaleString() : '?'
}kb`
}kb`,
);
globalThis.gc?.();
};
7 changes: 2 additions & 5 deletions demo/es-bench/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,19 @@ const value = undefined;
function test_1(): boolean {
if (value === true) {
return true;
}
else {
} else {
return false;
}
}

function test_2(): boolean {
if (value) {
return true;
}
else {
} else {
return false;
}
}


bench('test_1', test_1);
bench('test_2', test_2);

Expand Down
14 changes: 6 additions & 8 deletions demo/es-bench/flat-str.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {bench} from './bench.js';

function flatstr (s: string) {
function flatstr(s: string) {
// @ts-ignore
s | 0
return s
s | 0;
return s;
}

let temp = '';

function test_1(): void {
let s = '';
let n = 1_000_000;
while(n--) {
while (n--) {
s += 'ali';
}
temp = s;
Expand All @@ -20,13 +20,12 @@ function test_1(): void {
function test_2(): void {
let s = '';
let n = 1_000_000;
while(n--) {
while (n--) {
s += 'ali';
}
temp = flatstr(s);
}


bench('test_1', test_1, 10);
bench('test_2', test_2, 10);

Expand All @@ -36,5 +35,4 @@ bench('test_2', test_2, 10);
bench('test_1', test_1, 10);
bench('test_2', test_2, 10);


console.log(temp.length)
console.log(temp.length);
2 changes: 1 addition & 1 deletion demo/es-bench/import-tmp.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export {}
export {};

console.log('test');
2 changes: 1 addition & 1 deletion demo/es-bench/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
Expand Down
1 change: 0 additions & 1 deletion demo/es-bench/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ bench('test_without_logger 1st', () => test_without_logger(getUserList()));
bench('test_with_logger 2nd', () => test_with_logger(getUserList()));
bench('test_without_logger 2nd', () => test_without_logger(getUserList()));


globalThis.document?.body.append(' Done. Check the console.');
16 changes: 8 additions & 8 deletions demo/es-bench/many-bind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ function test3(id: string): void {
console.log(id);
}

const bind = (id: string) => ({
id,
test1: test1.bind(null, id),
test2: test2.bind(null, id),
test3: test3.bind(null, id),
} as const);
const bind = (id: string) =>
({
id,
test1: test1.bind(null, id),
test2: test2.bind(null, id),
test3: test3.bind(null, id),
}) as const;

class MyClass {
constructor(public id: string) {
}
constructor(public id: string) {}

test1(): void {
console.log(this.id);
Expand Down
11 changes: 5 additions & 6 deletions demo/es-bench/node-exist.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {accessSync, existsSync, constants} from 'node:fs';
import { bench } from './bench.js';
import {bench} from './bench.js';

const filePath = './temp-file.txt';
function exist(): boolean {
Expand All @@ -10,14 +10,13 @@ function access(): boolean {
try {
accessSync(filePath, constants.F_OK);
return true;
}
catch {
return false
} catch {
return false;
}
}

console.log('exist(%s) => %s', filePath, exist())
console.log('access(%s) => %s', filePath, access())
console.log('exist(%s) => %s', filePath, exist());
console.log('access(%s) => %s', filePath, access());

bench('exist', exist);
bench('access', access);
2 changes: 1 addition & 1 deletion demo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
{"path": "../packages/crypto"},
{"path": "../packages/math"},
{"path": "../packages/util"},
{"path": "../packages/validator"},
{"path": "../packages/validator"}
]
}
57 changes: 8 additions & 49 deletions demo/validator/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,31 @@ import {validator} from '@alwatr/validator';

console.log('basic test');
console.log(
validator<
{num: number; str: string; bool: boolean; _null: null; ali: 'ali'; five: 5; true: true}
>(
validator<{num: number; str: string; bool: boolean; _null: null; ali: 'ali'; five: 5; true: true}>(
{num: Number, str: String, bool: Boolean, _null: null, ali: 'ali', five: 5, true: true},
{num: 123, str: 'test', bool: false, _null: null, ali: 'ali', five: 5, true: true},
),
);

console.log('sanitize value test');
console.log(
validator<
{num: number; str: string; bool: boolean; _null: null; ali: 'ali'; five: 5; true: true}
>(
validator<{num: number; str: string; bool: boolean; _null: null; ali: 'ali'; five: 5; true: true}>(
{num: Number, str: String, bool: Boolean, _null: null, ali: 'ali', five: 5, true: true},
{num: '123', str: 'test', bool: 'false', _null: null, ali: 'ali', five: 5, true: true},
),
);

console.log('nested value test');
console.log(
validator<
{a: {num: number; str: string; bool: boolean; _null: null; ali: 'ali'; five: 5; true: true}}
>(
validator<{a: {num: number; str: string; bool: boolean; _null: null; ali: 'ali'; five: 5; true: true}}>(
{a: {num: Number, str: String, bool: Boolean, _null: null, ali: 'ali', five: 5, true: true}},
{a: {num: '123', str: 'test', bool: 'false', _null: null, ali: 'ali', five: 5, true: true}},
),
);

console.log('not valid test');
try {
console.log(
validator<
{num: number}
>(
{num: Number},
{num: 'test'},
),
);
console.log(validator<{num: number}>({num: Number}, {num: 'test'}));
throw new Error('validator_not_work');
}
catch (err) {
Expand All @@ -52,14 +39,7 @@ catch (err) {
}

try {
console.log(
validator<
{num: boolean}
>(
{num: Boolean},
{num: 'true'},
),
);
console.log(validator<{num: boolean}>({num: Boolean}, {num: 'true'}));
throw new Error('validator_not_work');
}
catch (err) {
Expand All @@ -72,14 +52,7 @@ catch (err) {
}

try {
console.log(
validator<
{num: null}
>(
{num: null},
{num: 'test'},
),
);
console.log(validator<{num: null}>({num: null}, {num: 'test'}));
throw new Error('validator_not_work');
}
catch (err) {
Expand All @@ -92,14 +65,7 @@ catch (err) {
}

try {
console.log(
validator<
{num: number}
>(
{num: Number},
{num: 'test'},
),
);
console.log(validator<{num: number}>({num: Number}, {num: 'test'}));
throw new Error('validator_not_work');
}
catch (err) {
Expand All @@ -112,14 +78,7 @@ catch (err) {
}

try {
console.log(
validator<
{num: string}
>(
{num: 'test'},
{num: 'tes'},
),
);
console.log(validator<{num: string}>({num: 'test'}, {num: 'tes'}));
throw new Error('validator_not_work');
}
catch (err) {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "module",
"private": true,
"engines": {
"node": ">=18.18.0"
"node": ">=18.16.0"
},
"workspaces": [
"packages/*",
Expand Down Expand Up @@ -50,8 +50,8 @@
"@lerna-lite/run": "^2.5.1",
"@lerna-lite/version": "^2.5.1",
"@types/node": "^20.6.1",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"@typescript-eslint/eslint-plugin": "^6.7.2",
"@typescript-eslint/parser": "^6.7.2",
"@web/dev-server": "^0.3.1",
"eslint": "^8.49.0",
"eslint-config-google": "^0.14.0",
Expand Down
Loading

0 comments on commit e225301

Please sign in to comment.