Skip to content

Commit

Permalink
adding tslint-microsoft-contrib
Browse files Browse the repository at this point in the history
  • Loading branch information
swaathee committed Jun 29, 2020
1 parent 3d8f2c9 commit 15925eb
Show file tree
Hide file tree
Showing 67 changed files with 291 additions and 222 deletions.
3 changes: 2 additions & 1 deletion packages/clarity-decode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"url": "https://github.com/Microsoft/clarity/issues"
},
"dependencies": {
"clarity-js": "^0.5.9"
"clarity-js": "^0.5.9",
"tslint-microsoft-contrib": "^6.2.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^11.1.0",
Expand Down
30 changes: 15 additions & 15 deletions packages/clarity-decode/src/clarity.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Data, version } from "clarity-js";
import { DecodedPayload, DecodedVersion } from "../types/data";
import { MetricEvent, PageEvent, PingEvent, SummaryEvent, TagEvent, TargetEvent, UpgradeEvent, UploadEvent } from "../types/data";
import { ImageErrorEvent, InternalErrorEvent, ScriptErrorEvent } from "../types/diagnostic";
import { ClickEvent, InputEvent, PointerEvent, ResizeEvent, ScrollEvent } from "../types/interaction";
import { SelectionEvent, UnloadEvent, VisibilityEvent } from "../types/interaction";
import { BoxModelEvent, DocumentEvent, DomEvent, HashEvent, ResourceEvent } from "../types/layout";
import { ConnectionEvent, LargestContentfulPaintEvent, LongTaskEvent, MemoryEvent } from "../types/performance";
import { NavigationEvent, NetworkEvent, PaintEvent } from "../types/performance";
import { DecodedPayload, DecodedVersion } from "@clarity-types/data";
import { MetricEvent, PageEvent, PingEvent, SummaryEvent, TagEvent, TargetEvent, UpgradeEvent, UploadEvent } from "@clarity-types/data";
import { ImageErrorEvent, InternalErrorEvent, ScriptErrorEvent } from "@clarity-types/diagnostic";
import { ClickEvent, InputEvent, PointerEvent, ResizeEvent, ScrollEvent } from "@clarity-types/interaction";
import { SelectionEvent, UnloadEvent, VisibilityEvent } from "@clarity-types/interaction";
import { BoxModelEvent, DocumentEvent, DomEvent, HashEvent, ResourceEvent } from "@clarity-types/layout";
import { ConnectionEvent, LargestContentfulPaintEvent, LongTaskEvent, MemoryEvent } from "@clarity-types/performance";
import { NavigationEvent, NetworkEvent, PaintEvent } from "@clarity-types/performance";

import * as data from "./data";
import * as diagnostic from "./diagnostic";
import * as interaction from "./interaction";
import * as layout from "./layout";
import * as performance from "./performance";
import * as data from "@src/data";
import * as diagnostic from "@src/diagnostic";
import * as interaction from "@src/interaction";
import * as layout from "@src/layout";
import * as performance from "@src/performance";

export function decode(input: string): DecodedPayload {
let json: Data.Payload = JSON.parse(input);
Expand All @@ -34,7 +34,7 @@ export function decode(input: string): DecodedPayload {
throw new Error(`Invalid version. Actual: ${payload.envelope.version} | Expected: ${version} (+/- 1) | ${input.substr(0, 250)}`);
}

/* Reset components before decoding to keep them stateless */
// Reset components before decoding to keep them stateless
data.reset();
layout.reset();

Expand Down Expand Up @@ -175,7 +175,7 @@ export function decode(input: string): DecodedPayload {
}
}

/* Enrich decoded payload with derived events */
// Enrich decoded payload with derived events
payload.summary = data.summary() as SummaryEvent[];
if (payload.dom && payload.dom.length > 0) { payload.hash = layout.hash() as HashEvent[]; }
if (layout.resources.length > 0) { payload.resource = layout.resource() as ResourceEvent[]; }
Expand Down
2 changes: 1 addition & 1 deletion packages/clarity-decode/src/data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Data } from "clarity-js";
import { DataEvent } from "../types/data";
import { DataEvent } from "@clarity-types/data";

