Eslint / Prettier Ignoring files with .mock extension - eslint

I am using Angular with Eslint and Prettier configured for the entire project. All the files are checked correctly according to rules. Unfortunately, the files that have .mock in name are completely ignored. The file is called for example test.mock.ts and is ignored by Eslint/Prettier. If I rename it to test.mocks.ts or anything else without the mock keyword, it starts to work.
Does anyone know why it behave like this?
Eslint config file:
{
"extends": ["prettier"],
"plugins": ["prettier"],
"rules": {
"prettier/prettier": ["error"]
},
"root": true,
"ignorePatterns": [
"projects/**/*"
],
"overrides": [
{
"files": [
"*.ts"
],
"parserOptions": {
"project": [
"tsconfig.json"
],
"createDefaultProgram": true
},
"extends": [
"plugin:#angular-eslint/recommended",
"plugin:#angular-eslint/template/process-inline-templates"
],
"rules": {
...some rules...
}
}
]
}
Tsconfig file:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"downlevelIteration": true,
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2020",
"moduleResolution": "node",
"experimentalDecorators": true,
"importHelpers": true,
"typeRoots": [
"node_modules/#types"
],
"target": "es2020",
"lib": [
"es2020",
"dom"
],
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"paths": {
"#generated/*": [
"libs/shared/*"
],
}
}
}

Turned out I had in .eslintignore file rule to ignore all .mock files.

Related

SWC typescript is not affect fast reload

I'm trying to improve nodemon server/start speed.
my script command in package.json is
installed npm install --save-dev ts-node #swc/core #swc/helpers regenerator-runtime
scripts: {
"dev": "nodemon --watch src server.ts"
}
and tsconfig.json is
{
"compilerOptions": {
"baseUrl": ".",
"target": "ES6",
"module": "commonjs",
"removeComments": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"types": [
"node",
"bytebuffer"
],
"moduleResolution": "node",
"pretty": true,
"sourceMap": true,
"skipLibCheck": true,
"suppressImplicitAnyIndexErrors": true,
// "noImplicitAny": false,
"resolveJsonModule": true,
"outDir": "./build",
"typeRoots": [
"./src/interfaces/index.d.ts",
"node_modules/#types"
],
"paths": {
"#config/*": [
"./src/config/*"
],
"#controllers/*": [
"./src/controllers/*"
],
"#dao/*": [
"./src/dao/*"
],
"#json/*": [
"./src/json/*"
],
"#lib/*": [
"./src/lib/*"
],
"#mappers/*": [
"./src/mappers/*"
],
"#models/*": [
"./src/models/*"
],
"#plugins/*": [
"./src/plugins/*"
],
"#routes/*": [
"./src/routes/*"
],
"#utils/*": [
"./src/utils/*"
]
}
},
"ts-node": {
"swc": true
},
"filesGlob": [
"./src/**/*.ts"
],
"exclude": [
"node_modules",
"src/lib/customTypings"
]
}
and mainly also mentioned in tsconfig.json file
ts-node: {
"swc": true
}
after Configuring all the steps still nodemon server taking 2 min to restart after changes.
Are there any changes that need to do to the current setup? and I followed this question
I did all the changes still it is not effect in speed of compile

serverless framework not recognizing tsconfig's paths

I'm trying to deploy my Node.js app to Lambda using Serverless framework, however, my Node code uses paths from tsconfig.json for referencing imports but the Serverless deploy process fails. How do you wire up serverless.yml to acknowledge and use paths defined in tsconfig.json?
I've installed serverless-plugin-typescript, but it does not seem to recognize paths from tsconfig.
serverless.yml
service:
name: app-name
custom:
webpack:
webpackConfig: ./webpack.config.js
includeModules: true
plugins:
- serverless-webpack
- serverless-plugin-typescript
...
tsconfig.ts
{
"compileOnSave": true,
"compilerOptions": {
"lib": [
"es2017"
],
"baseUrl": "./src",
"declaration": true,
"downlevelIteration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"module": "commonjs",
"moduleResolution": "node",
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "./dist",
"paths": {
"#config/*": [
"config/*"
],
"#core/*": [
"core/*"
],
"#infra/*": [
"infra/*"
],
"#modules/*": [
"modules/*"
],
"#shared/*": [
"shared/*"
]
},
"preserveConstEnums": true,
"removeComments": true,
"rootDir": "./src",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"strictNullChecks": false,
"target": "es2017",
"typeRoots": [
"node_modules/#types"
],
"types": [
"node"
]
},
"include": [
"./**/*.ts"
],
"exclude": [
"node_modules/**/*",
".serverless/**/*",
".webpack/**/*",
"_warmup/**/*",
".vscode/**/*"
]
}
I found an answer. Turns out you need to install tsconfig-paths-webpack-plugin. Then in webpack.config.js you add the following:
npm install --save-dev tsconfig-paths-webpack-plugin
inside webpack.config.js:
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
module.exports = {
...
resolve: {
plugins: [new TsconfigPathsPlugin({ configFile: "./tsconfig.json" })]
},
...
};
NOTE: be sure to use the plugins inside the resolve section. There is a plugins a the root, however, TsconfigPathsPlugin only works in resolve/plugins.
I hope this helps you if you experience this same issue.

