diff --git a/.vscode/settings.json b/.vscode/settings.json index f013869b..0b4e6fbc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,4 +5,7 @@ "jest.rootPath": ".", "jest.pathToConfig": "jest.config.js", "jest.showCoverageOnLoad": true, + "prettier.semi": true, + "prettier.singleQuote": false, + "prettier.trailingComma": "all" } \ No newline at end of file diff --git a/src/DependencyManager/Dependency.ts b/src/DependencyManager/Dependency.ts index 42d00160..b8781c2f 100644 --- a/src/DependencyManager/Dependency.ts +++ b/src/DependencyManager/Dependency.ts @@ -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; @@ -82,7 +82,7 @@ export interface BaseDependencyOptions { export enum DependencyType { Node = "node", - Executable = "exec" + Executable = "exec", } export interface NodeDependencyOptions extends BaseDependencyOptions { diff --git a/src/DependencyManager/DependencyFactory.ts b/src/DependencyManager/DependencyFactory.ts index 0649e7e2..e190416f 100644 --- a/src/DependencyManager/DependencyFactory.ts +++ b/src/DependencyManager/DependencyFactory.ts @@ -1,8 +1,4 @@ -import { - Dependency, - DependencyType, - DependencyOptions -} from "./Dependency"; +import { Dependency, DependencyType, DependencyOptions } from "./Dependency"; import { NodeDependency } from "./NodeDependency"; import { ExecutableDependency } from "./ExecutableDependency"; @@ -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)}`, ); } } diff --git a/src/DependencyManager/DependencyManager.ts b/src/DependencyManager/DependencyManager.ts index c44cda77..905adad5 100644 --- a/src/DependencyManager/DependencyManager.ts +++ b/src/DependencyManager/DependencyManager.ts @@ -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, }), - {} + {}, ); } @@ -31,7 +31,7 @@ export class DependencyManager { return Promise.all( this.dependencies.map(dep => { return dep.load(); - }) + }), ).then(() => true); } } diff --git a/src/DependencyManager/ExecutableDependency.ts b/src/DependencyManager/ExecutableDependency.ts index e0416593..db68f14c 100644 --- a/src/DependencyManager/ExecutableDependency.ts +++ b/src/DependencyManager/ExecutableDependency.ts @@ -1,7 +1,4 @@ -import { - Dependency, - ExecutableDependencyOptions -} from "./Dependency"; +import { Dependency, ExecutableDependencyOptions } from "./Dependency"; export class ExecutableDependency extends Dependency { constructor(protected options: ExecutableDependencyOptions) { @@ -20,7 +17,7 @@ export class ExecutableDependency extends Dependency { return Promise.resolve({ exitCode: 0, stderr: "", - stdout: "executable run output" + stdout: "executable run output", }); } } diff --git a/src/DependencyManager/NodeDependency.ts b/src/DependencyManager/NodeDependency.ts index 37d2c74f..d494a686 100644 --- a/src/DependencyManager/NodeDependency.ts +++ b/src/DependencyManager/NodeDependency.ts @@ -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); } diff --git a/test/DependencyManager/DependencyManager.spec.ts b/test/DependencyManager/DependencyManager.spec.ts index 4dd29d74..0ceb035c 100644 --- a/test/DependencyManager/DependencyManager.spec.ts +++ b/test/DependencyManager/DependencyManager.spec.ts @@ -2,7 +2,7 @@ import { DependencyOptions, DependencyType, DependencyManager, - NodeDependency + NodeDependency, } from "../../src/DependencyManager"; test("should fail to load dependencies", async () => { @@ -10,13 +10,13 @@ test("should fail to load dependencies", async () => { 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.', ); }); }); @@ -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]); @@ -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]); @@ -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]); @@ -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]); diff --git a/test/DependencyManager/NodeDependency.spec.ts b/test/DependencyManager/NodeDependency.spec.ts index 5f8aa388..63dc902a 100644 --- a/test/DependencyManager/NodeDependency.spec.ts +++ b/test/DependencyManager/NodeDependency.spec.ts @@ -1,7 +1,7 @@ import { NodeDependency, DependencyType, - DependencyOptions + DependencyOptions, } from "../../src/DependencyManager"; test("should fail to load Node dependency", async () => { @@ -9,13 +9,13 @@ test("should fail to load Node dependency", async () => { 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); @@ -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); diff --git a/test/InlineFlagManager.spec.ts b/test/InlineFlagManager.spec.ts index cd64e92f..d2ffb48a 100644 --- a/test/InlineFlagManager.spec.ts +++ b/test/InlineFlagManager.spec.ts @@ -244,5 +244,4 @@ describe("disable/enable", () => { const finalText = manager.text; expect(finalText).toEqual(expectedText); }); - }); diff --git a/test/beautifier/beautifier.spec.ts b/test/beautifier/beautifier.spec.ts index f4738905..108c3477 100644 --- a/test/beautifier/beautifier.spec.ts +++ b/test/beautifier/beautifier.spec.ts @@ -76,7 +76,7 @@ test("should successfully beautify text", () => { languageName: "TestLang", options: {}, text: "test", - }) + }), ).resolves.toBe(beautifierResult); }); @@ -98,7 +98,7 @@ test("should fail to find beautifier", () => { languageName: "TestLang", options: {}, text: "test", - }) + }), ).rejects.toThrowError(`Beautifiers not found for Language: ${lang.name}`); }); @@ -110,7 +110,7 @@ test("should fail to find language", () => { languageName: "TestLang", options: {}, text: "test", - }) + }), ).rejects.toThrowError("Cannot find language."); }); @@ -176,7 +176,7 @@ 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(); @@ -184,7 +184,7 @@ test("should successfully transform option values for beautifier", () => { 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({ @@ -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, ); }); @@ -239,6 +239,6 @@ test("should successfully ignore-next-line", () => { languageName: "TestLang", options: {}, text: originalText, - }) + }), ).resolves.toBe(originalText); }); diff --git a/test/beautifier/dependency.spec.ts b/test/beautifier/dependency.spec.ts index 63cc765f..8d92106c 100644 --- a/test/beautifier/dependency.spec.ts +++ b/test/beautifier/dependency.spec.ts @@ -3,7 +3,7 @@ import { Language, Beautifier, DependencyOptions, - DependencyType + DependencyType, } from "../../src/"; test("should throw Error when dependency type is unknown", () => { @@ -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 }) => { @@ -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); @@ -47,7 +47,7 @@ describe("Node", () => { namespace: "test", since: "0.1.0", sublimeSyntaxes: [], - vscodeLanguages: [] + vscodeLanguages: [], }; unibeautify.loadLanguage(lang); @@ -55,7 +55,7 @@ describe("Node", () => { const dependency: DependencyOptions = { name: "Fakedep", package: "fake", - type: DependencyType.Node + type: DependencyType.Node, }; const beautifier: Beautifier = { beautify: ({ Promise }) => { @@ -64,8 +64,8 @@ describe("Node", () => { dependencies: [dependency], name: "TestBeautify", options: { - TestLang: false - } + TestLang: false, + }, }; unibeautify.loadBeautifier(beautifier); @@ -73,10 +73,10 @@ describe("Node", () => { 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.', ); }); }); @@ -91,7 +91,7 @@ describe("Executable", () => { namespace: "test", since: "0.1.0", sublimeSyntaxes: [], - vscodeLanguages: [] + vscodeLanguages: [], }; unibeautify.loadLanguage(lang); @@ -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 }) => { @@ -110,8 +110,8 @@ describe("Executable", () => { dependencies: [dependency], name: "TestBeautify", options: { - TestLang: false - } + TestLang: false, + }, }; unibeautify.loadBeautifier(beautifier); @@ -119,10 +119,10 @@ describe("Executable", () => { 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.', ); }); }); diff --git a/test/beautifier/languages.spec.ts b/test/beautifier/languages.spec.ts index d2f32041..55a51972 100644 --- a/test/beautifier/languages.spec.ts +++ b/test/beautifier/languages.spec.ts @@ -93,7 +93,7 @@ test("should loaded languages which support a given beautifier", () => { }; unibeautify.loadBeautifier(beautifier); expect( - unibeautify.getLanguagesForBeautifier(beautifier).map(({ name }) => name) + unibeautify.getLanguagesForBeautifier(beautifier).map(({ name }) => name), ).toEqual([lang1.name]); }); @@ -130,9 +130,9 @@ test("should loaded languages which support a given beautifier", () => { }; unibeautify.loadBeautifier(beautifier); expect( - unibeautify.getBeautifiersForLanguage(lang1).map(({ name }) => name) + unibeautify.getBeautifiersForLanguage(lang1).map(({ name }) => name), ).toEqual([beautifier.name]); expect( - unibeautify.getBeautifiersForLanguage(lang2).map(({ name }) => name) + unibeautify.getBeautifiersForLanguage(lang2).map(({ name }) => name), ).toEqual([]); }); diff --git a/test/beautifier/options.spec.ts b/test/beautifier/options.spec.ts index 57e9c127..28dc0fd3 100644 --- a/test/beautifier/options.spec.ts +++ b/test/beautifier/options.spec.ts @@ -71,7 +71,9 @@ test("should get languages with a loaded beautifier supporting the given option" }; unibeautify.loadBeautifier(beautifier); expect( - unibeautify.getLanguagesSupportingOption(optionName).map(({ name }) => name) + unibeautify + .getLanguagesSupportingOption(optionName) + .map(({ name }) => name), ).toEqual([lang1.name]); }); @@ -133,7 +135,7 @@ test("should get beautifiers with a loaded language supporting the given option" expect( unibeautify .getBeautifiersSupportingOption(optionName) - .map(({ name }) => name) + .map(({ name }) => name), ).toEqual([beautifier2.name]); }); @@ -198,35 +200,35 @@ test("should correctly determine whether beautifier supports option for a langua beautifier: beautifier1, language: lang1, optionName, - }) + }), ).toEqual(false); expect( unibeautify.doesBeautifierSupportOptionForLanguage({ beautifier: beautifier1, language: lang1, optionName, - }) + }), ).toEqual(false); expect( unibeautify.doesBeautifierSupportOptionForLanguage({ beautifier: beautifier2, language: lang1, optionName: undefinedOptionName, - }) + }), ).toEqual(false); expect( unibeautify.doesBeautifierSupportOptionForLanguage({ beautifier: beautifier1, language: lang2, optionName, - }) + }), ).toEqual(false); expect( unibeautify.doesBeautifierSupportOptionForLanguage({ beautifier: beautifier2, language: lang2, optionName, - }) + }), ).toEqual(false); }); @@ -305,10 +307,10 @@ test("should get options supported for a language", () => { }; unibeautify.loadBeautifiers([beautifier1, beautifier2]); expect( - Object.keys(unibeautify.getOptionsSupportedForLanguage(lang1)) + Object.keys(unibeautify.getOptionsSupportedForLanguage(lang1)), ).toEqual([optionName1, optionName2, optionName3]); expect( - Object.keys(unibeautify.getOptionsSupportedForLanguage(lang2)) + Object.keys(unibeautify.getOptionsSupportedForLanguage(lang2)), ).toEqual([optionName2]); }); @@ -372,32 +374,32 @@ test("should get options supported by a beautifier for a language", () => { unibeautify.getOptionsSupportedByBeautifierForLanguage({ beautifier: beautifier1, language: lang1, - }) - ) + }), + ), ).toEqual([]); expect( Object.keys( unibeautify.getOptionsSupportedByBeautifierForLanguage({ beautifier: beautifier2, language: lang1, - }) - ) + }), + ), ).toEqual([optionName]); expect( Object.keys( unibeautify.getOptionsSupportedByBeautifierForLanguage({ beautifier: beautifier1, language: lang2, - }) - ) + }), + ), ).toEqual([]); expect( Object.keys( unibeautify.getOptionsSupportedByBeautifierForLanguage({ beautifier: beautifier2, language: lang2, - }) - ) + }), + ), ).toEqual([]); }); @@ -437,6 +439,8 @@ test("should get languages with a loaded beautifier supporting a transform of th }; unibeautify.loadBeautifier(beautifier); expect( - unibeautify.getLanguagesSupportingOption(optionName).map(({ name }) => name) + unibeautify + .getLanguagesSupportingOption(optionName) + .map(({ name }) => name), ).toEqual([lang1.name]); }); diff --git a/test/beautifier/pipeline.spec.ts b/test/beautifier/pipeline.spec.ts index 31492edb..b1a69fb2 100644 --- a/test/beautifier/pipeline.spec.ts +++ b/test/beautifier/pipeline.spec.ts @@ -14,7 +14,7 @@ test("should fail when beautifiers option containers unknown beautifier", () => }, }, text: "test", - }) + }), ).rejects.toThrowError(`Beautifier not found: ${beautifierName}`); }); @@ -52,7 +52,7 @@ test("should use named beautifier from beautifiers option", () => { }, }, text: "test", - }) + }), ).resolves.toEqual(beautifierResult); }); @@ -80,7 +80,7 @@ test("should fail to use named beautifier which does not support language", () = }, }, text: "test", - }) + }), ).rejects.toThrowError(`Beautifier not found: ${beautifierName}`); }); @@ -117,7 +117,7 @@ test("should use all beautifiers for language when beautifiers option is empty", }, }, text: "Test", - }) + }), ).resolves.toEqual(beautifierResult); }); @@ -152,7 +152,7 @@ test("should use all beautifiers for language when beautifiers option is missing JavaScript: {}, }, text: "Test", - }) + }), ).resolves.toEqual(beautifierResult); }); @@ -189,6 +189,6 @@ test("should use beautifiers in order of beautifiers option", () => { }, }, text: "0", - }) + }), ).resolves.toBe(beautifierResult); }); diff --git a/test/index.spec.ts b/test/index.spec.ts index 3d345533..c4dfa427 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -7,7 +7,7 @@ test("should fail to find language", () => { languageName: "TestLang", options: {}, text: "test", - }) + }), ).rejects.toThrowError("Cannot find language."); }); @@ -17,7 +17,7 @@ test("should find JavaScript language and no Beautifier for Language", () => { languageName: "JavaScript", options: {}, text: "test", - }) + }), ).rejects.toThrowError("Beautifiers not found for Language: JavaScript"); }); @@ -42,7 +42,7 @@ test("should find JavaScript Language and Beautifier", () => { languageName: "JavaScript", options: {}, text: "test", - }) + }), ).resolves.toEqual(beautifierResult); }); @@ -66,6 +66,6 @@ test("should find JavaScript Language and not Beautifier", () => { languageName: "JavaScript", options: {}, text: "test", - }) + }), ).rejects.toThrowError("Beautifiers not found for Language: JavaScript"); });