Parcourir la source

style: Unify tslint configs and fix outstanding issues

Michael Bromley il y a 7 ans
Parent
commit
9d6f45522b

+ 0 - 14
admin-ui/e2e/src/app.e2e-spec.ts

@@ -1,14 +0,0 @@
-import { AppPage } from './app.po';
-
-describe('workspace-project App', () => {
-  let page: AppPage;
-
-  beforeEach(() => {
-    page = new AppPage();
-  });
-
-  it('should display welcome message', () => {
-    page.navigateTo();
-    expect(page.getParagraphText()).toEqual('Welcome to vendure-admin!');
-  });
-});

+ 0 - 11
admin-ui/e2e/src/app.po.ts

@@ -1,11 +0,0 @@
-import { browser, by, element } from 'protractor';
-
-export class AppPage {
-  navigateTo() {
-    return browser.get('/');
-  }
-
-  getParagraphText() {
-    return element(by.css('vdr-root h1')).getText();
-  }
-}

+ 1 - 0
admin-ui/package.json

@@ -54,6 +54,7 @@
     "protractor": "~5.3.0",
     "ts-node": "~5.0.1",
     "tslint": "~5.9.1",
+    "tslint-language-service": "^0.9.9",
     "typescript": "~2.7.2"
   }
 }

+ 0 - 27
admin-ui/src/app/app.component.spec.ts

@@ -1,27 +0,0 @@
-import { TestBed, async } from '@angular/core/testing';
-import { AppComponent } from './app.component';
-describe('AppComponent', () => {
-  beforeEach(async(() => {
-    TestBed.configureTestingModule({
-      declarations: [
-        AppComponent
-      ],
-    }).compileComponents();
-  }));
-  it('should create the app', async(() => {
-    const fixture = TestBed.createComponent(AppComponent);
-    const app = fixture.debugElement.componentInstance;
-    expect(app).toBeTruthy();
-  }));
-  it(`should have as title 'vdr'`, async(() => {
-    const fixture = TestBed.createComponent(AppComponent);
-    const app = fixture.debugElement.componentInstance;
-    expect(app.title).toEqual('vdr');
-  }));
-  it('should render title in a h1 tag', async(() => {
-    const fixture = TestBed.createComponent(AppComponent);
-    fixture.detectChanges();
-    const compiled = fixture.debugElement.nativeElement;
-    expect(compiled.querySelector('h1').textContent).toContain('Welcome to vendure-admin!');
-  }));
-});

+ 3 - 3
admin-ui/src/app/app.component.ts

@@ -5,7 +5,7 @@ import gql from 'graphql-tag';
 @Component({
   selector: 'vdr-root',
   templateUrl: './app.component.html',
-  styleUrls: ['./app.component.scss']
+  styleUrls: ['./app.component.scss'],
 })
 export class AppComponent {
   title = 'Vendure';
@@ -23,10 +23,10 @@ export class AppComponent {
             description
           }
         }
-      `
+      `,
     })
     .subscribe(result => {
       this.products = result.data.products;
-    })
+    });
   }
 }

+ 7 - 8
admin-ui/src/app/app.module.ts

@@ -1,26 +1,26 @@
-import { BrowserModule } from '@angular/platform-browser';
+import { HttpClientModule } from '@angular/common/http';
 import { NgModule } from '@angular/core';
-
-import { AppComponent } from './app.component';
+import { BrowserModule } from '@angular/platform-browser';
 import { ClarityModule } from '@clr/angular';
-import { HttpClientModule } from '@angular/common/http';
 import { Apollo, ApolloModule } from 'apollo-angular';
 import { HttpLink, HttpLinkModule } from 'apollo-angular-link-http';
 import { InMemoryCache } from 'apollo-cache-inmemory';
 
+import { AppComponent } from './app.component';
+
 @NgModule({
   declarations: [
-    AppComponent
+    AppComponent,
   ],
   imports: [
     BrowserModule,
     ClarityModule,
     HttpClientModule,
     ApolloModule,
-    HttpLinkModule
+    HttpLinkModule,
   ],
   providers: [],
-  bootstrap: [AppComponent]
+  bootstrap: [AppComponent],
 })
 export class AppModule {
 
@@ -31,5 +31,4 @@ export class AppModule {
     });
   }
 
-
 }

+ 1 - 1
admin-ui/src/environments/environment.prod.ts

