Skip to content

Commit de7a524

Browse files
committed
init commit
0 parents  commit de7a524

File tree

287 files changed

+32891
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

287 files changed

+32891
-0
lines changed

.eslintrc.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/** @type {import('eslint').Linter.Config} */
2+
module.exports = {
3+
root: true,
4+
extends: [`../.eslintrc.js`],
5+
parserOptions: {
6+
project: `${__dirname}/tsconfig.json`,
7+
sourceType: "module",
8+
},
9+
};

.gitignore

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
lib-cov
2+
*.seed
3+
*.log
4+
*.csv
5+
*.dat
6+
*.out
7+
*.pid
8+
*.gz
9+
*.swp
10+
*.tsbuildinfo
11+
12+
pids
13+
logs
14+
results
15+
tmp
16+
out
17+
18+
# Build
19+
public/css/main.css
20+
21+
# Coverage reports
22+
coverage
23+
24+
# API keys and secrets
25+
.env
26+
27+
# Dependency directory
28+
node_modules
29+
bower_components
30+
31+
# Editors
32+
.idea
33+
*.iml
34+
35+
# OS metadata
36+
.DS_Store
37+
Thumbs.db
38+
39+
# Ignore built ts files
40+
out/**/*

.mocharc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
file: ["./test/setup.ts"],
3+
require: "ts-node/register",
4+
spec: "test/**/*.ts",
5+
timeout: 5000,
6+
exit: true,
7+
};

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
!out/
2+
src/
3+
test/

.nycrc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"extends": "@istanbuljs/nyc-config-typescript",
3+
"check-coverage": true,
4+
"statements": 71,
5+
"branches": 55,
6+
"functions": 66,
7+
"lines": 71,
8+
"all": true,
9+
"include": [
10+
"src/**/*.ts"
11+
],
12+
"reporter": [
13+
"html",
14+
"lcov",
15+
"text",
16+
"text-summary"
17+
],
18+
"report-dir": "coverage"
19+
}

.vscodeignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.vscode
2+
node_modules
3+
out/
4+
src/
5+
tsconfig.json
6+
webpack.config.js

package.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"name": "solsp",
3+
"description": "",
4+
"version": "1.0.0",
5+
"license": "MIT",
6+
"author": "Riphal <bjankovic998@gmail.com>",
7+
"main": "./out/index.js",
8+
"types": "./out/index.d.ts",
9+
"bin": {
10+
"solsp": "./out/index.js"
11+
},
12+
"engines": {
13+
"node": "*"
14+
},
15+
"scripts": {
16+
"build": "tsc -b tsconfig.build.json",
17+
"test": "cross-env TS_NODE_FILES=true mocha",
18+
"test:coverage": "cross-env TS_NODE_FILES=true nyc mocha",
19+
"lint": "yarn prettier --check && yarn eslint",
20+
"lint:fix": "yarn prettier --write && yarn lint --fix",
21+
"eslint": "eslint --max-warnings 0 \"./src/**/*.ts\" \"./test/**/*.ts\"",
22+
"prettier": "prettier \"*.json\" \"src/**/*.{ts,js,md,json,yml}\" \"test/**/*.{ts,js,md,json,yml}\"",
23+
"clean": "rimraf out .nyc_output coverage *.tsbuildinfo",
24+
"test:codecov": "cross-env TS_NODE_FILES=true nyc --reporter=lcov mocha && codecov"
25+
},
26+
"devDependencies": {
27+
"@istanbuljs/nyc-config-typescript": "1.0.2",
28+
"@sentry/types": "6.19.1",
29+
"@types/chai": "4.3.0",
30+
"@types/fs-extra": "^9.0.13",
31+
"@types/js-yaml": "^4.0.5",
32+
"@types/mocha": "9.0.0",
33+
"@types/module-alias": "^2.0.1",
34+
"@types/node": "^14.14.37",
35+
"@types/qs": "^6.9.7",
36+
"@types/sinon": "10.0.6",
37+
"@types/uuid": "^8.3.1",
38+
"chai": "4.3.4",
39+
"codecov": "3.8.3",
40+
"cross-env": "7.0.3",
41+
"eslint": "^7.23.0",
42+
"mocha": "9.1.3",
43+
"nyc": "15.1.0",
44+
"rimraf": "3.0.2",
45+
"sinon": "12.0.1",
46+
"ts-node": "10.4.0",
47+
"typescript": "4.5.4"
48+
},
49+
"dependencies": {
50+
"@nomicfoundation/solidity-analyzer": "0.0.3",
51+
"@sentry/node": "6.19.1",
52+
"@sentry/tracing": "6.19.1",
53+
"@solidity-parser/parser": "^0.14.0",
54+
"@types/prettier": "2.4.3",
55+
"c3-linearization": "0.3.0",
56+
"fast-glob": "3.2.11",
57+
"fs-extra": "^10.0.0",
58+
"got": "^11.8.2",
59+
"hardhat": "^2.6.0",
60+
"js-yaml": "^4.1.0",
61+
"module-alias": "^2.2.2",
62+
"prettier": "2.5.1",
63+
"prettier-plugin-solidity": "1.0.0-beta.24",
64+
"qs": "^6.10.1",
65+
"serialize-error": "8.1.0",
66+
"uuid": "^8.3.2",
67+
"vscode-languageserver": "^7.0.0",
68+
"vscode-languageserver-protocol": "3.16.0",
69+
"vscode-languageserver-textdocument": "^1.0.1",
70+
"vscode-languageserver-types": "^3.16.0"
71+
}
72+
}

