# EditorConfig pack — Generalized Style Guide v1.2

Build-time enforcement for the Generalized Style Guide, built from the
SonarQube history of the house projects (mined 2026-12-02: Essentials,
Libraries.V1, MarketPulse, Sql — open plus resolved issues). The point:
every repeated Sonar finding fails the local build or the editor, before
the PR quality gate ever sees it.

## Size thresholds (SG-PAT-09 to SG-PAT-13, guide v1.2)

Hard caps, enforced at build: method 50 lines (`MA0051` with
`maximum_lines_per_method = 50`, plus `S138`), file 1000 lines (`S104`), cognitive
complexity 15 (`S3776`), cyclomatic complexity 10 (`CA1502`), parameters 7
(`S107`), nesting depth 3 (`S134`). Class 500 lines has no direct analyzer
rule; it is enforced by the review skill's responsibility check
(SG-PAT-09/SG-PAT-10) and the file cap. Tests keep the caps as suggestions
(long arrange blocks move into builders, SG-TEST-08).

## Adopt

Copy to the repository root: `.editorconfig`, `Directory.Build.props`,
`Directory.Packages.props`, `Directory.Build.targets`, `nuget.config`,
`global.json`. Copy `tests/.editorconfig` into the tests folder. Then:

1. Restore once and commit the generated `packages.lock.json` files.
2. In CI, restore with `dotnet restore --locked-mode`.
3. Record any deviation as an `OVERRIDE`/`BYPASS` tag in the project
   guide (validate with the bypass-tag validator), never as a silent
   local edit to these files.

Library vs application switches are automatic: packable projects treat
CA2007 and CS1591 as errors; applications silence CS1591. Test projects
relax CA1707/CS1591/CA2007 through `Directory.Build.targets` and
`tests/.editorconfig` — CA1861 and IDE0028 stay on in tests on purpose.

## Repeated Sonar findings and where they now fire

Counts are open + resolved across the four mined projects. PR-only rounds
(CA1861, IDE0028, S7636 on Essentials PR #8) are marked PR.

| Sonar rule | Count | Pre-PR enforcement |
|---|---|---|
| S2306 async/await as identifiers | 82 | SonarAnalyzer in build, error |
| S6966 awaitable method should be used | 51 | SonarAnalyzer + CA1849, warning |
| IDE0022 expression body | 20 | editorconfig style, warning |
| S3776 cognitive complexity | 16 | SonarAnalyzer (threshold 15 = SG-TEST-08) |
| S3358 nested ternary | 16 | SonarAnalyzer, warning |
| CA1031 catch general exception | 16 | Roslyn, warning (SG-ERR-03) |
| S107 too many parameters | 14 | SonarAnalyzer (threshold 7 = SG-TEST-08) |
| S4136 overloads grouped | 12 | SonarAnalyzer, suggestion |
| IDE0028 collection initialization | 8 + PR | editorconfig style, warning |
| S2326 unused type parameters | 8 | SonarAnalyzer, warning |
| IDE0007 use var | 7 | editorconfig style, warning |
| S101 PascalCase types | 6 | naming rules + S101, warning |
| S1192 duplicated string literals | 6 | SonarAnalyzer, suggestion |
| S1135 TODO tags | 5 | suggestion; TODOs need issues (SG-FMT-12) |
| S3267 loops to LINQ | 4 | SonarAnalyzer, suggestion |
| S2743 static fields in generic types | 4 | SonarAnalyzer, warning |
| S8969 redundant null-forgiving | 4 | SonarAnalyzer, warning |
| S2365 properties copying collections | 4 | SonarAnalyzer, warning |
| S3871 exception types public | 3 | SonarAnalyzer, warning |
| SYSLIB1045 GeneratedRegex | 3 | Roslyn, warning |
| docker:S6471 containers run as root | 3 | Dockerfile snippet below (SG-BUILD-06) |
| S3011 reflection accessibility | 2 | SonarAnalyzer, warning |
| S2436 too many generic parameters | 2 | SonarAnalyzer, suggestion |
| CA1716 keyword-conflicting identifiers | 2 | Roslyn, warning |
| S6562 DateTimeKind on new DateTime | 2 | SonarAnalyzer, warning (SG-TIME-03) |
| S6444 regex timeout | 2 | SonarAnalyzer, warning |
| S3220 params overload ambiguity | 2 | SonarAnalyzer, suggestion |
| S127 loop stop condition | 2 | SonarAnalyzer, warning |
| S3604 redundant member initializer | 2 | SonarAnalyzer, suggestion |
| CA1304 specify CultureInfo | 2 | Roslyn, warning |
| githubactions:S7636 secrets in run | 2 + PR | CI snippet below |
| githubactions:S8233/S8264 job permissions | 3 | CI snippet below |
| CA1861 constant array arguments | PR | Roslyn, warning (also in tests) |
| S125 commented-out code | 1 | SonarAnalyzer, warning (SG-FMT-11) |
| S2245 insecure Random | 1 | SonarAnalyzer + CA5394, warning |
| S2178 short-circuit logic | 1 | SonarAnalyzer, warning |
| S3218 inner class shadowing | 1 | SonarAnalyzer, warning |
| S3875 operator== on reference types | 1 | SonarAnalyzer, warning |
| S2583/S2589 gratuitous conditions | 2 | SonarAnalyzer, warning |
| S1751 single-iteration loops | 1 | SonarAnalyzer, warning |
| S1481 unused local | 1 | SonarAnalyzer, warning |
| S3398 private method placement | 1 | SonarAnalyzer, suggestion |
| S4035 IEquatable classes sealed | 1 | SonarAnalyzer, suggestion |
| S3878 arrays for params | 1 | SonarAnalyzer, suggestion |
| S6672 logger type mismatch | 1 | SonarAnalyzer, warning |
| IDE0021 expression-body constructor | 1 | editorconfig style, warning |
| CS9236 lambda binding | 1 | compiler warning (already build-visible) |

Not build-enforceable, handled elsewhere: new-code coverage (SG-GATE-01)
is a test-writing discipline — run the local scanner before push
(SG-GATE-02):

```text
dotnet sonarscanner begin /k:"<project-key>" /d:sonar.host.url="https://sonar.hassanragai.dev" /d:sonar.token="$SONAR_TOKEN"
dotnet build
dotnet sonarscanner end /d:sonar.token="$SONAR_TOKEN"
```

## CI and Docker snippets (S7636, S8233, S8264, S6471)

Secrets reach steps through `env:`, never expanded inside `run:`.
Permissions are declared per job, least-privilege. Third-party actions
are pinned by commit SHA.

```yaml
jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - uses: actions/checkout@<sha>
      - name: Restore
        env:
          NUGET_TOKEN: ${{ secrets.NUGET_PRIVATE_FEED_API_KEY }}
        run: dotnet restore --locked-mode
```

Containers run as a non-root user (SG-BUILD-06):

```dockerfile
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime
USER $APP_UID
```

## ReSharper/Rider profile items

Spaced parentheses (`if ( x )`), spaced attribute brackets and
column-aligned `=` (SG-FMT-01/02) have no Visual Studio/Roslyn
editorconfig keys. The pack carries best-effort `resharper_*` keys;
the exact profile lives in Rider settings. Reviews flag deviations at
LOW/nitpick only where tooling does not catch them.

## Versioning

Pack version tracks the guide: v1.1 (2026-12-02). Analyzer pins carry
health-gate evidence in `Directory.Packages.props`; re-check quarterly
(SG-DEP-05).
