check-types or check-lint similar command to stylelint - stylelint

When running a lint like Eslint, I can use the command npm run check-lint to check all the code on my project. The same goes with npm run check-types from typescript. Is there a similar command with stylelint? I didn't find anything on their docs about it. I know there is a --fix flag, but that's not exactly what I want.

These are npm run scripts, and unrelated to Stylelint itself. You can use run scripts to run any arbitrary command from a package's "scripts" object.
For example, to add a check-styles command to your project you should edit your package.json file and add:
{
"scripts": {
"check-styles": "stylelint \"**/*.css\""
}
}
You'll then be able to use npm run check-styles.

Related

How do I run an npm script directly in VS code terminal

I am trying to follow this MS tutorial.
So I install the CLI from the VS code terminal: npm install #azure/static-web-apps-cli
Works.
But following the instructions using "swa init" in the terminal I get this response:
swa : The term 'swa' is not recognized.... etc.
Adding the command to package.json as a script will work, but how do I run it directly from the terminal without adding it to package.json?
npx swa init would pull the swa package and execute it as if it was run from within package.json. You can read more about it on npmjs.com/package/npx
Alternatively, you could have the swa package installed globally with npm i -g #azure/static-web-apps-cli

Opening a new powershell/windows terminal while react app is running

Hi I made two react apps which should interact with each other(both start with npm start). And I want to ask if it is possible to make a script to run the start up commands like a script file on Linux. (It will be like cd.. npm start then start powershell(not sure about this) then cd ... npm sart)
Sorry if the question is vague
You are looking for "concurrently",
npm i concurrently --save-dev
And then change commands in the "package.json"
"scripts": {
"dev": "concurrently --kill-others \"cd backend && node server.js\" \"react-scripts start\""
},
Now, You can run all commands at once with this;
npm run dev

VSCode git "npm command not found" [duplicate]

I've setup a node project with husky but when my collegue tries to run npm install on his Mac he gets the following error :
noa-be#1.0.0 prepare
husky install
sh: husky: command not found
npm ERR! code 127
npm ERR! path /Users/X/Desktop/Workspace/project
npm ERR! command failed
npm ERR! command sh -c husky install
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/X/.npm/_logs/2021-04-12T13_07_25_842Z-debug.log
These are the relevant package.json parts:
{
"scripts": {
"prepare": "husky install"
},
"devDependencies": {
"husky": "^5.2.0",
}
}
I thought this would be enough for husky to be installed when running npm install, but it's not. What am I missing?
If you are using nvm, you might want to create a file called .huskyrc in your home directory and add the following lines of code to it:
~/.huskyrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
I was struggling with the same exact problem for hours. Finally, I could install dependencies and start working on my project by doing this:
Temporarily remove the "prepare": "husky install" script from the package.json file.
Run npm i (npm install). Dependencies installed successfuly.
Add again the "prepare" script that you removed in step 1.
Run again npm i to install the husky git hooks, so husky can do its job from now on.
This error is also thrown by npm ci if the NODE_ENV is set to "production" pre-install
I've been able to solve the problem by upgrading to latest Husky version (7.0.1, from 5.2.0).
Git was also helpful, and told me that the files weren't executables. (Git V 2.24.1)
So I give them executable rights :
chmod +x PATH_TO_HUSKY_FILE
You'll need to execute this command for every hooks
I believe it could be version specific issue. Install version 6, npm i husky#6.0.0 --save-dev, and it should work as the husky doc says.
Apparently, when I did npm i husky --save-dev, it was installing "husky": "^0.8.1" for me for some strange reason, giving me the exact same error: sh: husky: command not found.
Method 1:
Update manually, in your package.json:
{
"scripts": {
"prepare": "husky install",
"create-hook": "husky add .husky/pre-commit \"npm test\"",
}
}
Then, run npm run prepare && npm run create-hook.
It should create .husky directory with .pre-commit file in it.
Method 2:
npx husky install
npm set-script prepare "husky install"
npx husky add .husky/pre-commit "npm test"
It worked in my terminal but not in VSCode version control. So had to force quite the vscode app and restarting it worked.
Faced this issue in Github Desktop.
solved it by quit Github Desktop and re-open it.
I was able to fix this by providing an explicit location for husky
"scripts": {
"prepare": "node_modules/.bin/husky-run install"
},
Using Lerna
When I upgraded husky from version 4 to 8 there was information todo first pre commit manually. For this purpose pre-commit bash script was generated in .husky directory.
What I had todo was simply run the command included in this file:
lerna run precommit --concurrency 2 --stream

