@girardmedia/bootspring 3.3.2 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/agents/accessibility-auditor.md +39 -0
- package/assets/agents/api-designer.md +40 -0
- package/assets/agents/auth-implementer.md +64 -0
- package/assets/agents/bug-hunter.md +42 -0
- package/assets/agents/bundle-analyzer.md +40 -0
- package/assets/agents/cache-optimizer.md +55 -0
- package/assets/agents/changelog-writer.md +55 -0
- package/assets/agents/ci-cd-builder.md +40 -0
- package/assets/agents/code-explainer.md +39 -0
- package/assets/agents/code-reviewer.md +39 -0
- package/assets/agents/cost-optimizer.md +57 -0
- package/assets/agents/cron-scheduler.md +51 -0
- package/assets/agents/data-seeder.md +56 -0
- package/assets/agents/database-architect.md +40 -0
- package/assets/agents/dependency-updater.md +40 -0
- package/assets/agents/deploy-checker.md +40 -0
- package/assets/agents/docker-optimizer.md +40 -0
- package/assets/agents/documentation-writer.md +40 -0
- package/assets/agents/email-builder.md +55 -0
- package/assets/agents/env-setup.md +40 -0
- package/assets/agents/error-handler.md +40 -0
- package/assets/agents/eslint-fixer.md +46 -0
- package/assets/agents/feature-flagger.md +69 -0
- package/assets/agents/git-detective.md +39 -0
- package/assets/agents/graphql-builder.md +60 -0
- package/assets/agents/incident-responder.md +59 -0
- package/assets/agents/log-analyzer.md +39 -0
- package/assets/agents/migration-planner.md +41 -0
- package/assets/agents/monorepo-navigator.md +39 -0
- package/assets/agents/nextjs-expert.md +57 -0
- package/assets/agents/notification-builder.md +56 -0
- package/assets/agents/onboarding-guide.md +39 -0
- package/assets/agents/performance-profiler.md +40 -0
- package/assets/agents/prisma-expert.md +57 -0
- package/assets/agents/rate-limiter.md +58 -0
- package/assets/agents/react-expert.md +58 -0
- package/assets/agents/refactorer.md +42 -0
- package/assets/agents/regex-builder.md +46 -0
- package/assets/agents/release-manager.md +40 -0
- package/assets/agents/s3-manager.md +58 -0
- package/assets/agents/schema-validator.md +40 -0
- package/assets/agents/search-builder.md +62 -0
- package/assets/agents/security-auditor.md +39 -0
- package/assets/agents/sitemap-generator.md +53 -0
- package/assets/agents/stripe-integrator.md +59 -0
- package/assets/agents/tailwind-expert.md +55 -0
- package/assets/agents/tech-debt-tracker.md +39 -0
- package/assets/agents/test-writer.md +42 -0
- package/assets/agents/type-fixer.md +45 -0
- package/assets/agents/webhook-builder.md +54 -0
- package/assets/rules/cpp.md +53 -0
- package/assets/rules/css.md +52 -0
- package/assets/rules/go.md +50 -0
- package/assets/rules/html.md +52 -0
- package/assets/rules/java.md +51 -0
- package/assets/rules/kotlin.md +50 -0
- package/assets/rules/php.md +51 -0
- package/assets/rules/python.md +51 -0
- package/assets/rules/ruby.md +51 -0
- package/assets/rules/rust.md +49 -0
- package/assets/rules/shell.md +52 -0
- package/assets/rules/sql.md +49 -0
- package/assets/rules/swift.md +50 -0
- package/assets/rules/typescript.md +52 -0
- package/assets/rules/yaml-json.md +51 -0
- package/assets/skills/accessibility.md +210 -0
- package/assets/skills/agent-patterns.md +387 -0
- package/assets/skills/ai-integration.md +263 -0
- package/assets/skills/animation-patterns.md +224 -0
- package/assets/skills/api-design.md +218 -0
- package/assets/skills/api-gateway.md +341 -0
- package/assets/skills/api-versioning.md +226 -0
- package/assets/skills/astro-patterns.md +233 -0
- package/assets/skills/auth-patterns.md +248 -0
- package/assets/skills/aws-patterns.md +171 -0
- package/assets/skills/background-jobs.md +162 -0
- package/assets/skills/browser-extensions.md +309 -0
- package/assets/skills/caching-patterns.md +253 -0
- package/assets/skills/ci-cd.md +251 -0
- package/assets/skills/cli-development.md +296 -0
- package/assets/skills/code-review.md +185 -0
- package/assets/skills/cron-patterns.md +327 -0
- package/assets/skills/data-fetching.md +231 -0
- package/assets/skills/database-migrations.md +346 -0
- package/assets/skills/database-patterns.md +219 -0
- package/assets/skills/debugging.md +281 -0
- package/assets/skills/design-system.md +289 -0
- package/assets/skills/django-patterns.md +182 -0
- package/assets/skills/docker-patterns.md +235 -0
- package/assets/skills/e2e-testing.md +287 -0
- package/assets/skills/edge-computing.md +268 -0
- package/assets/skills/electron-patterns.md +266 -0
- package/assets/skills/email-templates.md +206 -0
- package/assets/skills/error-handling.md +265 -0
- package/assets/skills/event-driven.md +232 -0
- package/assets/skills/express-patterns.md +239 -0
- package/assets/skills/fastapi-patterns.md +198 -0
- package/assets/skills/feature-flags.md +212 -0
- package/assets/skills/figma-to-code.md +298 -0
- package/assets/skills/file-upload.md +228 -0
- package/assets/skills/forms-patterns.md +264 -0
- package/assets/skills/gcp-patterns.md +189 -0
- package/assets/skills/git-workflow.md +187 -0
- package/assets/skills/golang-patterns.md +185 -0
- package/assets/skills/graphql-patterns.md +244 -0
- package/assets/skills/i18n-patterns.md +172 -0
- package/assets/skills/image-processing.md +350 -0
- package/assets/skills/java-springboot.md +226 -0
- package/assets/skills/kotlin-patterns.md +207 -0
- package/assets/skills/kubernetes-patterns.md +326 -0
- package/assets/skills/laravel-patterns.md +261 -0
- package/assets/skills/llm-fine-tuning.md +335 -0
- package/assets/skills/load-testing.md +303 -0
- package/assets/skills/logging-observability.md +228 -0
- package/assets/skills/markdown-processing.md +318 -0
- package/assets/skills/mcp-server-patterns.md +292 -0
- package/assets/skills/microservices.md +272 -0
- package/assets/skills/migration-patterns.md +239 -0
- package/assets/skills/mongodb-patterns.md +189 -0
- package/assets/skills/monorepo-patterns.md +287 -0
- package/assets/skills/nextjs-app-router.md +237 -0
- package/assets/skills/notification-patterns.md +348 -0
- package/assets/skills/oauth-patterns.md +246 -0
- package/assets/skills/payment-integration.md +222 -0
- package/assets/skills/pdf-generation.md +307 -0
- package/assets/skills/performance-optimization.md +277 -0
- package/assets/skills/php-patterns.md +210 -0
- package/assets/skills/prisma-patterns.md +241 -0
- package/assets/skills/prompt-engineering.md +193 -0
- package/assets/skills/pwa-patterns.md +247 -0
- package/assets/skills/python-patterns.md +158 -0
- package/assets/skills/python-testing.md +172 -0
- package/assets/skills/queue-patterns.md +295 -0
- package/assets/skills/rag-patterns.md +159 -0
- package/assets/skills/rate-limiting.md +319 -0
- package/assets/skills/react-components.md +201 -0
- package/assets/skills/react-native-patterns.md +299 -0
- package/assets/skills/real-time-patterns.md +181 -0
- package/assets/skills/redis-patterns.md +188 -0
- package/assets/skills/refactoring.md +218 -0
- package/assets/skills/regex-patterns.md +191 -0
- package/assets/skills/remix-patterns.md +262 -0
- package/assets/skills/responsive-design.md +199 -0
- package/assets/skills/ruby-rails-patterns.md +178 -0
- package/assets/skills/rust-patterns.md +211 -0
- package/assets/skills/search-patterns.md +227 -0
- package/assets/skills/security-hardening.md +237 -0
- package/assets/skills/seo-patterns.md +179 -0
- package/assets/skills/serverless-patterns.md +223 -0
- package/assets/skills/sql-optimization.md +154 -0
- package/assets/skills/state-management.md +254 -0
- package/assets/skills/storybook-patterns.md +330 -0
- package/assets/skills/svelte-patterns.md +258 -0
- package/assets/skills/swift-patterns.md +227 -0
- package/assets/skills/tailwind-patterns.md +272 -0
- package/assets/skills/tdd-workflow.md +199 -0
- package/assets/skills/terraform-patterns.md +270 -0
- package/assets/skills/testing-react.md +240 -0
- package/assets/skills/testing-vitest.md +232 -0
- package/assets/skills/typescript-strict.md +159 -0
- package/assets/skills/video-processing.md +340 -0
- package/assets/skills/vue-patterns.md +247 -0
- package/assets/skills/web-workers.md +327 -0
- package/assets/skills/webhooks-patterns.md +283 -0
- package/assets/skills/websocket-patterns.md +306 -0
- package/dist/cli/index.js +941 -958
- package/dist/core/index.d.ts +341 -11
- package/dist/core.js +58 -95
- package/dist/mcp/index.d.ts +33 -1
- package/dist/mcp-server.js +177 -255
- package/package.json +4 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: css
|
|
3
|
+
description: Code style and best practice rules for CSS, SCSS, and Less.
|
|
4
|
+
globs:
|
|
5
|
+
- "**/*.css"
|
|
6
|
+
- "**/*.scss"
|
|
7
|
+
- "**/*.less"
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# CSS Rules
|
|
11
|
+
|
|
12
|
+
## Style
|
|
13
|
+
- Use BEM naming convention: `.block__element--modifier`; keep class names lowercase with hyphens
|
|
14
|
+
- Use custom properties (`--color-primary: #0066cc`) for all design tokens: colors, spacing, fonts, radii
|
|
15
|
+
- Define custom properties on `:root` for global tokens; scope component tokens on the component selector
|
|
16
|
+
- Use `rem` for font sizes and spacing; use `px` only for borders and fine details like box shadows
|
|
17
|
+
- Order declarations logically: positioning, display/layout, box model, typography, visual, animation
|
|
18
|
+
- Use shorthand properties (`margin`, `padding`, `border`) only when setting all sides; use longhand for single-side overrides
|
|
19
|
+
- Keep selectors under 3 levels of specificity; never use `!important` except for utility overrides
|
|
20
|
+
- One declaration per line; include a space after the colon and before the opening brace
|
|
21
|
+
- Use meaningful class names that describe purpose, not appearance: `.card-header` not `.big-blue-text`
|
|
22
|
+
- In SCSS, limit nesting to 3 levels maximum; flatten deeply nested selectors into new BEM classes
|
|
23
|
+
|
|
24
|
+
## Patterns
|
|
25
|
+
- Use CSS Grid for two-dimensional layouts (rows and columns); use Flexbox for one-dimensional alignment
|
|
26
|
+
- Use `gap` property on Grid and Flex containers instead of margins on children
|
|
27
|
+
- Use logical properties (`margin-inline-start`, `padding-block-end`) instead of physical properties for internationalization
|
|
28
|
+
- Use `clamp()` for responsive typography: `font-size: clamp(1rem, 2.5vw, 2rem)`
|
|
29
|
+
- Use `@media (prefers-color-scheme: dark)` for dark mode; toggle custom properties rather than rewriting rules
|
|
30
|
+
- Use `@container` queries for component-level responsive design when supported; fall back to media queries
|
|
31
|
+
- Use `aspect-ratio` property instead of the padding-top hack for maintaining element proportions
|
|
32
|
+
- Use `:is()` and `:where()` pseudo-classes to group selectors and reduce repetition
|
|
33
|
+
- Use `@layer` for managing cascade priority across utility classes, components, and third-party styles
|
|
34
|
+
- Use `prefers-reduced-motion: reduce` to disable animations for accessibility; provide static fallbacks
|
|
35
|
+
- Use `will-change` sparingly and only on elements that are about to animate; remove after animation completes
|
|
36
|
+
|
|
37
|
+
## Avoid
|
|
38
|
+
- Never use ID selectors (`#header`) for styling; IDs are for JavaScript hooks and anchor links
|
|
39
|
+
- Never use inline styles in HTML; all styles belong in stylesheets or CSS-in-JS with class extraction
|
|
40
|
+
- Never use `float` for layout; it is a legacy technique superseded by Grid and Flexbox
|
|
41
|
+
- Never use `@import` in plain CSS for performance; use build tool bundling or `@use` in SCSS
|
|
42
|
+
- Never hardcode color values in component styles; reference custom properties or design tokens
|
|
43
|
+
- Never use `z-index` values above 100 without a documented z-index scale for the project
|
|
44
|
+
- Never use `*` universal selector in component styles; it causes unnecessary style recalculation
|
|
45
|
+
- Never animate `width`, `height`, `top`, or `left`; animate `transform` and `opacity` for GPU-accelerated performance
|
|
46
|
+
|
|
47
|
+
## Testing
|
|
48
|
+
- Use Stylelint with a shared config in CI; fix all warnings before merging
|
|
49
|
+
- Test responsive layouts at standard breakpoints: 320px, 768px, 1024px, 1440px minimum
|
|
50
|
+
- Verify color contrast meets WCAG 2.1 AA (4.5:1 for text, 3:1 for large text) using automated tools
|
|
51
|
+
- Test dark mode by toggling `prefers-color-scheme` in DevTools; verify all text remains readable
|
|
52
|
+
- Use visual regression testing (Percy, Chromatic, or BackstopJS) for component libraries
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: go
|
|
3
|
+
description: Code style and best practice rules for Go.
|
|
4
|
+
globs:
|
|
5
|
+
- "**/*.go"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Go Rules
|
|
9
|
+
|
|
10
|
+
## Style
|
|
11
|
+
- Use `gofmt` and `goimports` on every file; never commit unformatted code
|
|
12
|
+
- Use `MixedCaps` (exported) and `mixedCaps` (unexported); never use underscores in Go names except in test files
|
|
13
|
+
- Keep package names short, lowercase, single-word; the package name should not repeat the import path
|
|
14
|
+
- Place the package comment directly above the `package` declaration in `doc.go` or the primary file
|
|
15
|
+
- Group imports: stdlib, external, internal; separated by blank lines, sorted within each group
|
|
16
|
+
- Declare variables close to where they are first used; avoid package-level `var` unless truly global
|
|
17
|
+
- Keep functions under 50 lines; extract helper functions with descriptive names for complex logic
|
|
18
|
+
- Use named return values only for documentation in short functions; avoid naked returns
|
|
19
|
+
- Receiver names should be one or two letters, consistent across all methods of a type
|
|
20
|
+
- Accept interfaces, return concrete types; define interfaces at the consumer, not the implementer
|
|
21
|
+
|
|
22
|
+
## Patterns
|
|
23
|
+
- Always check errors immediately after the call; never discard with `_` unless you add a comment explaining why
|
|
24
|
+
- Wrap errors with `fmt.Errorf("operation: %w", err)` to build an error chain; use `%w` not `%v`
|
|
25
|
+
- Pass `context.Context` as the first parameter to functions that perform I/O or may be cancelled
|
|
26
|
+
- Use `defer` for cleanup immediately after acquiring a resource; order defers intentionally
|
|
27
|
+
- Use goroutines only with clear ownership; always ensure every goroutine can terminate
|
|
28
|
+
- Use channels for communication between goroutines; use `sync.Mutex` only for protecting shared state
|
|
29
|
+
- Use `sync.WaitGroup` or `errgroup.Group` to wait for concurrent work to complete
|
|
30
|
+
- Prefer `errors.Is()` and `errors.As()` over type assertions or string matching on error messages
|
|
31
|
+
- Use struct embedding for composition, not inheritance; embed interfaces only in concrete types
|
|
32
|
+
- Use `context.WithTimeout` or `context.WithCancel` for all operations that may hang
|
|
33
|
+
- Use `io.Reader` and `io.Writer` interfaces for streaming data; avoid loading entire files into memory
|
|
34
|
+
|
|
35
|
+
## Avoid
|
|
36
|
+
- Never use `init()` functions for anything other than registering drivers or codecs
|
|
37
|
+
- Never use `panic` for expected error conditions; reserve it for truly unrecoverable programmer errors
|
|
38
|
+
- Never use `interface{}` or `any` without immediately asserting or switching on the concrete type
|
|
39
|
+
- Never launch a goroutine without a plan for how it will stop (cancellation, done channel, or context)
|
|
40
|
+
- Never use `time.Sleep` in production code for synchronization; use channels, tickers, or context deadlines
|
|
41
|
+
- Never ignore the second return value from map lookups, type assertions, or channel receives
|
|
42
|
+
- Never use global mutable state; pass dependencies explicitly via function parameters or struct fields
|
|
43
|
+
|
|
44
|
+
## Testing
|
|
45
|
+
- Use table-driven tests with `t.Run` sub-tests for each case; name sub-tests descriptively
|
|
46
|
+
- Use `t.Helper()` in test helper functions so failures report the correct call site
|
|
47
|
+
- Use `t.Parallel()` for tests that do not share state to speed up the test suite
|
|
48
|
+
- Use `testify/assert` or `testify/require` for readable assertions; use `require` for fatal preconditions
|
|
49
|
+
- Use `httptest.NewServer` for HTTP integration tests; never hit real external services
|
|
50
|
+
- Place test fixtures in a `testdata/` directory; Go tooling ignores this directory automatically
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: html
|
|
3
|
+
description: Code style and best practice rules for HTML.
|
|
4
|
+
globs:
|
|
5
|
+
- "**/*.html"
|
|
6
|
+
- "**/*.htm"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# HTML Rules
|
|
10
|
+
|
|
11
|
+
## Style
|
|
12
|
+
- Use lowercase for all element names, attribute names, and attribute values (except `ARIA` and `data-*` values)
|
|
13
|
+
- Use double quotes for attribute values: `class="container"` not `class='container'`
|
|
14
|
+
- Use 2-space indentation for nested elements; never use tabs
|
|
15
|
+
- Place block-level elements on their own line; inline elements may remain on the same line as their parent
|
|
16
|
+
- Include the `lang` attribute on the `<html>` element: `<html lang="en">`
|
|
17
|
+
- Include `<meta charset="UTF-8">` as the first child of `<head>`
|
|
18
|
+
- Include `<meta name="viewport" content="width=device-width, initial-scale=1">` for responsive design
|
|
19
|
+
- Self-close void elements without a slash in HTML5: `<img>`, `<br>`, `<input>`, `<meta>`, `<link>`
|
|
20
|
+
- Order attributes: `id`, `class`, `name`, `data-*`, `src`/`href`, `type`, `alt`/`title`, ARIA, `role`
|
|
21
|
+
- Keep templates under 150 lines; extract reusable partials or components for repeated markup
|
|
22
|
+
|
|
23
|
+
## Patterns
|
|
24
|
+
- Use semantic elements: `<header>`, `<nav>`, `<main>`, `<article>`, `<section>`, `<aside>`, `<footer>` instead of generic `<div>`
|
|
25
|
+
- Use `<button>` for clickable actions and `<a>` for navigation; never use `<div onclick>`
|
|
26
|
+
- Use the `<picture>` element with `<source>` for art direction and format selection (WebP, AVIF fallbacks)
|
|
27
|
+
- Use `loading="lazy"` on images and iframes below the fold; omit it for above-the-fold hero images
|
|
28
|
+
- Use `<label>` explicitly associated with form controls via `for` attribute matching the input `id`
|
|
29
|
+
- Use `<fieldset>` and `<legend>` to group related form controls; use `<optgroup>` in long `<select>` lists
|
|
30
|
+
- Use `<time datetime="2024-01-15">` for machine-readable dates; use `<abbr title="...">` for abbreviations
|
|
31
|
+
- Use `<details>` and `<summary>` for expandable content instead of JavaScript-driven toggles
|
|
32
|
+
- Use `aria-label`, `aria-labelledby`, and `aria-describedby` when visible text does not sufficiently describe an element
|
|
33
|
+
- Use `role="alert"` for dynamic error messages and `role="status"` for non-critical live updates
|
|
34
|
+
- Provide `alt` text on all `<img>` elements; use `alt=""` for decorative images to hide them from screen readers
|
|
35
|
+
|
|
36
|
+
## Avoid
|
|
37
|
+
- Never use `<table>` for layout; tables are for tabular data only
|
|
38
|
+
- Never use `<br>` for spacing; use CSS `margin` or `padding` instead
|
|
39
|
+
- Never use `<b>` or `<i>` for styling; use `<strong>` for importance and `<em>` for emphasis, or use CSS
|
|
40
|
+
- Never omit `alt` attributes on `<img>` elements; missing `alt` fails WCAG 2.1 Level A
|
|
41
|
+
- Never use `autofocus` on elements that are not the primary interaction point of the page
|
|
42
|
+
- Never use `tabindex` values greater than 0; use 0 for focusable elements and -1 for programmatic focus only
|
|
43
|
+
- Never use `target="_blank"` without `rel="noopener noreferrer"` to prevent reverse tabnapping
|
|
44
|
+
- Never nest interactive elements (`<a>` inside `<button>`, `<button>` inside `<a>`)
|
|
45
|
+
- Never use `placeholder` as a substitute for `<label>`; placeholders disappear on focus and lack contrast
|
|
46
|
+
|
|
47
|
+
## Testing
|
|
48
|
+
- Validate HTML with the W3C Markup Validation Service or `html-validate` in CI
|
|
49
|
+
- Run `axe-core` or Lighthouse accessibility audit; fix all critical and serious violations
|
|
50
|
+
- Test keyboard navigation: every interactive element must be reachable with Tab and operable with Enter/Space
|
|
51
|
+
- Test with a screen reader (VoiceOver, NVDA) to verify heading hierarchy, landmark regions, and form labels
|
|
52
|
+
- Verify that the page is functional with CSS disabled; content order and form submission must still work
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: java
|
|
3
|
+
description: Code style and best practice rules for Java.
|
|
4
|
+
globs:
|
|
5
|
+
- "**/*.java"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Java Rules
|
|
9
|
+
|
|
10
|
+
## Style
|
|
11
|
+
- Use `PascalCase` for classes and interfaces; `camelCase` for methods and variables; `UPPER_SNAKE_CASE` for static final constants
|
|
12
|
+
- One top-level class per file; the file name must match the class name exactly
|
|
13
|
+
- Use `var` for local variables when the type is obvious from the right-hand side
|
|
14
|
+
- Order class members: static fields, instance fields, constructors, public methods, private methods
|
|
15
|
+
- Keep methods under 30 lines; extract private helper methods for complex logic
|
|
16
|
+
- Use `record` types for immutable data carriers instead of classes with manual getters/equals/hashCode
|
|
17
|
+
- Annotate overridden methods with `@Override`; annotate nullable parameters and returns with `@Nullable`
|
|
18
|
+
- Use `sealed` classes and `permits` to restrict class hierarchies for domain modeling
|
|
19
|
+
- Write Javadoc on all public classes and methods; include `@param`, `@return`, and `@throws` tags
|
|
20
|
+
- Use diamond operator (`<>`) for generic type inference; never repeat type parameters on both sides
|
|
21
|
+
|
|
22
|
+
## Patterns
|
|
23
|
+
- Use `Optional<T>` as a return type for methods that may not produce a value; never use it as a field or parameter type
|
|
24
|
+
- Use `try-with-resources` for all `AutoCloseable` resources: streams, connections, readers
|
|
25
|
+
- Use Stream API for collection transformations; prefer method references over lambdas when the body is a single call
|
|
26
|
+
- Use `switch` expressions (Java 14+) with arrow syntax and exhaustive cases for enum and sealed class dispatch
|
|
27
|
+
- Throw specific checked exceptions for recoverable errors; use unchecked exceptions for programming errors
|
|
28
|
+
- Use `CompletableFuture` for async composition; avoid raw `Thread` creation
|
|
29
|
+
- Use the `java.time` API exclusively for dates and times; never use `java.util.Date` or `Calendar`
|
|
30
|
+
- Use `List.of()`, `Map.of()`, `Set.of()` for immutable collections; use `List.copyOf()` for defensive copies
|
|
31
|
+
- Prefer composition over inheritance; inject dependencies via constructor parameters
|
|
32
|
+
- Use `String.formatted()` or `MessageFormat` for parameterized strings; avoid concatenation in loops
|
|
33
|
+
- Validate method preconditions with `Objects.requireNonNull()` and guard clauses at method entry
|
|
34
|
+
|
|
35
|
+
## Avoid
|
|
36
|
+
- Never return `null` from a method that returns a collection; return an empty collection instead
|
|
37
|
+
- Never catch `Exception` or `Throwable` broadly; catch the most specific exception type
|
|
38
|
+
- Never use raw types (`List` instead of `List<String>`); always specify generic type parameters
|
|
39
|
+
- Never use `synchronized` methods; use `java.util.concurrent` locks or concurrent collections
|
|
40
|
+
- Never use `finalize()`; use `try-with-resources` or `Cleaner` for cleanup
|
|
41
|
+
- Never use `==` to compare objects; use `.equals()` and override `hashCode` when overriding `equals`
|
|
42
|
+
- Never swallow exceptions with empty catch blocks; log at minimum, rethrow if appropriate
|
|
43
|
+
- Never use `Thread.stop()` or `Thread.suspend()`; use interruption and cooperative cancellation
|
|
44
|
+
|
|
45
|
+
## Testing
|
|
46
|
+
- Use JUnit 5 (`@Test`, `@BeforeEach`, `@DisplayName`); migrate away from JUnit 4 annotations
|
|
47
|
+
- Name tests with `@DisplayName` using plain English: `@DisplayName("rejects negative withdrawal amounts")`
|
|
48
|
+
- Use `assertThrows` to verify exception type and message; prefer specific assertions over `assertTrue`
|
|
49
|
+
- Use `@ParameterizedTest` with `@CsvSource` or `@MethodSource` for data-driven tests
|
|
50
|
+
- Use Mockito's `verify()` sparingly; prefer testing observable outcomes over interaction verification
|
|
51
|
+
- Use `@Nested` inner classes to group related test cases by scenario
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: kotlin
|
|
3
|
+
description: Code style and best practice rules for Kotlin.
|
|
4
|
+
globs:
|
|
5
|
+
- "**/*.kt"
|
|
6
|
+
- "**/*.kts"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Kotlin Rules
|
|
10
|
+
|
|
11
|
+
## Style
|
|
12
|
+
- Use `PascalCase` for classes, interfaces, and objects; `camelCase` for functions and properties; `UPPER_SNAKE_CASE` for compile-time constants (`const val`)
|
|
13
|
+
- Use `data class` for value objects with structural equality; keep them in their own file or co-located with the primary consumer
|
|
14
|
+
- Prefer expression body syntax (`fun x() = ...`) for single-expression functions
|
|
15
|
+
- Place extension functions in a separate file named `<Type>Extensions.kt` when they are reusable across modules
|
|
16
|
+
- Order class members: companion object, properties, init blocks, constructors, public functions, private functions
|
|
17
|
+
- Use trailing commas in multi-line parameter lists, argument lists, and when-branches for cleaner diffs
|
|
18
|
+
- Keep files under 200 lines; split large classes into focused interfaces and implementations
|
|
19
|
+
- Use `internal` visibility for module-scoped API; default to `private` for implementation details
|
|
20
|
+
- Annotate platform types from Java interop with explicit nullability (`String?` or `String`)
|
|
21
|
+
- Use backtick-quoted test names for readability: `` `should return empty list when no items match` ``
|
|
22
|
+
|
|
23
|
+
## Patterns
|
|
24
|
+
- Use `sealed class` or `sealed interface` for restricted type hierarchies; use `when` exhaustively without `else`
|
|
25
|
+
- Use `?.let { }`, `?.run { }`, or `?: return` for null handling instead of nested if-null checks
|
|
26
|
+
- Use `require()` for argument validation and `check()` for state validation; both throw descriptive exceptions
|
|
27
|
+
- Use coroutines with structured concurrency (`coroutineScope`, `supervisorScope`); never launch fire-and-forget jobs
|
|
28
|
+
- Use `Flow` for cold asynchronous streams; use `StateFlow` and `SharedFlow` for hot state
|
|
29
|
+
- Use `apply` for object configuration, `let` for null-safe transformations, `also` for side effects, `run` for scoped computation
|
|
30
|
+
- Use `sequence { yield() }` for lazily computed collections instead of building full lists
|
|
31
|
+
- Prefer `List`, `Map`, `Set` (read-only interfaces) in API signatures; use `MutableList` only internally
|
|
32
|
+
- Use `Result<T>` or `runCatching` for operations that may fail; propagate errors with `fold` or `getOrElse`
|
|
33
|
+
- Use `by lazy` for expensive property initialization that should happen at most once
|
|
34
|
+
- Use `typealias` to simplify complex generic signatures at module boundaries
|
|
35
|
+
|
|
36
|
+
## Avoid
|
|
37
|
+
- Never use `!!` (not-null assertion) except in tests or where a null value is a genuine programmer error with an obvious fix
|
|
38
|
+
- Never use `var` for properties that do not change after initialization; use `val` everywhere possible
|
|
39
|
+
- Never catch `Exception` broadly; catch specific exception types and rethrow `CancellationException` in coroutines
|
|
40
|
+
- Never use Java collection types (`java.util.ArrayList`) directly; use Kotlin stdlib collection functions
|
|
41
|
+
- Never use `companion object` as a namespace for unrelated utility functions; use top-level functions instead
|
|
42
|
+
- Never use string concatenation in loops; use `StringBuilder` or `buildString { }`
|
|
43
|
+
- Never call blocking I/O from coroutines without wrapping in `withContext(Dispatchers.IO)`
|
|
44
|
+
|
|
45
|
+
## Testing
|
|
46
|
+
- Use JUnit 5 with Kotlin; prefer `kotest` assertions for more idiomatic test code
|
|
47
|
+
- Use `@ParameterizedTest` or Kotest's `forAll` for property-based and data-driven tests
|
|
48
|
+
- Test coroutine code with `runTest` from `kotlinx-coroutines-test`; use `advanceUntilIdle()` for time-based tests
|
|
49
|
+
- Use `mockk` over Mockito for mocking; prefer `coEvery` and `coVerify` for suspending functions
|
|
50
|
+
- Verify sealed-class exhaustiveness in tests by covering every subtype in dedicated test cases
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: php
|
|
3
|
+
description: Code style and best practice rules for PHP.
|
|
4
|
+
globs:
|
|
5
|
+
- "**/*.php"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# PHP Rules
|
|
9
|
+
|
|
10
|
+
## Style
|
|
11
|
+
- Follow PSR-12 coding style; enforce with PHP-CS-Fixer or PHP_CodeSniffer in CI
|
|
12
|
+
- Use `PascalCase` for classes, interfaces, traits, and enums; `camelCase` for methods and properties; `UPPER_SNAKE_CASE` for class constants
|
|
13
|
+
- Declare `strict_types=1` at the top of every file: `declare(strict_types=1);`
|
|
14
|
+
- Add type declarations to all function parameters, return types, and class properties; never omit types
|
|
15
|
+
- One class per file; the file name must match the class name and follow PSR-4 autoloading
|
|
16
|
+
- Use `readonly` properties (PHP 8.1+) for immutable data; prefer constructor promotion for brevity
|
|
17
|
+
- Order `use` imports alphabetically; group classes, functions, and constants with blank lines
|
|
18
|
+
- Keep methods under 25 lines; extract private methods for complex logic
|
|
19
|
+
- Use `enum` (PHP 8.1+) backed by `string` or `int` instead of class constants for finite value sets
|
|
20
|
+
- Place the opening brace on the same line for control structures, next line for classes and methods (PSR-12)
|
|
21
|
+
|
|
22
|
+
## Patterns
|
|
23
|
+
- Use `match` expressions instead of `switch` for value-returning conditionals; `match` is strict and exhaustive
|
|
24
|
+
- Use named arguments for functions with boolean flags or multiple optional parameters: `array_slice(array: $a, offset: 2)`
|
|
25
|
+
- Use PHP 8 attributes (`#[Route('/api')]`) instead of docblock annotations for metadata
|
|
26
|
+
- Use `null` coalescing (`??`) and nullsafe operator (`?->`) for null handling chains
|
|
27
|
+
- Use constructor property promotion to reduce boilerplate in value objects and DTOs
|
|
28
|
+
- Use `array_map`, `array_filter`, `array_reduce` with arrow functions (`fn($x) => $x * 2`) for collection operations
|
|
29
|
+
- Throw specific domain exceptions extending a base exception; catch at the boundary layer
|
|
30
|
+
- Use dependency injection via constructor; never use service locators or global `app()` helpers in domain code
|
|
31
|
+
- Use generators (`yield`) for processing large datasets without loading everything into memory
|
|
32
|
+
- Use `DateTimeImmutable` exclusively; never use mutable `DateTime`
|
|
33
|
+
- Use `Stringable` interface and `__toString()` for objects that represent displayable values
|
|
34
|
+
|
|
35
|
+
## Avoid
|
|
36
|
+
- Never use `@` error suppression operator; handle errors explicitly or configure error reporting
|
|
37
|
+
- Never use `eval()`, `extract()`, or `compact()` in application code
|
|
38
|
+
- Never compare with `==` for type-sensitive values; always use `===` (strict equality)
|
|
39
|
+
- Never use global variables or the `global` keyword; pass dependencies through function parameters
|
|
40
|
+
- Never use `array` when a typed collection class or DTO would be clearer
|
|
41
|
+
- Never concatenate user input into SQL queries; use prepared statements with parameter binding
|
|
42
|
+
- Never use `die()` or `exit()` in library code; throw an exception instead
|
|
43
|
+
- Never suppress PHPStan/Psalm errors without a documented justification
|
|
44
|
+
|
|
45
|
+
## Testing
|
|
46
|
+
- Use PHPUnit with `#[Test]` attributes (PHPUnit 10+); name methods descriptively: `testRejectsExpiredToken()`
|
|
47
|
+
- Use `#[DataProvider]` for parameterized tests instead of loops inside test methods
|
|
48
|
+
- Assert specific exception classes and messages with `$this->expectException()` and `$this->expectExceptionMessage()`
|
|
49
|
+
- Use `setUp()` for shared fixtures; avoid shared state between test methods
|
|
50
|
+
- Mock interfaces at boundaries with PHPUnit mocks or Mockery; never mock the class under test
|
|
51
|
+
- Run tests with `--strict-coverage` and `--fail-on-risky` to catch untested code paths
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: python
|
|
3
|
+
description: Code style and best practice rules for Python.
|
|
4
|
+
globs:
|
|
5
|
+
- "**/*.py"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Python Rules
|
|
9
|
+
|
|
10
|
+
## Style
|
|
11
|
+
- Use `snake_case` for functions, variables, and modules; `PascalCase` for classes; `UPPER_SNAKE_CASE` for module-level constants
|
|
12
|
+
- Add type hints to all function signatures including return types; use `-> None` explicitly for procedures
|
|
13
|
+
- Use `dataclasses` or `attrs` for data containers instead of plain dicts or tuples with index access
|
|
14
|
+
- Keep imports grouped: stdlib, third-party, local; one import per line, sorted alphabetically within each group
|
|
15
|
+
- Limit line length to 88 characters (Black default); use implicit line continuation inside brackets
|
|
16
|
+
- Place module docstrings at the top; use Google-style docstrings for public functions and classes
|
|
17
|
+
- Use `__all__` in modules to declare the public API explicitly
|
|
18
|
+
- Define constants at module level, never inside functions unless scoped for performance
|
|
19
|
+
- One class per file for major classes; group small related classes together
|
|
20
|
+
- Use f-strings for all string formatting; never use `%` formatting or `.format()` in new code
|
|
21
|
+
|
|
22
|
+
## Patterns
|
|
23
|
+
- Use `pathlib.Path` instead of `os.path` for all filesystem operations
|
|
24
|
+
- Use context managers (`with` statements) for all resource acquisition: files, locks, database connections
|
|
25
|
+
- Prefer list/dict/set comprehensions over `map()` and `filter()` for simple transformations
|
|
26
|
+
- Use `match`/`case` statements (Python 3.10+) for structural pattern matching on complex data
|
|
27
|
+
- Use `Enum` or `StrEnum` for finite sets of related constants instead of bare strings
|
|
28
|
+
- Raise specific exceptions with descriptive messages; create custom exception classes per domain
|
|
29
|
+
- Use `functools.lru_cache` or `functools.cache` for expensive pure computations
|
|
30
|
+
- Use `typing.Protocol` for structural subtyping instead of ABC when only method signatures matter
|
|
31
|
+
- Return early from functions to reduce nesting; guard clauses go at the top
|
|
32
|
+
- Use `itertools` and generator expressions for lazy evaluation of large sequences
|
|
33
|
+
- Use `collections.defaultdict` instead of manual key-existence checks when building aggregations
|
|
34
|
+
|
|
35
|
+
## Avoid
|
|
36
|
+
- Never use mutable default arguments (`def f(items=[])`); use `None` and assign inside the function
|
|
37
|
+
- Never use bare `except:` or `except Exception:`; catch the most specific exception type
|
|
38
|
+
- Never use `global` or `nonlocal` for state management; pass state explicitly or use a class
|
|
39
|
+
- Never use `type()` for type checks; use `isinstance()` with a tuple of types
|
|
40
|
+
- Never use wildcard imports (`from module import *`); import specific names
|
|
41
|
+
- Never store secrets or credentials in source code; use environment variables or a secrets manager
|
|
42
|
+
- Never use `eval()` or `exec()` on untrusted input
|
|
43
|
+
- Never ignore return values of functions that indicate success/failure
|
|
44
|
+
|
|
45
|
+
## Testing
|
|
46
|
+
- Use `pytest` with fixtures; avoid `unittest.TestCase` unless integrating with legacy code
|
|
47
|
+
- Name test files `test_<module>.py` and test functions `test_<behavior>_<scenario>`
|
|
48
|
+
- Use `pytest.raises` as a context manager to test exceptions, checking both type and message
|
|
49
|
+
- Use `pytest.mark.parametrize` for data-driven tests instead of loops inside test functions
|
|
50
|
+
- Use `tmp_path` fixture for filesystem tests; never write to the real filesystem
|
|
51
|
+
- Mock external services with `unittest.mock.patch` at the call site, not the definition site
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ruby
|
|
3
|
+
description: Code style and best practice rules for Ruby.
|
|
4
|
+
globs:
|
|
5
|
+
- "**/*.rb"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Ruby Rules
|
|
9
|
+
|
|
10
|
+
## Style
|
|
11
|
+
- Use `snake_case` for methods, variables, and file names; `PascalCase` for classes and modules; `SCREAMING_SNAKE_CASE` for constants
|
|
12
|
+
- Add `# frozen_string_literal: true` magic comment to the top of every file
|
|
13
|
+
- Keep methods under 15 lines; extract private methods with descriptive names for complex logic
|
|
14
|
+
- Use 2-space indentation; never use tabs
|
|
15
|
+
- Prefer `do...end` for multi-line blocks and `{ }` for single-line blocks
|
|
16
|
+
- Define one class or module per file; nest modules to match the directory structure
|
|
17
|
+
- Use keyword arguments for methods with more than two parameters or when parameter meaning is ambiguous
|
|
18
|
+
- Document public methods with YARD (`@param`, `@return`, `@raise`) comments
|
|
19
|
+
- Limit line length to 120 characters; break long method chains with trailing dots
|
|
20
|
+
- Order class contents: constants, includes/extends, attribute accessors, class methods, public methods, protected methods, private methods
|
|
21
|
+
|
|
22
|
+
## Patterns
|
|
23
|
+
- Use pattern matching (`case...in`) for destructuring hashes and arrays (Ruby 3.0+)
|
|
24
|
+
- Use `Struct` or `Data.define` (Ruby 3.2+) for simple value objects; use full classes only when behavior is needed
|
|
25
|
+
- Use `Enumerable` methods (`map`, `select`, `reduce`) instead of manual loops with `each` and mutation
|
|
26
|
+
- Use `begin...rescue...ensure` for error handling; rescue specific exception classes, not `StandardError` broadly
|
|
27
|
+
- Use `Module#prepend` for method wrapping instead of `alias_method_chain` or monkey patching
|
|
28
|
+
- Return `nil` only when absence is meaningful; raise an exception for error conditions
|
|
29
|
+
- Use `Comparable` and `<=>` for custom ordering; implement `hash` and `eql?` for hash key usage
|
|
30
|
+
- Use `StringIO` for in-memory I/O in tests; use `Tempfile` for filesystem tests
|
|
31
|
+
- Prefer `fetch` over `[]` for hash access when the key must exist; use `fetch` with a default for optional keys
|
|
32
|
+
- Use `freeze` on constants that are arrays or hashes to prevent accidental mutation
|
|
33
|
+
- Use `tap` for object initialization chains that return the object itself
|
|
34
|
+
|
|
35
|
+
## Avoid
|
|
36
|
+
- Never use `eval`, `class_eval`, or `instance_eval` with string arguments; use block forms if metaprogramming is necessary
|
|
37
|
+
- Never rescue `Exception`; rescue `StandardError` or a more specific subclass
|
|
38
|
+
- Never use `and`/`or` for control flow; use `&&`/`||` for boolean logic and `if`/`unless` for control flow
|
|
39
|
+
- Never mutate method arguments; return a new value instead
|
|
40
|
+
- Never use `for...in` loops; use `each` or other `Enumerable` methods
|
|
41
|
+
- Never use global variables (`$foo`); pass state explicitly through method parameters
|
|
42
|
+
- Never open classes to monkeypatch in library code; use `Refinements` if modification is required
|
|
43
|
+
- Never use `Thread` directly for concurrency; use `Concurrent::Ruby` primitives or Ractors
|
|
44
|
+
|
|
45
|
+
## Testing
|
|
46
|
+
- Use RSpec with `describe`/`context`/`it` blocks; write expectations as `expect(result).to eq(expected)`
|
|
47
|
+
- Use `let` for lazy fixtures and `let!` for eager fixtures; avoid `before` blocks that build too much state
|
|
48
|
+
- Use `shared_examples` for behavior shared across multiple contexts; include them with `it_behaves_like`
|
|
49
|
+
- Use `instance_double` and `class_double` for type-checked mocks; avoid `allow_any_instance_of`
|
|
50
|
+
- Use `aggregate_failures` to report all assertion failures in a single example, not just the first
|
|
51
|
+
- Use Sorbet type signatures (`sig { params(...).returns(...) }`) for public API methods and verify in CI with `srb tc`
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: rust
|
|
3
|
+
description: Code style and best practice rules for Rust.
|
|
4
|
+
globs:
|
|
5
|
+
- "**/*.rs"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Rust Rules
|
|
9
|
+
|
|
10
|
+
## Style
|
|
11
|
+
- Use `snake_case` for functions, variables, and modules; `PascalCase` for types, traits, and enums; `SCREAMING_SNAKE_CASE` for constants and statics
|
|
12
|
+
- Run `cargo fmt` on every file before committing; configure `rustfmt.toml` for the project
|
|
13
|
+
- Run `cargo clippy -- -D warnings` and fix all lints; do not suppress lints without a `#[allow()]` comment explaining why
|
|
14
|
+
- Keep functions under 40 lines; extract helper functions or closures for complex logic
|
|
15
|
+
- Use module files (`mod.rs` or `module_name.rs`) to organize code by responsibility; re-export public API from `lib.rs`
|
|
16
|
+
- Place `use` statements at the top: `std`, external crates, internal modules; sorted alphabetically within groups
|
|
17
|
+
- Document all public items with `///` doc comments; include examples in `# Examples` sections that compile as doctests
|
|
18
|
+
- Prefer turbofish (`::<Type>`) only when inference fails; let the compiler infer types when unambiguous
|
|
19
|
+
- Use `pub(crate)` for items shared within the crate but not part of the public API
|
|
20
|
+
|
|
21
|
+
## Patterns
|
|
22
|
+
- Use `Result<T, E>` for fallible operations; define domain error types with `thiserror::Error` for libraries, use `anyhow::Result` for applications
|
|
23
|
+
- Use `Option<T>` instead of sentinel values; chain operations with `.map()`, `.and_then()`, `.unwrap_or_default()`
|
|
24
|
+
- Use the `?` operator for early error propagation; avoid manual match-on-Result boilerplate
|
|
25
|
+
- Implement traits for shared behavior; prefer trait bounds (`impl Trait` or `where T: Trait`) over dynamic dispatch (`dyn Trait`) unless object safety requires it
|
|
26
|
+
- Use `enum` with variants carrying data for state machines; implement methods on the enum to enforce valid transitions
|
|
27
|
+
- Use iterators and combinators (`.filter()`, `.map()`, `.collect()`) over manual loops for transformations
|
|
28
|
+
- Use `Arc<Mutex<T>>` for shared mutable state across threads; prefer channels (`mpsc`, `crossbeam`) for message passing
|
|
29
|
+
- Use `#[derive(...)]` for `Debug`, `Clone`, `PartialEq`, and `Eq` on data types; derive `Serialize`/`Deserialize` for I/O boundaries
|
|
30
|
+
- Use builder pattern for types with many optional configuration fields
|
|
31
|
+
- Use `Cow<'_, str>` when a function may or may not need to allocate a new string
|
|
32
|
+
- Use `impl Into<T>` for function parameters to accept both owned and borrowed values ergonomically
|
|
33
|
+
|
|
34
|
+
## Avoid
|
|
35
|
+
- Never use `unwrap()` or `expect()` in library code; reserve them for tests and provably infallible cases with a comment
|
|
36
|
+
- Never use `unsafe` without a `// SAFETY:` comment proving the invariant; prefer safe abstractions
|
|
37
|
+
- Never use `clone()` to fix borrow checker errors without understanding the ownership model; restructure the code instead
|
|
38
|
+
- Never leak resources by holding `MutexGuard` across `.await` points; restructure to drop the guard before awaiting
|
|
39
|
+
- Never use `String` where `&str` suffices in function parameters; accept the borrowed form
|
|
40
|
+
- Never ignore compiler warnings; treat `#[deny(warnings)]` as the baseline for CI
|
|
41
|
+
- Never use `Box<dyn Error>` as a return type in libraries; use a concrete error enum
|
|
42
|
+
|
|
43
|
+
## Testing
|
|
44
|
+
- Place unit tests in a `#[cfg(test)] mod tests` block at the bottom of each source file
|
|
45
|
+
- Place integration tests in the `tests/` directory; each file compiles as a separate crate
|
|
46
|
+
- Use `#[should_panic(expected = "message")]` for panic tests; use `assert!(result.is_err())` for Result tests
|
|
47
|
+
- Use `proptest` or `quickcheck` for property-based testing of pure functions
|
|
48
|
+
- Use `mockall` for trait mocking; define traits at boundaries (HTTP, DB) to enable testability
|
|
49
|
+
- Run `cargo test --all-features` in CI to ensure no feature flag combination breaks
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: shell
|
|
3
|
+
description: Code style and best practice rules for Shell scripts.
|
|
4
|
+
globs:
|
|
5
|
+
- "**/*.sh"
|
|
6
|
+
- "**/*.bash"
|
|
7
|
+
- "**/*.zsh"
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Shell Rules
|
|
11
|
+
|
|
12
|
+
## Style
|
|
13
|
+
- Start every script with a shebang: `#!/usr/bin/env bash` for portability; use `#!/usr/bin/env zsh` only for zsh-specific scripts
|
|
14
|
+
- Set strict mode at the top: `set -euo pipefail` to fail on errors, unset variables, and pipe failures
|
|
15
|
+
- Use `snake_case` for function names and local variables; `UPPER_SNAKE_CASE` for exported environment variables and constants
|
|
16
|
+
- Indent with 2 spaces; never use tabs
|
|
17
|
+
- Keep scripts under 200 lines; split complex workflows into multiple scripts or functions
|
|
18
|
+
- Add a usage comment block at the top of every script describing purpose, arguments, and examples
|
|
19
|
+
- Use `local` keyword for all variables inside functions to avoid polluting the global scope
|
|
20
|
+
- Quote all variable expansions: `"${var}"` not `$var`; this prevents word splitting and glob expansion
|
|
21
|
+
- Place `main()` function at the bottom of the script; call it with `main "$@"` as the last line
|
|
22
|
+
- Group related functions together; define utility functions before the functions that call them
|
|
23
|
+
|
|
24
|
+
## Patterns
|
|
25
|
+
- Use `readonly` for constants: `readonly CONFIG_DIR="/etc/myapp"`
|
|
26
|
+
- Use `trap` for cleanup on exit: `trap cleanup EXIT` with a cleanup function that removes temp files and restores state
|
|
27
|
+
- Use `mktemp` for temporary files and directories: `tmpdir=$(mktemp -d)` instead of hardcoded `/tmp/foo`
|
|
28
|
+
- Use `"${variable:-default}"` for default values; use `"${variable:?error message}"` for required variables
|
|
29
|
+
- Use `[[ ]]` for conditionals instead of `[ ]`; it handles empty strings and regex without quoting issues
|
|
30
|
+
- Use `printf` instead of `echo` for portable, format-controlled output; `echo` behavior varies across shells
|
|
31
|
+
- Use `command -v` to check if a program exists instead of `which`; it is POSIX-compliant
|
|
32
|
+
- Use `while IFS= read -r line` for reading files line by line; never use `for line in $(cat file)`
|
|
33
|
+
- Use arrays for lists of items: `files=("a.txt" "b.txt")` and iterate with `for f in "${files[@]}"`
|
|
34
|
+
- Use `getopts` or a manual `case` loop for argument parsing; document every flag
|
|
35
|
+
- Use `shellcheck` as a mandatory CI lint step; fix all warnings before merging
|
|
36
|
+
|
|
37
|
+
## Avoid
|
|
38
|
+
- Never use backticks for command substitution; use `$(command)` for nesting and readability
|
|
39
|
+
- Never use `eval`; it creates injection vulnerabilities and makes code impossible to reason about
|
|
40
|
+
- Never parse `ls` output; use globbing (`for f in *.txt`) or `find` with `-print0` and `xargs -0`
|
|
41
|
+
- Never use unquoted variables in conditionals, assignments, or command arguments
|
|
42
|
+
- Never hardcode paths like `/home/user/`; use `$HOME`, `$(dirname "$0")`, or environment variables
|
|
43
|
+
- Never write to files without checking if the target directory exists; create with `mkdir -p` first
|
|
44
|
+
- Never pipe `find` results into `xargs` without `-print0` and `-0`; filenames may contain spaces or newlines
|
|
45
|
+
- Never use `cd` without checking return value; use `cd /path || exit 1` or `pushd`/`popd`
|
|
46
|
+
|
|
47
|
+
## Testing
|
|
48
|
+
- Use `bats` (Bash Automated Testing System) for structured shell testing; one `.bats` file per script
|
|
49
|
+
- Test exit codes explicitly: `run my_command; [ "$status" -eq 0 ]`
|
|
50
|
+
- Use `setup()` and `teardown()` functions in bats for fixture creation and cleanup
|
|
51
|
+
- Test error conditions by providing invalid input and asserting non-zero exit codes and stderr messages
|
|
52
|
+
- Run `shellcheck --severity=warning` on all scripts in CI; treat warnings as errors
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sql
|
|
3
|
+
description: Code style and best practice rules for SQL.
|
|
4
|
+
globs:
|
|
5
|
+
- "**/*.sql"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# SQL Rules
|
|
9
|
+
|
|
10
|
+
## Style
|
|
11
|
+
- Write SQL keywords in uppercase: `SELECT`, `FROM`, `WHERE`, `JOIN`, `INSERT`, `UPDATE`, `DELETE`
|
|
12
|
+
- Use `snake_case` for table names, column names, indexes, and constraints; never use spaces or mixed case
|
|
13
|
+
- Name tables as plural nouns (`users`, `orders`); name join tables as `left_right` (`user_roles`)
|
|
14
|
+
- Prefix boolean columns with `is_`, `has_`, or `can_`: `is_active`, `has_subscription`
|
|
15
|
+
- Name primary keys `id`; name foreign keys `<referenced_table_singular>_id`: `user_id`, `order_id`
|
|
16
|
+
- Place each major clause (`SELECT`, `FROM`, `WHERE`, `JOIN`, `GROUP BY`, `ORDER BY`) on its own line
|
|
17
|
+
- Indent joined tables and sub-conditions by 2 or 4 spaces consistently throughout the project
|
|
18
|
+
- Name constraints explicitly: `pk_users`, `fk_orders_user_id`, `uq_users_email`, `idx_orders_created_at`
|
|
19
|
+
- Use `-- comment` for single-line comments above the clause they describe; avoid inline comments after code
|
|
20
|
+
- Add a trailing semicolon to every statement; separate statements with a blank line
|
|
21
|
+
|
|
22
|
+
## Patterns
|
|
23
|
+
- Use Common Table Expressions (CTEs) with `WITH` instead of nested subqueries for readability
|
|
24
|
+
- Use explicit `JOIN ... ON` syntax; never use implicit joins with comma-separated tables in `FROM`
|
|
25
|
+
- Use `COALESCE()` to provide default values for nullable columns in result sets
|
|
26
|
+
- Use `EXISTS` instead of `IN` with subqueries for better query plan optimization on large tables
|
|
27
|
+
- Use parameterized queries (`$1`, `?`, or `:name`) for all user-supplied values; never interpolate strings
|
|
28
|
+
- Use `RETURNING` clause (PostgreSQL) on `INSERT`, `UPDATE`, `DELETE` to avoid a separate `SELECT`
|
|
29
|
+
- Use `ON CONFLICT ... DO UPDATE` (upsert) instead of check-then-insert patterns to avoid race conditions
|
|
30
|
+
- Use window functions (`ROW_NUMBER()`, `RANK()`, `LAG()`, `LEAD()`) instead of self-joins for row-relative calculations
|
|
31
|
+
- Use `LIMIT` with `OFFSET` only for small result sets; use keyset pagination (`WHERE id > $last_id`) for large tables
|
|
32
|
+
- Add `NOT NULL` constraints to every column unless null has an explicit domain meaning
|
|
33
|
+
- Use `TIMESTAMP WITH TIME ZONE` (`TIMESTAMPTZ`) for all datetime columns; store times in UTC
|
|
34
|
+
|
|
35
|
+
## Avoid
|
|
36
|
+
- Never use `SELECT *` in application queries; list columns explicitly to avoid breakage on schema changes
|
|
37
|
+
- Never store comma-separated values in a single column; normalize into a related table
|
|
38
|
+
- Never use `FLOAT` or `DOUBLE` for monetary values; use `NUMERIC(precision, scale)` or `DECIMAL`
|
|
39
|
+
- Never use `TRUNCATE` or `DELETE` without a `WHERE` clause unless intentionally clearing the entire table
|
|
40
|
+
- Never rely on implicit type coercion; cast explicitly with `CAST(column AS type)` when types differ
|
|
41
|
+
- Never create indexes on every column; index only columns used in `WHERE`, `JOIN`, and `ORDER BY` clauses
|
|
42
|
+
- Never use reserved words (`user`, `order`, `group`) as unquoted identifiers; rename or quote them
|
|
43
|
+
|
|
44
|
+
## Testing
|
|
45
|
+
- Write migration rollback (`DOWN`) scripts for every `UP` migration; test both directions
|
|
46
|
+
- Use a dedicated test database seeded with deterministic fixture data; never test against production
|
|
47
|
+
- Verify query plans with `EXPLAIN ANALYZE` for queries on tables expected to exceed 10,000 rows
|
|
48
|
+
- Test constraints by asserting that invalid inserts raise the expected constraint violation error
|
|
49
|
+
- Use transactions with `ROLLBACK` in test harnesses to isolate tests without leaving residual data
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: swift
|
|
3
|
+
description: Code style and best practice rules for Swift.
|
|
4
|
+
globs:
|
|
5
|
+
- "**/*.swift"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Swift Rules
|
|
9
|
+
|
|
10
|
+
## Style
|
|
11
|
+
- Use `PascalCase` for types, protocols, and enum cases; `camelCase` for functions, properties, and variables
|
|
12
|
+
- Use `struct` by default for data models; use `class` only when reference semantics or inheritance is required
|
|
13
|
+
- Keep functions under 30 lines; extract helper functions with clear names for complex logic
|
|
14
|
+
- Place extensions in the same file as the type for protocol conformance; use separate files for large extensions
|
|
15
|
+
- Mark access levels explicitly: `private` for implementation details, `internal` (default) for module-scoped, `public` for API
|
|
16
|
+
- Use trailing closure syntax when the last parameter is a closure; use labeled arguments for multiple closure parameters
|
|
17
|
+
- Group properties at the top of a type: stored properties first, then computed properties, then methods
|
|
18
|
+
- Use `// MARK: -` comments to organize sections within large files
|
|
19
|
+
- Prefer `let` over `var` everywhere; use `var` only when mutation is necessary
|
|
20
|
+
- Limit files to 400 lines; split large types into extensions organized by protocol conformance
|
|
21
|
+
|
|
22
|
+
## Patterns
|
|
23
|
+
- Use protocol-oriented design: define protocols for shared behavior, provide default implementations in extensions
|
|
24
|
+
- Use `guard` clauses for early exits instead of nested `if` statements; place guards at the top of the function
|
|
25
|
+
- Use `async`/`await` for all asynchronous work; prefer structured concurrency with `TaskGroup` over unstructured `Task { }`
|
|
26
|
+
- Use `Codable` with custom `CodingKeys` for JSON serialization; use `JSONDecoder`/`JSONEncoder` with `keyDecodingStrategy`
|
|
27
|
+
- Use `Result<Success, Failure>` when a function needs to return success or a typed error; use `throws` for simple cases
|
|
28
|
+
- Use `@MainActor` for UI-related code; use `Sendable` conformance for types passed across concurrency boundaries
|
|
29
|
+
- Use `enum` without cases as a namespace for static utility functions and constants
|
|
30
|
+
- Use `weak self` in closures that capture `self` and may outlive the owner; use `[weak self]` capture lists explicitly
|
|
31
|
+
- Use `map`, `compactMap`, `filter`, `reduce` on collections instead of manual loop-and-append
|
|
32
|
+
- Use `@Published` and `ObservableObject` for SwiftUI state management; keep view models as separate classes
|
|
33
|
+
- Use `defer` for cleanup code that must run regardless of how a scope exits
|
|
34
|
+
|
|
35
|
+
## Avoid
|
|
36
|
+
- Never force-unwrap (`!`) optionals outside of tests or `IBOutlet` declarations; use `guard let` or `if let`
|
|
37
|
+
- Never use `Any` or `AnyObject` when a protocol or generic constraint can express the requirement
|
|
38
|
+
- Never use `class` inheritance hierarchies deeper than two levels; prefer composition with protocols
|
|
39
|
+
- Never use `NSNotificationCenter` string-based notifications; use `Combine` publishers or `async` streams
|
|
40
|
+
- Never perform synchronous I/O on the main thread; use `Task` or `DispatchQueue.global()` for background work
|
|
41
|
+
- Never use singletons for testable dependencies; inject them through initializers
|
|
42
|
+
- Never use implicitly unwrapped optionals (`String!`) except for `@IBOutlet` or two-phase initialization
|
|
43
|
+
|
|
44
|
+
## Testing
|
|
45
|
+
- Use XCTest with descriptive names: `func testLogin_withExpiredToken_returnsAuthError()`
|
|
46
|
+
- Use `XCTAssertEqual` with specific values; avoid `XCTAssertTrue` for equality checks
|
|
47
|
+
- Use `async` test methods for testing async code; use `XCTestExpectation` only for callback-based APIs
|
|
48
|
+
- Test SwiftUI views with `ViewInspector` or snapshot tests; test view models independently with unit tests
|
|
49
|
+
- Use protocol-based dependency injection to swap real services for test doubles
|
|
50
|
+
- Use `throws` in test methods and `XCTUnwrap` instead of force-unwrapping in test assertions
|