All Projects → sudo-suhas → Lint Staged Multi Pkg

sudo-suhas / Lint Staged Multi Pkg

Licence: mit
Example repo to demonstrate use of `lint-staged` with multi-pkg projects

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Lint Staged Multi Pkg

React Antd Todo
A simple todo list app built with React, Redux and Antd - Ant Design
Stars: ✭ 42 (-71.62%)
Mutual labels:  example-project
Flutter Watchtips
Flutter App (Embedded Watch Kit app with iOS version)
Stars: ✭ 114 (-22.97%)
Mutual labels:  example-project
Vlingo Examples
The VLINGO/PLATFORM examples demonstrating features and functionality available in the reactive components.
Stars: ✭ 121 (-18.24%)
Mutual labels:  example-project
Bmi Calculator
React Hooks app for calculating BMI
Stars: ✭ 80 (-45.95%)
Mutual labels:  example-project
Go Examples
examples written using golang third party packages.
Stars: ✭ 106 (-28.38%)
Mutual labels:  example-project
Razzle Material Ui Styled Example
Razzle Material-UI example with Styled Components using Express with compression
Stars: ✭ 117 (-20.95%)
Mutual labels:  example-project
Asp.net User Role Membership Example
Asp.Net Core Mvc Full Implementation Example of User Role & Membership.
Stars: ✭ 33 (-77.7%)
Mutual labels:  example-project
Angular9 Example App
Angular 13 Example App + Angular CLI + i18n + GraphQL
Stars: ✭ 1,769 (+1095.27%)
Mutual labels:  example-project
Godot public examples
Stars: ✭ 106 (-28.38%)
Mutual labels:  example-project
Angular5 Example Shopping App
Angular 5 Example Shopping App + Angular Material + Responsive
Stars: ✭ 120 (-18.92%)
Mutual labels:  example-project
Flask Restplus Server Example
Real-life RESTful server example on Flask-RESTplus
Stars: ✭ 1,240 (+737.84%)
Mutual labels:  example-project
Jni By Examples
🎇Fun Java JNI By Examples - with CMake and C++ (or C, of course!) ‼️ Accepting PRs
Stars: ✭ 99 (-33.11%)
Mutual labels:  example-project
Django Crud Ajax Login Register Fileupload
Django Crud, Django Crud Application, Django ajax CRUD,Django Boilerplate application, Django Register, Django Login,Django fileupload, CRUD, Bootstrap, AJAX, sample App
Stars: ✭ 118 (-20.27%)
Mutual labels:  example-project
Play Scala Slick Example
Example Play Scala project with Slick
Stars: ✭ 59 (-60.14%)
Mutual labels:  example-project
Reactnativetemplate
Our example of simple application using ReactNative and some recommendations
Stars: ✭ 127 (-14.19%)
Mutual labels:  example-project
Kioskmode Android
Screen Pinning Android Lollipop with enable Device Administrator without Root needed
Stars: ✭ 40 (-72.97%)
Mutual labels:  example-project
Annotation Processing Example
It is the example project for the annotation processing tutorial.
Stars: ✭ 116 (-21.62%)
Mutual labels:  example-project
Android Base Mvp
Android Base MVP Concept with RXJava, Dagger, Event Bus, Retrofit, Glide, OkHTTP
Stars: ✭ 141 (-4.73%)
Mutual labels:  example-project
Android Clean Architecture Mvvm Dagger Rx
Implemented by Clean Architecture, Dagger2, MVVM, LiveData, RX, Retrofit2, Room, Anko
Stars: ✭ 138 (-6.76%)
Mutual labels:  example-project
Godot tutorials
Code and examples for KidsCanCode Godot Tutorials.
Stars: ✭ 119 (-19.59%)
Mutual labels:  example-project

lint-staged-multi-pkg

Example repo to demostrate use of lint-staged in multi package project with lerna and husky.

pre-commit hook

husky is installed in the root package.json as recommended in husky docs.

The pre-commit hook is configured with the script lerna run --concurrency 1 --stream precommit --since HEAD --exclude-dependents. This executes the precommit script for each package (if it exists). Execution is limited to only those packages with modified files, however the --since HEAD --exclude-dependents option does not consider whether the file is staged. To further limit precommit to only staged files please look at the discussion in sudo-suhas/lint-staged-multi-pkg#4. Furthermore, concurrent execution is disabled because it can cause problems during git add (see okonet/lint-staged#225).

