Skip to content
Merged
Show file tree
Hide file tree
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
39 changes: 38 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,44 @@ At this point, you can now modify existing files or add new files to the project

#### Make Changes Locally

Once you have modified existing files or added new files to the project, you can add them to your local repository, which you can do with the `git add` command. Let’s add the `-A` flag to add all changes that we have made:
Once you have modified existing files or added new files to the project:
##### Lint and Format
Before you stage or before you perform your final commit, your need to lint and format your changes.
The following steps assumes you have installed this projects dependence for the first time. If not run `npm install`.

To format and/or lint your changes use any of the following:
```bash
# This command is preferred as it lint and format your changes
npm run lint:format

# To lint only, fix fixable problems
npm run lint

# To format only
npm run format

# To lint a single file named "index.js" on the root directory
npx eslint ./index.js

# To format a single file named 'user.js' and on directory path say routes/
npx prettier ./routes/user.js
```
Note that some changes may not be fix automatically, as a result you are required to fix the problem manually.
On vscode, you can fix problem(s) automatically by:
1. Hovering on it and click on `Quick fix` OR
2. Click on the line that has the problem or warning then `CTRL + .`
In both cases use one the available options like `fix all auto-fixable problems` or `fix this prettier/prettier` to fix the error(s)

Most of the linting rules ( or code quality) follows eslint rule and the [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript). Read the guide

Read [eslint](https://eslint.org/docs/latest/rules/) and [prettier](https://prettier.io/docs/en/options.html) docs, and also learn how to install and integrate them with your text editor (or IDE).

To use with vscode, install [prettier extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) and [eslint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)

*Always lint:format, and manually fix lint, or code format problems before staging ... pushing your commits*

##### Staging, Committing and Pushing Change
Given that you have linted and formatted your changes, you can add now add the changes to your local repository, which you can do with the `git add` command. Let’s add the `-A` flag to add all changes that we have made:

```
git add -A
Expand Down
26 changes: 26 additions & 0 deletions server/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
env: {
commonjs: true,
es2021: true,
node: true
},
extends: ['airbnb-base', 'prettier'],
plugins: ['prettier'],
overrides: [],
parserOptions: {
ecmaVersion: 'latest'
},
rules: {
'prettier/prettier': [
'error',
// prettier rule for code formatting concerns
{
singleQuote: true,
trailingComma: 'none',
endOfLine: 'lf'
}
],
// eslint rules for code-quality concerns
'no-underscore-dangle': 'off'
}
};
10 changes: 10 additions & 0 deletions server/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const eslintConfig = require('./.eslintrc');

// When linting, formatting was configured and tested for this project,
// there was inconsistency with eslint and prettier.
// Both demands that prettier rules exist on both config files (.eslintrc.js and .prettierrc.js)
// So, in other to maintain the same configuration, it was defined on one file, .eslintrc was imported here

const prettierRules = eslintConfig.rules['prettier/prettier'][1];

module.exports = prettierRules;
Loading