|
| 1 | +# Copilot Instructions |
| 2 | + |
| 3 | +You are an AI assistant that specializes in software development for the Ruby programming language. |
| 4 | + |
| 5 | +## Environment Setup |
| 6 | + |
| 7 | +Regarding scripts that manage the environment or start the app, follow the guidance given by GitHub in their [Scripts to Rule Them All](https://github.blog/engineering/scripts-to-rule-them-all/) blog post. If the blog post conflicts with instructions written here, these instructions are authoritative. For example: |
| 8 | + |
| 9 | +Bootstrap the Ruby project by running: |
| 10 | + |
| 11 | +```bash |
| 12 | +script/bootstrap |
| 13 | +``` |
| 14 | + |
| 15 | +## Testing |
| 16 | + |
| 17 | +Ensure all unit tests pass by running the following: |
| 18 | + |
| 19 | +```bash |
| 20 | +script/test |
| 21 | +``` |
| 22 | + |
| 23 | +This project **requires 100% test coverage** of code, not including: |
| 24 | + |
| 25 | +- dependencies or their bin scripts |
| 26 | +- tests |
| 27 | +- scripts in `script/` |
| 28 | +- contents of directories that begin with a dot (`.`) |
| 29 | + |
| 30 | +Tests are powered by Ruby's `rspec`. By running `script/test`, the tool `simplecov` will be automatically used and will exit with a non-zero code if the coverage is below 100%. |
| 31 | + |
| 32 | +## Linting |
| 33 | + |
| 34 | +Ensure the linter passes by running: |
| 35 | + |
| 36 | +```bash |
| 37 | +script/lint |
| 38 | +``` |
| 39 | + |
| 40 | +The linter is powered by `rubocop` with its config file located at `.rubocop.yml`. The linter will exit with a non-zero code if any issues are found. To run with auto-fix, use `script/lint -A` (this writes changes/fixes as it finds them). |
| 41 | + |
| 42 | +## Project Guidelines |
| 43 | + |
| 44 | +- Follow: |
| 45 | + - Object-Oriented best practices, especially abstraction and encapsulation |
| 46 | + - GRASP Principles, especially Information Expert, Creator, Indirection, Low Coupling, High Cohesion, and Pure Fabrication |
| 47 | + - SOLID principles, especially Dependency Inversion, Open/Closed, and Single Responsibility |
| 48 | + - Design Patterns defined by the Gang of Four, especially Abstract Factory, Factory Method, Chain of Responsibility, Command, Mediator, Observer, State, and Adaptor patterns. |
| 49 | + - The YAGI rule: do not introduce extra indirection, abstraction, or complexity unless the benefits of doing so are immediately used. For example, do not use the factory method when there is only one type to be created. |
| 50 | +- Use double quotes for strings unless single quotes are absolutely required. |
| 51 | +- Base new work on latest `main` branch. |
| 52 | +- Changes should maintain consistency with existing patterns and style. |
| 53 | +- Document changes clearly and thoroughly, including updates to existing comments when appropriate. Try to use the same "voice" as the other comments, mimicking their tone and style. |
| 54 | +- When responding to code refactoring suggestions, function suggestions, or other code changes, please keep your responses as concise as possible. We are capable engineers and can understand the code changes without excessive explanation. If you feel that a more detailed explanation is necessary, you can provide it, but keep it concise. |
| 55 | +- When suggesting code changes, always opt for the most maintainable approach. Try your best to keep the code clean and follow DRY principles. Avoid unnecessary complexity and always consider the long-term maintainability of the code. |
| 56 | +- When writing unit tests, try to consider edge cases as well as the main path of success. This will help ensure that the code is robust and can handle unexpected inputs or situations. |
| 57 | +- If you are updating docs to be YARD-style, please ensure that you keep all and any existing notes or examples in the documentation. You can re-write the notes so that they are YARD-style, but please do not remove any helpful notes. For example, `# NOTE: this method is not thread safe` should be kept in the documentation. |
| 58 | +- No additions should ever include credentials, secrets, or personally-identifying information (except github.com usernames and/or names and email addresses stored within git commits in the .git directory). |
| 59 | +- Hard-coded strings should almost always be constant variables. |
| 60 | +- In general, avoid introducing new dependencies. Use the following guidance: |
| 61 | + - Some dependencies are the de facto way to accomplish a goal and should be introduced. For example: |
| 62 | + - using a dependency to connect to a database, such as mysql2 |
| 63 | + - using a dependency for instrumentation, such as dogstatsd-ruby |
| 64 | + - using a dependency for process management, such as puma |
| 65 | + - using a dependency for unit testing, such as rspec |
| 66 | + - using a dependency for serving HTTP requests, such as sinatra |
| 67 | + - Introducing a dependency to only use a single method from it should be avoided. Dependencies should help to avoid writing thousands of lines of code, not hundreds. |
| 68 | + - Introducing a dependency to use it for a different purpose than it was written for should be avoided |
| 69 | +- In writing code, take the following as preferences but not rules: |
| 70 | + - Understandability over concision |
| 71 | + - Syntax, expressions, and blocks that are common across many languages over language-specific syntax. |
| 72 | + - More descriptive names over brevity of variable, function, and class names. |
| 73 | + - The use of whitespace (newlines) over compactness of files. |
| 74 | + - Naming of variables and methods that lead to expressions and blocks reading more like English sentences. |
| 75 | + - Less lines of code over more. Keep changes minimal and focused. |
| 76 | + |
| 77 | +## Pull Request Requirements |
| 78 | + |
| 79 | +- All tests must pass. |
| 80 | +- The linter must pass. |
| 81 | +- Documentation must be up-to-date. |
| 82 | +- Any new dependencies must be vendored. |
| 83 | +- All new code must have YARD-style documentation. |
| 84 | +- The body of the Pull Request should: |
| 85 | + - Contain a summary of the changes. |
| 86 | + - Make special note of any changes to dependencies. |
| 87 | + - Comment on the security of the changes being made and offer suggestions for further securing the code. |
| 88 | + |
| 89 | +## Repository Organization |
| 90 | + |
| 91 | +- `.github/` - GitHub configurations and settings |
| 92 | +- `docs/` - Main documentation storage |
| 93 | +- `script/` - Repository maintenance scripts. Includes things like `script/bootstrap`, `script/test`, and `script/lint`. |
| 94 | +- `config/` - Configuration files for the project. |
| 95 | +- `lib/` - Main code for the project. This is where the main application/service code lives. |
| 96 | +- `spec/` - Tests for the project. This is where the unit tests and acceptance tests live. |
| 97 | +- `vendor/cache` - Vendored dependencies (Ruby Gems). |
| 98 | +- `vendor/gems` - Location to which bundler should install the Ruby Gems sourced from `vendor/cache`. |
0 commit comments