From 989c61521dad964f7175e6610c1f5ea75e350154 Mon Sep 17 00:00:00 2001 From: Zack Ream Date: Wed, 30 May 2018 16:35:43 -0400 Subject: [PATCH] fix(finnish): Handle undefined type symbol Closes #45 --- source/rules/rxjsFinnishRule.ts | 2 +- test/v5/fixtures/finnish/optional/fixture.ts.lint | 8 ++++++++ test/v5/fixtures/finnish/optional/tsconfig.json | 14 ++++++++++++++ test/v5/fixtures/finnish/optional/tslint.json | 8 ++++++++ .../fixtures/finnish/optional/fixture.ts.lint | 8 ++++++++ .../fixtures/finnish/optional/tsconfig.json | 14 ++++++++++++++ .../fixtures/finnish/optional/tslint.json | 8 ++++++++ test/v6/fixtures/finnish/optional/fixture.ts.lint | 8 ++++++++ test/v6/fixtures/finnish/optional/tsconfig.json | 14 ++++++++++++++ test/v6/fixtures/finnish/optional/tslint.json | 8 ++++++++ 10 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 test/v5/fixtures/finnish/optional/fixture.ts.lint create mode 100644 test/v5/fixtures/finnish/optional/tsconfig.json create mode 100644 test/v5/fixtures/finnish/optional/tslint.json create mode 100644 test/v6-compat/fixtures/finnish/optional/fixture.ts.lint create mode 100644 test/v6-compat/fixtures/finnish/optional/tsconfig.json create mode 100644 test/v6-compat/fixtures/finnish/optional/tslint.json create mode 100644 test/v6/fixtures/finnish/optional/fixture.ts.lint create mode 100644 test/v6/fixtures/finnish/optional/tsconfig.json create mode 100644 test/v6/fixtures/finnish/optional/tslint.json diff --git a/source/rules/rxjsFinnishRule.ts b/source/rules/rxjsFinnishRule.ts index ffeaa806..ce1bbfb1 100644 --- a/source/rules/rxjsFinnishRule.ts +++ b/source/rules/rxjsFinnishRule.ts @@ -196,7 +196,7 @@ class Walker extends Lint.ProgramAwareRuleWalker { } for (let i = 0; i < this.types.length; ++i) { const { regExp, validate } = this.types[i]; - if (regExp.test(type.symbol.name) && !validate) { + if (type.symbol !== undefined && regExp.test(type.symbol.name) && !validate) { return; } } diff --git a/test/v5/fixtures/finnish/optional/fixture.ts.lint b/test/v5/fixtures/finnish/optional/fixture.ts.lint new file mode 100644 index 00000000..44e7e5e9 --- /dev/null +++ b/test/v5/fixtures/finnish/optional/fixture.ts.lint @@ -0,0 +1,8 @@ +import { Observable, of } from "rxjs"; + +const someOptionalObservable$: Observable | undefined = of(); + +const someOptionalObservable: Observable | undefined = of(); + ~~~~~~~~~~~~~~~~~~~~~~ [finnish % ("someOptionalObservable")] + +[finnish]: Finnish notation required for %s diff --git a/test/v5/fixtures/finnish/optional/tsconfig.json b/test/v5/fixtures/finnish/optional/tsconfig.json new file mode 100644 index 00000000..c1f906cd --- /dev/null +++ b/test/v5/fixtures/finnish/optional/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "lib": ["es2015"], + "noEmit": true, + "paths": { + "rxjs": ["../../node_modules/rxjs"] + }, + "skipLibCheck": true, + "target": "es5", + "strictNullChecks": true + }, + "include": ["fixture.ts"] +} diff --git a/test/v5/fixtures/finnish/optional/tslint.json b/test/v5/fixtures/finnish/optional/tslint.json new file mode 100644 index 00000000..c11fbd9b --- /dev/null +++ b/test/v5/fixtures/finnish/optional/tslint.json @@ -0,0 +1,8 @@ +{ + "defaultSeverity": "error", + "jsRules": {}, + "rules": { + "rxjs-finnish": { "severity": "error" } + }, + "rulesDirectory": "../../../../../build/rules" +} diff --git a/test/v6-compat/fixtures/finnish/optional/fixture.ts.lint b/test/v6-compat/fixtures/finnish/optional/fixture.ts.lint new file mode 100644 index 00000000..44e7e5e9 --- /dev/null +++ b/test/v6-compat/fixtures/finnish/optional/fixture.ts.lint @@ -0,0 +1,8 @@ +import { Observable, of } from "rxjs"; + +const someOptionalObservable$: Observable | undefined = of(); + +const someOptionalObservable: Observable | undefined = of(); + ~~~~~~~~~~~~~~~~~~~~~~ [finnish % ("someOptionalObservable")] + +[finnish]: Finnish notation required for %s diff --git a/test/v6-compat/fixtures/finnish/optional/tsconfig.json b/test/v6-compat/fixtures/finnish/optional/tsconfig.json new file mode 100644 index 00000000..c1f906cd --- /dev/null +++ b/test/v6-compat/fixtures/finnish/optional/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "lib": ["es2015"], + "noEmit": true, + "paths": { + "rxjs": ["../../node_modules/rxjs"] + }, + "skipLibCheck": true, + "target": "es5", + "strictNullChecks": true + }, + "include": ["fixture.ts"] +} diff --git a/test/v6-compat/fixtures/finnish/optional/tslint.json b/test/v6-compat/fixtures/finnish/optional/tslint.json new file mode 100644 index 00000000..c11fbd9b --- /dev/null +++ b/test/v6-compat/fixtures/finnish/optional/tslint.json @@ -0,0 +1,8 @@ +{ + "defaultSeverity": "error", + "jsRules": {}, + "rules": { + "rxjs-finnish": { "severity": "error" } + }, + "rulesDirectory": "../../../../../build/rules" +} diff --git a/test/v6/fixtures/finnish/optional/fixture.ts.lint b/test/v6/fixtures/finnish/optional/fixture.ts.lint new file mode 100644 index 00000000..44e7e5e9 --- /dev/null +++ b/test/v6/fixtures/finnish/optional/fixture.ts.lint @@ -0,0 +1,8 @@ +import { Observable, of } from "rxjs"; + +const someOptionalObservable$: Observable | undefined = of(); + +const someOptionalObservable: Observable | undefined = of(); + ~~~~~~~~~~~~~~~~~~~~~~ [finnish % ("someOptionalObservable")] + +[finnish]: Finnish notation required for %s diff --git a/test/v6/fixtures/finnish/optional/tsconfig.json b/test/v6/fixtures/finnish/optional/tsconfig.json new file mode 100644 index 00000000..c1f906cd --- /dev/null +++ b/test/v6/fixtures/finnish/optional/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "lib": ["es2015"], + "noEmit": true, + "paths": { + "rxjs": ["../../node_modules/rxjs"] + }, + "skipLibCheck": true, + "target": "es5", + "strictNullChecks": true + }, + "include": ["fixture.ts"] +} diff --git a/test/v6/fixtures/finnish/optional/tslint.json b/test/v6/fixtures/finnish/optional/tslint.json new file mode 100644 index 00000000..c11fbd9b --- /dev/null +++ b/test/v6/fixtures/finnish/optional/tslint.json @@ -0,0 +1,8 @@ +{ + "defaultSeverity": "error", + "jsRules": {}, + "rules": { + "rxjs-finnish": { "severity": "error" } + }, + "rulesDirectory": "../../../../../build/rules" +}