question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Do not pass args into command

See original GitHub issue

Hi, is there any possibility to not pass any arguments into command. I’m using lint-staged like so:

  ...
  "scripts": {
    "build": "gulp build"
    },
    "lint-staged": {
        "resources/assets/client/js/application/**/*.js": [
            "npm run build",
            "eslint --fix",
            "git add"
        ]
    }
   ...

So I dont want to pass files args into my build task because it breaks.
npm run build -- file1.ext file2.ext

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

19reactions
trusktrcommented, Nov 9, 2018

You can very simply ignore args. For example:

npm run blah && :

The trailing : is the “no-op” command in Bash. Any args passed to it are always ignored, and it always exits 0.

For example, to use it in lint-staged:

	"lint-staged": {
		"*.{ts,tsx}": [
			"tsc -p ./tsconfig.json --noEmit && :"
		],
	},

that way for example lint-staged will not break the TypeScript tsc command (because passing it files changes the meaning, and in TypeScript you want it to check your whole project otherwise TypeScript won’t detect type errors in files that you didn’t modify in your commit, thus you will introduce errors into your commit).

Also because of the &&, if the tsc command fails, then the whole command will fail and the commit will fail (which is what you want).

14reactions
strelgacommented, Feb 7, 2019

@trusktr,

You can very simply ignore args. For example: …

"lint-staged": {
	"*.{ts,tsx}": [
		"tsc -p ./tsconfig.json --noEmit && :"
	],
},

Did you test this example? I tried it and it didn’t do the thing.

I followed through lint-staged source code and it seems like this example should not work.

lint-staged does not look at the command as at bash script. Instead, it thinks of it as a single binary with an array of arguments, so tsc -p ./tsconfig.json --noEmit && : translates into, roughly speaking, execFile('tsc', ['-p', './tsconfig.json', '--noEmit', '&&', ':']). So, && and : are just two another args of tsc command and are just ignored.

It seems like, if you want to ignore staged files as args in case of tsc command, you should use it like this:

"lint-staged": {
    "*.{ts,tsx}": [
        "bash -c \"tsc -p ./tsconfig.json --noEmit\""
    ],
},

Am I missing something?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parameters / Arguments - Windows CMD - SS64.com
How-to: Pass Command Line arguments (Parameters) to a Windows batch file. ... You can get the value of any argument using a %...
Read more >
How to pass arguments to a Button command in Tkinter?
This doesn't work if someNumber is in fact a variable that changes values inside a loop that creates many buttons. Then each button...
Read more >
How to pass arguments on the command line using bash script
The command -line argument is a parameter that we can pass to our Bash script during the execution ... Your browser can '...
Read more >
Passing Arguments to the Script - Free Interactive Shell Tutorial
Arguments can be passed to the script when it is executed, by writing them as a space-delimited list following the script file name....
Read more >
How to pass command line arguments to bash script when ...
You can't pass arguments to an at job really ( at -f job.sh argument ... would not work), so you must make the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found