Skip to content

Commit

Permalink
fix: fix lint problems and add ci workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Ovilia committed Jan 23, 2024
1 parent 926abff commit a9ffe73
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 18 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions src/core/PathProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,6 @@ export default class PathProxy {
const endAngle = delta + startAngle;
// TODO Arc 旋转
i += 1;
const anticlockwise = !data[i++];

if (isFirst) {
// 直接使用 arc 命令
// 第一个命令起点还未定义
Expand Down
4 changes: 2 additions & 2 deletions src/core/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 0 additions & 13 deletions src/core/timsort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ const DEFAULT_MIN_MERGE = 32;

const DEFAULT_MIN_GALLOPING = 7;

const DEFAULT_TMP_STORAGE_LENGTH = 256;

type CompareFunc<T> =(a: T, b: T) => number

function minRunLength(n: number): number {
Expand Down Expand Up @@ -217,23 +215,12 @@ function gallopRight<T>(value: T, array: T[], start: number, length: number, hin

function TimSort<T>(array: T[], compare: CompareFunc<T>) {
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 = [];

Expand Down
2 changes: 1 addition & 1 deletion src/svg/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a9ffe73

Please sign in to comment.