diff --git a/.editorconfig b/.editorconfig index 7f6de4d..3c8687f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -37,6 +37,10 @@ indent_size = 2 [*{_AssemblyInfo.cs,.notsupported.cs,*/obj/*/External/**/*,*/obj/dotnet-new.IntegrationTests/*/TemplatePackagesPaths.cs}] generated_code = true +# Thrift generated code +[src/Apache.IoTDB/Rpc/Generated/**] +generated_code = true + # C# files [*.cs] # New line preferences diff --git a/.github/workflows/pre-commit-format.yml b/.github/workflows/pre-commit-format.yml index 3b7589c..7ef53be 100644 --- a/.github/workflows/pre-commit-format.yml +++ b/.github/workflows/pre-commit-format.yml @@ -7,15 +7,13 @@ on: - "**" merge_group: branches: [main] - # schedule: - # - cron: "0 0 * * *" concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: - formatting-checks: + dotnet-format: runs-on: ubuntu-22.04 env: DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 @@ -29,27 +27,9 @@ jobs: with: dotnet-version: "9.0.x" - - name: Setup Python environment (for pre-commit) - uses: actions/setup-python@v5 - with: - python-version: "3.10" - - - name: Clean dotnet temporary folder - run: | - sudo rm -rf /tmp/.dotnet - mkdir -p ${{ runner.temp }}/dotnet-home - mkdir -p ${{ runner.temp }}/xdg-runtime - - - name: Install pre-commit and dependencies - run: | - pip install pre-commit - pre-commit install-hooks + - name: Restore dependencies + run: dotnet restore - - name: Run pre-commit checks - env: - TMPDIR: ${{ runner.temp }} - DOTNET_CLI_HOME: ${{ runner.temp }}/dotnet-home - XDG_RUNTIME_DIR: ${{ runner.temp }}/xdg-runtime - NUGET_PACKAGES: ${{ runner. temp }}/nuget-packages + - name: Check formatting run: | - pre-commit run --all-files + dotnet format --verify-no-changes --verbosity diagnostic diff --git a/README.md b/README.md index 7f46166..f395763 100644 --- a/README.md +++ b/README.md @@ -82,5 +82,23 @@ NLog >= 4.7.9 * dotnet CLI * Thrift +## Code Formatting + +This project uses `dotnet format` to enforce consistent code style based on the [.editorconfig](.editorconfig) rules. + +### Check formatting locally + +```bash +dotnet format --verify-no-changes +``` + +### Auto-fix formatting issues + +```bash +dotnet format +``` + +The CI pipeline will automatically check code formatting on all pull requests. Please ensure your code is properly formatted before submitting a PR. + ## Publish your own client on nuget.org You can find out how to publish from this [doc](./PUBLISH.md). \ No newline at end of file diff --git a/README_ZH.md b/README_ZH.md index 440477c..df2f500 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -81,5 +81,23 @@ NLog >= 4.7.9 * dotnet CLI * Thrift +## 代码格式化 + +本项目使用 `dotnet format` 基于 [.editorconfig](.editorconfig) 规则来强制执行一致的代码风格。 + +### 本地检查格式 + +```bash +dotnet format --verify-no-changes +``` + +### 自动修复格式问题 + +```bash +dotnet format +``` + +CI 流水线会在所有 Pull Request 上自动检查代码格式。请确保在提交 PR 之前代码格式正确。 + ## 在 nuget.org 上发布你自己的客户端 你可以在这个[文档](./PUBLISH.md)中找到如何发布 \ No newline at end of file diff --git a/src/Apache.IoTDB/PoolHealthMetrics.cs b/src/Apache.IoTDB/PoolHealthMetrics.cs index 938766c..52bcc5f 100644 --- a/src/Apache.IoTDB/PoolHealthMetrics.cs +++ b/src/Apache.IoTDB/PoolHealthMetrics.cs @@ -46,7 +46,7 @@ public void ResetAllCounters() } public int GetReconnectionFailureTally() => Volatile.Read(ref _reconnectionFailureTally); - + public int GetConfiguredMaxSize() => _configuredMaxSize; } } diff --git a/src/Apache.IoTDB/Rpc/TSStatusCode.cs b/src/Apache.IoTDB/Rpc/TSStatusCode.cs index e2eaca8..3f6cee9 100644 --- a/src/Apache.IoTDB/Rpc/TSStatusCode.cs +++ b/src/Apache.IoTDB/Rpc/TSStatusCode.cs @@ -285,4 +285,4 @@ public static string ToString(TSStatusCode statusCode) } } -} \ No newline at end of file +} diff --git a/src/Apache.IoTDB/SessionPool.cs b/src/Apache.IoTDB/SessionPool.cs index 60c8645..1d2aecf 100644 --- a/src/Apache.IoTDB/SessionPool.cs +++ b/src/Apache.IoTDB/SessionPool.cs @@ -21,9 +21,9 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Security.Cryptography.X509Certificates; using System.Threading; using System.Threading.Tasks; -using System.Security.Cryptography.X509Certificates; using Apache.IoTDB.DataStructure; using Microsoft.Extensions.Logging; using Thrift; @@ -64,19 +64,19 @@ public partial class SessionPool : IDisposable, IPoolDiagnosticReporter private ConcurrentClientQueue _clients; private ILogger _logger; private PoolHealthMetrics _healthMetrics; - + public delegate Task AsyncOperation(Client client); - + /// /// Retrieves current count of idle clients ready for operations. /// public int AvailableClients => _clients?.ClientQueue.Count ?? 0; - + /// /// Retrieves the configured maximum capacity of the session pool. /// public int TotalPoolSize => _healthMetrics?.GetConfiguredMaxSize() ?? _poolSize; - + /// /// Retrieves cumulative tally of reconnection failures since pool was opened. ///