@@ -1,3 +1,3 @@
 export const environment = {
-  production: true
+  production: true,
 };

+ 1 - 1
admin-ui/src/environments/environment.ts

@@ -3,7 +3,7 @@
 // The list of file replacements can be found in `angular.json`.
 
 export const environment = {
-  production: false
+  production: false,
 };
 
 /*

+ 4 - 1
admin-ui/src/main.ts

@@ -9,4 +9,7 @@ if (environment.production) {
 }
 
 platformBrowserDynamic().bootstrapModule(AppModule)
-  .catch(err => console.log(err));
+  .catch(err => {
+      // tslint:disable:no-console
+      console.log(err);
+  });

+ 1 - 5
admin-ui/src/polyfills.ts

@@ -40,12 +40,10 @@
 /** IE10 and IE11 requires the following for the Reflect API. */
 // import 'core-js/es6/reflect';
 
-
 /** Evergreen browsers require these. **/
 // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
 import 'core-js/es7/reflect';
 
-
 /**
  * Web Animations `@angular/platform-browser/animations`
  * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
@@ -73,11 +71,9 @@ import 'core-js/es7/reflect';
  */
 import 'zone.js/dist/zone';  // Included with Angular CLI.
 
-
-
 /***************************************************************************************************
  * APPLICATION IMPORTS
  */
 
-import '@webcomponents/custom-elements/custom-elements.min.js';
 import '@clr/icons';
+import '@webcomponents/custom-elements/custom-elements.min.js';

+ 3 - 3
admin-ui/src/test.ts

@@ -1,18 +1,18 @@
 // This file is required by karma.conf.js and loads recursively all the .spec and framework files
 
-import 'zone.js/dist/zone-testing';
 import { getTestBed } from '@angular/core/testing';
 import {
   BrowserDynamicTestingModule,
-  platformBrowserDynamicTesting
+  platformBrowserDynamicTesting,
 } from '@angular/platform-browser-dynamic/testing';
+import 'zone.js/dist/zone-testing';
 
 declare const require: any;
 
 // First, initialize the Angular testing environment.
 getTestBed().initTestEnvironment(
   BrowserDynamicTestingModule,
-  platformBrowserDynamicTesting()
+  platformBrowserDynamicTesting(),
 );
 // Then we find all the tests.
 const context = require.context('./', true, /\.spec\.ts$/);

+ 27 - 20
admin-ui/tsconfig.json

@@ -1,22 +1,29 @@
 {
-  "compileOnSave": false,
-  "compilerOptions": {
-    "baseUrl": "./",
-    "outDir": "./dist/out-tsc",
-    "sourceMap": true,
-    "declaration": false,
-    "moduleResolution": "node",
-    "emitDecoratorMetadata": true,
-    "experimentalDecorators": true,
-    "target": "es5",
-    "skipLibCheck": true,
-    "typeRoots": [
-      "node_modules/@types"
-    ],
-    "lib": [
-      "es2017",
-      "dom",
-      "esnext.asynciterable"
-    ]
-  }
+    "compileOnSave": false,
+    "compilerOptions": {
+        "baseUrl": "./",
+        "outDir": "./dist/out-tsc",
+        "sourceMap": true,
+        "declaration": false,
+        "moduleResolution": "node",
+        "emitDecoratorMetadata": true,
+        "experimentalDecorators": true,
+        "target": "es5",
+        "skipLibCheck": true,
+        "typeRoots": [
+            "node_modules/@types"
+        ],
+        "lib": [
+            "es2017",
+            "dom",
+            "esnext.asynciterable"
+        ],
+        "plugins": [
+            {
+                "name": "tslint-language-service",
+                "ignoreDefinitionFiles": true,
+                "supressWhileTypeErrorsPresent": true
+            }
+        ]
+    }
 }

+ 30 - 128
admin-ui/tslint.json

