Code Monkey home page Code Monkey logo

nano-staged's Introduction

nano-staged's People

Contributors

ai avatar amrsekilly avatar azat-io avatar michalkleiner avatar usmanyunusov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nano-staged's Issues

Better output on script error

I have script to be sure that I changed versions everywhere. If I made a mistake, this script will exit with 1 code and prints:

Update pnpm version in .github/workflows/test.yml

I add this script to nano-staged and it works well. But nano-staged has unnecessary Error block at the end of output.

Current output:

Nano Staged v0.4.1
- Preparing pipeliner...
  » Done backing up original repo state.
- Running tasks...
  *.(js|ts)      no staged files matching the pattern were found.
  *.css          no staged files matching the pattern were found.
  *.svelte       no staged files matching the pattern were found.
  .tool-versions node ./scripts/check-versions.js
- Restoring to its original state...
  » Done restoring up to its original state.
- Removing patch files...
  » Done removing up patch files.

node ./scripts/check-versions.js:
Update pnpm version in .github/workflows/test.yml
Error
    at Object.runTasks (file:///home/ai/Dev/slowreader/node_modules/.pnpm/[email protected]/node_modules/nano-staged/lib/pipeliner.js:118:21)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.backupUnstagedFiles (file:///home/ai/Dev/slowreader/node_modules/.pnpm/[email protected]/node_modules/nano-staged/lib/pipeliner.js:62:7)
    at async Object.run (file:///home/ai/Dev/slowreader/node_modules/.pnpm/[email protected]/node_modules/nano-staged/lib/pipeliner.js:42:7)
    at async run (file:///home/ai/Dev/slowreader/node_modules/.pnpm/[email protected]/node_modules/nano-staged/lib/run.js:58:5) {
  tasks: '\x1B[31mnode ./scripts/check-versions.js:\n' +
    '\x1B[39mUpdate pnpm version in .github/workflows/test.yml'
}

Expected output:

Nano Staged v0.4.1
- Preparing pipeliner...
  » Done backing up original repo state.
- Running tasks...
  *.(js|ts)      no staged files matching the pattern were found.
  *.css          no staged files matching the pattern were found.
  *.svelte       no staged files matching the pattern were found.
  .tool-versions node ./scripts/check-versions.js
- Restoring to its original state...
  » Done restoring up to its original state.
- Removing patch files...
  » Done removing up patch files.

node ./scripts/check-versions.js:
Update pnpm version in .github/workflows/test.yml

[Feature Request] Keep the color of the output like raw result scripts

Clear and concise description of the problem

Our project use kolorist and zx npm package to handle some config and log color in the terminal and CI/CD --> I thinks nano-staged should keep the raw result scripts from output.

Raw output from our scripts -->
image
Here the nano-staged output
image

Suggested solution

Sorry, I don't know it yet 🥲 - Thanks for reading this 🙏

Alternative

No response

Additional context

No response

Batched linting

Clear and concise description of the problem

lint-staged/lint-staged#147

Facing similar issue on Windows with nano-staged (specifically, receiving a 'command line is too long' when running nano-staged pre-commit hooks w/a large number of files).

lint-staged v10 allegedly fixes this issue by batching / parallelizing the list of files into chunks.

Suggested solution

batch, lint-staged/lint-staged#147 (comment)

Alternative

No response

Additional context

No response

Add external config

It will be nice to have support of .nano-staged.json config in additional to package.json. In webapps my team prefer separated configs.

Request: Support for git worktrees

Clear and concise description of the problem

Currently git worktree is not supported. The following error appears:

Screenshot_20220415_122454

Suggested solution

before attempting to read .git as a directory stat it to determine if it is a worktree (where .git is a file containing a path) or not (where it is a directory)

Alternative

No response

Additional context

To recreate create a new project:

mkdir test-project-master
cd test-project
git init
yarn init -y && yarn add nano-staged prettier

Then add a config such as this one to package.json

  "nano-staged": {
    "**/*.js": [
      "prettier -w"
    ],
  }

Now commit the initial setup, then create a new worktree and attempt to make a commit there

git add -A
git commit -m "Initial setup"

git worktree add ../test-project-dev -b dev-branch # creates new worktree with its own branch
# note that a branch cannot be checked out by multiple worktrees,
# thus a new branch is required
cd ../test-project-dev
yarn # install in the new worktree

touch a-file.js
git add a-file.js
git commit -m "added a file"

You should now get the error as in the current working directory .git is a file describing the location of its location in the .git directory of the main tree. For more information on worktrees see git-worktree

Prettify output log

Hey, is it possible to improve the message nano-staged produces? When a user uses a git client that doesn't support colors, the message looks unreadable

Tower git client

lint-staged:

yarn run v1.22.17
$ /Users/pavel/t/main/node_modules/.bin/lint-staged
[STARTED] Preparing...
[SUCCESS] Preparing...
[STARTED] Running tasks...
[STARTED] Running tasks for *.{js,jsx,ts,tsx}
[STARTED] Running tasks for *.scss
[SKIPPED] No staged files match *.scss
[STARTED] eslint --fix
[FAILED] eslint --fix [FAILED]
[SUCCESS] Running tasks...
[STARTED] Applying modifications...
[SKIPPED] Skipped because of errors from tasks.
[STARTED] Reverting to original state because of errors...
[SUCCESS] Reverting to original state because of errors...
[STARTED] Cleaning up...
[SUCCESS] Cleaning up...

✖ eslint --fix:

/Users/pavel/t/main/app/javascript/__tests__/sites/reports/loyalty/loyalty_members_report/loyalty_member_details/loyalty_member_details_render.test.js
  442:12  error  Do not access a member directly from an await expression  unicorn/no-await-expression-member

✖ 1 problem (1 error, 0 warnings)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
husky - pre-commit hook exited with code 1 (error)

nano-staged:

yarn run v1.22.17
$ /Users/pavel/t/main/node_modules/.bin/nano-staged
Nano Staged v0.4.1
- Preparing pipeliner...
  » Done backing up original repo state.
- Running tasks...
  *.scss            no staged files matching the pattern were found.
  *.{js,jsx,ts,tsx} eslint --fix
  *.{js,jsx,ts,tsx} stylelint --config '.stylelint_css_in_js.js' --syntax scss
- Restoring to its original state...
  » Done restoring up to its original state.
- Removing patch files...
  » Done removing up patch files.

eslint --fix:
�[0m�[0m
�[0m�[4m/Users/pavel/t/main/app/javascript/__tests__/sites/reports/loyalty/loyalty_members_report/loyalty_member_details/loyalty_member_details_render.test.js�[24m�[0m
�[0m  �[2m442:12�[22m  �[31merror�[39m  Do not access a member directly from an await expression  �[2municorn/no-await-expression-member�[22m�[0m
�[0m�[0m
�[0m�[31m�[1m✖ 1 problem (1 error, 0 warnings)�[22m�[39m�[0m
�[0m�[31m�[1m�[22m�[39m�[0m

Error
    at Object.runTasks (file:///Users/pavel/t/main/node_modules/nano-staged/lib/pipeliner.js:118:21)
    at async Object.backupUnstagedFiles (file:///Users/pavel/t/main/node_modules/nano-staged/lib/pipeliner.js:62:7)
    at async Object.run (file:///Users/pavel/t/main/node_modules/nano-staged/lib/pipeliner.js:42:7)
    at async run (file:///Users/pavel/t/main/node_modules/nano-staged/lib/run.js:58:5) {
  tasks: 'eslint --fix:\n' +
    '\x1B[0m\x1B[0m\n' +
    '\x1B[0m\x1B[4m/Users/pavel/t/main/app/javascript/__tests__/sites/reports/loyalty/loyalty_members_report/loyalty_member_details/loyalty_member_details_render.test.js\x1B[24m\x1B[0m\n' +
    '\x1B[0m  \x1B[2m442:12\x1B[22m  \x1B[31merror\x1B[39m  Do not access a member directly from an await expression  \x1B[2municorn/no-await-expression-member\x1B[22m\x1B[0m\n' +
    '\x1B[0m\x1B[0m\n' +
    '\x1B[0m\x1B[31m\x1B[1m✖ 1 problem (1 error, 0 warnings)\x1B[22m\x1B[39m\x1B[0m\n' +
    '\x1B[0m\x1B[31m\x1B[1m\x1B[22m\x1B[39m\x1B[0m\n'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
husky - pre-commit hook exited with code 1 (error)

Git console

lint-staged:

[~/t/main]$ git commit -m '.'                                                                                                                                                                                                 *[pp-js-deps][ruby-3.0.2@t]
yarn run v1.22.17
$ /Users/pavel/t/main/node_modules/.bin/lint-staged
✔ Preparing...
⚠ Running tasks...
  ❯ Running tasks for *.{js,jsx,ts,tsx}
    ✖ eslint --fix [FAILED]
    ◼ stylelint --config '.stylelint_css_in_js.js' --syntax scss
  ↓ No staged files match *.scss [SKIPPED]
↓ Skipped because of errors from tasks. [SKIPPED]
✔ Reverting to original state because of errors...
✔ Cleaning up...

✖ eslint --fix:

/Users/pavel/t/main/app/javascript/__tests__/sites/reports/loyalty/loyalty_members_report/loyalty_member_details/loyalty_member_details_render.test.js
  442:12  error  Do not access a member directly from an await expression  unicorn/no-await-expression-member

✖ 1 problem (1 error, 0 warnings)

error Command failed with exit code 1.

nano-staged

[~/t/main]$ git commit -m '.'                                                                                                                                                                                                  [pp-js-deps][ruby-3.0.2@t]
yarn run v1.22.17
$ /Users/pavel/t/main/node_modules/.bin/nano-staged
Nano Staged v0.4.1
- Preparing pipeliner...
  » Done backing up original repo state.
- Running tasks...
  *.scss            no staged files matching the pattern were found.
  *.{js,jsx,ts,tsx} eslint --fix
  *.{js,jsx,ts,tsx} stylelint --config '.stylelint_css_in_js.js' --syntax scss
- Restoring to its original state...
  » Done restoring up to its original state.
- Removing patch files...
  » Done removing up patch files.

eslint --fix:

/Users/pavel/t/main/app/javascript/__tests__/sites/reports/loyalty/loyalty_members_report/loyalty_member_details/loyalty_member_details_render.test.js
  442:12  error  Do not access a member directly from an await expression  unicorn/no-await-expression-member

✖ 1 problem (1 error, 0 warnings)


Error
    at Object.runTasks (file:///Users/pavel/t/main/node_modules/nano-staged/lib/pipeliner.js:118:21)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.backupUnstagedFiles (file:///Users/pavel/t/main/node_modules/nano-staged/lib/pipeliner.js:62:7)
    at async Object.run (file:///Users/pavel/t/main/node_modules/nano-staged/lib/pipeliner.js:42:7)
    at async run (file:///Users/pavel/t/main/node_modules/nano-staged/lib/run.js:58:5) {
  tasks: '\x1B[31meslint --fix:\n' +
    '\x1B[39m\x1B[0m\x1B[0m\n' +
    '\x1B[0m\x1B[4m/Users/pavel/t/main/app/javascript/__tests__/sites/reports/loyalty/loyalty_members_report/loyalty_member_details/loyalty_member_details_render.test.js\x1B[24m\x1B[0m\n' +
    '\x1B[0m  \x1B[2m442:12\x1B[22m  \x1B[31merror\x1B[39m  Do not access a member directly from an await expression  \x1B[2municorn/no-await-expression-member\x1B[22m\x1B[0m\n' +
    '\x1B[0m\x1B[0m\n' +
    '\x1B[0m\x1B[31m\x1B[1m✖ 1 problem (1 error, 0 warnings)\x1B[22m\x1B[39m\x1B[0m\n' +
    '\x1B[0m\x1B[31m\x1B[1m\x1B[22m\x1B[39m\x1B[0m\n'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
husky - pre-commit hook exited with code 1 (error)

glob-to-regex not correctly converting ! in combination with globstars

Use case

I have a codebase with some customized svg icons and would like to automatically run *.svg through svgo, but not touch *.inkscape.svg files. With lint-staged I solved this with the pattern "**/!(*inkscape).svg".

Expected behaviour

pattern matches any string unless it contains inkscape immediatly before .svg

Actual behaviour

foo.bar.svg is not matched.

Reproduction Steps:

I wrote the following test file to simulate my use-case:

import { is } from 'uvu/assert'
import { test } from 'uvu'

import { globToRegex } from '../lib/glob-to-regex.js' //nano-staged@git

function match(glob, path, opts = {}) {
  let regex = globToRegex(glob, opts)
  return regex.regex.test(path)
}

test('mitsunee use-case', () => {
  const pattern = '**/!(*foo).txt' // match all *.txt files other than *foo.txt
  is(match(pattern, 'bar.foo.txt', { extended: true }), false, "Doesn't match *.foo.txt")
  is(match(pattern, 'bar.baz.txt', { extended: true }), true, 'Does match *.baz.txt') // FAILS
  is(match(pattern, 'bar.txt', { extended: true }), true, 'Does match *.txt') // FAILS
  is(match(pattern, 'foo.bar.txt', { extended: true }), true, 'Does match foo*.txt') // FAILS
})

test.run()

I tried adjusting the pattern by (re)moving the single star and got the same result each time.

In addition I cloned the repository of micromatch (which lint-staged uses for glob pattern matching) and wrote the following tests to confirm my existing setup works as intended (all four tests passed):

'use strict';

require('mocha');
const { equal } = require('assert');
const { isMatch } = require('..'); //micromatch@git

describe('mitsunee use-case', () => {
  const pattern = '**/!(*foo).txt';

  it("Doesn't match *.foo.txt", () => {
    equal(isMatch('bar.foo.txt', pattern), false);
  });
  it('Does match *.baz.txt', () => {
    equal(isMatch('bar.baz.txt', pattern), true);
  });
  it('Does match *.txt', () => {
    equal(isMatch('bar.txt', pattern), true);
  });
  it('Does match foo.*.txt', () => {
    equal(isMatch('foo.bar.txt', pattern), true);
  });
});

Run commands from the nearest package.json's directory

Clear and concise description of the problem

Sometimes, running eslint on a monorepo workspace causes errors because the eslint binary is being run from the root workspace, causing issues for instance when using the TypeScript plugin, which relies on the tsconfig.json being on the workspace directory.

Suggested solution

When executing any of the scripts specified in nano-staged, we could use find-up to determine where the nearest package.json is located and use its directory as the cwd.

Alternative

No response

Additional context

No response

Error: spawn eslint ENOENT

I'm trying to migrate the project from lint-staged to nano-staged. Installed. Replaced configuration:

  "nano-staged": {
    "*.{js,ts,vue}": "eslint --cache --fix"
  },

Run

$ npx nano-staged
Nano Staged v0.3.1
- Preparing pipeliner...
  » Done backing up original repo state.
- Running tasks...
  *.{js,ts,vue} eslint --cache --fix
- Restoring to its original state...
  » Done restoring up to its original state.
- Removing patch files...
  » Done removing up patch files.

eslint --cache --fix:
Error: spawn eslint ENOENT

This is repeated with any command

  "nano-staged": {
    "*.{js,ts,vue}": "npx eslint --cache --fix"
  },
$ npx nano-staged
Nano Staged v0.3.1
- Preparing pipeliner...
  » Done backing up original repo state.
- Running tasks...
  *.{js,ts,vue} npx eslint --cache --fix
- Restoring to its original state...
  » Done restoring up to its original state.
- Removing patch files...
  » Done removing up patch files.

npx eslint --cache --fix:
Error: spawn npx ENOENT
  "nano-staged": {
    "*.{js,ts,vue}": "npm run lint"
  },
$ npx nano-staged
Nano Staged v0.3.1
- Preparing pipeliner...
  » Done backing up original repo state.
- Running tasks...
  *.{js,ts,vue} npm run lint
- Restoring to its original state...
  » Done restoring up to its original state.
- Removing patch files...
  » Done removing up patch files.

npm run lint:
Error: spawn npm ENOENT

Quiet mode wanted

Clear and concise description of the problem

Heey,
thanks for this piece of magic, I was disappointed with lint-staged so I came here!

I'd like to have a way to suppress any progress message printed during the lint process, I just need to know if all's done or if some error occurred. The git client I use (fork) doesn't support interactive output very well, so it logs all the lines every time:

image

Suggested solution

A --quiet command line flag might do the trick for me.

Alternative

No response

Additional context

No response

BANDE DE PDS

Describe the bug

PD

Reproduction

PD

System Info

PD

Used Package Manager

npm

Invalid config on lambda

Describe the bug

module.exports = {
  '*.{ts,tsx}': [
    'pnpm prettier --write',
    () => 'pnpm tsc -p tsconfig.json',
    'pnpm eslint --fix'
  ],
  '*.css': ['pnpm prettier --write', 'pnpm stylelint --fix']
};

Leads to:

./node_modules/.bin/nano-staged --config ./.nano-staged.cjs
× Nano Staged config invalid

Reproduction

mkdir test
cd test
git init
pnpm add .nano-staged.cjs
nano .nano-staged.cjs # copy config from above
pnpm nano-staged -c .nano-staged.cjs

System Info

System:
    OS: Linux 6.2 Fedora Linux 38 (Workstation Edition)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
    Memory: 5.24 GB / 15.31 GB
    Container: Yes
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.1.0 - ~/.asdf/installs/nodejs/20.1.0/bin/node
    Yarn: 1.22.19 - ~/.asdf/shims/yarn
    npm: 9.6.4 - ~/.asdf/plugins/nodejs/shims/npm
  Browsers:
    Chrome: 112.0.5615.165
    Firefox: 112.0.2

Used Package Manager

pnpm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.