I have eslint in my project and some rules.
In my package.json I have:
"lint": "eslint . --ext .js --ext .ts --ext .tsx --ignore-pattern 'node_modules/'".
Is there any way to set up extensions which i want to check in .eslintrc.json so in package.json i just set:
"lint": "eslint"?
package.json
{
"lint": "eslint . --ext .js --ext .ts --ext .tsx --ignore-pattern 'node_modules/'"
}
I want to have:
paxkage.json
"lint": "eslint"
I am afraid, that putting both parameters to a configuration file as you want them - file extensions to check and a directory pattern to ignore - is currently not possible. File extensions or files to check can be provided only on the command line, as documented and stated here and here.
You can leave the file extensions parameter on the command-line and shorten the command using commas:
eslint --ext .js,.ts,.tsx .
and move just the --ignore-pattern parameter to the .eslintignore file, which is a documented way how to exclude files and directories by multiple patterns. For example, .eslintignore for a simple JavaScript project:
# lcov web site
coverage
# bundled and minified output
dist
# external dependencies
node_modules
Patterns to ignore can be put to the package.json file too. Use the eslintIgnore key similarly to the eslintConfig key:
"eslintIgnore": [
"coverage", "dist", "node_modules"
]
Alternatively, you could try specifying all input files in the command-line using the glob pattern. Use single or double quotes to prevent the shell glob-pattern expansion:
eslint "**/*.{js,jsx,es6}"
And then specify the patterns to ignore using one of the two ways mentioned above to avoid checking other files than your sources.
Related
I am trying to create a regex glob for an NPM script. This is what I have:
"format": "prettier-eslint --write \"{,!(node_modules|cypressTests)/**/}*.{js,json,vue}\""
And this currently formats all .js, .json, and .vue files that are NOT in the node_modules folder or in the cypressTests folder.
The below is my problem:
The cypressTests folder ALSO contains a node_modules folder that I do not want to format. How can I exclude ./cypressTests/node_modules just like I am currently doing for the folder ./node_modules?
I tried like this and this does not work. It then excludes pretty much everything in the entire project for some reason:
"format": "prettier-eslint --write \"{,!(node_modules|cypressTests/node_modules)/**/}*.{js,json,vue}\""
Prettier has an easier solution to ignore files. You can make a .prettierignore file (which uses .gitignore syntax) to ignore files when prettifying. The file should be placed in the root directory of your project. I believe the syntax inside the file in your case would be:
**/node_modules
Which is actually what prettier ignores by default (among some other source-control folder exclusions)-- so unless you already have a .prettierignore file, all node_modules folders should already be excluded from prettification.
The command would then simply be:
"format": "prettier-eslint --write \"**/*.{js,json,vue}\""
or if you want your .prettierignore file to be somewhere else:
"format": "prettier-eslint --ignore-path <path-to-ignore-file> --write \"**/*.{js,json,vue}\""
If this solution doesn't work for you and you need to use the glob method, I wasn't quite able to figure that out, but this website was handy for testing globs.
I setup a basic web app in VS Code. I want to copy the html file to the out dir whenever it changes. My folder structure looks like this:
src
css
_Index.scss
global.scss
html
index.html
scripts
index.ts
In my package.json I included the following scripts to automatically compile TypeScript and SASS files:
"watch:tsc": "tsc --watch",
"watch:sass": "sass --watch --sourcemap=none src:out",
"watch": "concurrently --kill-others \"npm run watch:sass\" \"npm run watch:tsc\""
A tsconfig.json handles the TypeScript compilation. This is all working fine.
What do I need to setup to also copy the html file to the out dir? Simply including a copy statement feels wrong. Maybe at some point I'd like to include images as well, I wouldn't want to adjust the copy statement for every new file type would I?
I feel like I'm missing some super basic stuff here.
I want to run lint check all the file *.js without node_modules
Here my command: "lint": "eslint **/*.js",, My folder structure look like: app > module_name > module.js but in the app folder still having some files common like helpers.js server.js and I also want to check them.
In .eslint config I added "ignorePatterns": "node_modules" and tried added a file .eslintignore and add node_modules but it's not working.
When I run npm run lint it always throw error:
Oops! Something went wrong! :(
ESLint: 7.32.0
You are linting "node_modules/bignumber.js", but all of the files matching the glob pattern "node_modules/bignumber.js" are ignored.
If you don't want to lint these files, remove the pattern "node_modules/bignumber.js" from the list of arguments passed to ESLint.
If you do want to lint these files, try the following solutions:
* Check your .eslintignore file, or the eslintIgnore property in package.json, to ensure that the files are not configured to be ignored.
* Explicitly list the files from this glob that you'd like to lint on the command-line, rather than providing a glob as an argument.
You could add node_modules/ in your .eslintignore file, and update the package.json file with script: "lint": "eslint --ext .js app/", before running npm run lint.
You could add node_modules/ in your .eslintignore file, and update the package.json file with script:
if u r using ubuntu/linux
"lint": "eslint '**/*.js'"
if project structure like these folder/file.js
if u r using windows
"lint": "eslint **/*.js"
if project structure like these folder/file.js
Right now I have a package.json scripts section that looks like this:
"scripts": {
"views": "cp -r ./src/views/ ./dist/views/",
"dev": "tsc-watch --onSuccess \"./run.sh\"",
"prod": "./run.sh",
"test": "jest --coverage --verbose"
}
Inside run.sh I have:
npm run views && node ./dist/server.js
When I run npm run dev I expect it to compile .ts files within ./src/ to .js files within ./dist/ then copy everything (.html) within ./src/views/ to ./dist/views/ then wait for any changes to .ts files, once a .ts file change occurs tsc-watch would rerun the process.
However, tsc-watch somehow detects changes when cp -r ./src/views/ ./dist/views/ is run, despite it not changing any .ts files. This results in an infinite loop when running npm run dev where it compiles the .ts to .js then copies views, detects changes, and loops forever.
It appears a request for exactly what I'm trying to do was requested but shot down for some reason here.
So, with or without tsc-watch, how do I...
Watch for changes to any and all files.
When a change occurs, copy all files from src to dist, compiling any .ts to .js.
Do so with as little overhead as possible and without any infinite loops.
I've decided to rewrite my generator from ES5 syntax to ES6. But I faced the issue with transpiling generator on pre-publish.
Issue: As we know Yeoman generators have templates folder where different files is located. When Babel is traspiling all the generators sources via babel src --out-dir generators it skips the templates files or breaks the traspiling with error.
My Attepmts: I was trying to make something like babel src --out-dir generators && cp -rn src/ generators/ but I don't like this solution.
Question: How can I make old structure generators/sub-generators but in ES6 syntax, not in ES5.
Thanks.
UPD: I'm hoping that Yeoman has something like Mocha has --require babelhook.js.
I've found the solution for this case.
First of all, I've created src folder where generator sources in ES6 syntax is located. Structure of this folder is the same as in usual ES5 generator.
When I want to compile these sources I just need to copy them and compile in generators folders.
So I've written the following scripts in package.json;
"scripts": {
"clean": "rm -rf ./generators",
"compile": "npm run clean && cp -r src/ generators/ && babel src --out-dir generators",
"prepublish": "npm run compile",
"test": "istanbul cover _mocha"
}
And last thing that I've done is add ignore field in .babelrc file. So I'm sure that templates will be just copied but not traspiled.
{
"stage": 0,
"ignore": [
"app/templates",
]
}