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
Related
let's say, I have following project structure:
back/package.json
back/lib/Content/*.js
front/package.json
slices/budget/back/package.json
slices/budget/back/lib/Content/*.js
slices/budget/front/package.json
slices/accounting/back/package.json
slices/accounting/back/lib/Content/*.js
slices/accounting/front/package.json
how do I?
cd back && eslint ./lib/**/*.js ../slices/**/lib/Content/*.js
specifically, I want to
install eslint one time as devDependencies
somewhere in /back of root module
config eslint one time somewhere in /back/package.json:eslint key of root module
add eslint config in /back/package.json of root module just one time
eslint entire tree of modules
not in each slice seperatly
run from ci cd
so I need a way to run from /back
and later - maybe someway to respect eslint config hierarchy
not change project directory structure at all
what I receive
cd back && npm run lint
> back#1.0.0 lint
> eslint ../
Oops! Something went wrong! :(
ESLint: 8.23.1
ESLint couldn't find a configuration file
reason: https://eslint.org/docs/latest/user-guide/configuring/configuration-files#using-configuration-files
You can use the --ignore-path option to specify a file with patterns that should be ignored. The file should contain one pattern per line. For example, to ignore all files in the node_modules directory, you could create a .eslintignore file with the following contents:
node_modules
You can also use the --ignore-pattern option to specify a pattern that should be ignored. For example, to ignore all files in the node_modules directory, you could run:
eslint . --ignore-pattern node_modules
The error is probably because you haven't specified the eslint config file explicitly. To run eslint on all the modules, starting from the parent folder, run: eslint ../ -c .eslintrc.js (or whatever .eslintrc file you use in back). It seems like eslint is confused if it does not have the config file in the same directory it is running from hence you need to manually specify the path to it.
The correct way of solving this issue would be creating sharable config file with configuration you have in back right now:
module.exports = {
rules: {
semi: [2, "always"]
}
};
Then you publish it to public or private npm with a name #your-project/eslint-config and use it in .eslintrc.json that is the same in all your projects:
{
"extends": [
"#your-project/eslint-config"
]
}
This way gives you ability to configure CI in a simple and independent way if you have lots of repositories: just run eslint lib/*.js.
If you have all the repositories in one computer and want to lint all of them using one command, you can use one of my tools:
redfork, install eslint and redfork globally and run:
redfork 'eslint lib/*.js'
But maybe you need to have some changes in project structure.
runny, if you don't want to make changes in project structure, just add configuration file .runny.json:
{
"command": "eslint lib/*.js",
"directories": [
"~/one",
"~/two",
"~/three"
]
}
It will run the same command for any directory you need.
I had a similar issue and the following has solved my problem.
I guess you haven't specified the eslint config file explicitly.
To run eslint on all the modules
run: eslint ../ -c .eslintrc.js
It seems like eslint is confused if it does not have the config file in the same directory it is running from, so you need to manually specify the path to it.
no real answer, except to create .eslintignore, .eslintrc, package.json at project root
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 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.
I am using the npm scripts property / object to validate / lint my TypeScript files in my Angular2 project, you can see my npm run tslint task below:
"scripts": {
"tslint" : "tslint -c tslint.json app/src/**/*.ts -e app/src/**/*.spec.ts",
},
This all seems good as it is linting my actual app files, but not my tests (I will remove this later). However my real problem is that my main.ts file which is in the app/src/ folder and not one of the many subfolders app/src/*sub-folder* is not being included in the linting. How can I improve the wildcard above or tslint command to include typescript files in my app/src folder as well as those in any other subfolder?
If I haven't made myself clear please say so and I'll re-phrase the question.
Many thanks
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",
]
}