Symlink to file within same NPM module

In a GitHub module, it is possible to symlink to another file within the same module. But is it possible to have this symlink survive / work in the NPM package of same module?
I'm using a Mac and so far I've done
ln -s [filename-1.0.4.js] [filename.js]
This works great for github.io-pages, but the file disappears when published to NPM.
After some rounds with NPM support it seems that only folders can be linked with npm link
So the answer to my question is no. Here's the documentation for npm link
And here is the answer from support:
[...]
To create a symlink in a package.json, we recommend using the scripts field.
For example:
"scripts": {
"postinstall": "npm link ../somelocallib",
"postupdate": "npm link ../somelocallib"
}
[...]

how to use ejs lint in cli

I am using EJS as my view engine on a node and express setup. I want to use ejs-lint to help get the line for errors. I haven't use a linter before, but from reading through the documentation here: https://github.com/RyanZim/EJS-Lint
I'm assuming you can just check errors on a specified file in command line like this: ejslint
Are my assumptions right and what am I doing wrong? I've already installed using npm install ejs-lint --save-dev
Also, if I plan to add ESlint to my project I'm guessing I can have it work alongside EJSlint?
Short answer
Run it directly from the terminal:
./node_modules/.bin/ejslint src/templates/some-template.ejs
Or with npm script:
// package.json
{
...
"scripts": {
"lint:ejs": "ejslint src/templates/some-template.ejs"
}
}
// terminal
npm run lint:ejs
ESLint and EJSlint are different, exclusive processes. What is analysed by ESLint should not be analysed by EJSLint and vice versa. Having both installed will not cause any issues.
Extended answer
For what I have tested, you have to use the ejs linter CLI per file. Which is not as useful as eslint which can process multiple files, exclusions etc.
If you had some src/templates directory, you could lint all the EJS files by doing something like this:
find src/templates -type f -iname '*.ejs' -exec bash -c "./node_modules/.bin/ejslint '{}'" \;
Which would work for Unix but not for Windows. You could prepare some node script to do it cross system with the ejslint API.
There is also a grunt plugin for it.
If you want to have both ESLint and EJSLint, you should have different npm scripts for them, e.g:
// package.json
{
...
"scripts": {
"lint": "npm run lint:js && npm run lint:ejs",
"lint:js": "eslint src --ignore-path src/templates",
"lint:ejs": "find src/templates -type f -iname '*.ejs' -exec bash -c \"./node_modules/.bin/ejslint '{}'\" \\;"
}
}
If you are using grunt, you can create different tasks for eslint and ejslint and then create a group task:
grunt.registerTask('lint', ['eslint', 'ejslint']);
Actually, the following way is the easiest and by far the fastest execution time. It also has better error logging because it doesn't pass through the find command.
ejslint $(find ./ -type f -iname '*.ejs')
You can run npx ejslint **/*.ejs from the command-line in your project root to check all the ejs files in your project.
the npx is needed because you used --save-dev (or -D) if you used --global (or -g) then you can call ejs lint directly using ejslint **/*.ejs
**/*.ejs will select any file ending in .ejs in any folder.
they is no definitve instructions on usage ejslint on cmd. try and debug your lines of code yourself with a debug in your editor ,as it says its something to do with syntax error within your code. worked for me.!
Ohh ya and good news is that you can still run ESlint aswell to debug your Js files .