src/analytics/GoogleAnalytics.ts

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/* istanbul ignore file: external system */
2+
import * as os from "os";
3+
import got from "got";
4+
import * as qs from "qs";
5+
import { isTelemetryEnabled } from "@utils/serverStateUtils";
6+
import { ServerState } from "../types";
7+
import {
8+
Analytics,
9+
AnalyticsPayload,
10+
DefaultRawAnalyticsPayload,
11+
RawAnalyticsPayload,
12+
} from "./types";
13+
14+
const GOOGLE_ANALYTICS_URL = "https://www.google-analytics.com/collect";
15+
16+
export class GoogleAnalytics implements Analytics {
17+
private readonly googleTrackingId: string;
18+
private serverState: ServerState | null;
19+
private machineId: string | undefined;
20+
private extensionVersion: string | undefined;
21+
22+
constructor(googleTrackingId: string) {
23+
this.googleTrackingId = googleTrackingId;
24+
25+
this.machineId = undefined;
26+
this.extensionVersion = undefined;
27+
this.serverState = null;
28+
}
29+
30+
public init(
31+
machineId: string | undefined,
32+
extensionVersion: string | undefined,
33+
serverState: ServerState
34+
): void {
35+
this.machineId = machineId;
36+
this.extensionVersion = extensionVersion;
37+
this.serverState = serverState;
38+
}
39+
40+
public async sendPageView(
41+
taskName: string,
42+
more?: RawAnalyticsPayload
43+
): Promise<void> {
44+
try {
45+
if (
46+
this.serverState?.env !== "production" ||
47+
!isTelemetryEnabled(this.serverState) ||
48+
this.machineId === undefined
49+
) {
50+
return;
51+
}
52+
53+
const payload = this._buildPayloadFrom(taskName, this.machineId, more);
54+
55+
await this._sendHit(payload);
56+
} catch {
57+
// continue on failed analytics send
58+
return;
59+
}
60+
}
61+
62+
private _buildPayloadFrom(
63+
taskName: string,
64+
machineId: string,
65+
more?: RawAnalyticsPayload
66+
): AnalyticsPayload {
67+
const defaultAnalytics: DefaultRawAnalyticsPayload = {
68+
// Measurement protocol version.
69+
v: "1",
70+
71+
// Tracking Id.
72+
tid: this.googleTrackingId,
73+
74+
// User agent, must be present.
75+
// We use it to inform Node version used and OS.
76+
// Example:
77+
// Node/v8.12.0 (Darwin 17.7.0)
78+
ua: this._getUserAgent(),
79+
80+
// Client Id.
81+
cid: machineId,
82+
83+
// Hit type, we're only using timing for now.
84+
t: "pageview",
85+
86+
// Document page
87+
dp: `/${taskName}`,
88+
89+
// Custom dimension 1: extension version
90+
// Example: 'v1.0.0'.
91+
cd1: `v${this.extensionVersion}`,
92+
};
93+
94+
return { ...defaultAnalytics, ...(more || {}) };
95+
}
96+
97+
private _sendHit(hit: AnalyticsPayload) {
98+
const hitPayload = qs.stringify(hit);
99+
100+
return got.post(GOOGLE_ANALYTICS_URL, {
101+
headers: {
102+
Accept: "*/*",
103+
"Accept-Language": "en-US,en;q=0.5",
104+
"Content-Type": "text/plain;charset=UTF-8",
105+
},
106+
body: hitPayload,
107+
});
108+
}
109+
110+
private _getUserAgent(): string {
111+
return `Node/${process.version} ${this._getOperatingSystem()}`;
112+
}
113+
114+
/**
115+
* At the moment, we couldn't find a reliably way to report the OS () in Node,
116+
* as the versions reported by the various `os` APIs (`os.platform()`, `os.type()`, etc)
117+
* return values different to those expected by Google Analytics
118+
* We decided to take the compromise of just reporting the OS Platform (OSX/Linux/Windows) for now (version information is bogus for now).
119+
*/
120+
private _getOperatingSystem(): string {
121+
switch (os.type()) {
122+
case "Windows_NT":
123+
return "(Windows NT 6.1; Win64; x64)";
124+
case "Darwin":
125+
return "(Macintosh; Intel Mac OS X 10_13_6)";
126+
case "Linux":
127+
return "(X11; Linux x86_64)";
128+
default:
129+
return "(Unknown)";
130+
}
131+
}
132+
}

