opencode-conductor-cdd-plugin 1.0.0-beta.13
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/LICENSE +202 -0
- package/README.md +163 -0
- package/README.test.md +51 -0
- package/dist/commands/implement.d.ts +1 -0
- package/dist/commands/implement.js +30 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +108 -0
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +122 -0
- package/dist/prompts/agent/cdd.md +41 -0
- package/dist/prompts/agent/implementer.md +22 -0
- package/dist/prompts/agent.md +23 -0
- package/dist/prompts/cdd/implement.json +4 -0
- package/dist/prompts/cdd/newTrack.json +4 -0
- package/dist/prompts/cdd/revert.json +4 -0
- package/dist/prompts/cdd/setup.json +4 -0
- package/dist/prompts/cdd/setup.test.d.ts +1 -0
- package/dist/prompts/cdd/setup.test.js +132 -0
- package/dist/prompts/cdd/setup.test.ts +168 -0
- package/dist/prompts/cdd/status.json +4 -0
- package/dist/prompts/strategies/delegate.md +11 -0
- package/dist/prompts/strategies/manual.md +9 -0
- package/dist/templates/code_styleguides/c.md +28 -0
- package/dist/templates/code_styleguides/cpp.md +46 -0
- package/dist/templates/code_styleguides/csharp.md +115 -0
- package/dist/templates/code_styleguides/dart.md +238 -0
- package/dist/templates/code_styleguides/general.md +23 -0
- package/dist/templates/code_styleguides/go.md +48 -0
- package/dist/templates/code_styleguides/html-css.md +49 -0
- package/dist/templates/code_styleguides/java.md +39 -0
- package/dist/templates/code_styleguides/javascript.md +51 -0
- package/dist/templates/code_styleguides/julia.md +27 -0
- package/dist/templates/code_styleguides/kotlin.md +41 -0
- package/dist/templates/code_styleguides/php.md +37 -0
- package/dist/templates/code_styleguides/python.md +37 -0
- package/dist/templates/code_styleguides/react.md +37 -0
- package/dist/templates/code_styleguides/ruby.md +39 -0
- package/dist/templates/code_styleguides/rust.md +44 -0
- package/dist/templates/code_styleguides/shell.md +35 -0
- package/dist/templates/code_styleguides/solidity.md +60 -0
- package/dist/templates/code_styleguides/sql.md +39 -0
- package/dist/templates/code_styleguides/swift.md +36 -0
- package/dist/templates/code_styleguides/typescript.md +43 -0
- package/dist/templates/code_styleguides/vue.md +38 -0
- package/dist/templates/code_styleguides/zig.md +27 -0
- package/dist/templates/workflow.md +336 -0
- package/dist/tools/background.d.ts +54 -0
- package/dist/tools/background.js +198 -0
- package/dist/tools/commands.d.ts +11 -0
- package/dist/tools/commands.js +80 -0
- package/dist/tools/commands.test.d.ts +1 -0
- package/dist/tools/commands.test.js +142 -0
- package/dist/tools/delegate.d.ts +3 -0
- package/dist/tools/delegate.js +45 -0
- package/dist/utils/autogenerateFlow.d.ts +65 -0
- package/dist/utils/autogenerateFlow.js +391 -0
- package/dist/utils/autogenerateFlow.test.d.ts +1 -0
- package/dist/utils/autogenerateFlow.test.js +610 -0
- package/dist/utils/bootstrap.d.ts +1 -0
- package/dist/utils/bootstrap.js +46 -0
- package/dist/utils/commandFactory.d.ts +11 -0
- package/dist/utils/commandFactory.js +69 -0
- package/dist/utils/commitMessages.d.ts +35 -0
- package/dist/utils/commitMessages.js +33 -0
- package/dist/utils/commitMessages.test.d.ts +1 -0
- package/dist/utils/commitMessages.test.js +79 -0
- package/dist/utils/configDetection.d.ts +7 -0
- package/dist/utils/configDetection.js +49 -0
- package/dist/utils/configDetection.test.d.ts +1 -0
- package/dist/utils/configDetection.test.js +119 -0
- package/dist/utils/contentGeneration.d.ts +10 -0
- package/dist/utils/contentGeneration.js +141 -0
- package/dist/utils/contentGeneration.test.d.ts +1 -0
- package/dist/utils/contentGeneration.test.js +147 -0
- package/dist/utils/contextAnalysis.d.ts +100 -0
- package/dist/utils/contextAnalysis.js +308 -0
- package/dist/utils/contextAnalysis.test.d.ts +1 -0
- package/dist/utils/contextAnalysis.test.js +307 -0
- package/dist/utils/gitNotes.d.ts +23 -0
- package/dist/utils/gitNotes.js +53 -0
- package/dist/utils/gitNotes.test.d.ts +1 -0
- package/dist/utils/gitNotes.test.js +105 -0
- package/dist/utils/ignoreMatcher.d.ts +9 -0
- package/dist/utils/ignoreMatcher.js +77 -0
- package/dist/utils/ignoreMatcher.test.d.ts +1 -0
- package/dist/utils/ignoreMatcher.test.js +126 -0
- package/dist/utils/stateManager.d.ts +10 -0
- package/dist/utils/stateManager.js +30 -0
- package/package.json +90 -0
- package/scripts/convert-legacy.cjs +17 -0
- package/scripts/postinstall.cjs +38 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Effective Go Style Guide Summary
|
|
2
|
+
|
|
3
|
+
This document summarizes key rules and best practices from the official "Effective Go" guide for writing idiomatic Go code.
|
|
4
|
+
|
|
5
|
+
## 1. Formatting
|
|
6
|
+
- **`gofmt`:** All Go code **must** be formatted with `gofmt` (or `go fmt`). This is a non-negotiable, automated standard.
|
|
7
|
+
- **Indentation:** Use tabs for indentation (`gofmt` handles this).
|
|
8
|
+
- **Line Length:** Go has no strict line length limit. Let `gofmt` handle line wrapping.
|
|
9
|
+
|
|
10
|
+
## 2. Naming
|
|
11
|
+
- **`MixedCaps`:** Use `MixedCaps` or `mixedCaps` for multi-word names. Do not use underscores.
|
|
12
|
+
- **Exported vs. Unexported:** Names starting with an uppercase letter are exported (public). Names starting with a lowercase letter are not exported (private).
|
|
13
|
+
- **Package Names:** Short, concise, single-word, lowercase names.
|
|
14
|
+
- **Getters:** Do not name getters with a `Get` prefix. A getter for a field named `owner` should be named `Owner()`.
|
|
15
|
+
- **Interface Names:** One-method interfaces are named by the method name plus an `-er` suffix (e.g., `Reader`, `Writer`).
|
|
16
|
+
|
|
17
|
+
## 3. Control Structures
|
|
18
|
+
- **`if`:** No parentheses around the condition. Braces are mandatory. Can include an initialization statement (e.g., `if err := file.Chmod(0664); err != nil`).
|
|
19
|
+
- **`for`:** Go's only looping construct. Unifies `for` and `while`. Use `for...range` to iterate over slices, maps, strings, and channels.
|
|
20
|
+
- **`switch`:** More general than in C. Cases do not fall through by default (use `fallthrough` explicitly). Can be used without an expression to function as a cleaner `if-else-if` chain.
|
|
21
|
+
|
|
22
|
+
## 4. Functions
|
|
23
|
+
- **Multiple Returns:** Functions can return multiple values. This is the standard way to return a result and an error (e.g., `value, err`).
|
|
24
|
+
- **Named Result Parameters:** Return parameters can be named. This can make code clearer and more concise.
|
|
25
|
+
- **`defer`:** Schedules a function call to be run immediately before the function executing `defer` returns. Use it for cleanup tasks like closing files.
|
|
26
|
+
|
|
27
|
+
## 5. Data
|
|
28
|
+
- **`new` vs. `make`:**
|
|
29
|
+
- `new(T)`: Allocates memory for a new item of type `T`, zeroes it, and returns a pointer (`*T`).
|
|
30
|
+
- `make(T, ...)`: Creates and initializes slices, maps, and channels only. Returns an initialized value of type `T` (not a pointer).
|
|
31
|
+
- **Slices:** The preferred way to work with sequences. They are more flexible than arrays.
|
|
32
|
+
- **Maps:** Use the "comma ok" idiom to check for the existence of a key: `value, ok := myMap[key]`.
|
|
33
|
+
|
|
34
|
+
## 6. Interfaces
|
|
35
|
+
- **Implicit Implementation:** A type implements an interface by implementing its methods. No `implements` keyword is needed.
|
|
36
|
+
- **Small Interfaces:** Prefer many small interfaces over one large one. The standard library is full of single-method interfaces (e.g., `io.Reader`).
|
|
37
|
+
|
|
38
|
+
## 7. Concurrency
|
|
39
|
+
- **Share Memory By Communicating:** This is the core philosophy. Do not communicate by sharing memory; instead, share memory by communicating.
|
|
40
|
+
- **Goroutines:** Lightweight, concurrently executing functions. Start one with the `go` keyword.
|
|
41
|
+
- **Channels:** Typed conduits for communication between goroutines. Use `make` to create them.
|
|
42
|
+
|
|
43
|
+
## 8. Errors
|
|
44
|
+
- **`error` type:** The built-in `error` interface is the standard way to handle errors.
|
|
45
|
+
- **Explicit Error Handling:** Do not discard errors with the blank identifier (`_`). Check for errors explicitly.
|
|
46
|
+
- **`panic`:** Reserved for truly exceptional, unrecoverable situations. Generally, libraries should not panic.
|
|
47
|
+
|
|
48
|
+
*Source: [Effective Go](https://go.dev/doc/effective_go)*
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Google HTML/CSS Style Guide Summary
|
|
2
|
+
|
|
3
|
+
This document summarizes key rules and best practices from the Google HTML/CSS Style Guide.
|
|
4
|
+
|
|
5
|
+
## 1. General Rules
|
|
6
|
+
- **Protocol:** Use HTTPS for all embedded resources.
|
|
7
|
+
- **Indentation:** Indent by 2 spaces. Do not use tabs.
|
|
8
|
+
- **Capitalization:** Use only lowercase for all code (element names, attributes, selectors, properties).
|
|
9
|
+
- **Trailing Whitespace:** Remove all trailing whitespace.
|
|
10
|
+
- **Encoding:** Use UTF-8 (without a BOM). Specify `<meta charset="utf-8">` in HTML.
|
|
11
|
+
|
|
12
|
+
## 2. HTML Style Rules
|
|
13
|
+
- **Document Type:** Use `<!doctype html>`.
|
|
14
|
+
- **HTML Validity:** Use valid HTML.
|
|
15
|
+
- **Semantics:** Use HTML elements according to their intended purpose (e.g., use `<p>` for paragraphs, not for spacing).
|
|
16
|
+
- **Multimedia Fallback:** Provide `alt` text for images and transcripts/captions for audio/video.
|
|
17
|
+
- **Separation of Concerns:** Strictly separate structure (HTML), presentation (CSS), and behavior (JavaScript). Link to CSS and JS from external files.
|
|
18
|
+
- **`type` Attributes:** Omit `type` attributes for stylesheets (`<link>`) and scripts (`<script>`).
|
|
19
|
+
|
|
20
|
+
## 3. HTML Formatting Rules
|
|
21
|
+
- **General:** Use a new line for every block, list, or table element, and indent its children.
|
|
22
|
+
- **Quotation Marks:** Use double quotation marks (`""`) for attribute values.
|
|
23
|
+
|
|
24
|
+
## 4. CSS Style Rules
|
|
25
|
+
- **CSS Validity:** Use valid CSS.
|
|
26
|
+
- **Class Naming:** Use meaningful, generic names. Separate words with a hyphen (`-`).
|
|
27
|
+
- **Good:** `.video-player`, `.site-navigation`
|
|
28
|
+
- **Bad:** `.vid`, `.red-text`
|
|
29
|
+
- **ID Selectors:** Avoid using ID selectors for styling. Prefer class selectors.
|
|
30
|
+
- **Shorthand Properties:** Use shorthand properties where possible (e.g., `padding`, `font`).
|
|
31
|
+
- **`0` and Units:** Omit units for `0` values (e.g., `margin: 0;`).
|
|
32
|
+
- **Leading `0`s:** Always include leading `0`s for decimal values (e.g., `font-size: 0.8em;`).
|
|
33
|
+
- **Hexadecimal Notation:** Use 3-character hex notation where possible (e.g., `#fff`).
|
|
34
|
+
- **`!important`:** Avoid using `!important`.
|
|
35
|
+
|
|
36
|
+
## 5. CSS Formatting Rules
|
|
37
|
+
- **Declaration Order:** Alphabetize declarations within a rule.
|
|
38
|
+
- **Indentation:** Indent all block content.
|
|
39
|
+
- **Semicolons:** Use a semicolon after every declaration.
|
|
40
|
+
- **Spacing:**
|
|
41
|
+
- Use a space after a property name's colon (`font-weight: bold;`).
|
|
42
|
+
- Use a space between the last selector and the opening brace (`.foo {`).
|
|
43
|
+
- Start a new line for each selector and declaration.
|
|
44
|
+
- **Rule Separation:** Separate rules with a new line.
|
|
45
|
+
- **Quotation Marks:** Use single quotes (`''`) for attribute selectors and property values (e.g., `[type='text']`).
|
|
46
|
+
|
|
47
|
+
**BE CONSISTENT.** When editing code, match the existing style.
|
|
48
|
+
|
|
49
|
+
*Source: [Google HTML/CSS Style Guide](https://google.github.io/styleguide/htmlcssguide.html)*
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Google Java Style Guide Summary
|
|
2
|
+
|
|
3
|
+
This document summarizes key rules and best practices from the Google Java Style Guide.
|
|
4
|
+
|
|
5
|
+
## 1. Source File Organization
|
|
6
|
+
- **Filename**: The source file name is the case-sensitive name of the top-level class it contains, plus the `.java` extension.
|
|
7
|
+
- **File Encoding**: UTF-8.
|
|
8
|
+
- **Structure**:
|
|
9
|
+
1. License or copyright information (if any)
|
|
10
|
+
2. Package statement
|
|
11
|
+
3. Import statements
|
|
12
|
+
4. Exactly one top-level class
|
|
13
|
+
|
|
14
|
+
## 2. Formatting
|
|
15
|
+
- **Indentation**: 2 spaces (Google style).
|
|
16
|
+
- **Column limit**: 100 characters.
|
|
17
|
+
- **Braces**: Use Egyptian brackets (opening brace on the same line).
|
|
18
|
+
- **Empty blocks**: Can be concise `{}` if they contain no code.
|
|
19
|
+
|
|
20
|
+
## 3. Naming Conventions
|
|
21
|
+
- **Packages**: `lower.case.with.dots` (e.g., `com.google.common.base`).
|
|
22
|
+
- **Classes**: `UpperCamelCase` (e.g., `HttpRequest`).
|
|
23
|
+
- **Methods**: `lowerCamelCase` (e.g., `sendMessage`).
|
|
24
|
+
- **Variables**: `lowerCamelCase` (e.g., `userId`).
|
|
25
|
+
- **Constants**: `CONSTANT_CASE` (e.g., `MAX_RETRY_COUNT`).
|
|
26
|
+
- **Type Variables**: Single capital letter or `UpperCamelCase` followed by a capital letter (e.g., `T`, `RequestT`).
|
|
27
|
+
|
|
28
|
+
## 4. Programming Practices
|
|
29
|
+
- **Overrides**: Always use the `@Override` annotation.
|
|
30
|
+
- **Exceptions**: Never ignore exceptions. At least log them or explain why they are ignored in a comment.
|
|
31
|
+
- **Static Members**: Access static members via the class name, not an instance (e.g., `MyClass.staticMethod()`).
|
|
32
|
+
- **Finalizers**: Do not use `Object.finalize()`.
|
|
33
|
+
|
|
34
|
+
## 5. Javadoc
|
|
35
|
+
- **Formatting**: Use standard Javadoc format `/** ... */`.
|
|
36
|
+
- **At-clauses**: Use `@param`, `@return`, `@throws`, `@deprecated` in that order.
|
|
37
|
+
- **Summary**: The first sentence of each Javadoc block should be a concise summary.
|
|
38
|
+
|
|
39
|
+
*Source: [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html)*
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Google JavaScript Style Guide Summary
|
|
2
|
+
|
|
3
|
+
This document summarizes key rules and best practices from the Google JavaScript Style Guide.
|
|
4
|
+
|
|
5
|
+
## 1. Source File Basics
|
|
6
|
+
- **File Naming:** All lowercase, with underscores (`_`) or dashes (`-`). Extension must be `.js`.
|
|
7
|
+
- **File Encoding:** UTF-8.
|
|
8
|
+
- **Whitespace:** Use only ASCII horizontal spaces (0x20). Tabs are forbidden for indentation.
|
|
9
|
+
|
|
10
|
+
## 2. Source File Structure
|
|
11
|
+
- New files should be ES modules (`import`/`export`).
|
|
12
|
+
- **Exports:** Use named exports (`export {MyClass};`). **Do not use default exports.**
|
|
13
|
+
- **Imports:** Do not use line-wrapped imports. The `.js` extension in import paths is mandatory.
|
|
14
|
+
|
|
15
|
+
## 3. Formatting
|
|
16
|
+
- **Braces:** Required for all control structures (`if`, `for`, `while`, etc.), even single-line blocks. Use K&R style ("Egyptian brackets").
|
|
17
|
+
- **Indentation:** +2 spaces for each new block.
|
|
18
|
+
- **Semicolons:** Every statement must be terminated with a semicolon.
|
|
19
|
+
- **Column Limit:** 80 characters.
|
|
20
|
+
- **Line-wrapping:** Indent continuation lines at least +4 spaces.
|
|
21
|
+
- **Whitespace:** Use single blank lines between methods. No trailing whitespace.
|
|
22
|
+
|
|
23
|
+
## 4. Language Features
|
|
24
|
+
- **Variable Declarations:** Use `const` by default, `let` if reassignment is needed. **`var` is forbidden.**
|
|
25
|
+
- **Array Literals:** Use trailing commas. Do not use the `Array` constructor.
|
|
26
|
+
- **Object Literals:** Use trailing commas and shorthand properties. Do not use the `Object` constructor.
|
|
27
|
+
- **Classes:** Do not use JavaScript getter/setter properties (`get name()`). Provide ordinary methods instead.
|
|
28
|
+
- **Functions:** Prefer arrow functions for nested functions to preserve `this` context.
|
|
29
|
+
- **String Literals:** Use single quotes (`'`). Use template literals (`` ` ``) for multi-line strings or complex interpolation.
|
|
30
|
+
- **Control Structures:** Prefer `for-of` loops. `for-in` loops should only be used on dict-style objects.
|
|
31
|
+
- **`this`:** Only use `this` in class constructors, methods, or in arrow functions defined within them.
|
|
32
|
+
- **Equality Checks:** Always use identity operators (`===` / `!==`).
|
|
33
|
+
|
|
34
|
+
## 5. Disallowed Features
|
|
35
|
+
- `with` keyword.
|
|
36
|
+
- `eval()` or `Function(...string)`.
|
|
37
|
+
- Automatic Semicolon Insertion.
|
|
38
|
+
- Modifying builtin objects (`Array.prototype.foo = ...`).
|
|
39
|
+
|
|
40
|
+
## 6. Naming
|
|
41
|
+
- **Classes:** `UpperCamelCase`.
|
|
42
|
+
- **Methods & Functions:** `lowerCamelCase`.
|
|
43
|
+
- **Constants:** `CONSTANT_CASE` (all uppercase with underscores).
|
|
44
|
+
- **Non-constant Fields & Variables:** `lowerCamelCase`.
|
|
45
|
+
|
|
46
|
+
## 7. JSDoc
|
|
47
|
+
- JSDoc is used on all classes, fields, and methods.
|
|
48
|
+
- Use `@param`, `@return`, `@override`, `@deprecated`.
|
|
49
|
+
- Type annotations are enclosed in braces (e.g., `/** @param {string} userName */`).
|
|
50
|
+
|
|
51
|
+
*Source: [Google JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html)*
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Julia Style Guide Summary
|
|
2
|
+
|
|
3
|
+
This document summarizes key rules and best practices for Julia development, based on the official Julia Style Guide and common community patterns.
|
|
4
|
+
|
|
5
|
+
## 1. Naming Conventions
|
|
6
|
+
- **Variables**: `snake_case` (e.g., `user_id`).
|
|
7
|
+
- **Functions**: `snake_case` (e.g., `calculate_sum`).
|
|
8
|
+
- **Types (Modules, Types)**: `PascalCase` (e.g., `MemoryManager`).
|
|
9
|
+
- **Files**: `snake_case.jl` (e.g., `data_processing.jl`).
|
|
10
|
+
- **Mutating Functions**: Functions that modify their arguments should end with an exclamation mark (e.g., `sort!`).
|
|
11
|
+
|
|
12
|
+
## 2. Formatting
|
|
13
|
+
- **Indentation**: 4 spaces.
|
|
14
|
+
- **Line Length**: 92 characters limit is often recommended.
|
|
15
|
+
- **Braces**: Opening brace on the same line.
|
|
16
|
+
|
|
17
|
+
## 3. Idiomatic Julia
|
|
18
|
+
- **Type Annotations**: Avoid over-specifying types in function signatures unless needed for multiple dispatch.
|
|
19
|
+
- **Global Variables**: Avoid global variables where possible. Use `const` if globals are necessary.
|
|
20
|
+
- **Performance**: Use type-stable functions and avoid type-unstable constructs (like `Any` in performance-critical sections).
|
|
21
|
+
- **Arrays**: Indexing is 1-based. Use `eachindex(A)` for efficient iteration.
|
|
22
|
+
|
|
23
|
+
## 4. Documentation
|
|
24
|
+
- Use `""" ... """` for docstrings before function/type definitions.
|
|
25
|
+
- Document arguments, return values, and include examples.
|
|
26
|
+
|
|
27
|
+
*Source: [Official Julia Documentation - Style Guide](https://docs.julialang.org/en/v1/manual/style-guide/)*
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Kotlin Style Guide Summary
|
|
2
|
+
|
|
3
|
+
This document summarizes key rules and best practices for Kotlin development, based on the official Kotlin coding conventions and Google's Android Kotlin style guide.
|
|
4
|
+
|
|
5
|
+
## 1. Source File Organization
|
|
6
|
+
- **Encoding**: UTF-8.
|
|
7
|
+
- **Indentation**: 4 spaces.
|
|
8
|
+
- **Structure**:
|
|
9
|
+
1. Package header
|
|
10
|
+
2. Imports
|
|
11
|
+
3. Top-level declarations (classes, functions, etc.)
|
|
12
|
+
|
|
13
|
+
## 2. Naming Conventions
|
|
14
|
+
- **Classes/Interfaces**: `UpperCamelCase`.
|
|
15
|
+
- **Functions/Properties**: `lowerCamelCase`.
|
|
16
|
+
- **Constants**: `SCREAMING_SNAKE_CASE` (only for `const val`).
|
|
17
|
+
- **Packages**: `lower.case.without.underscores`.
|
|
18
|
+
|
|
19
|
+
## 3. Formatting
|
|
20
|
+
- Use 100 character line limit.
|
|
21
|
+
- Prefer expression bodies for simple one-line functions (e.g., `fun foo() = bar()`).
|
|
22
|
+
- Omit the unit return type explicitly (e.g., `fun foo(): Unit` \u2192 `fun foo()`).
|
|
23
|
+
|
|
24
|
+
## 4. Idiomatic Kotlin
|
|
25
|
+
- **Immutability**: Prefer `val` over `var` whenever possible.
|
|
26
|
+
- **Null Safety**:
|
|
27
|
+
- Use `?.` and `?:` (Elvis operator) instead of explicit null checks.
|
|
28
|
+
- Avoid `!!` (non-null assertion) unless absolutely certain.
|
|
29
|
+
- **Data Classes**: Use `data class` for simple data-holding classes.
|
|
30
|
+
- **Scope Functions**: Use `let`, `run`, `apply`, `also`, and `with` where they improve readability.
|
|
31
|
+
- **String Templates**: Prefer `"$foo"` over concatenation.
|
|
32
|
+
|
|
33
|
+
## 5. Collections
|
|
34
|
+
- Prefer read-only collection interfaces (`List`, `Map`, `Set`) over mutable ones.
|
|
35
|
+
- Use collection transformation methods (`map`, `filter`, etc.) instead of manual loops.
|
|
36
|
+
|
|
37
|
+
## 6. Documentation (KDoc)
|
|
38
|
+
- Use `/** ... */` for documentation comments.
|
|
39
|
+
- Use `[` and `]` to reference symbols within doc comments.
|
|
40
|
+
|
|
41
|
+
*Source: [Official Kotlin Coding Conventions](https://kotlinlang.org/docs/coding-conventions.html)*
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# PHP Style Guide Summary (PSR-12)
|
|
2
|
+
|
|
3
|
+
This document summarizes key rules from the PSR-12 Extended Coding Style Guide, which is the current standard for the PHP community.
|
|
4
|
+
|
|
5
|
+
## 1. Files and Basic Standards
|
|
6
|
+
- **PHP Tag**: Use only `<?php` or `<?=`.
|
|
7
|
+
- **Encoding**: UTF-8 without BOM.
|
|
8
|
+
- **Side Effects**: A file should either declare symbols (classes, functions, constants, etc.) or cause side effects, but not both.
|
|
9
|
+
- **Indentation**: 4 spaces.
|
|
10
|
+
|
|
11
|
+
## 2. Naming Conventions
|
|
12
|
+
- **Classes**: `UpperCamelCase` (e.g., `UserMapper`).
|
|
13
|
+
- **Methods**: `lowerCamelCase` (e.g., `getUserData`).
|
|
14
|
+
- **Constants**: `CONSTANT_CASE` (e.g., `MAX_RETRIES`).
|
|
15
|
+
- **Properties**: `lowerCamelCase` (preferred) or `snake_case` (be consistent).
|
|
16
|
+
|
|
17
|
+
## 3. Structure and Layout
|
|
18
|
+
- **Namespaces**: One declaration per line.
|
|
19
|
+
- **Imports**: Use `use` for imports. Group imports by type (classes, functions, constants).
|
|
20
|
+
- **Visibility**: Always declare visibility (`public`, `protected`, `private`) for properties and methods.
|
|
21
|
+
- **Strict Types**: Use `declare(strict_types=1);` at the top of every file.
|
|
22
|
+
|
|
23
|
+
## 4. Control Structures
|
|
24
|
+
- **Braces**: Opening brace on the same line for control structures, but on a new line for classes and methods (PSR style).
|
|
25
|
+
- **Conditionals**: Always use curly braces, even for one-line blocks.
|
|
26
|
+
- **Spaces**: One space after the control structure keyword, no space after the opening parenthesis.
|
|
27
|
+
|
|
28
|
+
## 5. Functions and Methods
|
|
29
|
+
- **Type Hinting**: Always use type hints for parameters and return types.
|
|
30
|
+
- **Nullables**: Use `?Type` or `Type | null` for nullable types.
|
|
31
|
+
- **Return Type**: The colon and type should follow the closing parenthesis with a space.
|
|
32
|
+
|
|
33
|
+
## 6. Documentation (DocBlocks)
|
|
34
|
+
- Use standard PHPDoc `/** ... */` for documenting classes, methods, and properties.
|
|
35
|
+
- Include `@param` and `@return` tags with specific types.
|
|
36
|
+
|
|
37
|
+
*Source: [PHP-FIG PSR-12](https://www.php-fig.org/psr/psr-12/)*
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Google Python Style Guide Summary
|
|
2
|
+
|
|
3
|
+
This document summarizes key rules and best practices from the Google Python Style Guide.
|
|
4
|
+
|
|
5
|
+
## 1. Python Language Rules
|
|
6
|
+
- **Linting:** Run `pylint` on your code to catch bugs and style issues.
|
|
7
|
+
- **Imports:** Use `import x` for packages/modules. Use `from x import y` only when `y` is a submodule.
|
|
8
|
+
- **Exceptions:** Use built-in exception classes. Do not use bare `except:` clauses.
|
|
9
|
+
- **Global State:** Avoid mutable global state. Module-level constants are okay and should be `ALL_CAPS_WITH_UNDERSCORES`.
|
|
10
|
+
- **Comprehensions:** Use for simple cases. Avoid for complex logic where a full loop is more readable.
|
|
11
|
+
- **Default Argument Values:** Do not use mutable objects (like `[]` or `{}`) as default values.
|
|
12
|
+
- **True/False Evaluations:** Use implicit false (e.g., `if not my_list:`). Use `if foo is None:` to check for `None`.
|
|
13
|
+
- **Type Annotations:** Strongly encouraged for all public APIs.
|
|
14
|
+
|
|
15
|
+
## 2. Python Style Rules
|
|
16
|
+
- **Line Length:** Maximum 80 characters.
|
|
17
|
+
- **Indentation:** 4 spaces per indentation level. Never use tabs.
|
|
18
|
+
- **Blank Lines:** Two blank lines between top-level definitions (classes, functions). One blank line between method definitions.
|
|
19
|
+
- **Whitespace:** Avoid extraneous whitespace. Surround binary operators with single spaces.
|
|
20
|
+
- **Docstrings:** Use `"""triple double quotes"""`. Every public module, function, class, and method must have a docstring.
|
|
21
|
+
- **Format:** Start with a one-line summary. Include `Args:`, `Returns:`, and `Raises:` sections.
|
|
22
|
+
- **Strings:** Use f-strings for formatting. Be consistent with single (`'`) or double (`"`) quotes.
|
|
23
|
+
- **`TODO` Comments:** Use `TODO(username): Fix this.` format.
|
|
24
|
+
- **Imports Formatting:** Imports should be on separate lines and grouped: standard library, third-party, and your own application's imports.
|
|
25
|
+
|
|
26
|
+
## 3. Naming
|
|
27
|
+
- **General:** `snake_case` for modules, functions, methods, and variables.
|
|
28
|
+
- **Classes:** `PascalCase`.
|
|
29
|
+
- **Constants:** `ALL_CAPS_WITH_UNDERSCORES`.
|
|
30
|
+
- **Internal Use:** Use a single leading underscore (`_internal_variable`) for internal module/class members.
|
|
31
|
+
|
|
32
|
+
## 4. Main
|
|
33
|
+
- All executable files should have a `main()` function that contains the main logic, called from a `if __name__ == '__main__':` block.
|
|
34
|
+
|
|
35
|
+
**BE CONSISTENT.** When editing code, match the existing style.
|
|
36
|
+
|
|
37
|
+
*Source: [Google Python Style Guide](https://google.github.io/styleguide/pyguide.html)*
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# React Best Practices & Style Guide
|
|
2
|
+
|
|
3
|
+
This document outlines recommended patterns and styles for building React applications with functional components and hooks.
|
|
4
|
+
|
|
5
|
+
## 1. Components
|
|
6
|
+
- **Functional Components**: Prefer functional components with Hooks over class components.
|
|
7
|
+
- **Naming**: Use `PascalCase` for component filenames and function names (e.g., `UserProfile.tsx`).
|
|
8
|
+
- **One Component per File**: Each file should export exactly one primary component.
|
|
9
|
+
- **Props**:
|
|
10
|
+
- Use TypeScript interfaces/types for prop definitions.
|
|
11
|
+
- Destructure props in the function signature for clarity.
|
|
12
|
+
- Provide default values using ES6 default parameters.
|
|
13
|
+
|
|
14
|
+
## 2. Hooks
|
|
15
|
+
- **Rules of Hooks**: Follow the official rules (only call at top level, only in React functions).
|
|
16
|
+
- **Custom Hooks**: Extract complex logic into custom hooks (`useSomeLogic`). Name them with the `use` prefix.
|
|
17
|
+
- **Dependencies**: Be exhaustive with dependency arrays in `useEffect`, `useMemo`, and `useCallback`.
|
|
18
|
+
|
|
19
|
+
## 3. Styling
|
|
20
|
+
- **CSS-in-JS / Modules**: Prefer CSS Modules or a utility-first framework like Tailwind CSS over global CSS.
|
|
21
|
+
- **Conditional Classes**: Use a utility like `clsx` or `classnames` for managing conditional class strings.
|
|
22
|
+
|
|
23
|
+
## 4. State Management
|
|
24
|
+
- **Local State**: Use `useState` for simple, component-specific state.
|
|
25
|
+
- **Complex State**: Use `useReducer` for more complex state logic or when state transitions depend on previous state.
|
|
26
|
+
- **Context API**: Use `useContext` for sharing state that is "global" to a tree of components (e.g., theme, user session).
|
|
27
|
+
|
|
28
|
+
## 5. Patterns
|
|
29
|
+
- **Container/Presenter**: While less strict now, keep data fetching/logic separate from pure presentation components where it improves testability.
|
|
30
|
+
- **Composition**: Prefer component composition (`children` prop) over deep prop drilling.
|
|
31
|
+
- **Early Returns**: Use early returns for conditional rendering (e.g., loading or error states).
|
|
32
|
+
|
|
33
|
+
## 6. Performance
|
|
34
|
+
- **useMemo/useCallback**: Use sparingly. Only memoize when profiling shows a performance bottleneck or when passing objects/functions to memoized child components.
|
|
35
|
+
- **Fragment**: Use `<React.Fragment>` or `<>` to avoid unnecessary DOM nodes.
|
|
36
|
+
|
|
37
|
+
*Source: [Official React Documentation](https://react.dev/)*
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Ruby Style Guide Summary
|
|
2
|
+
|
|
3
|
+
This document summarizes key rules and best practices for Ruby development, largely based on the community-driven Ruby Style Guide and RuboCop defaults.
|
|
4
|
+
|
|
5
|
+
## 1. Source Code Layout
|
|
6
|
+
- **Indentation**: 2 spaces per indentation level.
|
|
7
|
+
- **Line Length**: Limit lines to 80 characters where possible.
|
|
8
|
+
- **Spaces**: Use spaces around operators, after commas, colons, and semicolons.
|
|
9
|
+
- **Newlines**: End each file with a single newline.
|
|
10
|
+
|
|
11
|
+
## 2. Naming Conventions
|
|
12
|
+
- **Classes and Modules**: `UpperCamelCase`.
|
|
13
|
+
- **Methods and Variables**: `snake_case`.
|
|
14
|
+
- **Constants**: `SCREAMING_SNAKE_CASE`.
|
|
15
|
+
- **Predicate Methods**: Methods returning booleans should end with a question mark (e.g., `is_empty?`).
|
|
16
|
+
- **Bang Methods**: Methods that modify the receiver or are "dangerous" should end with an exclamation mark (e.g., `save!`).
|
|
17
|
+
|
|
18
|
+
## 3. Syntax and Style
|
|
19
|
+
- **Quoting**: Prefer single quotes (`'`) for strings that don't require interpolation or special characters.
|
|
20
|
+
- **Interpolation**: Use `#{expression}` for string interpolation.
|
|
21
|
+
- **Arrays**: Prefer the literal syntax `[]`. Use `%w()` for arrays of words.
|
|
22
|
+
- **Hashes**: Use the Ruby 1.9+ syntax `key: value` for symbol keys.
|
|
23
|
+
- **Conditionals**: Avoid `then` in `if/unless` statements. Use `unless` instead of `if !condition`.
|
|
24
|
+
- **Method Definitions**: Use parentheses when a method has parameters. Omit them when it doesn't.
|
|
25
|
+
|
|
26
|
+
## 4. Collections
|
|
27
|
+
- **Iteration**: Prefer `each` over `for`.
|
|
28
|
+
- **Transformation**: Use `map`, `select`, `reduce` for collection operations.
|
|
29
|
+
- **Selection**: Use `find` or `detect` to find a single element.
|
|
30
|
+
|
|
31
|
+
## 5. Exceptions
|
|
32
|
+
- **Control Flow**: Avoid using exceptions for control flow.
|
|
33
|
+
- **Rescue**: Be specific about the exception classes you rescue. Never rescue `Exception` (rescue `StandardError` instead).
|
|
34
|
+
|
|
35
|
+
## 6. Documentation
|
|
36
|
+
- **Comments**: Use `#` for comments.
|
|
37
|
+
- **Yard**: Use YARD-style documentation tags for methods and classes.
|
|
38
|
+
|
|
39
|
+
*Source: [The Ruby Style Guide](https://rubystyle.guide/)*
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Rust Style Guide Summary
|
|
2
|
+
|
|
3
|
+
This document summarizes key rules and best practices for Rust development, based on the official Rust style guidelines and common idiomatic patterns.
|
|
4
|
+
|
|
5
|
+
## 1. Naming Conventions
|
|
6
|
+
- **`UpperCamelCase`**: Types (structs, enums, traits), type aliases, and enum variants.
|
|
7
|
+
- **`snake_case`**: Crates, modules, functions, methods, variables, and arguments.
|
|
8
|
+
- **`SCREAMING_SNAKE_CASE`**: Statics and constants.
|
|
9
|
+
- **`T` (Single Letter)**: Type parameters (e.g., `<T>`, `<U>`).
|
|
10
|
+
|
|
11
|
+
## 2. Formatting (Rustfmt)
|
|
12
|
+
- Use 4-space indentation.
|
|
13
|
+
- Maximum line width: 100 characters.
|
|
14
|
+
- Use curly braces for all `if`, `else`, `while`, and `loop` blocks.
|
|
15
|
+
- Place the opening brace on the same line as the declaration.
|
|
16
|
+
|
|
17
|
+
## 3. Idiomatic Patterns
|
|
18
|
+
- **Pattern Matching**: Prefer `match` or `if let` over complex nested `if` statements.
|
|
19
|
+
- **Error Handling**:
|
|
20
|
+
- Use `Result<T, E>` for recoverable errors and `Option<T>` for optional values.
|
|
21
|
+
- Use the `?` operator for concise error propagation.
|
|
22
|
+
- Avoid `unwrap()` and `expect()` in production code unless a panic is truly intended.
|
|
23
|
+
- **Ownership and Borrowing**:
|
|
24
|
+
- Prefer immutable borrows (`&T`) by default.
|
|
25
|
+
- Use mutable borrows (`&mut T`) only when necessary.
|
|
26
|
+
- Avoid unnecessary cloning; prefer passing references.
|
|
27
|
+
- **Iterators**: Use iterator methods (`map`, `filter`, `fold`, etc.) instead of manual loops where it improves clarity.
|
|
28
|
+
|
|
29
|
+
## 4. Documentation
|
|
30
|
+
- Use `///` for documentation comments on items (functions, structs, etc.).
|
|
31
|
+
- Use `//!` for module-level or crate-level documentation.
|
|
32
|
+
- Documentation should include an "Examples" section using markdown code blocks.
|
|
33
|
+
- Markdown is supported and encouraged in doc comments.
|
|
34
|
+
|
|
35
|
+
## 5. Attributes and Macros
|
|
36
|
+
- Use `#[derive(...)]` for common traits like `Debug`, `Clone`, `PartialEq`, and `Serialize`.
|
|
37
|
+
- Keep macros simple and well-documented. Avoid complex macro logic where regular functions suffice.
|
|
38
|
+
|
|
39
|
+
## 6. Dependencies (Cargo.toml)
|
|
40
|
+
- Be explicit with versioning.
|
|
41
|
+
- Periodically run `cargo update` and `cargo audit` to manage security vulnerabilities.
|
|
42
|
+
- Prefer small, focused crates over large "kitchen sink" dependencies.
|
|
43
|
+
|
|
44
|
+
*Source: [Official Rust Style Guidelines](https://github.com/rust-lang/rust/tree/master/src/doc/style-guide)*
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Shell Style Guide Summary (Bash)
|
|
2
|
+
|
|
3
|
+
This document outlines best practices for writing clean, safe, and maintainable shell scripts, based on the Google Shell Style Guide and common idiomatic patterns.
|
|
4
|
+
|
|
5
|
+
## 1. General Principles
|
|
6
|
+
- **Shebang**: Use `#!/bin/bash` or `#!/usr/bin/env bash`.
|
|
7
|
+
- **Portability**: If you don't need Bash-specific features, use `#!/bin/sh`.
|
|
8
|
+
- **Fail Fast**: Use `set -euo pipefail` at the beginning of scripts to exit on errors, unset variables, and pipeline failures.
|
|
9
|
+
|
|
10
|
+
## 2. Naming Conventions
|
|
11
|
+
- **Files**: `snake_case` with `.sh` extension.
|
|
12
|
+
- **Variables**: `snake_case` for local variables. `UPPERCASE` for constants and environment variables.
|
|
13
|
+
- **Functions**: `snake_case`.
|
|
14
|
+
|
|
15
|
+
## 3. Formatting
|
|
16
|
+
- **Indentation**: 2 spaces.
|
|
17
|
+
- **Line Length**: Limit to 80 characters where possible.
|
|
18
|
+
- **Functions**: Use the standard `function_name() { ... }` syntax.
|
|
19
|
+
|
|
20
|
+
## 4. Safety and Robustness
|
|
21
|
+
- **Quoting**: Always quote variables that contain filenames or user input (e.g., `"$file"`) to prevent word splitting and globbing.
|
|
22
|
+
- **Command Substitution**: Use `$(command)` instead of backticks.
|
|
23
|
+
- **Conditionals**: Use `[[ ... ]]` instead of `[ ... ]` or `test` for Bash scripts.
|
|
24
|
+
- **Local Variables**: Always use the `local` keyword inside functions.
|
|
25
|
+
|
|
26
|
+
## 5. Idiomatic Patterns
|
|
27
|
+
- **Main Function**: Put the script logic in a `main` function and call it at the bottom.
|
|
28
|
+
- **Logging**: Use a dedicated `log` or `error` function for consistent output.
|
|
29
|
+
- **Check for Existence**: Always check if a command exists before using it (e.g., `command -v git >/dev/null 2>&1`).
|
|
30
|
+
|
|
31
|
+
## 6. Documentation
|
|
32
|
+
- **Header**: Include a brief description, usage examples, and author information at the top of the script.
|
|
33
|
+
- **Comments**: Use `#` to explain *why* complex commands are used.
|
|
34
|
+
|
|
35
|
+
*Source: [Google Shell Style Guide](https://google.github.io/styleguide/shellguide.html)*
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Solidity Style Guide Summary
|
|
2
|
+
|
|
3
|
+
This document summarizes key rules and best practices for Solidity development, based on the official Solidity Style Guide and industry standards from OpenZeppelin and ConsenSys.
|
|
4
|
+
|
|
5
|
+
## 1. Source File Organization
|
|
6
|
+
- **License Identifier**: Every source file should start with a machine-readable SPDX license identifier (e.g., `// SPDX-License-Identifier: MIT`).
|
|
7
|
+
- **Pragma**: Use a specific compiler version (e.g., `pragma solidity 0.8.20;`) rather than a floating pragma (`^0.8.20`) for deployed contracts to ensure deterministic builds.
|
|
8
|
+
- **Layout Order**:
|
|
9
|
+
1. License Identifier
|
|
10
|
+
2. Pragma statements
|
|
11
|
+
3. Import statements
|
|
12
|
+
4. Interfaces
|
|
13
|
+
5. Libraries
|
|
14
|
+
6. Contracts
|
|
15
|
+
|
|
16
|
+
## 2. Contract Layout
|
|
17
|
+
Inside each contract, library, or interface, use the following order:
|
|
18
|
+
1. Type declarations (enums, structs)
|
|
19
|
+
2. State variables
|
|
20
|
+
3. Events
|
|
21
|
+
4. Modifiers
|
|
22
|
+
5. Functions
|
|
23
|
+
|
|
24
|
+
**Function Order**:
|
|
25
|
+
- Constructor
|
|
26
|
+
- Receive function (if exists)
|
|
27
|
+
- Fallback function (if exists)
|
|
28
|
+
- External
|
|
29
|
+
- Public
|
|
30
|
+
- Internal
|
|
31
|
+
- Private
|
|
32
|
+
|
|
33
|
+
## 3. Naming Conventions
|
|
34
|
+
- **Contracts & Libraries**: `UpperCamelCase` (e.g., `SimpleToken`).
|
|
35
|
+
- **Structs & Enums**: `UpperCamelCase` (e.g., `UserAccount`).
|
|
36
|
+
- **Events**: `UpperCamelCase` (e.g., `Transfer`).
|
|
37
|
+
- **Functions**: `lowerCamelCase` (e.g., `getBalance`).
|
|
38
|
+
- **Function Arguments**: `lowerCamelCase` (e.g., `_address`).
|
|
39
|
+
- **Local & State Variables**: `lowerCamelCase` (e.g., `accountBalance`).
|
|
40
|
+
- **Constants**: `UPPER_CASE_WITH_UNDERSCORES` (e.g., `MAX_SUPPLY`).
|
|
41
|
+
- **Modifiers**: `lowerCamelCase` (e.g., `onlyOwner`).
|
|
42
|
+
- **Private/Internal**: It is common practice to prefix internal or private state variables and functions with an underscore (e.g., `_balances`).
|
|
43
|
+
|
|
44
|
+
## 4. Security Best Practices
|
|
45
|
+
- **Checks-Effects-Interactions**: Always follow this pattern to prevent reentrancy attacks.
|
|
46
|
+
1. **Checks**: Validate inputs and conditions (e.g., `require`).
|
|
47
|
+
2. **Effects**: Update the contract state (e.g., update balances).
|
|
48
|
+
3. **Interactions**: Interact with other contracts (e.g., `transfer` or external calls).
|
|
49
|
+
- **Visibility**: Always explicitly define visibility for all functions (`external`, `public`, `internal`, or `private`).
|
|
50
|
+
- **Error Handling**: Use `revert CustomError()` (Solidity 0.8.4+) for gas efficiency instead of string-based `require`.
|
|
51
|
+
- **Overflow/Underflow**: Use Solidity 0.8.0+ which has built-in overflow checks, or `SafeMath` for older versions.
|
|
52
|
+
|
|
53
|
+
## 5. Documentation (NatSpec)
|
|
54
|
+
Use Ethereum Natural Language Specification (NatSpec) for all public and external interfaces:
|
|
55
|
+
- `/// @notice`: Explain to an end user what this does.
|
|
56
|
+
- `/// @dev`: Explain to a developer any extra details.
|
|
57
|
+
- `/// @param`: Document a parameter.
|
|
58
|
+
- `/// @return`: Document a return value.
|
|
59
|
+
|
|
60
|
+
*Source: [Solidity Documentation - Style Guide](https://docs.soliditylang.org/en/latest/style-guide.html)*
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# SQL Style Guide Summary
|
|
2
|
+
|
|
3
|
+
This document outlines best practices for writing clean, readable, and maintainable SQL queries and schema definitions.
|
|
4
|
+
|
|
5
|
+
## 1. Keywords and Naming
|
|
6
|
+
- **Keywords**: Use `UPPERCASE` for all SQL keywords (e.g., `SELECT`, `FROM`, `WHERE`).
|
|
7
|
+
- **Identifiers**: Use `snake_case` for all table names, column names, and other identifiers.
|
|
8
|
+
- **Singular vs Plural**: Prefer singular table names (e.g., `user` instead of `users`).
|
|
9
|
+
- **Reserved Words**: Never use reserved SQL keywords as identifiers.
|
|
10
|
+
|
|
11
|
+
## 2. Query Structure
|
|
12
|
+
- **Formatting**:
|
|
13
|
+
- One major clause per line (`SELECT`, `FROM`, `JOIN`, `WHERE`, `GROUP BY`, `ORDER BY`).
|
|
14
|
+
- Indent subclauses (e.g., inside `WHERE` or `JOIN`) for clarity.
|
|
15
|
+
- **Columns**: Explicitly list all columns in `SELECT` statements. Avoid `SELECT *` in production code.
|
|
16
|
+
- **Joins**:
|
|
17
|
+
- Use explicit `JOIN` syntax (e.g., `INNER JOIN`, `LEFT JOIN`).
|
|
18
|
+
- Use the `ON` clause for join conditions.
|
|
19
|
+
- **Aliases**: Use descriptive aliases for tables, especially in multi-table joins.
|
|
20
|
+
|
|
21
|
+
## 3. Data Types and Constraints
|
|
22
|
+
- **Consistency**: Use consistent data types across the schema.
|
|
23
|
+
- **Constraints**:
|
|
24
|
+
- Always define a `PRIMARY KEY`.
|
|
25
|
+
- Use `FOREIGN KEY` constraints to enforce referential integrity.
|
|
26
|
+
- Use `NOT NULL` where appropriate.
|
|
27
|
+
- Use `DEFAULT` values instead of allowing `NULL` where a sensible default exists.
|
|
28
|
+
|
|
29
|
+
## 4. Performance and Best Practices
|
|
30
|
+
- **Indexing**: Create indexes on columns used in `WHERE`, `JOIN`, and `ORDER BY` clauses.
|
|
31
|
+
- **Transactions**: Use transactions for multi-step operations to ensure atomicity.
|
|
32
|
+
- **Comments**: Use `--` for single-line comments and `/* ... */` for block comments to explain complex logic.
|
|
33
|
+
|
|
34
|
+
## 5. Migrations
|
|
35
|
+
- **Incremental**: Apply schema changes through version-controlled migration files.
|
|
36
|
+
- **Idempotent**: Ensure migrations are idempotent where possible (though typically managed by a tool).
|
|
37
|
+
- **Rollback**: Always include a rollback path for schema changes.
|
|
38
|
+
|
|
39
|
+
*Source: [SQL Style Guide (General Best Practices)](https://www.sqlstyle.guide/)*
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Swift Style Guide Summary
|
|
2
|
+
|
|
3
|
+
This document summarizes key rules and best practices for Swift development, based on the official Swift API Design Guidelines and common community standards.
|
|
4
|
+
|
|
5
|
+
## 1. Naming Conventions
|
|
6
|
+
- **Types (Structs, Classes, Enums, Protocols)**: `UpperCamelCase`.
|
|
7
|
+
- **Functions, Variables, Arguments**: `lowerCamelCase`.
|
|
8
|
+
- **Enum Variants**: `lowerCamelCase`.
|
|
9
|
+
- **Clarity over Brevity**: Prefer descriptive names over short ones (e.g., `remove(at:)` instead of `delete()`).
|
|
10
|
+
|
|
11
|
+
## 2. Formatting
|
|
12
|
+
- **Indentation**: 4 spaces (standard for Xcode/Swift).
|
|
13
|
+
- **Line Width**: Limit to 100-120 characters.
|
|
14
|
+
- **Braces**: Opening brace on the same line as the declaration.
|
|
15
|
+
|
|
16
|
+
## 3. Optionals and Control Flow
|
|
17
|
+
- **Optional Binding**: Prefer `if let` or `guard let` over `!` (force unwrap).
|
|
18
|
+
- **Early Exit**: Use `guard` statements to keep the main logic at the lowest indentation level.
|
|
19
|
+
- **Switch Statements**: Always include a `default` case unless all cases are exhaustively covered.
|
|
20
|
+
|
|
21
|
+
## 4. Idiomatic Swift
|
|
22
|
+
- **Type Inference**: Rely on Swift's type inference for local variables.
|
|
23
|
+
- **Structs vs Classes**: Prefer `struct` by default. Use `class` only when you need reference semantics or inheritance.
|
|
24
|
+
- **Extensions**: Use `extension` to group related functionality or implement protocols.
|
|
25
|
+
- **Trailing Closures**: Use trailing closure syntax when a function's last argument is a closure.
|
|
26
|
+
|
|
27
|
+
## 5. Error Handling
|
|
28
|
+
- Use `Error` protocol and `throw` for recoverable errors.
|
|
29
|
+
- Use `Result` type for asynchronous error handling.
|
|
30
|
+
- Avoid `try!` unless failure is genuinely impossible.
|
|
31
|
+
|
|
32
|
+
## 6. Access Control
|
|
33
|
+
- Use `private` or `fileprivate` by default for implementation details.
|
|
34
|
+
- Be explicit about `public` or `internal` (though `internal` is the default).
|
|
35
|
+
|
|
36
|
+
*Source: [Swift.org API Design Guidelines](https://www.swift.org/documentation/api-design-guidelines/)*
|