Skip to content
forked from r2d2bzh/js-rules

r2d2bzh package to enforce some JS rules

Notifications You must be signed in to change notification settings

alshyra/js-rules

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JS-RULES

The R2D2 product stack is composed of multiple NodeJS micro-services. They need to be written with the same rules, and it’s a lot of time spent maintaining every config file on all repositories.

How ?

To do so we are using three tools:

What is Prettier? An opinionated code formatter

This tool is responsible for the code format: comma, semicolon, width, that’s for Prettier.

Eslint Find and fix problems in your JavaScript code

A useless variable? var, const or let? All these conventions are settled by the eslint configuration.

Husky can prevent a bad git commit, git push and more 🐶 woof!

This tool allows us to easily share git hooks. We are using it with the previous ones to keep our code base safe from linting errors.

On save

Prettier

When you save your file, you can ask your IDE to format your code for you. It will follow the rules described in the .prettier.js config file.

In order to make it work you may need some plugins:

Eslint

The exact same thing goes for eslint. You can ask your IDE to follow the rules specified in the eslint-config repository.

In order to make it work you may again need some plugins:

Note
These are not mandatory but strongly recommended.

On commit

When you commit your code modifications, Husky ensures that the following git hook is run:

link:./index.js[role=include]

Before committing husky calls prettier to format your code in case your IDE missed it. Then it will ask eslint to lint and fix your code.

Important

If an error is found during the validation the commit is canceled. You will have to first fix the lint errors before trying to commit again.

On push

There is currently no action on push but you can add some hooks yourself if you want.

You can add a pre-push action that will verify that the unit tests succeed, for instance:

huskyrc.js
module.exports = {
  hooks: {
    ...require('js-rules')('husky')({
      "pre-push": "docker-compose exec -T dev npm test"
    }),
  },
};

Install

You need to add the following NPM development dependency to the project that needs to be checked:

npm install --save-dev @r2d2bzh/eslint-config

This will add the package js-rules to the dependencies of your repository.

js-rules pulls the following dependencies so you don’t have to do it yourself:

package.json

link:./package.json[role=include]

About

r2d2bzh package to enforce some JS rules

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%