How to exclude a folder from tslint? - javascript

I like to exclude the test folder form linting with tslint in vscode. So I have placed an exclude into my tslint.json config file. Unfortunately the exclude statement is not working. Does any one know how to set the exclude up?
{
"exclude": "tests/**/*.ts",
"rulesDirectory": ["node_modules/tslint-microsoft-contrib"],
"rules": {
"export-name": true,
...
}
}

Latest update: this can now be set in in tslint.json (the following configuration works with tslint 5.11)
{
"linterOptions": {
"exclude": [
"bin",
"build",
"config",
"coverage",
"node_modules"
]
}
}

It seems that this is an open feature request.
Further information can be found here: https://github.com/palantir/tslint/issues/73
Update:
for those who use VSCode with tslint as editor/linting you can add the following to the VSCode config:
// Configure glob patterns of file paths to exclude from linting
"tslint.exclude": "**/PATH_eg_TESTS/**/*.ts"

This worked for me in tslint: 6.1.2.
In the root folder where tslint.json is located create the file path to directory.
"linterOptions": {
"exclude": [
"libs/folder/folder/**",
"apps/stuff/stuff/**"
]
}

Related

How to instruct ESLint to ignore a ruleset in a project?

In my VSCode (Win 10) I have installed the VSCode extension ESLint. On my computer is a Node project, with a JS file inside. If I open this JS file in VSCode, ESLint reports infractions from several different rule sets, including Prettier (screenshot). For this project only, how can I instruct ESLint to not check any of the rules in the Prettier rule set?
FYI when I open VSCode, here is a list of the extensions installed.
The .eslintrc.json file for this project contains the following:
{
"extends": [
"plugin:#wordpress/eslint-plugin/recommended"
],
"env": {
"browser": true,
"jquery": true
}
}
Note: The plugin #wordpress/eslint-plugin/recommended is a separate plugin I have added to this project, and it has rules that I want ESLint to list and report.
Inside eslintrc.js, you can omit/edit the rules you do not like, as such:
module.exports = {
extends: 'airbnb-base',
rules: {
'no-console': 'off',
'no-restricted-syntax': 'off',
'linebreak-style': 0,
'guard-for-in': 'off',
'max-len': ['error', { code: 160 }],
},
};
You can override such rules inside .eslintrc.json according to
{
"extends": [
...
],
...
"rules": {
"<rule1>": "off",
...
}
}
There are a few ways you can ignore rules from ESLint
Manually specify each rule in .eslintrc file as off
{
"extends": [
...
],
...
"rules": {
"<rule1>": "off",
...
}
}
Ignore files or folder from eslint rules i.e. add ignorePatterns
{
"ignorePatterns": ["temp.js", "**/vendor/*.js"],
"rules": {
//...
}
}
Create .eslintignore file and exclude the files or folder from being linted by ESLint. ESLint Ignore

How to include monorepo packages in Cypress code coverage

I have multi packages in monorepo.
/pkg1
/pkg2
/pkg3
- react-app
- cypress
- src
- package.json
I am using #cypress/instrument-cra to collect coverage and it works only to cover the code inside react-app.
I need to go further because react-app is actually just a playground while the src has to be covered along with other packages that are used inside the react-app. I am importing packages as following:
import pkg1 from #myProject/pkg1
How can I use code coverage for pkg1?
I tried to config nyc but it didn't work
"nyc": {
"all": true,
"include": [
"node_modules"
],
"excludeNodeModules": false
}
Thanks!
Create .nycrc file in your root folder and:
{
"all": true,
"include": [
"pkg1/src/**"
],
"exclude": [
"**/test/**"
],
}

ESLint define folder in config file. (Ignore all but..., Include only...)

How to set the folder to lint in the .eslintrc.json file, instead after the eslint command in package.json.
package.json (snippet)
"scripts: {
"lint": "eslint ./src --ext .js,.jsx,.ts,.tsx",
}
I want only:
"scripts: {
"lint": "eslint",
}
and define the path and ext in the .eslintrc.json.
Alternativ, set .eslintignore to ignore ALL but not ./src.
I only want to lint the src-folder. Not the root.
Also for the eslint plugin of vscode.
My current solution:
.eslintignore
/*
!/src
But I wondering, why is there no option in the config files to set the folder/s to lint.
I'm looking for the most common and elegant solution.
Maybe it sounds like a duplicate here. But I searched a lot of topics and found nothing similar to solve my problem.
Set in overrides inside .eslintrc.json
If you specified directories with CLI (e.g., eslint lib), ESLint searches target files in the directory to lint. The target files are *.js or the files that match any of overrides entries (but exclude entries that are any of files end with *).
{
"rules": {
"quotes": ["error", "double"]
},
"overrides": [
{
"files": ["bin/*.js", "lib/*.js"],
"excludedFiles": "*.test.js",
"rules": {
"quotes": ["error", "single"]
}
}
]
}
Refer: document of Configuring ESLint
I've adapted your solution with the .eslintignore file and put the rules directly into my config file's ignorePatterns option (.eslintrc.cjs in my case). Works like a charm for me:
module.exports = {
ignorePatterns: ['/*', '!/src']
[...]
}
In addition to #billythetalented's comment I had to add a dot in the package.json:
"scripts": {
"lint": "eslint .",
...
}
Otherwise, It didn't lint anything

angular tsconfig json Exclude not working when i use "**/*.spec.ts" pattern

I would like to exclude spec files inside this path "projects/sci-core/src/**/*".
I have exclude block with following config
"exclude": [
"node_modules/**/*",
"**/*.spec.ts"
]
The above config excluding the spec files inside the src folder(inside the root folder). but not excluding the under projects/sci-core/src folder.
below is my include block
"include": [
"src/**/*",
"projects/studio-widgets/**/*",
"!projects/sci-core/src/**/*.spec.ts",
"projects/sci-core/src/**/*"
],
I have tried with the below approach also.
"exclude": [
"node_modules/**/*",
"**/*.spec.ts",
"projects/sci-core/src/**/*.spec.ts",
]
Please help me to fix this issue.
The tsconfig file is only for the ts-compiler, you can't use it to exclude spec files. You should filter your spec files in the test file.
test.ts
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// Filter specify file
const specFiles = context.keys().filter((path: string) => !path.includes('sci-core'));
// And load the modules.
specFiles.map(context);

Exclude file from Typescript compile effect into one output JS in Visual Studio

I have a typescript project which I compile to a single file with VS. Everything works fine, but there is one library that I already have in the target environment and since it's 3000lines I want to exclude it from compiling to the output file. Unfortunately this library is not a d.ts file, simply .ts one. Is there a way to exclude it from compilation?
UPDATE:
I added tsconfig.json file. It does not exclude file that I want to be excluded. Is this because it is referenced in other file? My congif.json:
{
"compilerOptions": {
"outFile": "../pathTo/my/otuputFile.js",
"outDir": "./pathTo/my/",
"removeComments": false
},
"files": [
"../allmy/files/lsited.ts"
],
"exclude": [
"libraryIdontwant.ts"
]
}
In your tsconfig.json add it to the exclude array
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts",
"path/to/the/file.ts"
]

Categories

Resources