From 55d11a8e62ffbe1e7071c01bad0e1e2acc6ad289 Mon Sep 17 00:00:00 2001 From: dario-piotrowicz Date: Sun, 1 Aug 2021 16:48:30 +0100 Subject: [PATCH] refactor(docs-infra): use tslint in aio's tools-lint script (#43010) Instead of the deprecated tslint use eslint in the aio's tools-lint script PR Close #43010 --- aio/package.json | 2 +- aio/tools/firebase-test-utils/.eslintrc.json | 23 +++++ .../firebase-test-utils/FirebaseRedirect.ts | 9 +- .../FirebaseRedirectSource.spec.ts | 6 +- .../FirebaseRedirectSource.ts | 3 +- aio/tools/tslint.json | 87 ------------------- 6 files changed, 33 insertions(+), 97 deletions(-) create mode 100644 aio/tools/firebase-test-utils/.eslintrc.json delete mode 100644 aio/tools/tslint.json diff --git a/aio/package.json b/aio/package.json index 17096b7d4f1fa..1885993c93396 100644 --- a/aio/package.json +++ b/aio/package.json @@ -56,7 +56,7 @@ "docs-test": "node tools/transforms/test.js", "redirects-test": "node tests/deployment/unit/test", "firebase-utils-test": "node tools/firebase-test-utils/test", - "tools-lint": "tslint --config \"tools/tslint.json\" --project \"tools/firebase-test-utils\" && eslint tools/ng-packages-installer", + "tools-lint": "eslint tools/firebase-test-utils && eslint tools/ng-packages-installer", "tools-test": "yarn docs-test && yarn boilerplate:test && jasmine tools/ng-packages-installer/index.spec.js && jasmine scripts/deploy-to-firebase.spec.js && yarn firebase-utils-test", "preserve-and-sync": "yarn docs", "serve-and-sync": "run-p \"docs-watch --watch-only\" \"start {@}\" --", diff --git a/aio/tools/firebase-test-utils/.eslintrc.json b/aio/tools/firebase-test-utils/.eslintrc.json new file mode 100644 index 0000000000000..6d720c8a5cb8c --- /dev/null +++ b/aio/tools/firebase-test-utils/.eslintrc.json @@ -0,0 +1,23 @@ +{ + "extends": "../../.eslintrc.json", + "overrides": [ + { + "files": ["*.js"], + "env": { + "es6": true, + "node": true + }, + "extends": [ + "eslint:recommended" + ], + "parserOptions": { + "ecmaVersion": 2020 + }, + "rules": { + "quotes": ["error", "single"], + "semi": ["error", "always"], + "no-var": ["error"] + } + } + ] +} diff --git a/aio/tools/firebase-test-utils/FirebaseRedirect.ts b/aio/tools/firebase-test-utils/FirebaseRedirect.ts index 69c85f45cf3f8..8c32367043dab 100644 --- a/aio/tools/firebase-test-utils/FirebaseRedirect.ts +++ b/aio/tools/firebase-test-utils/FirebaseRedirect.ts @@ -7,11 +7,10 @@ export class FirebaseRedirect { destination: string; constructor(readonly rawConfig: FirebaseRedirectConfig) { - const {source, regex, destination} = rawConfig; - this.source = (typeof source === 'string') ? - FirebaseRedirectSource.fromGlobPattern(source) : - FirebaseRedirectSource.fromRegexPattern(regex!); - this.destination = destination; + this.source = (rawConfig.regex === undefined) ? + FirebaseRedirectSource.fromGlobPattern(rawConfig.source) : + FirebaseRedirectSource.fromRegexPattern(rawConfig.regex); + this.destination = rawConfig.destination; } replace(url: string): string | undefined { diff --git a/aio/tools/firebase-test-utils/FirebaseRedirectSource.spec.ts b/aio/tools/firebase-test-utils/FirebaseRedirectSource.spec.ts index eeb2d6375a55d..c8d760c79ec20 100644 --- a/aio/tools/firebase-test-utils/FirebaseRedirectSource.spec.ts +++ b/aio/tools/firebase-test-utils/FirebaseRedirectSource.spec.ts @@ -344,21 +344,21 @@ function testSource(source: FirebaseRedirectSource, matches: string[], nonMatche function testGlobMatch( pattern: string, captures: { named?: string[], rest?: string[] }, - matches: { [url: string]: object|undefined }) { + matches: { [url: string]: unknown|undefined }) { return testSourceMatch(FirebaseRedirectSource.fromGlobPattern(pattern), captures, matches); } function testRegexMatch( pattern: string, captures: { named?: string[], rest?: string[] }, - matches: { [url: string]: object|undefined }) { + matches: { [url: string]: unknown|undefined }) { return testSourceMatch(FirebaseRedirectSource.fromRegexPattern(pattern), captures, matches); } function testSourceMatch( source: FirebaseRedirectSource, captures: { named?: string[], rest?: string[] }, - matches: { [url: string]: object|undefined }) { + matches: { [url: string]: unknown|undefined }) { expect(source.namedGroups).toEqual(captures.named || []); expect(source.restNamedGroups).toEqual(captures.rest || []); Object.keys(matches).forEach(url => expect(source.match(url)).toEqual(matches[url])); diff --git a/aio/tools/firebase-test-utils/FirebaseRedirectSource.ts b/aio/tools/firebase-test-utils/FirebaseRedirectSource.ts index fe57927115039..94ba1196e9551 100644 --- a/aio/tools/firebase-test-utils/FirebaseRedirectSource.ts +++ b/aio/tools/firebase-test-utils/FirebaseRedirectSource.ts @@ -40,7 +40,7 @@ export class FirebaseRedirectSource { restNamedGroups.push(groupName); return `(?:${leadingSlash}(?<${groupName}>.🐷))?`; }) - .replace(namedParam, `$1(?<$2>[^/]+)`) + .replace(namedParam, '$1(?<$2>[^/]+)') .replace(doubleStar, '$1.🐷$2') // use the pig to avoid replacing ** in next rule .replace(star, '[^/]*') // match a single segment .replace(possiblyEmptyInitialSegments, '(?:.*)')// deal with **/ special cases @@ -89,6 +89,7 @@ export class FirebaseRedirectSource { const result: { [key: string]: string } = {}; const names = this.regex.xregexp.captureNames || []; + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion names.forEach(name => result[name] = match.groups![name]); return result; } diff --git a/aio/tools/tslint.json b/aio/tools/tslint.json deleted file mode 100644 index 0888e2beb158c..0000000000000 --- a/aio/tools/tslint.json +++ /dev/null @@ -1,87 +0,0 @@ -{ - "rulesDirectory": [ - "../node_modules/codelyzer" - ], - "rules": { - "class-name": true, - "comment-format": [ - true, - "check-space" - ], - "curly": true, - "eofline": true, - "forin": true, - "indent": [ - true, - "spaces" - ], - "label-position": true, - "max-line-length": [ - true, - 140 - ], - "member-access": false, - "no-arg": true, - "no-bitwise": true, - "no-console": [ - true, - "debug", - "info", - "time", - "timeEnd", - "trace" - ], - "no-construct": true, - "no-debugger": true, - "no-duplicate-variable": true, - "no-empty": false, - "no-eval": true, - "no-inferrable-types": true, - "no-string-literal": false, - "no-switch-case-fall-through": true, - "no-trailing-whitespace": true, - "no-unused-expression": true, - "no-var-keyword": true, - "object-literal-sort-keys": false, - "one-line": [ - true, - "check-open-brace", - "check-catch", - "check-else", - "check-whitespace" - ], - "quotemark": [ - true, - "single" - ], - "radix": true, - "semicolon": [ - true - ], - "triple-equals": [ - true, - "allow-null-check" - ], - "typedef-whitespace": [ - true, - { - "call-signature": "nospace", - "index-signature": "nospace", - "parameter": "nospace", - "property-declaration": "nospace", - "variable-declaration": "nospace" - } - ], - "variable-name": false, - "whitespace": [ - true, - "check-branch", - "check-decl", - "check-operator", - "check-separator", - "check-type" - ], - - "import-destructuring-spacing": true - } - }