-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: updates styleguide markdown #78
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
Open
seanmnguyen
wants to merge
5
commits into
develop
Choose a base branch
from
feature/76-add-styleguide-markdown
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aaef93c
feat: updates style guide markdown
seanmnguyen 0d145e6
Merge branch 'develop' into feature/76-add-styleguide-markdown
soramicha 13b3d2c
feat: updates style guide, addressing PR comments
seanmnguyen 46e4b0c
Merge branch 'develop' into feature/76-add-styleguide-markdown
seanmnguyen 765a363
Merge branch 'develop' into feature/76-add-styleguide-markdown
soramicha 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 |
|---|---|---|
|
|
@@ -66,12 +66,134 @@ npx prettier . --check | |
|
|
||
| - Use function declarations - not arrow functions | ||
|
|
||
| ### Naming Conventions | ||
|
|
||
| - Use **camelCase** (e.g. firstName, lastName) for variables, functions, class members, and type members. | ||
| - Use **UPPER_CASE** (e.g. FIRST_NAME, LAST_NAME) with underscores between words for constants/globals | ||
| - Use **PascalCase** (e.g. FirstName, LastName) for class, interface, enum, and type names; enum members should also be in PascalCase; exported components should also be in PascalCase. | ||
| - Boolean variables should be prefixed with a verb (e.g. isEnabled) | ||
| - Use **camelCase** for file names _unless_ the file exports a component, in which case use **PascalCase** | ||
|
|
||
| ### Variables | ||
|
|
||
| - Use the `const` keyword for constant variables | ||
| - Use the `let` keyword for local variables. `let` has scoping restrictions, `var`, does not. | ||
| - Do NOT use the `var` keyword for variables | ||
| - Use meaningful variable names. Better to have longer, useful names than shorter, confusing ones. | ||
| - Do not use a variable if it will only be used once. | ||
| - Booleans: don't use negative names for boolean variables (BAD: `const isNotEnabled = true`, GOOD: `const isEnabled = true`) | ||
|
|
||
| ### Commenting | ||
|
|
||
| #### When to add Comments | ||
|
|
||
| - Include comments for intricate or non-obvious code segments | ||
| - Clarify how your code handles edge cases or exceptional scenarios | ||
| - Document workarounds due to limitations or external dependencies | ||
| - Mark areas where improvements or additional features are needed. Link to GitHub Issue, if possible. | ||
|
|
||
| #### When NOT to add Comments | ||
|
|
||
| - Avoid redundant comments that merely repeat what the code already expresses clearly. | ||
| - If the code’s purpose is evident (e.g., simple variable assignments), skip unnecessary comments. | ||
| - Remove temporary comments used for debugging once the issue is resolved. | ||
| - Incorrect comments can mislead other developers, so ensure accuracy. | ||
|
|
||
| #### TODO Comments | ||
|
|
||
| In general, TODO comments are a big risk. We may see something that we want to do later so we drop a quick `// TODO: Replace this method` thinking we'll come back to it but never do. | ||
|
|
||
| If you're going to write a TODO comment, **link to the GitHub Issues board**. | ||
|
|
||
| There are valid use cases for a TODO comment. For example, you may be working on a big feature and you want to make a pull request that only fixes part of it. Or, you may want to call out some refactoring that still needs to be done, but that you'll fix in another PR. | ||
|
|
||
| ``` | ||
| // TODO: Refactor this class. Issue #123 | ||
| ``` | ||
|
|
||
| This is actionable because it forces us to go to our issue tracker and create a ticket. That is less likely to get lost. | ||
|
|
||
| ### Writing Tests | ||
|
|
||
| See the test templates for writing tests in `/docs/examples/` | ||
|
|
||
| - [GraphQL Template](https://github.com/hack4impact/operations-api/blob/main/docs/examples/graphql-examples.md) | ||
| - [REST Template](https://github.com/hack4impact/operations-api/blob/main/docs/examples/rest-examples.md) | ||
|
|
||
| ### Writing Queries | ||
|
|
||
| #### Filtering/Sorting | ||
|
|
||
| Use the following structure for writing queries with filters and sorts. Note: you **MUST** name the variables **"filter"** and **"sort"**, nothing else. | ||
|
|
||
| Example query using filter and sort: | ||
|
|
||
| ``` | ||
| query { | ||
| volunteers( | ||
| filter: { | ||
| statuses: ["PROFESSIONAL", "STUDENT"], | ||
| roles: ["Developer"], | ||
| chapters: ["Cal high"] | ||
| }, | ||
| sort: { | ||
| firstName: ascending | ||
| } | ||
| ) { | ||
| volunteer_id | ||
| first_name | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Code Organization | ||
|
|
||
| #### General Structure | ||
|
|
||
| Our code should follow the structure below, from top to bottom: | ||
|
|
||
| 1. Imports are first at the top of the file. Only include used imports, and they should be grouped appropriately (see _Organize Imports_ for more). | ||
| 2. Constant variable declarations should follow after the imports and before any class definitions. | ||
| 3. Type declarations follow constants (e.g. `type CreateChatperInputs`). | ||
| 4. Enum declarations. | ||
| 5. Interface definitions should be next (e.g. `NonprofitsQueryArgs`). | ||
| 6. Core logic/component definition should be next (e.g. `export const className`). This includes the core class, function, component that the file primarily exports. | ||
| 7. Helper functions/methods. Define event handlers, utility functions, or methods used internally by the main logic. | ||
| 8. Export should be last. Explicitly export the primary functionality along with additional exports at the bottom. | ||
|
|
||
| #### Organize Imports | ||
|
|
||
| - With clean and easy to read import statements you can quickly see the dependencies of current code. Make sure you apply following good practices for import statements. | ||
| - Unused imports should be removed. | ||
| - Groups of imports are delineated by one blank line before and after. | ||
|
|
||
| ### Use TypeScript Aliases | ||
|
|
||
| This will avoid long relative paths when doing imports. | ||
|
|
||
| Bad: | ||
|
|
||
| ``` | ||
| import { UserService } from '../../../services/UserService'; | ||
| ``` | ||
|
|
||
| Good: | ||
|
|
||
| ``` | ||
| import { UserService } from '@services/UserService'; | ||
| ``` | ||
|
|
||
| ## Pull Request Instructions | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add more details on what a PR should include? Basically reiterating the PR template that's shown whenever we make a PR, and what additional things or examples we can write in it. |
||
|
|
||
| - Set base branch to "develop" | ||
| - Add screenshots of results | ||
| - Follow the PR template | ||
| - Link your issue so it the first line reads "Closes #{ISSUE NUMBER}" (replace curly braces with number) | ||
| - Describe your changes and the ticket in the **"Overview"** section | ||
| - Describe what testing you completed to verify the feature (manual/unit testing) in the **"Testing"** section | ||
| - Add screenshots of results in the **"Screenshots"** section | ||
| - Complete the checklist by replacing the "[ ]" with "[x]" (or simply checking the boxes after publishing the PR) | ||
| - Add any additional notes at the bottom in the **"Notes"** section | ||
| - Assign at least 2 reviewers | ||
| - Link your issue (follow the PR template) | ||
|
|
||
| ### Best Practices to Write REST API | ||
|
|
||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a file naming convention as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and specify for which types of files we would name in what certain way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There doesn't seem to be a universal consensus for filenaming conventions in particular. I found camelCase (with some exceptions) to be the most consistent across sources.
It seems like most of the codebase uses dot.case. I know it's used, but I haven't been able to find much about the standards for it. But from what I can see with ESLint and some StackOverflow posts, dot.case in the way we use it seems fine