Răsfoiți Sursa

Run tslint as a ts-server plugin, add no-floating-promises rule

Wasted a bit of time on bugs where I forgot to await a promise. This rule will catch such instances and flag them as TS errors now.
Michael Bromley 7 ani în urmă
părinte
comite
13bebe597f

+ 1 - 0
modules/core/main.hmr.ts

@@ -12,4 +12,5 @@ async function bootstrap() {
         module.hot.dispose(() => app.close());
     }
 }
+// tslint:disable:no-floating-promises
 bootstrap();

+ 1 - 0
modules/core/main.ts

@@ -5,4 +5,5 @@ async function bootstrap() {
     const app = await NestFactory.create(AppModule);
     await app.listen(3000);
 }
+// tslint:disable:no-floating-promises
 bootstrap();

+ 2 - 2
modules/core/service/product-variant.service.spec.ts

@@ -23,9 +23,9 @@ describe('ProductVariantService', () => {
     });
 
     describe('create()', () => {
-        it('calls ProductVariantRepository.create with product and translation entities', () => {
+        it('calls ProductVariantRepository.create with product and translation entities', async () => {
             const productEntity = new Product();
-            productVariantService.create(productEntity, {
+            await productVariantService.create(productEntity, {
                 sku: '123456',
                 price: 123,
                 translations: [

+ 2 - 2
modules/core/service/product.service.spec.ts

@@ -24,8 +24,8 @@ describe('ProductService', () => {
     });
 
     describe('create()', () => {
-        it('calls ProductRepository.create with product and translation entities', () => {
-            productService.create({
+        it('calls ProductRepository.create with product and translation entities', async () => {
+            await productService.create({
                 translations: [
                     {
                         languageCode: LanguageCode.EN,

+ 2 - 1
package.json

@@ -13,7 +13,7 @@
     "prestart:prod": "rimraf dist && tsc",
     "start:prod": "node dist/main.js",
     "start:hmr": "node dist/server",
-    "lint": "tslint -p tsconfig.json -c tslint.json",
+    "lint": "tslint --type-check --project tsconfig.json -c tslint.json",
     "test": "jest",
     "test:watch": "jest --watch",
     "test:cov": "jest --coverage",
@@ -73,6 +73,7 @@
     "ts-node": "^6.0.0",
     "tsconfig-paths": "^3.3.1",
     "tslint": "5.3.2",
+    "tslint-language-service": "^0.9.9",
     "webpack": "^4.2.0",
     "webpack-cli": "^2.0.13",
     "webpack-node-externals": "^1.6.0"

+ 7 - 1
tsconfig.json

@@ -15,6 +15,12 @@
     "strictPropertyInitialization": false,
     "sourceMap": true,
     "outDir": "./dist",
-    "baseUrl": "./src"
+    "baseUrl": "./src",
+    "plugins": [
+      {
+        "name": "tslint-language-service",
+        "ignoreDefinitionFiles": true
+      }
+    ]
   }
 }

+ 3 - 2
tslint.json

@@ -41,7 +41,7 @@
         "no-empty": false,
         "arrow-parens": false,
         "object-literal-sort-keys": false,
-        "no-unused-expression": false,
+        "no-unused-expression": true,
         "max-classes-per-file": [
             false
         ],
@@ -53,7 +53,8 @@
         ],
         "one-variable-per-declaration": [
             false
-        ]
+        ],
+        "no-floating-promises": true
     },
     "rulesDirectory": []
 }

+ 22 - 0
yarn.lock

@@ -1556,6 +1556,12 @@ call-me-maybe@^1.0.1:
   version "1.0.1"
   resolved "https://registry.yarnpkg.com/call-me-maybe/-/call-me-maybe-1.0.1.tgz#26d208ea89e37b5cbde60250a15f031c16a4d66b"
 
+caller-id@^0.1.0:
+  version "0.1.0"
+  resolved "https://registry.yarnpkg.com/caller-id/-/caller-id-0.1.0.tgz#59bdac0893d12c3871408279231f97458364f07b"
+  dependencies:
+    stack-trace "~0.0.7"
+
 callsites@^2.0.0:
   version "2.0.0"
   resolved "https://registry.yarnpkg.com/callsites/-/callsites-2.0.0.tgz#06eb84f00eea413da86affefacbffb36093b3c50"
@@ -4828,6 +4834,12 @@ mixin-deep@^1.2.0:
   dependencies:
     minimist "0.0.8"
 
+mock-require@^2.0.2:
+  version "2.0.2"
+  resolved "https://registry.yarnpkg.com/mock-require/-/mock-require-2.0.2.tgz#1eaa71aad23013773d127dc7e91a3fbb4837d60d"
+  dependencies:
+    caller-id "^0.1.0"
+
 move-concurrently@^1.0.1:
   version "1.0.1"
   resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92"
@@ -6462,6 +6474,10 @@ ssri@^5.2.4:
   dependencies:
     safe-buffer "^5.1.1"
 
+stack-trace@~0.0.7:
+  version "0.0.10"
+  resolved "https://registry.yarnpkg.com/stack-trace/-/stack-trace-0.0.10.tgz#547c70b347e8d32b4e108ea1a2a159e5fdde19c0"
+
 staged-git-files@1.1.1:
   version "1.1.1"
   resolved "https://registry.yarnpkg.com/staged-git-files/-/staged-git-files-1.1.1.tgz#37c2218ef0d6d26178b1310719309a16a59f8f7b"
@@ -6911,6 +6927,12 @@ tslib@^1.6.0, tslib@^1.8.1, tslib@^1.9.0:
   version "1.9.1"
   resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.1.tgz#a5d1f0532a49221c87755cfcc89ca37197242ba7"
 
+tslint-language-service@^0.9.9:
+  version "0.9.9"
+  resolved "https://registry.yarnpkg.com/tslint-language-service/-/tslint-language-service-0.9.9.tgz#f546dc38483979e6fb3cfa59584ad8525b3ad4da"
+  dependencies:
+    mock-require "^2.0.2"
+
 tslint@5.3.2:
   version "5.3.2"
   resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.3.2.tgz#e56459fb095a7307f103b84052174f5e3bbef6ed"