@@ -1,130 +1,32 @@
 {
-  "rulesDirectory": [
-    "node_modules/codelyzer"
-  ],
-  "rules": {
-    "arrow-return-shorthand": true,
-    "callable-types": true,
-    "class-name": true,
-    "comment-format": [
-      true,
-      "check-space"
-    ],
-    "curly": true,
-    "deprecation": {
-      "severity": "warn"
-    },
-    "eofline": true,
-    "forin": true,
-    "import-blacklist": [
-      true,
-      "rxjs/Rx"
-    ],
-    "import-spacing": true,
-    "indent": [
-      true,
-      "spaces"
-    ],
-    "interface-over-type-literal": true,
-    "label-position": true,
-    "max-line-length": [
-      true,
-      140
-    ],
-    "member-access": false,
-    "member-ordering": [
-      true,
-      {
-        "order": [
-          "static-field",
-          "instance-field",
-          "static-method",
-          "instance-method"
-        ]
-      }
-    ],
-    "no-arg": true,
-    "no-bitwise": true,
-    "no-console": [
-      true,
-      "debug",
-      "info",
-      "time",
-      "timeEnd",
-      "trace"
-    ],
-    "no-construct": true,
-    "no-debugger": true,
-    "no-duplicate-super": true,
-    "no-empty": false,
-    "no-empty-interface": true,
-    "no-eval": true,
-    "no-inferrable-types": [
-      true,
-      "ignore-params"
-    ],
-    "no-misused-new": true,
-    "no-non-null-assertion": true,
-    "no-shadowed-variable": true,
-    "no-string-literal": false,
-    "no-string-throw": true,
-    "no-switch-case-fall-through": true,
-    "no-trailing-whitespace": true,
-    "no-unnecessary-initializer": true,
-    "no-unused-expression": true,
-    "no-use-before-declare": true,
-    "no-var-keyword": true,
-    "object-literal-sort-keys": false,
-    "one-line": [
-      true,
-      "check-open-brace",
-      "check-catch",
-      "check-else",
-      "check-whitespace"
-    ],
-    "prefer-const": true,
-    "quotemark": [
-      true,
-      "single"
-    ],
-    "radix": true,
-    "semicolon": [
-      true,
-      "always"
-    ],
-    "triple-equals": [
-      true,
-      "allow-null-check"
-    ],
-    "typedef-whitespace": [
-      true,
-      {
-        "call-signature": "nospace",
-        "index-signature": "nospace",
-        "parameter": "nospace",
-        "property-declaration": "nospace",
-        "variable-declaration": "nospace"
-      }
-    ],
-    "unified-signatures": true,
-    "variable-name": false,
-    "whitespace": [
-      true,
-      "check-branch",
-      "check-decl",
-      "check-operator",
-      "check-separator",
-      "check-type"
-    ],
-    "no-output-on-prefix": true,
-    "use-input-property-decorator": true,
-    "use-output-property-decorator": true,
-    "use-host-property-decorator": true,
-    "no-input-rename": true,
-    "no-output-rename": true,
-    "use-life-cycle-interface": true,
-    "use-pipe-transform-interface": true,
-    "component-class-suffix": true,
-    "directive-class-suffix": true
-  }
+    "extends": [
+        "../tslint.json"
+    ],
+    "rulesDirectory": [
+        "node_modules/codelyzer"
+    ],
+    "rules": {
+        "deprecation": {
+            "severity": "warn"
+        },
+        "import-blacklist": [
+            true,
+            "rxjs/Rx"
+        ],
+        "indent": [
+            true,
+            "spaces"
+        ],
+        "no-string-literal": false,
+        "no-output-on-prefix": true,
+        "use-input-property-decorator": true,
+        "use-output-property-decorator": true,
+        "use-host-property-decorator": true,
+        "no-input-rename": true,
+        "no-output-rename": true,
+        "use-life-cycle-interface": true,
+        "use-pipe-transform-interface": true,
+        "component-class-suffix": true,
+        "directive-class-suffix": true
+    }
 }

+ 22 - 0
admin-ui/yarn.lock

@@ -1127,6 +1127,12 @@ cache-loader@^1.2.2:
     neo-async "^2.5.0"
     schema-utils "^0.4.2"
 
+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"
+
 callsite@1.0.0:
   version "1.0.0"
   resolved "https://registry.yarnpkg.com/callsite/-/callsite-1.0.0.tgz#280398e5d664bd74038b6f0905153e6e8af1bc20"
@@ -4033,6 +4039,12 @@ mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.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"
@@ -5722,6 +5734,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"
+
 static-extend@^0.1.1:
   version "0.1.2"
   resolved "https://registry.yarnpkg.com/static-extend/-/static-extend-0.1.2.tgz#60809c39cbff55337226fd5e0b520f341f1fb5c6"
