Skip to content

Commit aa15ba1

Browse files
authored
Merge pull request #137 from Crypto-Punkers/ritave/lint
Added linting
2 parents 0cba639 + a0efd4f commit aa15ba1

20 files changed

+263
-91
lines changed

Diff for: .circleci/config.yml

+48-25
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,50 @@
11
version: 2
22
jobs:
3-
build:
4-
docker:
5-
- image: circleci/node:10.15
6-
steps:
7-
- checkout
8-
- restore_cache:
9-
name: Restore yarn cache
10-
key: node-modules-{{ .Branch }}-{{ checksum "yarn.lock" }}
11-
- run:
12-
name: Install modules
13-
command: yarn --frozen-lockfile install
14-
- save_cache:
15-
name: Save yarn cache
16-
key: node-modules-{{ .Branch }}-{{ checksum "yarn.lock" }}
17-
paths:
18-
- node_modules
19-
- run:
20-
name: Build
21-
command: yarn build
22-
- run:
23-
name: Tests
24-
command: yarn test
25-
- run: # TODO(ritave): Move into seperate workspace that lints everything
26-
name: Prettier
27-
command: yarn prettier
3+
test:
4+
docker:
5+
- image: circleci/node:10.15
6+
steps:
7+
- checkout
8+
- restore_cache:
9+
name: Restore yarn cache
10+
key: node-modules-{{ .Branch }}-{{ checksum "yarn.lock" }}
11+
- run:
12+
name: Install modules
13+
command: yarn --frozen-lockfile install
14+
- save_cache:
15+
name: Save yarn cache
16+
key: node-modules-{{ .Branch }}-{{ checksum "yarn.lock" }}
17+
paths:
18+
- node_modules
19+
- run:
20+
name: Build
21+
command: yarn build
22+
- run:
23+
name: Tests
24+
command: yarn test
25+
lint:
26+
docker:
27+
- image: circleci/node:10.15
28+
steps:
29+
- checkout
30+
- restore_cache:
31+
name: Restore yarn cache
32+
key: node-modules-{{ .Branch }}-{{ checksum "yarn.lock" }}
33+
- run:
34+
name: Install modules
35+
command: yarn --frozen-lockfile install
36+
- save_cache:
37+
name: Save yarn cache
38+
key: node-modules-{{ .Branch }}-{{ checksum "yarn.lock" }}
39+
paths:
40+
- node_modules
41+
- run:
42+
name: Lint
43+
command: yarn lint
44+
45+
workflows:
46+
version: 2
47+
main:
48+
jobs:
49+
- test
50+
- lint

Diff for: README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ resolver
4141
```typescript
4242
import { parsers, resolvers, ResolverEngine } from "@resolver-engine/core";
4343

44-
const resolver = new ResolverEngine<string>()
45-
.addResolver(resolvers.UriResolver())
46-
.addParser(parsers.UrlParser());
44+
const resolver = new ResolverEngine<string>().addResolver(resolvers.UriResolver()).addParser(parsers.UrlParser());
4745

4846
resolver.resolve("https://pastebin.com/raw/D8ziKX0a").then(console.log);
4947
```