let summaries: { [key: number]: Data.SummaryData[] } = null;
const SUMMARY_THRESHOLD = 30;
Expand Down
2 changes: 1 addition & 1 deletion packages/clarity-decode/src/diagnostic.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Data, Diagnostic } from "clarity-js";
import { DiagnosticEvent } from "../types/diagnostic";
import { DiagnosticEvent } from "@clarity-types/diagnostic";

export function decode(tokens: Data.Token[]): DiagnosticEvent {
let time = tokens[0] as number;
Expand Down
1 change: 1 addition & 0 deletions packages/clarity-decode/src/global.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as decode from "@src/clarity";

// Expose clarity variable globally to allow access to public interface in a browser
// tslint:disable-next-line:no-typeof-undefined
if (typeof window !== "undefined") {
if ((window as any).clarity === undefined || (window as any).clarity === null) {
(window as any).clarity = {};
Expand Down
2 changes: 1 addition & 1 deletion packages/clarity-decode/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { decode } from "./clarity";
export { decode } from "@src/clarity";
4 changes: 2 additions & 2 deletions packages/clarity-decode/src/interaction.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Data, Interaction } from "clarity-js";
import { InteractionEvent } from "../types/interaction";
import { InteractionEvent } from "@clarity-types/interaction";

export function decode(tokens: Data.Token[]): InteractionEvent {
export function decode(tokens: Data.Token[]): InteractionEvent {
let time = tokens[0] as number;
let event = tokens[1] as Data.Event;
switch (event) {
Expand Down
10 changes: 5 additions & 5 deletions packages/clarity-decode/src/layout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { helper, Data, Layout } from "clarity-js";
import { DomData, LayoutEvent } from "../types/layout";
import { DomData, LayoutEvent } from "@clarity-types/layout";

let placeholderImage = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGNiOAMAANUAz5n+TlUAAAAASUVORK5CYII=";
export let hashes: { [key: number]: Layout.HashData } = {};
Expand Down Expand Up @@ -39,7 +39,7 @@ export function decode(tokens: Data.Token[]): LayoutEvent {
let domData: DomData[] = [];
for (let i = 2; i < tokens.length; i++) {
let token = tokens[i];
let type = typeof(token);
let type = typeof (token);
switch (type) {
case "number":
if (type !== lastType && lastType !== null) {
Expand All @@ -55,7 +55,7 @@ export function decode(tokens: Data.Token[]): LayoutEvent {
break;
case "object":
let subtoken = token[0];
let subtype = typeof(subtoken);
let subtype = typeof (subtoken);
switch (subtype) {
case "number":
for (let t of (token as number[])) {
Expand Down Expand Up @@ -85,7 +85,7 @@ export function resource(): LayoutEvent[] {
}

function process(node: any[] | number[], tagIndex: number): DomData {
let [tag, position]: string[] = node[tagIndex] ? node[tagIndex].split("~") : [node[tagIndex]];
let [tag, position]: string[] = node[tagIndex] ? node[tagIndex].split("~") : [node[tagIndex]];
let output: DomData = {
id: node[0],
parent: tagIndex > 1 ? node[1] : null,
Expand Down Expand Up @@ -137,7 +137,7 @@ function getResource(tag: string, attributes: Layout.Attributes): void {
switch (tag) {
case "LINK":
if ("href" in attributes && "rel" in attributes && attributes["rel"] === "stylesheet") {
resources.push({ tag, url: attributes["href"]});
resources.push({ tag, url: attributes["href"] });
}
break;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/clarity-decode/src/performance.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Data, Performance } from "clarity-js";
import { PerformanceEvent } from "../types/performance";
import { PerformanceEvent } from "@clarity-types/performance";

export function decode(tokens: Data.Token[]): PerformanceEvent {
export function decode(tokens: Data.Token[]): PerformanceEvent {
let time = tokens[0] as number;
let event = tokens[1] as Data.Event;
switch (event) {
Expand Down Expand Up @@ -64,7 +64,7 @@ export function decode(tokens: Data.Token[]): PerformanceEvent {
let networkData: Performance.NetworkData[] = [];
for (let i = 2; i < tokens.length; i++) {
let token = tokens[i];
let type = typeof(token);
let type = typeof (token);
switch (type) {
case "number":
if (type !== lastType && lastType !== null) {
Expand All @@ -89,7 +89,7 @@ export function decode(tokens: Data.Token[]): PerformanceEvent {
network.push(token);
} else {
let subtoken = token[0];
let subtype = typeof(subtoken);
let subtype = typeof (subtoken);
switch (subtype) {
case "number":
for (let t of (token as number[])) {
Expand Down
27 changes: 21 additions & 6 deletions packages/clarity-decode/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"compilerOptions": {
"module": "esnext",
"target": "es5",
"lib": ["es6", "dom", "es2016", "es2017"],
"lib": [
"es6",
"dom",
"es2016",
"es2017"
],
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
Expand All @@ -11,10 +16,20 @@
"esModuleInterop": true,
"baseUrl": ".",
"paths": {
"@src/*": ["src/*"],
"@clarity-types/*": ["types/*"]
"@src/*": [
"src/*"
],
"@clarity-types/*": [
"types/*"
]
}
},
"include":["src/**/*.ts","types/**/*.d.ts"],
"exclude": ["node_modules", "build"]
}
"include": [
"src/**/*.ts",
"types/**/*.d.ts"
],
"exclude": [
"node_modules",
"build"
]
}
12 changes: 11 additions & 1 deletion packages/clarity-decode/tslint.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"extends": "tslint:recommended",
"extends": [
"tslint-microsoft-contrib/recommended",
"tslint:recommended"
],
"rules": {
"max-line-length": [
true,
Expand All @@ -20,6 +23,13 @@
"interface-name": false,
"interface-over-type-literal": false,
"only-arrow-functions": false,
"prefer-type-cast": false,
"export-name": false,
"max-func-body-length": [
true,
200
],
"no-for-in": false,
"typedef": [
true,
"call-signature",
Expand Down
3 changes: 2 additions & 1 deletion packages/clarity-devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"dependencies": {
"clarity-decode": "^0.5.9",
"clarity-js": "^0.5.9",
"clarity-visualize": "^0.5.9"
"clarity-visualize": "^0.5.9",
"tslint-microsoft-contrib": "^6.2.0"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^7.1.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/clarity-devtools/src/content.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { regions } from "@src/regions";
import { clarity, Layout } from "clarity-js";
import { regions } from "./regions";

chrome.runtime.onMessage.addListener(function(message: any): void {
if (message.action === "activate") {
Expand Down
5 changes: 2 additions & 3 deletions packages/clarity-devtools/src/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ chrome.devtools.panels.elements.createSidebarPane("Clarity", function(sidebar: a
function updateClarityInfo(): void {
let code = "(" + inspect.toString() + ")()";
let inspectedWindow = chrome.devtools.inspectedWindow as any;
inspectedWindow.eval(code, {useContentScriptContext: true}, function(result: any): void {
inspectedWindow.eval(code, { useContentScriptContext: true }, function(result: any): void {
sidebar.setObject(result);
});
}
Expand All @@ -26,6 +26,5 @@ function inspect(): any {
let id = hookEnabled && value ? value.id : null;
let history = hookEnabled && id ? window[DEVTOOLS_HOOK].history(id) : null;
let parent = hookEnabled && value ? window[DEVTOOLS_HOOK].getNode(value.parent) : null;
let output = { id, tag, node: $0, parent, value, history };
return output;
return { id, tag, node: $0, parent, value, history };
}
6 changes: 3 additions & 3 deletions packages/clarity-devtools/src/panel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as data from "@src/data";
import { Data, decode } from "clarity-decode";
import { visualize } from "clarity-visualize";
import * as data from "./data";

let activeTabId = chrome.devtools.inspectedWindow.tabId;
let background = chrome.runtime.connect({ name: "panel" });
Expand All @@ -11,8 +11,8 @@ let dJson: Data.DecodedPayload[] = [];

function save(encoded: boolean = true): void {
let json = encoded ? JSON.stringify(eJson) : JSON.stringify(dJson, null, 2);
let blob = new Blob([json], {type: "application/json"});
let url = URL.createObjectURL(blob);
let blob = new Blob([json], { type: "application/json" });
let url = URL.createObjectURL(blob);

let a = document.createElement("a");
let suffix = encoded ? "encoded" : "decoded";
Expand Down
4 changes: 2 additions & 2 deletions packages/clarity-devtools/src/regions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Following regions are for demonstration purposes only
export const regions = {
/* Bing */
// Bing
Body: "body",
Answers: ".b_ans",
SearchBox: ".b_searchboxForm",
Expand All @@ -9,7 +9,7 @@ export const regions = {
WebResults: ".b_algo",
DisambiguationAnswer: ".disambig-outline",
Footer: "#b_footer",
/* Wordpress */
// Wordpress
Header: "header",
SlickStream: ".slick-film-strip",
PostPhoto: ".size-full",
Expand Down
8 changes: 7 additions & 1 deletion packages/clarity-devtools/tslint.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"extends": "tslint:recommended",
"extends": [
"tslint-microsoft-contrib/recommended",
"tslint:recommended"
],
"rules": {
"max-line-length": [
true,
Expand All @@ -20,6 +23,9 @@
"interface-name": false,
"interface-over-type-literal": false,
"only-arrow-functions": false,
"no-function-expression": false,
"prefer-type-cast": false,
"export-name": false,
"typedef": [
true,
"call-signature",
Expand Down
5 changes: 3 additions & 2 deletions packages/clarity-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"rollup-plugin-typescript2": "^0.27.0",
"ts-node": "8.8.2",
"tslint": "6.1.1",
"typescript": "^3.8.3"
"typescript": "^3.8.3",
"tslint-microsoft-contrib": "^6.2.0"
},
"scripts": {
"build": "yarn build:clean && yarn build:main",
Expand All @@ -55,4 +56,4 @@
"tslint --format codeFrame"
]
}
}
}
2 changes: 1 addition & 1 deletion packages/clarity-js/src/clarity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function config(override: Config): boolean {
// Process custom configuration overrides, if available
if (active) { return false; }
for (let key in override) {
if (key in configuration) { configuration[key] = override[key]; }
if (key in config) { configuration[key] = override[key]; }
}
return true;
}
Expand Down
16 changes: 8 additions & 8 deletions packages/clarity-js/src/core/event.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { BrowserEvent } from "@clarity-types/core";
import measure from "./measure";
import measure from "@src/core/measure";

let bindings: BrowserEvent[] = [];

export function bind(target: EventTarget, event: string, listener: EventListener, capture: boolean = false): void {
listener = measure(listener) as EventListener;
// Wrapping following lines inside try / catch to cover edge cases where we might try to access an inaccessible element.
// E.g. Iframe may start off as same-origin but later turn into cross-origin, and the following lines will throw an exception.
try {
target.addEventListener(event, listener, capture);
bindings.push({ event, target, listener, capture });
} catch { /* do nothing */ }
listener = measure(listener) as EventListener;
// Wrapping following lines inside try / catch to cover edge cases where we might try to access an inaccessible element.
// E.g. Iframe may start off as same-origin but later turn into cross-origin, and the following lines will throw an exception.
try {
target.addEventListener(event, listener, capture);
bindings.push({ event, target, listener, capture });
} catch { /* do nothing */ }
}

export function reset(): void {
Expand Down
4 changes: 2 additions & 2 deletions packages/clarity-js/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ export function end(): void {

export function check(): boolean {
try {
return typeof Promise !== "undefined" &&
return window["Promise"] &&
window["MutationObserver"] &&
document["createTreeWalker"] &&
"now" in Date &&
"now" in performance &&
typeof WeakMap !== "undefined";
!!window["WeakMap"];
} catch (ex) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/clarity-js/src/core/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export async function schedule(task: TaskFunction, priority: Priority = Priority

let promise = new Promise<void>((resolve: TaskResolve): void => {
let insert = priority === Priority.High ? "unshift" : "push";
queuedTasks[insert]({task, resolve});
queuedTasks[insert]({ task, resolve });
});

// If there is no active task running, and Clarity is not in pause state,
Expand Down
Loading

0 comments on commit 15925eb

Please sign in to comment.