@@ -6053,6 +6069,12 @@ tslib@^1.7.1, tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0:
   version "1.9.2"
   resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.2.tgz#8be0cc9a1f6dc7727c38deb16c2ebd1a2892988e"
 
+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.9.1:
   version "5.9.1"
   resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.9.1.tgz#1255f87a3ff57eb0b0e1f0e610a8b4748046c9ae"

+ 1 - 1
server/src/common/utils.ts

@@ -9,6 +9,6 @@ export function not(predicate: (...args: any[]) => boolean) {
  * Returns a predicate function which returns true if the item is found in the set,
  * as determined by a === equality check on the given compareBy property.
  */
-export function foundIn<T>(set: Array<T>, compareBy: keyof T) {
+export function foundIn<T>(set: T[], compareBy: keyof T) {
     return (item: T) => set.some(t => t[compareBy] === item[compareBy]);
 }

+ 1 - 1
server/src/entity/product-option-group/product-option-group.entity.ts

@@ -24,7 +24,7 @@ export class ProductOptionGroup implements Translatable {
     @UpdateDateColumn() updatedAt: string;
 
     @OneToMany(type => ProductOptionGroupTranslation, translation => translation.base, { eager: true })
-    translations: Translation<ProductOptionGroup>[];
+    translations: Array<Translation<ProductOptionGroup>>;
 
     @OneToMany(type => ProductOption, option => option.group)
     options: ProductOption[];

+ 1 - 1
server/src/entity/product-option/product-option.entity.ts

@@ -31,7 +31,7 @@ export class ProductOption implements Translatable {
     @UpdateDateColumn() updatedAt: string;
 
     @OneToMany(type => ProductOptionTranslation, translation => translation.base, { eager: true })
-    translations: Translation<ProductOption>[];
+    translations: Array<Translation<ProductOption>>;
 
     @ManyToOne(type => ProductOptionGroup, group => group.options)
     group: ProductOptionGroup;

+ 1 - 1
server/src/entity/product-variant/product-variant.entity.ts

@@ -38,7 +38,7 @@ export class ProductVariant implements Translatable {
     @UpdateDateColumn() updatedAt: string;
 
     @OneToMany(type => ProductVariantTranslation, translation => translation.base, { eager: true })
-    translations: Translation<ProductVariant>[];
+    translations: Array<Translation<ProductVariant>>;
 
     @ManyToOne(type => Product, product => product.variants)
     product: Product;

+ 1 - 1
server/src/entity/product/product.entity.ts

@@ -37,7 +37,7 @@ export class Product implements Translatable {
     @UpdateDateColumn() updatedAt: string;
 
     @OneToMany(type => ProductTranslation, translation => translation.base, { eager: true })
-    translations: Translation<Product>[];
+    translations: Array<Translation<Product>>;
 
     @OneToMany(type => ProductVariant, variant => variant.product)
     variants: ProductVariant[];

+ 1 - 1
server/src/locale/locale-types.ts

@@ -14,7 +14,7 @@ export type NonTranslateableKeys<T> = { [K in keyof T]: T[K] extends LocaleStrin
 /**
  * Entities which have localizable string properties should implement this type.
  */
-export interface Translatable { translations: Translation<any>[]; }
+export interface Translatable { translations: Array<Translation<any>>; }
 
 // prettier-ignore
 /**

+ 2 - 2
server/src/locale/translate-entity.spec.ts

@@ -96,7 +96,7 @@ describe('translateDeep()', () => {
         id: number;
         singleTestVariant: TestVariantEntity;
         singleRealVariant: ProductVariant;
-        translations: Translation<TestProduct>[];
+        translations: Array<Translation<TestProduct>>;
     }
 
     interface TestVariant {
@@ -106,7 +106,7 @@ describe('translateDeep()', () => {
     class TestVariantEntity implements Translatable {
         id: number;
         singleOption: ProductOption;
-        translations: Translation<TestVariant>[];
+        translations: Array<Translation<TestVariant>>;
     }
 
     let testProduct: TestProductEntity;

+ 8 - 6
server/src/locale/translate-entity.ts

@@ -7,17 +7,17 @@ export type TranslatableRelationsKeys<T> = {
     T[K] extends number ? never :
     T[K] extends boolean ? never :
     T[K] extends undefined ? never :
-    T[K] extends Array<string> ? never :
-    T[K] extends Array<number> ? never :
-    T[K] extends Array<boolean> ? never :
+    T[K] extends string[] ? never :
+    T[K] extends number[] ? never :
+    T[K] extends boolean[] ? never :
     K extends 'translations' ? never : K
 }[keyof T];
 
-export type UnwrappedArray<T extends Array<any>> = T[number];
+export type UnwrappedArray<T extends any[]> = T[number];
 
 // prettier-ignore
 export type NestedTranslatableRelations<T> = {
-    [K in TranslatableRelationsKeys<T>]: T[K] extends Array<any> ?
+    [K in TranslatableRelationsKeys<T>]: T[K] extends any[] ?
         [K, TranslatableRelationsKeys<UnwrappedArray<T[K]>>]:
         [K, TranslatableRelationsKeys<T[K]>]
 };
@@ -84,6 +84,7 @@ export function translateDeep<T extends Translatable>(
                     property = path1;
                     object[property] = translateLeaf(object, property, languageCode);
                 });
+                property = '';
                 object = null;
             } else {
                 object = translatedEntity[path0];
@@ -95,7 +96,8 @@ export function translateDeep<T extends Translatable>(
             property = path as any;
             value = translateLeaf(object, property, languageCode);
         }
-        if (object && property!) {
+
+        if (object && property) {
             object[property] = value;
         }
     }

+ 1 - 1
server/src/locale/translation-updater.spec.ts

@@ -79,7 +79,7 @@ describe('TranslationUpdater', () => {
         });
 
         it('correctly marks languages for update, addition and deletion', async () => {
-            const updated: TranslationInput<Product>[] = [
+            const updated: Array<TranslationInput<Product>> = [
                 {
                     languageCode: LanguageCode.EN,
                     name: '',

+ 2 - 57
server/tslint.json

@@ -1,60 +1,5 @@
 {
-    "defaultSeverity": "error",
     "extends": [
-        "tslint:recommended"
-    ],
-    "jsRules": {
-        "no-unused-expression": true
-    },
-    "rules": {
-        "eofline": false,
-        "quotemark": [
-            true,
-            "single"
-        ],
-        "indent": false,
-        "member-access": [
-            false
-        ],
-        "ordered-imports": [
-            true,
-            {
-                "grouped-imports": true
-            }
-        ],
-        "import-spacing": true,
-        "max-line-length": [
-            true,
-            150
-        ],
-        "member-ordering": [
-            false
-        ],
-        "curly": false,
-        "interface-name": [
-            false
-        ],
-        "array-type": [
-            false
-        ],
-        "no-empty-interface": false,
-        "no-empty": false,
-        "arrow-parens": false,
-        "object-literal-sort-keys": false,
-        "no-unused-expression": true,
-        "max-classes-per-file": [
-            false
-        ],
-        "variable-name": [
-            false
-        ],
-        "one-line": [
-            false
-        ],
-        "one-variable-per-declaration": [
-            false
-        ],
-        "no-floating-promises": true
-    },
-    "rulesDirectory": []
+        "../tslint.json"
+    ]
 }

+ 53 - 0
tslint.json

@@ -0,0 +1,53 @@
+{
+    "defaultSeverity": "error",
+    "extends": [
+        "tslint:recommended"
+    ],
+    "jsRules": {
+        "no-unused-expression": true
+    },
+    "rules": {
+        "interface-over-type-literal": false,
+        "quotemark": [
+            true,
+            "single"
+        ],
+        "indent": false,
+        "ordered-imports": [
+            true,
+            {
+                "grouped-imports": true
+            }
+        ],
+        "jsdoc-format": false,
+        "no-inferrable-types": [
+            true,
+            "ignore-params"
+        ],
+        "max-line-length": [
+            true,
+            150
+        ],
+        "member-access": false,
+        "member-ordering": false,
+        "interface-name": false,
+        "array-type": [
+            true,
+            "array-simple"
+        ],
+        "no-non-null-assertion": true,
+        "no-empty-interface": false,
+        "no-switch-case-fall-through": true,
+        "arrow-parens": false,
+        "object-literal-sort-keys": false,
+        "no-unused-expression": true,
+        "max-classes-per-file": [
+            false
+        ],
+        "variable-name": [
+            false
+        ],
+        "no-floating-promises": true
+    },
+    "rulesDirectory": []
+}