-
Notifications
You must be signed in to change notification settings - Fork 24
Add cursor rules for development / testing #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kieran-osgood-shopify
merged 5 commits into
main
from
kieran-osgood/chore/add-cursor-rules
Jul 24, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0e10b59
feat: add cursor rules for improving usage on swift
kieran-osgood-shopify 07cf334
Apply suggestions from code review
kieran-osgood-shopify 5536a81
fix: update mdc files to add more context and refactor wording
kieran-osgood-shopify 37b64d2
refactor: add more examples for cursor rules and move dev description…
kieran-osgood-shopify c30c1cf
Merge branch 'main' into kieran-osgood/chore/add-cursor-rules
kieran-osgood-shopify File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--- | ||
description: Swift development workflow and language server workarounds | ||
globs: ["**/*.swift"] | ||
alwaysApply: true | ||
--- | ||
|
||
# SWIFT DEVELOPMENT WORKFLOW | ||
|
||
## ⚠️ IMPORTANT: Language Server Issues | ||
|
||
**IGNORE ALL LANGUAGE SERVER ERRORS IN SWIFT FILES** | ||
- The language server reports errors erroneously while code compiles fine | ||
- Do NOT trust red squiggles or inline error messages | ||
- Always verify issues using the commands below instead | ||
|
||
## Verification Commands | ||
|
||
### Check your work systematically: | ||
1. **Lint & Format** → `dev lint` (or `dev style`) - Checks for linting and stylistic errors | ||
2. **Build Issues** → `dev build` - Checks for compilation issues | ||
3. **Test Issues** → `dev test` - Checks for failing tests | ||
|
||
### Available dev commands: | ||
**See `dev.yml` in project root for complete list of commands and descriptions.** | ||
|
||
Key commands for verification: | ||
- `dev lint` (alias: `dev style`) - Check format & lint issues | ||
- `dev fix` - Auto-fix formatting and linting issues | ||
- `dev build packages` - Build both packages | ||
- `dev test packages` - Run all tests | ||
|
||
## Concurrency Best Practices | ||
|
||
### DO: Use actors for thread-safe shared state | ||
```swift | ||
actor QueryCache { | ||
private var cache: [String: Any] = [:] | ||
private var inflightRequests: [String: Any] = [:] | ||
|
||
func loadCached<T>(...) async throws -> T { | ||
// Safe concurrent access to shared state | ||
} | ||
} | ||
``` | ||
|
||
## Workflow Best Practices | ||
|
||
### When you see errors: | ||
❌ DON'T: Trust language server errors in Xcode/editor | ||
✅ DO: Run the appropriate dev command to verify | ||
|
||
### After making changes: | ||
- ALWAYS run `dev fix && dev lint` to check your code is formatted and written in our style. | ||
|
||
## Example Workflow | ||
|
||
```bash | ||
# Make your Swift changes... | ||
|
||
# Fix any auto-fixable issues | ||
dev fix | ||
|
||
# Check for any remaining lint issues | ||
dev lint | ||
|
||
# Verify it compiles | ||
dev build | ||
|
||
# Run tests if needed | ||
dev test packages | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
--- | ||
description: Swift testing best practices and requirements | ||
globs: ["Tests/**/*.swift"] | ||
alwaysApply: true | ||
--- | ||
|
||
# SWIFT TESTING RULES | ||
|
||
## Test Structure Requirements | ||
|
||
### DO: | ||
- Create separate test methods for each test case | ||
- Use `guard` statements with `XCTFail` for unwrapping optionals | ||
```swift | ||
func testSomething() { | ||
guard let result = someOptionalValue else { | ||
XCTFail("Expected non-nil value") | ||
return | ||
} | ||
XCTAssertEqual(result, expectedValue) | ||
} | ||
``` | ||
- Write focused tests that test one thing at a time | ||
- Use descriptive test method names in the format `test_<methodName>_<withCircumstances>_<shouldExpectation>` | ||
``` | ||
func test_canTransition_fromAppleSheetPresentedState_shouldAllowPaymentAuthorizationAndInterruptAndCompleted() | ||
func test_ensureCurrencyNotChanged_withNoInitialCurrency_shouldNotThrow() | ||
``` | ||
|
||
- If a function may throw multiple types of errors, write multiple tests to capture them in isolation | ||
``` | ||
func throwingFunction() { | ||
if someCondition { | ||
throw Error.foo | ||
} else | ||
throw Error.bar | ||
} | ||
|
||
func test_throwingFunction_whenSomeConditionTrue_shouldThrowFoo() { | ||
do { | ||
_ = try await storefront.createCart() | ||
XCTFail("Expected error to be thrown") | ||
} catch { | ||
guard case let error = Error.foo else { | ||
XCTFail("Expected .foo") | ||
} | ||
} | ||
} | ||
func test_throwingFunction_whenSomeConditionTrue_shouldThrowBar(){ | ||
do { | ||
_ = try await storefront.createCart() | ||
XCTFail("Expected error to be thrown") | ||
} catch { | ||
guard case let error = Error.foo else { | ||
XCTFail("Expected .foo") | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Code Examples | ||
|
||
### ✅ CORRECT: Unwrapping optionals | ||
```swift | ||
func testSomething() { | ||
guard let result = someOptionalValue else { | ||
XCTFail("Expected non-nil value") | ||
return | ||
} | ||
XCTAssertEqual(result, expectedValue) | ||
} | ||
``` | ||
|
||
### DON'T: | ||
- Use typed catches when testing throwing expressions | ||
- Delete and recreate test files when debugging | ||
- Add boilerplate comments like "// Given", "// When", "// Then" | ||
|
||
## Comments | ||
|
||
- Use comments ONLY to explain non-obvious side effects or complex reasoning | ||
- Keep comments minimal and purposeful | ||
- Focus on WHY something is done, not WHAT is being done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.