Skip to content

Commit

Permalink
See #58. Fix code format issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavin001 committed Mar 27, 2018
1 parent 68c8818 commit f04258f
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 92 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
"jest.rootPath": ".",
"jest.pathToConfig": "jest.config.js",
"jest.showCoverageOnLoad": true,
"prettier.semi": true,
"prettier.singleQuote": false,
"prettier.trailingComma": "all"
}
4 changes: 2 additions & 2 deletions src/DependencyManager/Dependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export abstract class Dependency {
.then(isInstalled => {
if (this.required && !isInstalled) {
throw new Error(
`Dependency "${this.name}" is required and not installed.`
`Dependency "${this.name}" is required and not installed.`,
);
}
return isInstalled;
Expand Down Expand Up @@ -82,7 +82,7 @@ export interface BaseDependencyOptions {

export enum DependencyType {
Node = "node",
Executable = "exec"
Executable = "exec",
}

export interface NodeDependencyOptions extends BaseDependencyOptions {
Expand Down
8 changes: 2 additions & 6 deletions src/DependencyManager/DependencyFactory.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
Dependency,
DependencyType,
DependencyOptions
} from "./Dependency";
import { Dependency, DependencyType, DependencyOptions } from "./Dependency";
import { NodeDependency } from "./NodeDependency";
import { ExecutableDependency } from "./ExecutableDependency";

Expand All @@ -18,7 +14,7 @@ export class DependencyFactory {
return new ExecutableDependency(options);
default:
throw new Error(
`Dependency type not found for: ${JSON.stringify(options)}`
`Dependency type not found for: ${JSON.stringify(options)}`,
);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/DependencyManager/DependencyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ export class DependencyManager {

constructor(dependencies: DependencyOptions[]) {
this.dependencies = dependencies.map(dependency =>
new DependencyFactory(dependency).dependency()
new DependencyFactory(dependency).dependency(),
);
this.lookup = this.dependencies.reduce(
(lookup, dep) => ({
...lookup,
[dep.name]: dep
[dep.name]: dep,
}),
{}
{},
);
}

Expand All @@ -31,7 +31,7 @@ export class DependencyManager {
return Promise.all(
this.dependencies.map(dep => {
return dep.load();
})
}),
).then(() => true);
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/DependencyManager/ExecutableDependency.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
Dependency,
ExecutableDependencyOptions
} from "./Dependency";
import { Dependency, ExecutableDependencyOptions } from "./Dependency";

export class ExecutableDependency extends Dependency {
constructor(protected options: ExecutableDependencyOptions) {
Expand All @@ -20,7 +17,7 @@ export class ExecutableDependency extends Dependency {
return Promise.resolve({
exitCode: 0,
stderr: "",
stdout: "executable run output"
stdout: "executable run output",
});
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/DependencyManager/NodeDependency.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import {
Dependency,
NodeDependencyOptions
} from "./Dependency";
import { Dependency, NodeDependencyOptions } from "./Dependency";

// tslint:disable-next-line:no-require-imports no-var-requires
const requireg = require("requireg");

export class NodeDependency extends Dependency {

constructor(protected options: NodeDependencyOptions) {
super(options);
}
Expand Down
14 changes: 7 additions & 7 deletions test/DependencyManager/DependencyManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ import {
DependencyOptions,
DependencyType,
DependencyManager,
NodeDependency
NodeDependency,
} from "../../src/DependencyManager";

test("should fail to load dependencies", async () => {
expect.assertions(1);
const options: DependencyOptions = {
name: "NotFound",
package: "notfound",
type: DependencyType.Node
type: DependencyType.Node,
};
const manager = new DependencyManager([options]);

return await manager.load().catch(error => {
expect(error.message).toMatch(
'Dependency "NotFound" is required and not installed.'
'Dependency "NotFound" is required and not installed.',
);
});
});
Expand All @@ -27,7 +27,7 @@ describe("successfully loads dependency", () => {
const options: DependencyOptions = {
name: "FakeDep",
package: "fakedep",
type: DependencyType.Node
type: DependencyType.Node,
};
const manager = new DependencyManager([options]);

Expand All @@ -40,7 +40,7 @@ describe("successfully loads dependency", () => {
const options: DependencyOptions = {
name: packageName,
package: packageName,
type: DependencyType.Node
type: DependencyType.Node,
};
const manager = new DependencyManager([options]);

Expand All @@ -55,7 +55,7 @@ describe("successfully loads dependency", () => {
const options: DependencyOptions = {
name: packageName,
package: packageName,
type: DependencyType.Node
type: DependencyType.Node,
};
const manager = new DependencyManager([options]);

Expand All @@ -71,7 +71,7 @@ describe("successfully loads dependency", () => {
const options: DependencyOptions = {
name: packageName,
package: packageName,
type: DependencyType.Node
type: DependencyType.Node,
};
const manager = new DependencyManager([options]);

Expand Down
8 changes: 4 additions & 4 deletions test/DependencyManager/NodeDependency.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import {
NodeDependency,
DependencyType,
DependencyOptions
DependencyOptions,
} from "../../src/DependencyManager";

test("should fail to load Node dependency", async () => {
expect.assertions(3);
const options: DependencyOptions = {
name: "NotFound",
package: "NotFound",
type: DependencyType.Node
type: DependencyType.Node,
};
const dependency = new NodeDependency(options);

return await dependency.load().catch(error => {
expect(error.message).toMatch(
'Dependency "NotFound" is required and not installed.'
'Dependency "NotFound" is required and not installed.',
);
expect(dependency.isInstalled).toBe(false);
expect(dependency.errors).toHaveLength(1);
Expand All @@ -28,7 +28,7 @@ describe("successfully loaded Node dependency", () => {
const options: DependencyOptions = {
name: "FakeDep",
package: "fakedep",
type: DependencyType.Node
type: DependencyType.Node,
};
const dependency = new NodeDependency(options);

Expand Down
1 change: 0 additions & 1 deletion test/InlineFlagManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,4 @@ describe("disable/enable", () => {
const finalText = manager.text;
expect(finalText).toEqual(expectedText);
});

});
16 changes: 8 additions & 8 deletions test/beautifier/beautifier.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ test("should successfully beautify text", () => {
languageName: "TestLang",
options: {},
text: "test",
})
}),
).resolves.toBe(beautifierResult);
});

Expand All @@ -98,7 +98,7 @@ test("should fail to find beautifier", () => {
languageName: "TestLang",
options: {},
text: "test",
})
}),
).rejects.toThrowError(`Beautifiers not found for Language: ${lang.name}`);
});

Expand All @@ -110,7 +110,7 @@ test("should fail to find language", () => {
languageName: "TestLang",
options: {},
text: "test",
})
}),
).rejects.toThrowError("Cannot find language.");
});

Expand Down Expand Up @@ -176,15 +176,15 @@ test("should successfully transform option values for beautifier", () => {
const result1 = Unibeautify.getOptionsForBeautifier(
beautifier,
lang1,
options
options,
);
expect(result1.value1).toEqual(options.value1); // "Allow option"
expect(result1.value2).toBeUndefined();
expect(result1.isUndefined).toBeUndefined();
expect(result1.renamed1).toEqual(options.value1); // "Rename option"
expect(result1.basicTransform).toEqual(options.basicTransform + 1); // "Perform basic transformation"
expect(result1.complexTransform).toEqual(
options.value1 + options.basicTransform
options.value1 + options.basicTransform,
); // "Perform complex transformation"
expect(result1.willBeReplaced).toEqual(options.value1); // "Replace global option with language-specific option"
expect(result1).toEqual({
Expand All @@ -198,13 +198,13 @@ test("should successfully transform option values for beautifier", () => {
const result2 = Unibeautify.getOptionsForBeautifier(
beautifier,
lang2,
options
options,
);

const result3 = Unibeautify.getOptionsForBeautifier(
beautifier,
lang3,
options
options,
);
});

Expand Down Expand Up @@ -239,6 +239,6 @@ test("should successfully ignore-next-line", () => {
languageName: "TestLang",
options: {},
text: originalText,
})
}),
).resolves.toBe(originalText);
});
38 changes: 19 additions & 19 deletions test/beautifier/dependency.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
Language,
Beautifier,
DependencyOptions,
DependencyType
DependencyType,
} from "../../src/";

test("should throw Error when dependency type is unknown", () => {
Expand All @@ -15,12 +15,12 @@ test("should throw Error when dependency type is unknown", () => {
namespace: "test",
since: "0.1.0",
sublimeSyntaxes: [],
vscodeLanguages: []
vscodeLanguages: [],
};
unibeautify.loadLanguage(lang);
const beautifierResult = "Testing Result";
const dependency: any = {
type: "wrong"
type: "wrong",
};
const beautifier: Beautifier = {
beautify: ({ Promise }) => {
Expand All @@ -29,8 +29,8 @@ test("should throw Error when dependency type is unknown", () => {
dependencies: [dependency],
name: "TestBeautify",
options: {
TestLang: false
}
TestLang: false,
},
};
return expect(() => {
unibeautify.loadBeautifier(beautifier);
Expand All @@ -47,15 +47,15 @@ describe("Node", () => {
namespace: "test",
since: "0.1.0",
sublimeSyntaxes: [],
vscodeLanguages: []
vscodeLanguages: [],
};
unibeautify.loadLanguage(lang);

const beautifierResult = "Testing Result";
const dependency: DependencyOptions = {
name: "Fakedep",
package: "fake",
type: DependencyType.Node
type: DependencyType.Node,
};
const beautifier: Beautifier = {
beautify: ({ Promise }) => {
Expand All @@ -64,19 +64,19 @@ describe("Node", () => {
dependencies: [dependency],
name: "TestBeautify",
options: {
TestLang: false
}
TestLang: false,
},
};
unibeautify.loadBeautifier(beautifier);

return expect(
unibeautify.beautify({
languageName: "TestLang",
options: {},
text: "test"
})
text: "test",
}),
).rejects.toThrowError(
'Dependency "Fakedep" is required and not installed.'
'Dependency "Fakedep" is required and not installed.',
);
});
});
Expand All @@ -91,7 +91,7 @@ describe("Executable", () => {
namespace: "test",
since: "0.1.0",
sublimeSyntaxes: [],
vscodeLanguages: []
vscodeLanguages: [],
};
unibeautify.loadLanguage(lang);

Expand All @@ -100,7 +100,7 @@ describe("Executable", () => {
name: "Fake Program",
parseVersion: text => "",
program: "fakeprogram",
type: DependencyType.Executable
type: DependencyType.Executable,
};
const beautifier: Beautifier = {
beautify: ({ Promise, dependencies }) => {
Expand All @@ -110,19 +110,19 @@ describe("Executable", () => {
dependencies: [dependency],
name: "TestBeautify",
options: {
TestLang: false
}
TestLang: false,
},
};
unibeautify.loadBeautifier(beautifier);

return expect(
unibeautify.beautify({
languageName: "TestLang",
options: {},
text: "test"
})
text: "test",
}),
).rejects.toThrowError(
'Dependency "Fake Program" is required and not installed.'
'Dependency "Fake Program" is required and not installed.',
);
});
});
Loading

0 comments on commit f04258f

Please sign in to comment.