lint-staged configuration

Starting with v5.0, lint-staged automatically resolves the git root without any additional configuration. You configure lint-staged as you normally would, if your project root and git root were the same directory.

Project structure:

.
|-- .git
|-- .gitattributes
|-- .gitignore
|-- lerna.json
|-- license
|-- package.json
|-- packages
|   |-- say-bye
|   |   |-- .eslintrc.yml
|   |   |-- .lintstagedrc.yml
|   |   |-- lib
|   |   |   `-- index.js
|   |   |-- package.json
|   |   `-- yarn.lock
|   `-- say-hi
|       |-- .eslintrc.yml
|       |-- .lintstagedrc.yml
|       |-- package.json
|       |-- src
|       |   `-- index.js
|       `-- yarn.lock
|-- readme.md
`-- yarn.lock

lint-staged config for package say-hi, .lintstagedrc.yml:

linters:
  src/*.js:
    - eslint --fix
    - git add

Note: lint-staged has not been upgraded to v8 as it requires Node >= 8.6.

Output

Example output from the git hook execution:

$ git commit
husky > pre-commit (node v11.9.0)
lerna notice cli v3.13.1
lerna info Executing command in 2 packages: "yarn run precommit"
say-bye: yarn run v1.13.0
say-bye: $ lint-staged
say-bye: Running tasks for lib/*.js [started]
say-bye: eslint --fix [started]
say-bye: eslint --fix [completed]
say-bye: git add [started]
say-bye: git add [completed]
say-bye: Running tasks for lib/*.js [completed]
say-bye: Done in 1.05s.
say-hi: yarn run v1.13.0
say-hi: $ lint-staged
say-hi: Running tasks for src/*.js [started]
say-hi: eslint --fix [started]
say-hi: eslint --fix [completed]
say-hi: git add [started]
say-hi: git add [completed]
say-hi: Running tasks for src/*.js [completed]
say-hi: Done in 1.03s.
lerna success run Ran npm script 'precommit' in 2 packages in 2.5s:
lerna success - say-bye
lerna success - say-hi

What if I don't want to or can't use lerna?

You might not want to use lerna either because you think it is overkill or if you have a different monorepo setup than the one required by lerna. You can still use lint-staged, though not as easily:

Install lint-staged at the package root

Install lint-staged and husky at the project root and configure all linters at the root:

Project structure:

.
|-- .git
|-- .gitignore
|-- .lintstagedrc.yml 🢀 Our `lint-staged` config at the monorepo root.
|-- package.json
|-- prj-1
|   |-- .eslintrc.yml
|   |-- .gitignore
|   |-- package.json
|   |-- src
|   |   `-- index.js
|   `-- yarn.lock
`-- prj-2
    |-- .eslintrc.yml
    |-- .gitignore
    |-- package.json
    |-- src
    |   `-- index.js
    `-- yarn.lock

.lintstagedrc.yml:

linters:
  prj-1/*.js:
    - eslint --fix
    - some-other-cmd
    - git add
  prj-2/**/*.js:
    - eslint --fix
    - git add

Note: All linters would have to be installed in the root package.

Manually call precommit in each package

Install husky at the project root and setup the pre-commit hook to execute the precommit script in each package. npm-run-all could also be used to make things a bit easier:

// package.json
{
  "...": "...",
  "scripts": {
    "precommit:prj-1": "cd prj-1 && npm run precommit",
    "precommit:prj-2": "cd prj-2 && npm run precommit",
    "precommit": "npm-run-all precommit:*"
  },
}

Project structure:

.
|-- .gitignore
|-- package.json
|-- prj-1
|   |-- .eslintrc.yml
|   |-- .gitignore
|   |-- .lintstagedrc.yml 🢀 Each project has it's own config.
|   |-- package.json
|   |-- src
|   |   `-- index.js
|   `-- yarn.lock
`-- prj-2
    |-- .eslintrc.yml
    |-- .gitignore
    |-- .lintstagedrc.yml
    |-- package.json
    |-- src
    |   `-- index.js
    `-- yarn.lock

License

MIT © Suhas Karanth

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].