Skip to content

fix(cli): tighten please-style check heuristics deferred from #36 - #42

Merged
amondnet merged 6 commits into
mainfrom
amondnet/please-style-check-remaining-framework-conventio
Oct 12, 2026
Merged

amondnet merged 6 commits into
mainfrom
amondnet/please-style-check-remaining-framework-conventio

Conversation

@amondnet

@amondnet amondnet commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Tightens the please-style check heuristics that were deferred from #36. The PR has four commits covering these five changes:

  1. Dart generated-file suffixes (check-filenames.ts): The blanket "dotted stem" exemption is narrowed to a generator-suffix list (g, freezed, mocks, gr, config, gen, chopper, mapper, gql, graphql, pb, pbenum, pbjson, pbserver, pbgrpc). Mockito *.mocks.dart and protobuf files are now exempt even though their headers don't match GENERATED_HEADER. Handwritten dotted names such as widgets.custom.dart are now judged.
  2. Framework-reserved export names (loader, action, Route, HTTP verbs) are reserved only for files under a routes/ or pages/ directory. Elsewhere they are judged like any other export. Inside route directories the behavior is unchanged (withheld with a notice).
  3. Rust test-attr extraction rule now recognizes #[cfg_attr(<pred>, test)] and #[cfg_attr(<pred>, tokio::test(…))] through an AST branch. A test inside the predicate (cfg_attr(all(unix, test), ignore)) or as the predicate (cfg_attr(test, derive(Debug))) does not count. Known gap: nested cfg_attr(a, cfg_attr(b, test)) still under-reports.
  4. Kotlin kotlin-error-outside-errors-file ignores **/src/*Test/** (Android androidUnitTest, KMP commonTest, jvmTest, iosTest, jsTest, …). An e2e test confirms commonMain is still reported.
  5. Yarn Plug'n'Play (appliers.ts): when .pnp.cjs or .pnp.js exists, init does not write sgconfig.yml, because the node_modules/... rules path would not exist. It prints an en/ko warning to set nodeLinker: node-modules and reports the step as skipped.

The READMEs (en/ko) and the Kotlin rule README are updated.

Related issue

Closes #37

Verification

  • packages/cli: bun test — 241 pass
  • packages/ast-grep-config: ast-grep test — 11 rules pass; e2e — 3 pass
  • bun run build and bun run lint pass
  • tsc --noEmit on packages/cli passes
  • The new tests were confirmed to fail before the fix (the Rust test by reverting the rule)

Out of scope (follow-ups)

  • The .editorconfig applier and please-style check's rule resolution also assume node_modules under PnP.
  • jvmLayout in layouts.ts only recognizes src/main|test|testFixtures, so KMP source sets are not covered by the test-path check.

Checklist

  • PR title follows Conventional Commits
  • Packages build (bun run build)
  • Lint/format pass (bun run lint)
  • Documentation updated if behavior changed
  • No breaking change, or a BREAKING CHANGE: note is included

Summary by cubic

Tightens the please-style check heuristics deferred from #36, closing #37.

  • Dart: files are exempt only when their last stem segment is a known generator suffix (g, freezed, mocks, gr, config, gen, chopper, mapper, gql, graphql, pb, pbenum, pbjson, pbserver, pbgrpc), so handwritten dotted names like widgets.custom.dart are now judged.
  • Framework-reserved export names (Route, HTTP verbs, loader, action) are withheld only under routes/ or pages/ directories; elsewhere they are judged like any other export.
  • Rust test detection now recognizes #[cfg_attr(<pred>, test)] and #[cfg_attr(<pred>, tokio::test(…))], without counting test inside the predicate, as the predicate, or as a path-qualified test::… attribute.
  • kotlin-error-outside-errors-file now ignores **/src/*Test/**, covering Android androidUnitTest and Kotlin Multiplatform commonTest, jvmTest, iosTest, jsTest, and so on.
  • Under Yarn Plug'n'Play, init skips writing sgconfig.yml with a warning when .pnp.cjs or .pnp.js is found in the project or an enclosing workspace root, unless the project has its own installed rules directory.

Known gap: nested cfg_attr(a, cfg_attr(b, test)) still under-reports Rust tests.

Written for commit 495764c. Summary will update on new commits.

Turn on auto-fix

…ramework-reserved names

Exempt Dart files only when the last stem segment names a known generator
(g, freezed, mocks, gr, pb, ...), so a handwritten dotted name is judged.
Treat Route/GET/loader/action etc. as framework-reserved only under routes/
or pages/ directories.

Refs #37
… error-file rule

The kotlin-error-outside-errors-file rule now ignores Kotlin Multiplatform
test source sets.

Refs #37
@amondnet
amondnet marked this pull request as ready for review October 12, 2026 09:03
@codacy-production

codacy-production Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 2 high

Alerts:
⚠ 2 issues (≤ 0 issues of at least minor severity)

Results:
2 new issues

Category Results
Security 2 high

View in Codacy

🟢 Metrics 17 complexity · 0 duplication

Metric Results
Complexity 17
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the style checker by expanding Rust test attribute detection to support conditionally applied attributes like #[cfg_attr(..., test)], updating Kotlin rules to ignore all test source sets ending in Test, and adding support for Yarn Plug'n'Play environments by skipping sgconfig.yml generation with a warning. Additionally, it refines TypeScript/TSX filename checks to restrict framework-reserved exports to route or page directories and expands Dart generator output exemptions to cover several new suffixes. As there are no review comments provided, I have no feedback to evaluate.

@greptile-apps

greptile-apps Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issue remains.

Summary

This PR tightens filename and test checks and avoids writing an unusable sgconfig.yml under Yarn Plug'n'Play.

  • Dart filename checks exempt known generator outputs.
  • Framework-reserved export names are exempt only in route folders.
  • Rust checks find test files marked through cfg_attr.
  • Kotlin error checks skip more test source sets.
  • init skips ast-grep config when Yarn PnP has no local rules.

Reviews (2) · Last reviewed commit: "chore: apply AI code review suggestions" · Reviewed by Greptile

Comment thread packages/cli/src/appliers.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 12 files

Architecture diagram
sequenceDiagram
    participant CLI as please-style check CLI
    participant FS as File System
    participant Config as sgconfig.yml
    participant Extractor as Extract Rules
    participant FilenameCheck as check-filenames
    participant RustCheck as Rust check
    participant KotlinCheck as Kotlin check
    participant Init as init command

    Note over CLI,FS: Runtime flow for please-style check

    CLI->>FS: Read project files
    CLI->>Extractor: Run ast-grep extraction
    Extractor->>FS: Read rules from node_modules/@pleaseai/ast-grep-config
    
    Note over FilenameCheck: TypeScript/Dart filename validation
    FilenameCheck->>FS: Read source files
    FilenameCheck->>FilenameCheck: Evaluate export names
    
    alt TypeScript file in routes/ or pages/
        FilenameCheck->>FilenameCheck: Check if export is framework-reserved
        Note over FilenameCheck: Reserved: Route, GET, POST, loader, action...
        FilenameCheck-->>CLI: Skip with notice
    else TypeScript file elsewhere
        FilenameCheck->>FilenameCheck: Check export name against filename
        FilenameCheck-->>CLI: Report if mismatch
    end
    
    alt Dart file with generator suffix
        FilenameCheck->>FilenameCheck: Check for .g, .freezed, .mocks, .gr, etc.
        Note over FilenameCheck: Generated: *.g.dart, *.freezed.dart, *.mocks.dart...
        FilenameCheck-->>CLI: Exempt from check
    else Dart file with handwritten name
        FilenameCheck->>FilenameCheck: Check stem against filename
        FilenameCheck-->>CLI: Report if mismatch
    end

    Note over RustCheck: Rust test detection
    RustCheck->>FS: Read Cargo metadata
    RustCheck->>FS: Parse Rust files
    RustCheck->>RustCheck: Extract #[cfg_attr(...)] attributes
    alt cfg_attr with test argument
        RustCheck->>RustCheck: Check predicate (test NOT in predicate)
        RustCheck-->>CLI: Mark as test file
    else test used as predicate or in predicate
        RustCheck-->>CLI: Not counted as test
    end

    Note over KotlinCheck: Kotlin error file validation
    KotlinCheck->>FS: Read Kotlin source files
    KotlinCheck->>KotlinCheck: Check path pattern
    alt Path matches **/src/*Test/**
        Note over KotlinCheck: androidTest, commonTest, jvmTest, iosTest...
        KotlinCheck-->>CLI: Exempt from error check
    else Path is in main source set
        KotlinCheck-->>CLI: Report if error outside errors file
    end

    Note over Init: Init command with Yarn PnP
    Init->>FS: Check for .pnp.cjs or .pnp.js
    alt Yarn PnP detected
        Init->>Init: Warning: node_modules not available
        Init-->>CLI: Report step skipped
    else Normal setup
        Init->>Config: Write sgconfig.yml
        Init->>FS: Reference rules in node_modules
    end
Loading

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread packages/cli/README.md Outdated
Comment thread packages/cli/src/appliers.ts Outdated
Comment thread packages/ast-grep-config/extract/rust.yml
Comment thread packages/cli/README.ko.md Outdated
- Detect Yarn Plug'n'Play from a workspace package (.pnp.cjs at an enclosing root),
  unless the project has its own installed rules directory
- Do not treat cfg_attr(…, test::helper) as a Rust test attribute
- Document .pnp.js and the yarn install + init rerun step

Refs #37
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Deploying code-style with  Cloudflare Pages  Cloudflare Pages

Latest commit: 495764c
Status:🚫  Build failed.

View logs

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 6 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread packages/cli/README.md
Document that an installed rules directory overrides an enclosing Plug'n'Play root.

Refs #37
@sonarqubecloud

Copy link
Copy Markdown

@amondnet
amondnet merged commit 42a5f65 into main Oct 12, 2026
11 of 13 checks passed
@amondnet
amondnet deleted the amondnet/please-style-check-remaining-framework-conventio branch October 12, 2026 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

please-style check: remaining framework conventions and heuristic tightening after #36

1 participant