Skip to content

Commit cc23749

Browse files
committed
first commit
0 parents  commit cc23749

File tree

10 files changed

+216
-0
lines changed

10 files changed

+216
-0
lines changed

.eslintrc.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"env": {
3+
"commonjs": true,
4+
"es2021": true,
5+
"node": true,
6+
"jest/globals": true
7+
},
8+
"extends": [
9+
"eslint:recommended",
10+
"plugin:jest/recommended",
11+
"prettier"
12+
],
13+
"parserOptions": {
14+
"ecmaVersion": "latest"
15+
},
16+
"plugins": [
17+
"jest"
18+
],
19+
"rules": {}
20+
}

.github/workflows/ci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Node.js CI
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [18.x, 20.x]
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Use Node.js ${{ matrix.node-version }}
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
cache: 'npm'
24+
- name: Install dependencies
25+
run: npm ci
26+
- name: Lint code
27+
run: npm run lint
28+
- name: Check formatting
29+
run: npm run format
30+
- name: Run tests
31+
run: npm test

.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Dependencies
2+
/node_modules
3+
4+
# Logs
5+
logs
6+
*.log
7+
npm-debug.log*
8+
yarn-debug.log*
9+
yarn-error.log*
10+
lerna-debug.log*
11+
12+
# Diagnostic reports (https://nodejs.org/api/report.html)
13+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
14+
15+
# Test coverage
16+
/coverage
17+
18+
# Build output
19+
/dist
20+
/build
21+
22+
# Misc
23+
.DS_Store
24+
.env
25+
.env.local
26+
.env.development.local
27+
.env.test.local
28+
.env.production.local

.prettierignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore artifacts:
2+
build
3+
coverage
4+
dist
5+
node_modules

.prettierrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"semi": true,
3+
"trailingComma": "es5",
4+
"singleQuote": true,
5+
"printWidth": 80,
6+
"tabWidth": 2
7+
}

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# js-quality-starter
2+
3+
A starter repository for JavaScript projects with pre-configured linting, formatting, testing, and CI using GitHub Actions.
4+
5+
This template provides a solid foundation for any new JavaScript project, ensuring code quality and consistency from the start.
6+
7+
## Features
8+
9+
- **Linting** with [ESLint](https://eslint.org/) to find and fix problems in your JavaScript code.
10+
- **Formatting** with [Prettier](https://prettier.io/) for a consistent code style.
11+
- **Testing** with [Jest](https://jestjs.io/) as the testing framework.
12+
- **CI/CD** with [GitHub Actions](https://github.com/features/actions) to automate linting, formatting checks, and testing on every push and pull request.
13+
- **Pre-commit Hooks** with [Husky](https://typicode.github.io/husky/) and [lint-staged](https://github.com/okonet/lint-staged) to lint and format your code before you even commit it.
14+
15+
## Getting Started
16+
17+
### Using as a Template
18+
19+
Click the "Use this template" button on the GitHub repository page to create a new repository with the same directory structure and files.
20+
21+
### Manual Setup
22+
23+
1. Clone the repository:
24+
```bash
25+
git clone https://github.com/your-username/js-quality-starter.git
26+
cd js-quality-starter
27+
```
28+
29+
2. Install dependencies:
30+
```bash
31+
npm install
32+
```
33+
34+
## Available Scripts
35+
36+
In the project directory, you can run:
37+
38+
- `npm test`: Runs the tests using Jest.
39+
- `npm run lint`: Lints all `.js` files in the project.
40+
- `npm run lint:fix`: Lints and automatically fixes fixable issues.
41+
- `npm run format`: Checks for formatting issues with Prettier.
42+
- `npm run format:fix`: Formats all supported files with Prettier.
43+
44+
## How It Works
45+
46+
### Pre-commit Hook
47+
48+
This project uses `husky` and `lint-staged` to run `eslint --fix` and `prettier --write` on staged `.js` files every time you make a commit. This ensures that no code that violates the style guide gets into the codebase.
49+
50+
After running `npm install`, the `prepare` script sets up the husky hooks.
51+
52+
### CI Pipeline
53+
54+
The `.github/workflows/ci.yml` file defines a GitHub Actions workflow that runs on every push and pull request to the `main` branch. It performs the following checks on Node.js 18.x and 20.x:
55+
56+
1. Installs dependencies.
57+
2. Runs `npm run lint` to check for linting errors.
58+
3. Runs `npm run format` to check for formatting errors.
59+
4. Runs `npm test` to execute the test suite.
60+
61+
This ensures that all code in the `main` branch is high quality and passes all checks.

jest.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** @type {import('jest').Config} */
2+
const config = {
3+
verbose: true,
4+
testEnvironment: 'node',
5+
coverageProvider: 'v8',
6+
};
7+
8+
module.exports = config;

package.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "js-quality-starter",
3+
"version": "1.0.0",
4+
"description": "A starter repository for JavaScript projects with pre-configured linting, formatting, testing, and CI using GitHub Actions.",
5+
"main": "src/index.js",
6+
"scripts": {
7+
"test": "jest",
8+
"lint": "eslint .",
9+
"lint:fix": "eslint . --fix",
10+
"format": "prettier --check .",
11+
"format:fix": "prettier --write .",
12+
"prepare": "husky install"
13+
},
14+
"keywords": [
15+
"javascript",
16+
"template",
17+
"eslint",
18+
"prettier",
19+
"jest",
20+
"ci",
21+
"starter"
22+
],
23+
"author": "",
24+
"license": "MIT",
25+
"devDependencies": {
26+
"eslint": "^8.57.0",
27+
"eslint-config-prettier": "^9.1.0",
28+
"eslint-plugin-jest": "^28.2.0",
29+
"husky": "^8.0.0",
30+
"jest": "^29.7.0",
31+
"lint-staged": "^15.2.2",
32+
"prettier": "^3.2.5"
33+
},
34+
"lint-staged": {
35+
"*.js": [
36+
"eslint --fix",
37+
"prettier --write"
38+
]
39+
}
40+
}

src/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function add(a, b) {
2+
return a + b;
3+
}
4+
5+
module.exports = add;

src/index.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const add = require('./index');
2+
3+
describe('add function', () => {
4+
test('should add two numbers correctly', () => {
5+
expect(add(1, 2)).toBe(3);
6+
});
7+
8+
test('should handle negative numbers', () => {
9+
expect(add(-1, -1)).toBe(-2);
10+
});
11+
});

0 commit comments

Comments
 (0)