Skip to content

Commit

Permalink
feat: dual-linting implementado
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Bezerra committed Feb 7, 2022
1 parent 00e2cdd commit 21c7829
Show file tree
Hide file tree
Showing 11 changed files with 2,552 additions and 3 deletions.
29 changes: 29 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"airbnb-base"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"semi": ["warn", "always"],
"quotes": ["error", "double"],
"import/extensions": "off"
},
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".ts"]
}
}
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

echo 'Starting pre-commit'
npm run lint-staged
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"editor.codeActionsOnSave": {
"editor.formatOnSave": false,
"source.fixAll.eslint": true
},
"eslint.format.enable": true,
}
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,22 @@
This is POC shows that it's possible to have only one code style on server-side and each developer could have their own code style simultaneously.

## How?
There are two eslint configuration files: (1) one on the root of the project - the server code style, (2) another one on ./src - each devs code style.
There are two eslint configuration files:

1. One on the root of the project - the server code style;
2. Another one on ./src - each devs code style.

(1) By using Git Hooks (Husky and Lint-staged), before committing the code will always be linted using this eslint configuration.
(2) is on .gitignore, so that no dev overrides the others configurations.
While coding, each developer can override the second configuration file, so it be the way they want during development. But when the developer wants to commit their changes, the server code style should be applied instead of their own. This is possible by using ESLint's scripts.

eslint ./src --ext .js --ext .ts --fix -c ./.eslintrc.json --no-eslintrc

Where .src is the path you want to lint, --ext is the extensions you want to lint, -c is the configuration file you want to use, and --no-eslintrc says no other configuration file should be used.

> **_Note:_** The dev configuration file should be on .gitignore, so that it doesn't override the others configurations.

## Husky and lint-staged

By using Git Hooks with the lib Husky, you can call a script on package.json. So before committing the changes, the code will always be linted using the server's configuration file.

Lint-staged is reponsible for re-adding the files which were changed by the linting process.
3 changes: 3 additions & 0 deletions app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import sayHello from "./src/hello";

sayHello();
Loading

0 comments on commit 21c7829

Please sign in to comment.