Skip to content

Commit ef2fc53

Browse files
committed
chore: use ubuntu to lint code style
1 parent 59e3325 commit ef2fc53

File tree

4 files changed

+19
-28
lines changed

4 files changed

+19
-28
lines changed

.github/workflows/commit-ci.yml

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,15 @@ on:
1111

1212
jobs:
1313
lint:
14-
runs-on: windows-latest
14+
runs-on: ubuntu-latest
1515
steps:
1616
- name: Checkout last commit
1717
uses: actions/checkout@v4
18-
- name: Install clang-format@18
19-
shell: pwsh
18+
19+
- name: Install clang-format-18
2020
run: |
21-
$version = ""
22-
if (Get-Command "clang-format" -ErrorAction SilentlyContinue){
23-
$version = clang-format --version
24-
$pat = ".*\s+(\d+\.\d+\.\d+)"
25-
if ($version -match $pat) {
26-
$version = $matches[1]
27-
}
28-
}
29-
if ($version -ne "") {
30-
Write-Host "clang-format version:$version"
31-
if ([version]$version -eq [version]"18.1.8") {
32-
Write-Host "clang-format OK"
33-
} else {
34-
Write-Host "clang-format version does not meet"
35-
choco install llvm --version=18.1.8 --force
36-
}
37-
} else {
38-
Write-Host "clang-format not installed"
39-
choco install llvm --version=18.1.8
40-
}
21+
./action-install-clang-format.sh 18
22+
4123
- name: Code style lint
4224
run: make clang-format-lint
4325

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ all: release
4747

4848
clang-format-lint:
4949
find ${RIME_SOURCE_PATH} \! -path 'plugins/*/*' -a \( -name '*.cc' -o -name '*.h' \) | \
50-
xargs clang-format -Werror --dry-run || { echo Please lint your code by '"'"make clang-format-apply"'"'.; false; }
50+
xargs clang-format --style=file:.clang-format -Werror --dry-run || { echo Please lint your code by '"'"make clang-format-apply"'"'.; false; }
5151

5252
clang-format-apply:
53-
find ${RIME_SOURCE_PATH} \! -path 'plugins/*/*' -a \( -name '*.cc' -o -name '*.h' \) | xargs clang-format --verbose -i
53+
find ${RIME_SOURCE_PATH} \! -path 'plugins/*/*' -a \( -name '*.cc' -o -name '*.h' \) | xargs clang-format --style=file:.clang-format --verbose -i
5454

5555
deps:
5656
$(MAKE) -f deps.mk

action-install-clang-format.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
# https://apt.llvm.org/
4+
sudo apt install -y wget
5+
wget https://apt.llvm.org/llvm.sh
6+
chmod +x llvm.sh
7+
sudo ./llvm.sh $1
8+
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-$1 100

src/rime/dict/corrector.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,10 @@ Distance EditDistanceCorrector::RestrictedDistance(const std::string& s1,
207207
for (size_t i = 1; i <= len1; ++i) {
208208
auto min_d = threshold + 1;
209209
for (size_t j = 1; j <= len2; ++j) {
210-
d[index(i, j)] = (std::min)(
211-
{d[index(i - 1, j)] + 2, d[index(i, j - 1)] + 2,
212-
d[index(i - 1, j - 1)] + SubstCost(s1[i - 1], s2[j - 1])});
210+
d[index(i, j)] =
211+
(std::min)({d[index(i - 1, j)] + 2, d[index(i, j - 1)] + 2,
212+
d[index(i - 1, j - 1)] +
213+
SubstCost(s1[i - 1], s2[j - 1])});
213214
if (i > 1 && j > 1 && s1[i - 2] == s2[j - 1] && s1[i - 1] == s2[j - 2]) {
214215
d[index(i, j)] = (std::min)(d[index(i, j)], d[index(i - 2, j - 2)] + 2);
215216
}

0 commit comments

Comments
 (0)