Diff for: integration-tests/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66
"author": "Crypto Punkers <[email protected]>",
77
"license": "LGPL-3.0-or-later",
88
"scripts": {
9-
"test": "jest"
9+
"test": "jest",
10+
"lint": "tslint -c ./tslint.json -p ./"
1011
},
1112
"devDependencies": {
1213
"@types/debug": "^4.1.1",
14+
"@types/jest": "^24.0.6",
1315
"@types/nock": "^9.3.1",
1416
"@types/node": "^11.9.4",
15-
"@types/jest": "^24.0.6",
1617
"jest": "<25.0.0",
17-
"ts-jest": "^24.0.0",
1818
"memfs": "^2.15.0",
1919
"nock": "^10.0.6",
2020
"rimraf": "^2.6.2",
21+
"ts-jest": "^24.0.0",
2122
"typescript": "^3.2.4"
2223
},
2324
"dependencies": {

Diff for: integration-tests/src/__tests__/determineProvider.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import mockedFS from "../__mocks__/MockedFs";
77
type input_t = [string, string | undefined];
88
type output_t = [string, string];
99

10-
const data: [input_t, output_t][] = [
10+
const data: Array<[input_t, output_t]> = [
1111
[
1212
["https://github.com/Crypto-Punkers/resolver-engine/examples/github.ts", undefined],
1313
["https://raw.githubusercontent.com/Crypto-Punkers/resolver-engine/master/examples/github.ts", "github"],

Diff for: integration-tests/src/__tests__/findImports.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { findImports, ImportFile } from "@resolver-engine/imports";
22

33
describe("findImports", function() {
4-
let providedFile: ImportFile = { url: "", source: "", provider: "" };
4+
const providedFile: ImportFile = { url: "", source: "", provider: "" };
55

66
describe("Double quotes", function() {
77
it('finds statements like: import "file";', function() {

Diff for: integration-tests/src/__tests__/gatherSources.spec.ts

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
jest.mock("fs");
2-
import nock from "nock";
3-
import { vol } from "memfs";
4-
import { ImportsFsEngine } from "@resolver-engine/imports-fs";
52
import { gatherSources, ImportFile } from "@resolver-engine/imports";
3+
import { ImportsFsEngine } from "@resolver-engine/imports-fs";
4+
import { vol } from "memfs";
5+
import nock from "nock";
66

7-
type dictionary = { [s: string]: string };
7+
interface Dictionary {
8+
[s: string]: string;
9+
}
810

9-
function expectedOutput(filesObj: dictionary, provider: string, namePrefix: string): ImportFile[] {
10-
let result: ImportFile[] = [];
11+
function expectedOutput(filesObj: Dictionary, provider: string, namePrefix: string): ImportFile[] {
12+
const result: ImportFile[] = [];
1113
let prefix = namePrefix;
1214
if (namePrefix !== "") {
1315
prefix += "/";
@@ -16,13 +18,13 @@ function expectedOutput(filesObj: dictionary, provider: string, namePrefix: stri
1618
result.push({
1719
url: prefix + k,
1820
source: filesObj[k],
19-
provider: provider,
21+
provider,
2022
});
2123
}
2224
return result;
2325
}
2426

25-
const data: [string, dictionary, string[], string, string][] = [
27+
const data: Array<[string, Dictionary, string[], string, string]> = [
2628
[
2729
"gathers files included by given file",
2830
{
@@ -130,22 +132,22 @@ describe("gatherSources function", function() {
130132
vol.reset();
131133
});
132134

133-
it.each(data)("%s", async function(message, test_fs, input, cwd, provider) {
134-
const EXPECTED_FILES = expectedOutput(test_fs, provider, cwd);
135+
it.each(data)("%s", async function(message, testFs, input, cwd, provider) {
136+
const EXPECTED_FILES = expectedOutput(testFs, provider, cwd);
135137

136-
vol.fromJSON(test_fs);
138+
vol.fromJSON(testFs);
137139
const fileList = await gatherSources(input, cwd, resolver);
138140
expect(fileList.sort((a, b) => a.url.localeCompare(b.url))).toEqual(
139141
EXPECTED_FILES.sort((a, b) => a.url.localeCompare(b.url)),
140142
);
141143
});
142144

143145
it("throws when imported file doesn't exist", async function() {
144-
const test_fs: dictionary = {
146+
const testFs: Dictionary = {
145147
"main.sol": 'import "./otherfile.sol";\nrestoffileblahblah',
146148
};
147149

148-
vol.fromJSON(test_fs);
150+
vol.fromJSON(testFs);
149151
await expect(gatherSources(["main.sol"], __dirname, resolver)).rejects.toThrowError();
150152
});
151153

Diff for: integration-tests/tslint.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": ["../tslint.json"],
3+
"rules": { "only-arrow-functions": false }
4+
}

Diff for: package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"repository": "[email protected]:Crypto-Punkers/resolver-engine.git",
88
"author": "Crypto Punkers <[email protected]>",
99
"scripts": {
10-
"prepare": "run-s clean build",
1110
"build": "tsc -b tsproject.json",
1211
"build:core": "wsrun -p core --stages build",
1312
"build:fs": "wsrun -p fs --stages build",
@@ -17,7 +16,8 @@
1716
"clean": "wsrun --exclude-missing clean",
1817
"prettier": "prettier --config .prettierrc.yaml --write --list-different './**/*.{ts,tsx,json,md}'",
1918
"test": "run-s build test:execute",
20-
"test:execute": "wsrun --parallel --collect-logs test"
19+
"test:execute": "wsrun --parallel --collect-logs test",
20+
"lint": "wsrun --parallel --collect-logs lint"
2121
},
2222
"devDependencies": {
2323
"@types/debug": "^4.1.1",
@@ -32,6 +32,9 @@
3232
"prettier": "1.16.4",
3333
"rimraf": "^2.6.2",
3434
"ts-jest": "^24.0.0",
35+
"tslint": "^5.15.0",
36+
"tslint-config-prettier": "^1.18.0",
37+
"tslint-plugin-prettier": "^2.0.1",
3538
"typescript": "^3.2.4",
3639
"wsrun": "^3.6.2"
3740
},

Diff for: packages/core/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"build": "tsc",
1111
"tsc": "tsc",
1212
"clean": "rimraf build/",
13-
"test": "jest"
13+
"test": "jest",
14+
"lint": "tslint -c ../../tslint.json -p ./"
1415
},
1516
"dependencies": {
1617
"debug": "^3.1.0",

Diff for: packages/core/src/parsers/urlparser.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export function UrlParser(): SubParser<string> {
88
return (url: string): Promise<string | null> =>
99
new Promise((resolve, reject) => {
1010
try {
11+
// We're using this line for the side-effects
12+
// tslint:disable-next-line:no-unused-expression
1113
new URL(url);
1214
} catch (err) {
1315
// Not an actual browser url, might be filesystem

Diff for: packages/core/src/resolverengine.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface Options {
1414

1515
export class ResolverEngine<R> {
1616
private resolvers: SubResolver[] = [];
17-
private parsers: SubParser<R>[] = [];
17+
private parsers: Array<SubParser<R>> = [];
1818

1919
constructor(options?: Options) {
2020
const opts: Options = { ...options };
@@ -51,7 +51,7 @@ export class ResolverEngine<R> {
5151
cwd: workingDir,
5252
};
5353

54-
const url = await firstResult(this.resolvers, resolver => resolver(uri, ctx));
54+
const url = await firstResult(this.resolvers, currentResolver => currentResolver(uri, ctx));
5555

5656
if (url === null) {
5757
throw resolverError(uri);

Diff for: packages/fs/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"build": "tsc",
1111
"tsc": "tsc",
1212
"clean": "rimraf build/",
13-
"test": "jest"
13+
"test": "jest",
14+
"lint": "tslint -c ../../tslint.json -p ./"
1415
},
1516
"dependencies": {
1617
"@resolver-engine/core": "0.3.0",

Diff for: packages/fs/src/resolvers/fsresolver.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Context, SubResolver } from "@resolver-engine/core";
2-
import * as fs from "fs";
3-
import * as path from "path";
2+
import * as fsSys from "fs";
3+
import * as pathSys from "path";
44

5-
const statAsync = (path: string): Promise<fs.Stats> =>
6-
new Promise<fs.Stats>((resolve, reject) => {
7-
fs.stat(path, (err, stats) => {
5+
const statAsync = (path: string): Promise<fsSys.Stats> =>
6+
new Promise<fsSys.Stats>((resolve, reject) => {
7+
fsSys.stat(path, (err, stats) => {
88
if (err) {
99
reject(err);
1010
}
@@ -19,8 +19,8 @@ export function FsResolver(): SubResolver {
1919
const cwd = ctx.cwd || process.cwd();
2020

2121
let myPath: string;
22-
if (!path.isAbsolute(resolvePath)) {
23-
myPath = path.join(cwd, resolvePath);
22+
if (!pathSys.isAbsolute(resolvePath)) {
23+
myPath = pathSys.join(cwd, resolvePath);
2424
} else {
2525
myPath = resolvePath;
2626
}

Diff for: packages/imports-fs/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"build": "tsc",
1111
"tsc": "tsc",
1212
"clean": "rimraf build/",
13-
"test": "jest"
13+
"test": "jest",
14+
"lint": "tslint -c ../../tslint.json -p ./"
1415
},
1516
"dependencies": {
1617
"@resolver-engine/fs": "0.3.0",

Diff for: packages/imports/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"build": "tsc",
1111
"tsc": "tsc",
1212
"clean": "rimraf build/",
13-
"test": "jest"
13+
"test": "jest",
14+
"lint": "tslint -c ../../tslint.json -p ./"
1415
},
1516
"dependencies": {
1617
"@resolver-engine/core": "0.3.0",

Diff for: packages/imports/src/importsengine.ts

+6-11
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,10 @@ import { IPFSResolver } from "./resolvers/ipfsresolver";
55
import { SwarmResolver } from "./resolvers/swarmresolver";
66

77
export function ImportsEngine(): ResolverEngine<ImportFile> {
8-
return (
9-
new ResolverEngine<ImportFile>()
10-
//.addResolver(FsResolver())
11-
//.addResolver(EthPmResolver())
12-
//.addResolver(NodeResolver())
13-
.addResolver(GithubResolver())
14-
.addResolver(SwarmResolver())
15-
.addResolver(IPFSResolver())
16-
.addResolver(resolvers.UriResolver())
17-
.addParser(ImportParser([parsers.UrlParser()]))
18-
);
8+
return new ResolverEngine<ImportFile>()
9+
.addResolver(GithubResolver())
10+
.addResolver(SwarmResolver())
11+
.addResolver(IPFSResolver())
12+
.addResolver(resolvers.UriResolver())
13+
.addParser(ImportParser([parsers.UrlParser()]));
1914
}

Diff for: packages/imports/src/parsers/importparser.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ export interface ImportFile {
77
url: string;
88
source: string;
99
provider: string;
10-
//internalImportURis: string[];
1110
}
1211

13-
export function ImportParser(sourceParsers: SubParser<string>[]): SubParser<ImportFile> {
12+
export function ImportParser(sourceParsers: Array<SubParser<string>>): SubParser<ImportFile> {
1413
return async (url: string, ctx: Context): Promise<ImportFile | null> => {
1514
const source = await firstResult(sourceParsers, parser => parser(url, ctx));
1615
if (!source) {

0 commit comments

Comments
 (0)