Angular 7: adding local module with npm link

I've created a package with a module outside of folder with an appication that should contain the module to test it. Then I've added package with npm link #scope/module-name. After that I've added paths to root tsconfig.json.
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es5",
"typeRoots": [
"node_modules/#types"
],
"lib": [
"es2018",
"dom"
],
"paths": {
"#scope/module-name": [
"node_modules/#scope/module-name"
],
"#scope/module-name/*": [
"node_modules/#scope/module-name/*"
]
}
}
}
I've also added package to include in tsconfig.app.json
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"types": []
},
"include": [
"**/*.ts",
"../node_modules/#scope/**/*.ts",
],
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}
And yes, I've added "preserveSymlinks": true in angular.json as it's said in similar questions on SO.
In app.module.ts I'm doing
import { DispRegistryModule } from "#scope/module-name/public_api.d.ts";
But still I'm gettig an error
ERROR in ./node_modules/#scope/module-name/public_api.d.ts Module
build failed (from ./node_modules/#ngtools/webpack/src/index.js):
Error:
D:\internal\test-app\node_modules#scope\module-name\public_api.d.ts
is missing from the TypeScript compilation. Please make sure it is in
your tsconfig via the 'files' or 'include' property.
How can I fix the error?

Not able to hit breakpoints inside src folders in vscode while debugging zest testcases

Version:11.10.0
OS:Ubuntu
Scope:Debugging testcases
Module: Zest Test Framework
IDE:VSCode
I'm trying to debug my test cases. All breakpoints in spec.ts file works. but breakpoints in src/folders, ie, controller files never works. VSCode shows them as a unverified breakpoints.
launch.json:
{
"type": "node",
"request": "launch",
"name": "Jest Tests",
"program": "${workspaceRoot}/node_modules/jest/bin/jest.js",
"args": ["--runInBand","-i", "--config=${workspaceFolder}/jest.config.js"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"outFiles": [
"${workspaceRoot}/dist/**/*"
],
"envFile": "${workspaceRoot}/.env"
}
tsconfig.js:
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": false,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"esModuleInterop": false,
"allowJs": true /* Allow javascript files to be compiled. */,
"checkJs": false /* Report errors in .js files. */,
"sourceMap": true,
"outDir": "./dist",
"baseUrl": ".",
"paths": {
"*": [
"node_modules/*",
"src/types/*"
]
},
"types": ["jest"]
},
"exclude": ["dist", "src/test"],
"include": [
"src"
],
"types": ["src/types"]
}
jest.config.js
module.exports = {
globals: {
'ts-jest': {
tsConfigFile: 'tsconfig.json'
}
},
moduleFileExtensions: [
'ts',
'js'
],
transform: {
'^.+\\.tsx?$': 'ts-jest',
'^.+\\.js$': 'babel-jest'
},
transformIgnorePatterns: ["[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$"],
testMatch: [
'**/*.spec.ts'
],
testEnvironment: 'node',
testResultsProcessor: "jest-sonar-reporter",
coveragePathIgnorePatterns: [".*\\.d\\.ts"],
collectCoverageFrom: [
"src/**/**/*.{ts}",
"!src/index.ts"
]
};

tslint exclude not working for tsoa routes

I want to exclude the routes.ts file which is created by tsoa routes from tslint compiler option. I tried exclude option, Still no success.
exclude option is working for remaining files, am facing issue only with routes.ts which is generated by tsoa routes.
This is my tsconfig json
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"moduleResolution": "node",
"outDir": "outputdir/mysrc",
"rootDir": "mysrc",
"noUnusedParameters": true,
"noUnusedLocals": false
},
"filesglob": [
"typings",
"mysrc/**/*.ts"
],
"exclude": [
"node_modules",
"typings",
"outputdir",
"mysrc/routes/routes.ts",
"mysrc/helpers/temp.ts"
],
"compileOnSave": false
}
You have mysrc/routes/routes.ts in the wrong config file. You don't want that in tsconfig.json you want it in tslint.json as follows:
{
"extends": [
"tslint:recommended"
],
"rules": {
}
linterOptions: {
"exclude: [
"mysrc/routes/routes.ts"
]
}
}
You can read more here: https://palantir.github.io/tslint/usage/configuration/

Resources