Skip to content
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

Ch config eslint 187584901 #12

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
3 changes: 0 additions & 3 deletions .env.example

This file was deleted.

41 changes: 41 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "import"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"quotes": ["warn", "double"],
"one-var": 0,
"one-var-declaration-per-line": 0,
"new-cap": 0,
"consistent-return": 0,
"no-param-reassign": 0,
"comma-dangle": 2,
"curly": ["warn", "multi-line"],
"import/no-unresolved": "off",
"no-shadow": ["error", { "allow": ["req", "res", "err"] }],
"valid-jsdoc": [
"warn",
{
"requireReturn": true,
"requireReturnType": true,
"requireParamDescription": false,
"requireReturnDescription": true
}
],
"require-jsdoc": [
"warn",
{
"require": {
"FunctionDeclaration": true,
"MethodDefinition": true,
"ClassDeclaration": true
}
}
]
}
}
49 changes: 42 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ This is the backend for E-Commerce-Ninjas, written in Node.js with TypeScript.

[https://github.com/atlp-rwanda/e-commerce-ninjas-bn](https://github.com/atlp-rwanda/e-commerce-ninjas-bn)


## Completed Features

- Setup an empty express boilerplate with dotenv
Expand All @@ -32,12 +31,9 @@ This is the backend for E-Commerce-Ninjas, written in Node.js with TypeScript.

## TABLE OF API ENDPOINTS SPECIFICATION AND DESCRIPTION


| No | VERBS | ENDPOINTS | STATUS | ACCESS | DESCRIPTION |
|----|-------|-----------|--------|--------|-------------------- |
| 1 | GET | / | 200 OK | public | Show welcome message|


| No | VERBS | ENDPOINTS | STATUS | ACCESS | DESCRIPTION |
| --- | ----- | --------- | ------ | ------ | -------------------- |
| 1 | GET | / | 200 OK | public | Show welcome message |

## Installation

Expand Down Expand Up @@ -81,5 +77,44 @@ This is the backend for E-Commerce-Ninjas, written in Node.js with TypeScript.
- `services/`: Service functions like sendEmails.
- `index.ts`: Startup file for all requests.

## ESLint Configuration

ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code. It helps maintain code quality and ensures consistency across the codebase.

We use ESLint in our project to enforce coding standards and catch common programming errors. Here's how we've configured ESLint for our project:

- We've extended the "airbnb-base" configuration to inherit a set of common JavaScript style rules recommended by Airbnb.
- We've disabled the "one-var", "one-var-declaration-per-line", and "new-cap" rules to allow multiple variable declarations in a single line and to disable the requirement for capitalizing constructor functions.
- We've set the "curly" rule to "warn" instead of "error" to raise a warning instead of an error when curly braces are omitted in control structures.
- We've enabled the "require-jsdoc" rule to enforce the presence of JSDoc comments for functions, methods, and classes, ensuring better code documentation.

### Usage

-To use eslint you should run

```bash
npm run lint
```

### Fixing Issues

ESLint can automatically fix many common issues in your code, such as formatting inconsistencies and stylistic errors. To automatically fix issues reported by ESLint, run the following command:

```bash
npm run lint -- --fix
```

## Husky

Husky is a tool that allows you to set up pre-commit hooks in your Git repository. Pre-commit hooks are scripts that run before each commit to enforce code quality and consistency.

In our project, we've configured Husky to run ESLint and lint-staged before each commit. Here's how it works:

When you run git commit, Husky triggers the pre-commit hook.

The pre-commit hook runs the following commands:

- npm run lint: This runs ESLint to check your code for errors and style issues.
- lint-staged: This runs lint-staged, a tool that runs ESLint (or other linters) on files staged for commit. This ensures that only staged files are checked by ESLint, making the process faster.

If any issues are found during these checks, the commit is aborted, and you'll need to fix the issues before committing again.
Loading
Loading