From a9ffe73547e504acace00f67828d0053745e8509 Mon Sep 17 00:00:00 2001 From: Ovilia Date: Tue, 23 Jan 2024 14:45:14 +0800 Subject: [PATCH] fix: fix lint problems and add ci workflow --- .github/workflows/ci.yml | 91 ++++++++++++++++++++++++++++++++++++++++ src/core/PathProxy.ts | 2 - src/core/env.ts | 4 +- src/core/timsort.ts | 13 ------ src/svg/patch.ts | 2 +- 5 files changed, 94 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..b71d1386d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,91 @@ +name: Node CI + +on: + pull_request: + types: [opened, reopened, synchronize] + +concurrency: + # Note that the `teardown-pr-preview` workflow needs the same group name + # to cancel the running `ci` workflows + group: ${{ github.workflow }}-${{ github.event.number }} + cancel-in-progress: true + +jobs: + lint: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x] + + steps: + - name: Fetch commit count + env: + PR_COMMIT_COUNT: ${{ github.event.pull_request.commits }} + run: | + echo "FETCH_DEPTH=$(($PR_COMMIT_COUNT + 1))" >> $GITHUB_ENV + + - uses: actions/checkout@v4 + with: + fetch-depth: ${{ env.FETCH_DEPTH }} + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + + - name: Cache node modules + id: cache-dep + uses: actions/cache@v3 + env: + cache-name: cache-node-modules + with: + path: node_modules + key: ${{ runner.os }}-lint-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + + - name: Install dependencies + if: steps.cache-dep.outputs.cache-hit != 'true' + run: npm ci + + - name: Collect changed files + run: | + mkdir ~/tmp/ + git diff ${{ github.event.pull_request.base.sha }} ${{ github.sha }} --diff-filter=ACM --name-only --relative '*src/**/*.ts' > ~/tmp/changed_files + echo -e "Changed files: \n$(cat ~/tmp/changed_files)" + + - name: Lint + run: npx eslint $(cat ~/tmp/changed_files) + + build: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x] + + steps: + - uses: actions/checkout@v4 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + + - name: Cache node modules + id: cache-dep + uses: actions/cache@v3 + env: + cache-name: cache-node-modules + with: + path: node_modules + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + + - name: Install dependencies + if: steps.cache-dep.outputs.cache-hit != 'true' + run: npm ci + + - name: Unit Test + run: npm run test + + - name: Build release + run: npm run release diff --git a/src/core/PathProxy.ts b/src/core/PathProxy.ts index f0331f947..08c789e62 100644 --- a/src/core/PathProxy.ts +++ b/src/core/PathProxy.ts @@ -675,8 +675,6 @@ export default class PathProxy { const endAngle = delta + startAngle; // TODO Arc 旋转 i += 1; - const anticlockwise = !data[i++]; - if (isFirst) { // 直接使用 arc 命令 // 第一个命令起点还未定义 diff --git a/src/core/env.ts b/src/core/env.ts index 92c7f9e74..cadec6688 100644 --- a/src/core/env.ts +++ b/src/core/env.ts @@ -38,8 +38,8 @@ else if (typeof document === 'undefined' && typeof self !== 'undefined') { env.worker = true; } else if ( - typeof navigator === 'undefined' || - navigator.userAgent.indexOf('Node.js') === 0 + typeof navigator === 'undefined' + || navigator.userAgent.indexOf('Node.js') === 0 ) { // In node env.node = true; diff --git a/src/core/timsort.ts b/src/core/timsort.ts index ee602f229..75b7dbfed 100644 --- a/src/core/timsort.ts +++ b/src/core/timsort.ts @@ -3,8 +3,6 @@ const DEFAULT_MIN_MERGE = 32; const DEFAULT_MIN_GALLOPING = 7; -const DEFAULT_TMP_STORAGE_LENGTH = 256; - type CompareFunc =(a: T, b: T) => number function minRunLength(n: number): number { @@ -217,23 +215,12 @@ function gallopRight(value: T, array: T[], start: number, length: number, hin function TimSort(array: T[], compare: CompareFunc) { let minGallop = DEFAULT_MIN_GALLOPING; - let length = 0; - let tmpStorageLength = DEFAULT_TMP_STORAGE_LENGTH; - let stackLength = 0; let runStart: number[]; let runLength: number[]; let stackSize = 0; - length = array.length; - - if (length < 2 * DEFAULT_TMP_STORAGE_LENGTH) { - tmpStorageLength = length >>> 1; - } - var tmp: T[] = []; - stackLength = length < 120 ? 5 : length < 1542 ? 10 : length < 119151 ? 19 : 40; - runStart = []; runLength = []; diff --git a/src/svg/patch.ts b/src/svg/patch.ts index edea6ae86..4dc93b97b 100644 --- a/src/svg/patch.ts +++ b/src/svg/patch.ts @@ -144,7 +144,7 @@ export function updateAttrs(oldVnode: SVGVNode, vnode: SVGVNode): void { } else { if (key === 'style') { - elm.style.cssText = cur as string + elm.style.cssText = cur as string; } else if (key.charCodeAt(0) !== xChar) { elm.setAttribute(key, cur as any);