From 48b92389eaf66d4267d9eb3e183d9c81f75704c2 Mon Sep 17 00:00:00 2001 From: Amedeo Lepore Date: Fri, 16 Sep 2022 11:25:11 +0200 Subject: [PATCH] [AAE-10474] review why xit and console log is allowed to be committed (#7829) * [AAE-10474] Add husky pre-commit script to run lint-staged * [AAE-10474] Enable lint rules for console log * [AAE-10474] Run affected:lint command on pre-commit, remoive old scripts that use tslint * [AAE-10474] Remove console.log * [AAE-10474] Disable no-console lint rule for 'testing' and 'cli' projects --- .eslintrc.json | 25 +++++++++++++++++++ .husky/pre-commit | 4 +++ lib/cli/.eslintrc.json | 3 ++- .../pagination/pagination.component.spec.ts | 2 +- .../rich-text-editor.component.ts | 2 +- lib/testing/.eslintrc.json | 1 + package.json | 17 ++----------- 7 files changed, 36 insertions(+), 18 deletions(-) create mode 100755 .husky/pre-commit diff --git a/.eslintrc.json b/.eslintrc.json index 069e5461e9..e881d667cc 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -116,6 +116,31 @@ } ], "no-bitwise": "off", + "no-console": [ + "error", + { + "allow": [ + "warn", + "dir", + "timeLog", + "assert", + "clear", + "count", + "countReset", + "group", + "groupEnd", + "table", + "dirxml", + "error", + "groupCollapsed", + "Console", + "profile", + "profileEnd", + "timeStamp", + "context" + ] + } + ], "no-duplicate-imports": "error", "no-multiple-empty-lines": "error", "no-redeclare": "error", diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000000..760fc9e6ae --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +npm run affected:lint diff --git a/lib/cli/.eslintrc.json b/lib/cli/.eslintrc.json index 30028aeed4..ee4acdc5ef 100644 --- a/lib/cli/.eslintrc.json +++ b/lib/cli/.eslintrc.json @@ -34,7 +34,8 @@ "no-duplicate-imports": "error", "no-multiple-empty-lines": "error", "no-redeclare": "error", - "no-return-await": "error" + "no-return-await": "error", + "no-console": "off" } }, { diff --git a/lib/core/src/lib/pagination/pagination.component.spec.ts b/lib/core/src/lib/pagination/pagination.component.spec.ts index 313192beec..30e4ef8c00 100644 --- a/lib/core/src/lib/pagination/pagination.component.spec.ts +++ b/lib/core/src/lib/pagination/pagination.component.spec.ts @@ -386,7 +386,7 @@ describe('PaginationComponent', () => { const expectedPages = [1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 101]; - console.log(component.pagination.totalItems, component.pagination.skipCount); + expect(component.limitedPages).toEqual(expectedPages); expect(component.limitedPages).not.toEqual(component.pages); }); diff --git a/lib/core/src/lib/rich-text-editor/rich-text-editor.component.ts b/lib/core/src/lib/rich-text-editor/rich-text-editor.component.ts index ef25b12dfd..3653bde04f 100644 --- a/lib/core/src/lib/rich-text-editor/rich-text-editor.component.ts +++ b/lib/core/src/lib/rich-text-editor/rich-text-editor.component.ts @@ -74,7 +74,7 @@ export class RichTextEditorComponent implements OnInit, OnDestroy, AfterViewInit this.editorInstance.save().then((outputData) => { this._outputData.next(outputData); }).catch((error) => { - console.log('Saving failed: ', error); + console.error('Saving failed: ', error); }); } diff --git a/lib/testing/.eslintrc.json b/lib/testing/.eslintrc.json index ff2fbf47a9..3ff7e7e2c4 100644 --- a/lib/testing/.eslintrc.json +++ b/lib/testing/.eslintrc.json @@ -53,6 +53,7 @@ } ], "no-bitwise": "off", + "no-console": "off", "no-duplicate-imports": "error", "no-multiple-empty-lines": "error", "no-redeclare": "error", diff --git a/package.json b/package.json index 2b459c258b..f225d20fea 100644 --- a/package.json +++ b/package.json @@ -29,9 +29,7 @@ "print-affected:lint": "nx print-affected --target=lint --select=tasks.target.project", "03": "echo -------------------------------------------- Lint -----------------------------------------------", "03s": "", - "lint-demo": "tslint -p tsconfig.json -c tslint.json", - "lint-lib": "tslint -p ./lib/tsconfig.json -c ./lib/tslint.json", - "lint-e2e": "tsc -p tsconfig.e2e.json", + "affected:lint": "nx affected:lint", "validate-config": "ajv validate -s lib/core/src/lib/app-config/schema.json -d ./demo-shell/src/app.config.json --errors=text --verbose", "04": "echo -------------------------------------------- Demo Shell -----------------------------------------------", "04s": "", @@ -233,16 +231,5 @@ "node": ">=6.0.0" }, "module": "./index.js", - "typings": "./index.d.ts", - "lint-staged": { - "**/demo-shell/src/**/*.ts": "npm run lint-demo -- --fix", - "**/lib/**/*.ts": "npm run lint-lib -- --fix", - "**/e2e/**/*.ts": "npm run lint-e2e -- --fix", - "*.scss": "npm run stylelint -- --fix" - }, - "husky": { - "hooks": { - "pre-commit": "lint-staged" - } - } + "typings": "./index.d.ts" }