Skip to content

Commit

Permalink
fix: make ts rules stricter
Browse files Browse the repository at this point in the history
  • Loading branch information
stumpam committed Mar 3, 2022
1 parent dfb2e33 commit bf75851
Show file tree
Hide file tree
Showing 7 changed files with 1,705 additions and 2,434 deletions.
40 changes: 15 additions & 25 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@
"polyfills": "apps/demo/src/polyfills.ts",
"tsConfig": "apps/demo/tsconfig.app.json",
"aot": true,
"assets": [
"apps/demo/src/favicon.ico",
"apps/demo/src/assets"
],
"styles": [
"apps/demo/src/styles.scss"
],
"assets": ["apps/demo/src/favicon.ico", "apps/demo/src/assets"],
"styles": ["apps/demo/src/styles.scss"],
"scripts": []
},
"configurations": {
Expand Down Expand Up @@ -59,9 +54,7 @@
]
}
},
"outputs": [
"{options.outputPath}"
]
"outputs": ["{options.outputPath}"]
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
Expand All @@ -86,9 +79,7 @@
"jestConfig": "apps/demo/jest.config.js",
"passWithNoTests": true
},
"outputs": [
"coverage/apps/demo"
]
"outputs": ["coverage/apps/demo"]
}
},
"tags": []
Expand All @@ -113,38 +104,37 @@
}
},
"tags": [],
"implicitDependencies": [
"demo"
]
"implicitDependencies": ["demo"]
},
"ngx-masked-input": {
"projectType": "library",
"root": "libs/ngx-masked-input",
"sourceRoot": "libs/ngx-masked-input/src",
"prefix": "ngx-masked-input",
"architect": {
"targets": {
"build": {
"builder": "@nrwl/angular:package",
"executor": "@nrwl/angular:package",
"outputs": ["dist/libs/ngx-masked-input"],
"options": {
"tsConfig": "libs/ngx-masked-input/tsconfig.lib.json",
"project": "libs/ngx-masked-input/ng-package.json",
"buildableProjectDepsInPackageJsonType": "dependencies"
"project": "libs/ngx-masked-input/ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "libs/ngx-masked-input/tsconfig.lib.prod.json"
},
"development": {
"tsConfig": "libs/ngx-masked-input/tsconfig.lib.json"
}
}
},
"defaultConfiguration": "production"
},
"test": {
"builder": "@nrwl/jest:jest",
"options": {
"jestConfig": "libs/ngx-masked-input/jest.config.js",
"passWithNoTests": true
},
"outputs": [
"coverage/libs/ngx-masked-input"
]
"outputs": ["coverage/libs/ngx-masked-input"]
}
},
"schematics": {
Expand Down
9 changes: 6 additions & 3 deletions libs/ngx-masked-input/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@stumpam/ngx-masked-input",
"license": "MIT",
"version": "3.3.2",
"version": "3.3.3",
"description": "Angular Date picker with masked input.",
"homepage": "https://github.com/stumpam/ngx-masked-input",
"author": "Martin Štumpa (https://github.com/stumpam)",
Expand All @@ -24,7 +24,10 @@
"url": "https://github.com/stumpam/ngx-masked-input/issues"
},
"peerDependencies": {
"@angular/common": ">=13.2.2",
"@angular/core": ">=13.2.2"
"@angular/common": "^13.2.0",
"@angular/core": "^13.2.0"
},
"dependencies": {
"tslib": "^2.3.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,18 @@ export class MaskedInputDirective implements ControlValueAccessor {
this._options.max = 79999;
}

if (/\d/.test(this._options.prefix) || /\d/.test(this._options.suffix)) {
if (
(this._options?.prefix && /\d/.test(this._options.prefix)) ||
(this._options?.suffix && /\d/.test(this._options.suffix))
) {
this.numericAdditionals = true;
}
}

@Output() blurred = new EventEmitter();

numericAdditionals = false;
previousValue = '';
previousValue: string | undefined = '';

_options: Partial<MaskedInputOptions> = {
type: 'numeric',
Expand Down Expand Up @@ -107,7 +110,7 @@ export class MaskedInputDirective implements ControlValueAccessor {
}
}

onNumericInput(value: string | number | null) {
onNumericInput(value?: string | number | null) {
if (!value && value !== 0) {
if (this._options.ignoreEdgeOnBlur) {
this.updateValue(undefined);
Expand Down Expand Up @@ -223,20 +226,21 @@ export class MaskedInputDirective implements ControlValueAccessor {

const suffixPosition =
value.length -
(this._options.suffix?.length + +this._options.prependSuffix) -
((this._options.suffix?.length || 0) +
+(this._options.prependSuffix || 0)) -
(key ? 1 : 0);

const prefixPosition =
this._options.prefix?.length + +this._options.appendPrefix;
(this._options.prefix?.length || 0) + +(this._options.appendPrefix || 0);

if (this.field.nativeElement.selectionStart > suffixPosition) {
if ((this.field.nativeElement.selectionStart || -1) > suffixPosition) {
this.field.nativeElement.setSelectionRange(
suffixPosition,
suffixPosition,
);
}

if (this.field.nativeElement.selectionStart <= prefixPosition) {
if ((this.field.nativeElement.selectionStart || 9e4) <= prefixPosition) {
this.field.nativeElement.setSelectionRange(
prefixPosition + (key ? 1 : 0),
prefixPosition + (key ? 1 : 0),
Expand All @@ -249,7 +253,7 @@ export class MaskedInputDirective implements ControlValueAccessor {
let value = +elValue.replace(/\D/g, '');

if (elValue === '' && !this._options.enableEmpty) {
value = this._options.min ?? +this.previousValue;
value = this._options.min ?? +(this.previousValue || 0);
}

if (
Expand All @@ -275,7 +279,7 @@ export class MaskedInputDirective implements ControlValueAccessor {
this.touchedFn?.();
}

updateValue(value: string) {
updateValue(value?: string) {
this.previousValue = value;
this.renderer.setProperty(this.field.nativeElement, 'value', value ?? '');

Expand Down
13 changes: 12 additions & 1 deletion libs/ngx-masked-input/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"types": ["node", "jest"]
"types": ["node", "jest"],
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"angularCompilerOptions": {
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
},
"include": [],
"files": [],
Expand Down
1 change: 1 addition & 0 deletions libs/ngx-masked-input/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"outDir": "../../dist/out-tsc",
"target": "es2015",
"declaration": true,
"declarationMap": true,
"inlineSources": true,
"types": [],
"lib": ["dom", "es2018"]
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
"lib": ["es2017", "dom"],
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"strict": true,
"baseUrl": ".",
"paths": {
"@stumpam/ngx-masked-input": ["libs/ngx-masked-input/src/index.ts"]
}
},
"angularCompilerOptions": {
"strictTemplates": true,
"disableTypeScriptVersionCheck": true
},
"exclude": ["node_modules", "tmp"]
Expand Down
Loading

0 comments on commit bf75851

Please sign in to comment.