Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

[mrm-task-lint-staged] lint-staged task not suitable for running multiple times on a project #196

Closed
anshumanb opened this issue Sep 19, 2021 · 1 comment
Labels

Comments

@anshumanb
Copy link

lint-staged task appends npx lint-staged to .husky/pre-commit every time it runs which renders it unsuitable for running more than once. To reproduce:

$ mkdir test
$ cd test
$ git init
$ npm init -y
$ npm install -D eslint
$ npx mrm@2 lint-staged
$ cat .husky/pre-commit
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
$ npx mrm@2 lint-staged
$ cat .husky/pre-commit
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
npx lint-staged

Results are the same if I use npx mrm lint-staged instead of npx mrm@2 lint-staged.

My understanding is that mrm is meant to handle configuration upgrades so running npx mrm@2 lint-staged a second time should have resulted in no changes as there is nothing to upgrade.

$ npm ls
test@1.0.0 /tmp/test
├── eslint@7.32.0
├── husky@7.0.2
└── lint-staged@11.1.2

$ npm --version
7.22.0
$ node --version
v14.17.0
@anshumanb
Copy link
Author

anshumanb commented Sep 19, 2021

In my preset I added a workaround, which may/may not be suitable for the lint-staged task itself:

const lintStaged = require('mrm-task-lint-staged');
const { lines } = require('mrm-core');

const task = () => {
    // For every run of lint-staged, it appends "npx lint-staged" to pre-commit.
    // This needs to happen only once and on subsequent runs the file should
    // remain untouched
    const preCommit = lines('.husky/pre-commit');
    if (preCommit.exists()) {
        preCommit.remove('npx lint-staged').save();
    }

    lintStaged({
    ...

Happy to submit a PR with the above (or similar) if it's suitable.

@sapegin sapegin added the bug label Sep 13, 2023
Repository owner locked and limited conversation to collaborators Sep 13, 2023
@sapegin sapegin converted this issue into discussion #334 Sep 13, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Projects
None yet
Development

No branches or pull requests

2 participants