Add tslint report to sdc-pubsub sonar 15/62915/1
authorIdan Amit <ia096e@intl.att.com>
Sun, 26 Aug 2018 13:05:19 +0000 (16:05 +0300)
committerIdan Amit <ia096e@intl.att.com>
Sun, 26 Aug 2018 13:05:19 +0000 (16:05 +0300)
Added tslint report to sdc-pubsub sonar
Fixed all issues raised from tslint report

Change-Id: Iac8174b4a72f190c4b607c2d7ee55f7db457b4b5
Issue-ID: SDC-1668
Signed-off-by: Idan Amit <ia096e@intl.att.com>
lib/base-pubsub.ts
lib/plugin-pubsub.ts
package.json
pom.xml
tslint.json [new file with mode: 0644]

index 41e8039..36b959a 100644 (file)
@@ -3,20 +3,20 @@ declare const window: Window;
 export class BasePubSub {
 
     subscribers: Map<string, ISubscriber>;
-    eventsCallbacks: Array<Function>;
+    eventsCallbacks: Function[];
     clientId: string;
-    eventsToWait: Map<string, Array<string>>;
+    eventsToWait: Map<string, string[]>;
     lastEventNotified: string;
 
     constructor(pluginId: string) {
         this.subscribers = new Map<string, ISubscriber>();
         this.eventsCallbacks = [];
-        this.eventsToWait = new Map<string, Array<string>>();
+        this.eventsToWait = new Map<string, string[]>();
         this.clientId = pluginId;
-        this.lastEventNotified = "";
+        this.lastEventNotified = '';
         this.onMessage = this.onMessage.bind(this);
 
-        window.addEventListener("message", this.onMessage);
+        window.addEventListener('message', this.onMessage);
     }
 
     public register(subscriberId: string, subscriberWindow: Window, subscriberUrl: string) {
@@ -33,8 +33,8 @@ export class BasePubSub {
     }
 
     public on(callback: Function) {
-        let functionExists = this.eventsCallbacks.find((func: Function) => {
-            return callback.toString() == func.toString()
+        const functionExists = this.eventsCallbacks.find((func: Function) => {
+            return callback.toString() === func.toString();
         });
 
         if (!functionExists) {
@@ -43,12 +43,12 @@ export class BasePubSub {
     }
 
     public off(callback: Function) {
-        let index = this.eventsCallbacks.indexOf(callback);
-        this.eventsCallbacks.splice(index, 1)
+        const index = this.eventsCallbacks.indexOf(callback);
+        this.eventsCallbacks.splice(index, 1);
     }
 
-    public notify(eventType:string, eventData?:any) {
-        let eventObj = {
+    public notify(eventType: string, eventData?: any) {
+        const eventObj = {
             type: eventType,
             data: eventData,
             originId: this.clientId
@@ -63,12 +63,12 @@ export class BasePubSub {
         return {
             subscribe: function(callbackFn) {
 
-                if(this.subscribers.size !== 0) {
-                    let subscribersToNotify = Array.from(this.subscribers.keys());
+                if (this.subscribers.size !== 0) {
+                    const subscribersToNotify = Array.from(this.subscribers.keys());
 
                     const checkNotifyComplete = (subscriberId: string) => {
 
-                        let index = subscribersToNotify.indexOf(subscriberId);
+                        const index = subscribersToNotify.indexOf(subscriberId);
                         subscribersToNotify.splice(index, 1);
 
                         if (subscribersToNotify.length === 0) {
@@ -77,31 +77,30 @@ export class BasePubSub {
                     };
 
                     this.subscribers.forEach((subscriber: ISubscriber, subscriberId: string) => {
-                        if (this.eventsToWait.has(subscriberId) && this.eventsToWait.get(subscriberId).indexOf(eventType) !== -1) {
+                        if (this.eventsToWait.has(subscriberId) &&
+                            this.eventsToWait.get(subscriberId).indexOf(eventType) !== -1) {
 
-                            const actionCompletedFunction = (eventData, subId = subscriberId) => {
-                                if (eventData.type == "ACTION_COMPLETED") {
+                            const actionCompletedFunction = (actionCompletedEventData, subId = subscriberId) => {
+                                if (actionCompletedEventData.type === 'ACTION_COMPLETED') {
                                     checkNotifyComplete(subId);
                                 }
                                 this.off(actionCompletedFunction);
 
                             };
                             this.on(actionCompletedFunction);
-                        }
-                        else {
+                        } else {
                             checkNotifyComplete(subscriberId);
                         }
                     });
-                }
-                else {
+                } else {
                     callbackFn();
                 }
             }.bind(this)
-        }
+        };
     }
 
-    public isWaitingForEvent(eventName: string) : boolean {
-        return Array.from(this.eventsToWait.values()).some((eventsList: Array<string>) =>
+    public isWaitingForEvent(eventName: string): boolean {
+        return Array.from(this.eventsToWait.values()).some((eventsList: string[]) =>
             eventsList.indexOf(eventName) !== -1
         );
     }
@@ -110,7 +109,7 @@ export class BasePubSub {
         if (this.subscribers.has(event.data.originId)) {
             this.eventsCallbacks.forEach((callback: Function) => {
                 callback(event.data, event);
-            })
+            });
         }
     }
 }
index 3a34de9..ec4afb2 100644 (file)
@@ -1,16 +1,16 @@
-import {BasePubSub} from "./base-pubsub";
+import { BasePubSub } from './base-pubsub';
 
 declare const window: Window;
 
 export class PluginPubSub extends BasePubSub {
 
-    constructor(pluginId: string, parentUrl: string, eventsToWait?: Array<string>) {
+    constructor(pluginId: string, parentUrl: string, eventsToWait?: string[]) {
         super(pluginId);
         this.register('sdc-hub', window.parent, parentUrl);
         this.subscribe(eventsToWait);
     }
 
-    public subscribe(eventsToWait?: Array<string>) {
+    public subscribe(eventsToWait?: string[]) {
         const registerData = {
             pluginId: this.clientId,
             eventsToWait: eventsToWait || []
index a075e40..455d508 100644 (file)
@@ -8,7 +8,8 @@
   "scripts": {
     "clean": "rimraf dist",
     "build": "tsc && webpack --mode development",
-    "test": "jest"
+    "test": "jest",
+    "lint": "./node_modules/.bin/tslint -t json -o ./coverage/tslint-report.json --project ./tsconfig.json"
   },
   "keywords": [
     "sdc",
@@ -26,6 +27,8 @@
     "jest-sonar-reporter": "^2.0.0",
     "rimraf": "^2.6.2",
     "ts-jest": "^23.0.1",
+    "tslint": "^5.11.0",
+    "tslint-sonarts": "^1.7.0",
     "typescript": "2.7.2",
     "webpack": "4.12.0",
     "webpack-cli": "^3.1.0"
diff --git a/pom.xml b/pom.xml
index b186789..368de37 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -18,6 +18,7 @@
         <sonar.tests>lib</sonar.tests>
         <sonar.test.inclusions>lib/*.spec.ts</sonar.test.inclusions>
         <sonar.typescript.lcov.reportPaths>coverage/lcov.info</sonar.typescript.lcov.reportPaths>
+        <sonar.typescript.tslint.reportPaths>coverage/tslint-report.json</sonar.typescript.tslint.reportPaths>
         <sonar.testExecutionReportPaths>coverage/test-report.xml</sonar.testExecutionReportPaths>
        </properties>
        
                         </configuration>
                     </execution>
 
+                    <execution>
+                        <id>npm tslint</id>
+                        <goals>
+                            <goal>npm</goal>
+                        </goals>
+                        <configuration>
+                            <arguments>run lint</arguments>
+                        </configuration>
+                    </execution>
+
                     <execution>
                         <id>npm run build</id>
                         <goals>
diff --git a/tslint.json b/tslint.json
new file mode 100644 (file)
index 0000000..c08c75a
--- /dev/null
@@ -0,0 +1,133 @@
+{
+  "extends": [
+    "tslint:recommended",
+    "tslint-sonarts"
+  ],
+  "rules": {
+    "cognitive-complexity": false,
+    "trailing-comma": true,
+    "callable-types": true,
+    "class-name": true,
+    "comment-format": [
+      true,
+      "check-space"
+    ],
+    "curly": true,
+    "eofline": true,
+    "forin": true,
+    "import-spacing": true,
+    "indent": [
+      true,
+      "spaces"
+    ],
+    //"interface-over-type-literal": true,
+    //"label-position": true,
+    "max-line-length": [
+      true,
+      120
+    ],
+    "member-access": false,
+    "member-ordering": [
+      true,
+      {
+        "order": "fields-first"
+      }
+    ],
+    "no-arg": true,
+    "no-bitwise": true,
+    "no-console": [
+      true,
+      "debug",
+      "info",
+      "time",
+      "timeEnd",
+      "trace"
+    ],
+    "no-construct": true,
+    "no-debugger": true,
+    "no-empty": true,
+    "no-empty-interface": true,
+    "no-eval": true,
+    "no-inferrable-types": false,
+    "no-shadowed-variable": true,
+    "no-string-literal": true,
+    "no-string-throw": true,
+    "no-switch-case-fall-through": true,
+    "no-trailing-whitespace": true,
+    "no-unused-expression": [
+      true,
+      "allow-fast-null-checks"
+    ],
+    "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"
+    ],
+    "semicolon": [
+      true,
+      "always"
+    ],
+    "triple-equals": [
+      true,
+      "allow-null-check",
+      "allow-undefined-check"
+    ],
+    "typedef-whitespace": [
+      true,
+      {
+        "call-signature": "nospace",
+        "index-signature": "nospace",
+        "parameter": "nospace",
+        "property-declaration": "nospace",
+        "variable-declaration": "nospace"
+      }
+    ],
+    "variable-name": [
+      true,
+      "check-format",
+      "ban-keywords"
+    ],
+    "whitespace": [
+      true,
+      "check-branch",
+      "check-decl",
+      "check-operator",
+      "check-module",
+      "check-separator",
+      "check-type",
+      "check-preblock"
+    ],
+    "ban-types": [
+      true,
+      [
+        "Object",
+        "Avoid using the `Object` type. Did you mean `object`?"
+      ],
+      [
+        "Boolean",
+        "Avoid using the `Boolean` type. Did you mean `boolean`?"
+      ],
+      [
+        "Number",
+        "Avoid using the `Number` type. Did you mean `number`?"
+      ],
+      [
+        "String",
+        "Avoid using the `String` type. Did you mean `string`?"
+      ],
+      [
+        "Symbol",
+        "Avoid using the `Symbol` type. Did you mean `symbol`?"
+      ]
+    ]
+  }
+}
\ No newline at end of file