Skip to content

docs: update CONTRIBUTING_JS.md #784

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
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions CONTRIBUTING_JS.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,34 @@ We do not go out of our way to break compatibility with platforms, but we can on

Some modules do not support certain platforms, these should be easy to spot - e.g. `@libp2p/tcp` supports only Node.js and Electron because TCP does not work in web browsers.

#### Files

##### TypeScript

We encourage the use of TypeScript for type safety and improved developer experience. When adding new files, prefer .ts for standard TypeScript files and .tsx for React components. Ensure that TypeScript configurations align with the project's existing settings.

`aegir` can help you set up a new project with an appropriate tsconfig.json.

##### Case-sensitivity
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make a note that this is a recommendation and that at the very least it's important to maintain consistency on a project level. Because currently not all projects use kebab-case.

For example https://github.com/ipfs/ipld-explorer-components/tree/master/src/components uses PascalCase.


Adopt kebab-case (lowercase letters with hyphens separating words) for filenames to maintain consistency across all our projects and limit issues with case-insensitive filesystems. For instance, name a file `example-file.ts` instead of `exampleFile.ts` or `example_file.ts`.

#### Linting & Code Style

IPFS JavaScript projects default to [eslint-config-ipfs](https://github.com/ipfs/eslint-config-ipfs) which is based on [standard](https://github.com/feross/standard) code style. It is a clean codestyle, and its adoption is increasing significantly, making the code that we write familiar to the majority of the developers.

Using [aegir-lint](#aegir) will help you do this easily; it automatically lints your code.

##### Importing modules and files

When writing import statements, include file extensions to comply with ECMAScript Module (ESM) standards. For example:

```ts
import { exampleFunction } from './example-file.js';
```

This practice ensures compatibility across different environments and aligns with modern JavaScript standards.

#### Dependency Versions

Our rule is: Use ~ for everything below 1.0.0 and ^ for everything above 1.0.0. If you find a package.json that is not following this rule, please submit a PR.
Expand Down Expand Up @@ -135,6 +157,18 @@ A `gh-pages` branch will be created, and this should be published to via the Git

This makes API docs available, and the types are linked through to from other modules published by aegir.

aegir can also update the `About` section of a README.md based on the `@packageDocumentation` of your entry file via the `aegir docs` command.

#### Front-end and UI

##### React

For projects utilizing React, adhere to the following standards:

1. Component Naming: Use kebab-case for component names (e.g., `my-component`). This is different than idiomatic React, which uses PascalCase.​
2. File Extensions: Use .tsx for files containing React components to leverage TypeScript's JSX support.​
3. State Management: Prefer using React's built-in state management features. If additional state management libraries are needed, please ensure they are well-justified, align with the project's architecture, and are well-typed.
Copy link
Member Author

@SgtPooki SgtPooki Mar 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
3. State Management: Prefer using React's built-in state management features. If additional state management libraries are needed, please ensure they are well-justified, align with the project's architecture, and are well-typed.
3. State Management: Prefer using React's built-in state management features. If additional state management libraries are needed, please ensure they are well-justified, align with the project's architecture, and are well-typed. (e.g. do not use redux-bundler)
4. Do not use prop-types or `.defaultProps`
5. Use functional components, hooks, and context where appropriate. Classes may be used for the logic of your components, but the component itself should be functional.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@achingbrain any thoughts on these additions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have any strong preferences around react/redux/etc. I don't use it much and every time I do, it seems to have changed completely so happy to go with whatever.

Copy link
Member

@2color 2color Mar 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree redux-bundler proved to be a flop. Either way, I wouldn't prescribe this on an org level. Instead I'd leave it up to the maintainer of the specific library.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should advise against redux-bundler at the org level because it breaks type-safety.


### Commits

We have guidelines for how our git commit messages should be formatted. This leads to more readable messages that are easy to follow when looking through the project history. But also, we use the git commit messages to generate the change log.
Expand Down