src/analytics/types.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { ServerState } from "../types";
2+
3+
export interface AnalyticsData {
4+
clientId: string;
5+
isAllowed?: boolean;
6+
}
7+
8+
// VERY IMPORTANT:
9+
// The documentation doesn't say so, but the user-agent parameter is required (ua).
10+
// If you don't send it, you won't get an error or anything, Google will *silently* drop your hit.
11+
//
12+
// https://stackoverflow.com/questions/27357954/google-analytics-measurement-protocol-not-working
13+
export interface DefaultRawAnalyticsPayload {
14+
v: "1";
15+
tid: string;
16+
ua: string;
17+
cid: string;
18+
t: string;
19+
dp: string;
20+
cd1: string;
21+
}
22+
23+
export interface RawAnalyticsPayload {
24+
// Specifies the time it took for a page to load. The value is in milliseconds.
25+
plt?: number;
26+
}
27+
28+
export interface AnalyticsPayload
29+
extends DefaultRawAnalyticsPayload,
30+
RawAnalyticsPayload {}
31+
32+
export interface Analytics {
33+
init(
34+
trackingId: string | undefined,
35+
extensionVersion: string | undefined,
36+
serverState: ServerState
37+
): void;
38+
39+
sendPageView(taskName: string, more?: RawAnalyticsPayload): Promise<void>;
40+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { AddLicenseIdentifier } from "./diagnostics/AddLicenseIdentifier";
2+
import { AddMultiOverrideSpecifier } from "./diagnostics/AddMultiOverrideSpecifier";
3+
import { AddOverrideSpecifier } from "./diagnostics/AddOverrideSpecifier";
4+
import { AddVirtualSpecifier } from "./diagnostics/AddVirtualSpecifier";
5+
import { ConstrainMutability } from "./diagnostics/ConstrainMutability";
6+
import { ContractCodeSize } from "./diagnostics/ContractCodeSize";
7+
import { MarkContractAbstract } from "./diagnostics/MarkContractAbstract";
8+
import { SpecifyVisibility } from "./diagnostics/SpecifyVisibility";
9+
import { SpecifyCompilerVersion } from "./diagnostics/SpecifyCompilerVersion";
10+
import { CompilerDiagnostic } from "./types";
11+
12+
export const compilerDiagnostics: { [key: string]: CompilerDiagnostic } = [
13+
new AddOverrideSpecifier(),
14+
new AddLicenseIdentifier(),
15+
new AddMultiOverrideSpecifier(),
16+
new AddVirtualSpecifier(),
17+
new ConstrainMutability(),
18+
new ContractCodeSize(),
19+
new MarkContractAbstract(),
20+
new SpecifyVisibility(),
21+
new SpecifyCompilerVersion(),
22+
].reduce((acc, item) => ({ ...acc, [item.code]: item }), {});

0 commit comments

Comments
 (0)