From ff0d55b9448097c70f0fdd968d0d3559b705d636 Mon Sep 17 00:00:00 2001 From: Liam Rella Date: Mon, 24 Feb 2025 16:34:06 +1030 Subject: [PATCH] feat: add initial tests --- test/cli.test.ts | 151 ++++++++++++++++++ test/fixtures/input/Svelte.svelte | 56 +++++++ test/fixtures/input/css.css | 11 ++ test/fixtures/input/html.html | 28 ++++ test/fixtures/input/javascript.js | 66 ++++++++ test/fixtures/input/markdown.md | 35 ++++ test/fixtures/input/svg.svg | 25 +++ test/fixtures/input/tsconfig.testonly.json | 10 ++ test/fixtures/input/typescript.ts | 82 ++++++++++ test/fixtures/input/xml.xml | 13 ++ test/fixtures/output-fixed-auto/Svelte.svelte | 56 +++++++ test/fixtures/output-fixed-auto/css.css | 11 ++ test/fixtures/output-fixed-auto/html.html | 28 ++++ test/fixtures/output-fixed-auto/javascript.js | 69 ++++++++ test/fixtures/output-fixed-auto/markdown.md | 35 ++++ test/fixtures/output-fixed-auto/svg.svg | 25 +++ .../output-fixed-auto/tsconfig.testonly.json | 10 ++ test/fixtures/output-fixed-auto/typescript.ts | 79 +++++++++ test/fixtures/output-fixed-auto/xml.xml | 13 ++ .../output-fixed-manual/Svelte.svelte | 56 +++++++ test/fixtures/output-fixed-manual/css.css | 11 ++ test/fixtures/output-fixed-manual/html.html | 29 ++++ .../output-fixed-manual/javascript.js | 64 ++++++++ test/fixtures/output-fixed-manual/markdown.md | 35 ++++ test/fixtures/output-fixed-manual/svg.svg | 25 +++ .../tsconfig.testonly.json | 10 ++ .../output-fixed-manual/typescript.ts | 71 ++++++++ test/fixtures/output-fixed-manual/xml.xml | 13 ++ tsconfig.json | 7 +- 29 files changed, 1123 insertions(+), 1 deletion(-) create mode 100644 test/cli.test.ts create mode 100644 test/fixtures/input/Svelte.svelte create mode 100644 test/fixtures/input/css.css create mode 100644 test/fixtures/input/html.html create mode 100644 test/fixtures/input/javascript.js create mode 100644 test/fixtures/input/markdown.md create mode 100644 test/fixtures/input/svg.svg create mode 100644 test/fixtures/input/tsconfig.testonly.json create mode 100644 test/fixtures/input/typescript.ts create mode 100644 test/fixtures/input/xml.xml create mode 100644 test/fixtures/output-fixed-auto/Svelte.svelte create mode 100644 test/fixtures/output-fixed-auto/css.css create mode 100644 test/fixtures/output-fixed-auto/html.html create mode 100644 test/fixtures/output-fixed-auto/javascript.js create mode 100644 test/fixtures/output-fixed-auto/markdown.md create mode 100644 test/fixtures/output-fixed-auto/svg.svg create mode 100644 test/fixtures/output-fixed-auto/tsconfig.testonly.json create mode 100644 test/fixtures/output-fixed-auto/typescript.ts create mode 100644 test/fixtures/output-fixed-auto/xml.xml create mode 100644 test/fixtures/output-fixed-manual/Svelte.svelte create mode 100644 test/fixtures/output-fixed-manual/css.css create mode 100644 test/fixtures/output-fixed-manual/html.html create mode 100644 test/fixtures/output-fixed-manual/javascript.js create mode 100644 test/fixtures/output-fixed-manual/markdown.md create mode 100644 test/fixtures/output-fixed-manual/svg.svg create mode 100644 test/fixtures/output-fixed-manual/tsconfig.testonly.json create mode 100644 test/fixtures/output-fixed-manual/typescript.ts create mode 100644 test/fixtures/output-fixed-manual/xml.xml diff --git a/test/cli.test.ts b/test/cli.test.ts new file mode 100644 index 0000000..fe0401d --- /dev/null +++ b/test/cli.test.ts @@ -0,0 +1,151 @@ +import { execa } from 'execa'; +import fse from 'fs-extra'; +import path from 'node:path'; +import process from 'node:process'; +import { afterAll, beforeEach, describe, expect, it } from 'vitest'; +import { version } from '../package.json'; + +describe('CLI basics', () => { + it('should print version', async () => { + const { exitCode, stdout } = await execa('envsa', ['--version'], { + localDir: process.cwd(), + preferLocal: true, + }); + + expect(exitCode).toMatchInlineSnapshot(`0`); + expect(stdout).toBe(version); + }); + + it('should print version with short flag', async () => { + const { exitCode, stdout } = await execa('envsa', ['-v'], { + localDir: process.cwd(), + preferLocal: true, + }); + + expect(exitCode).toMatchInlineSnapshot(`0`); + expect(stdout).toBe(version); + }); + + it('should print help', async () => { + const { exitCode, stdout } = await execa('envsa', ['--help'], { + localDir: process.cwd(), + preferLocal: true, + }); + + expect(exitCode).toMatchInlineSnapshot(`0`); + expect(stdout).toMatchInlineSnapshot(` + "envsa + + Run aggregated @envsa/shared-config commands. + + Commands: + envsa Run aggregated @envsa/shared-config commands. [default] + envsa init Initialize configuration files for the entire suite of @envsa/shared-config tools. Will use option flags where possible if provided, but some of the invoked tools will ignore them. + envsa lint [files..] Lint your project with multiple tools in one go. Will use file arguments / globs where possible if provided, but some of the invoked tools only operate at the package-scope. + envsa fix [files..] Fix your project with multiple tools in one go. Will use file arguments / globs where possible if provided, but some of the invoked tools only operate at the package-scope. + envsa print-config [file] Print aggregated tool configuration data. Will use file arguments / globs where possible if provided, but some of the invoked tools only operate at the package-scope. + + Options: + -h, --help Show help [boolean] + -v, --version Show version number [boolean]" + `); + }); + + it('should print help with short flag', async () => { + const { exitCode, stdout } = await execa('envsa', ['-h'], { + localDir: process.cwd(), + preferLocal: true, + }); + + expect(exitCode).toMatchInlineSnapshot(`0`); + expect(stdout).toMatchInlineSnapshot(` + "envsa + + Run aggregated @envsa/shared-config commands. + + Commands: + envsa Run aggregated @envsa/shared-config commands. [default] + envsa init Initialize configuration files for the entire suite of @envsa/shared-config tools. Will use option flags where possible if provided, but some of the invoked tools will ignore them. + envsa lint [files..] Lint your project with multiple tools in one go. Will use file arguments / globs where possible if provided, but some of the invoked tools only operate at the package-scope. + envsa fix [files..] Fix your project with multiple tools in one go. Will use file arguments / globs where possible if provided, but some of the invoked tools only operate at the package-scope. + envsa print-config [file] Print aggregated tool configuration data. Will use file arguments / globs where possible if provided, but some of the invoked tools only operate at the package-scope. + + Options: + -h, --help Show help [boolean] + -v, --version Show version number [boolean]" + `); + }); +}); + +describe.skip('CLI rule configuration', () => { + const tempDirectory = './input-copy/'; + + beforeEach(async () => { + await fse.rm(tempDirectory, { force: true, recursive: true }); + }); + + afterAll(async () => { + await fse.rm(tempDirectory, { force: true, recursive: true }); + }); + + it('should not fix anything unless asked', { timeout: 60_000 }, async () => { + const sourceDirectory = './test/fixtures/input/'; + await fse.copy(sourceDirectory, tempDirectory); + + await execa('envsa', [], { + localDir: process.cwd(), + preferLocal: true, + reject: false, + }); + + for (const file of await fse.readdir(tempDirectory)) { + const fileContent = await fse.readFile(path.join(tempDirectory, file), 'utf8'); + const originalContent = await fse.readFile(path.join(sourceDirectory, file), 'utf8'); + expect(fileContent).toEqual(originalContent); + } + }); + + it('should fix auto-fixable things', { timeout: 60_000 }, async () => { + const sourceDirectory = './test/fixtures/input/'; + const destinationDirectory = './test/fixtures/output-fixed-auto/'; + await fse.copy(sourceDirectory, tempDirectory); + + await execa('envsa', ['--fix'], { + localDir: process.cwd(), + preferLocal: true, + reject: false, + }); + + for (const file of await fse.readdir(tempDirectory)) { + const fileContent = await fse.readFile(path.join(tempDirectory, file), 'utf8'); + const destinationFilePath = path.join('../', destinationDirectory, path.basename(file)); + + await fse.createFile(destinationFilePath); + await expect(fileContent).toMatchFileSnapshot(destinationFilePath); + } + }); + + it('should catch errors as expected', { timeout: 60_000 }, async () => { + const sourceDirectory = './test/fixtures/input/'; + await fse.copy(sourceDirectory, tempDirectory); + + const { exitCode, stdout } = await execa('envsa', [], { + // Disable color output + env: { + // Disable color output + // eslint-disable-next-line ts/naming-convention + NO_COLOR: '1', + }, + localDir: process.cwd(), + preferLocal: true, + reject: false, + }); + + expect(exitCode).toMatchInlineSnapshot(`1`); + // + /* cspell:disable */ + expect(stdout).toMatchInlineSnapshot(`""`); + // + /* cspell:enable */ + }); +}); diff --git a/test/fixtures/input/Svelte.svelte b/test/fixtures/input/Svelte.svelte new file mode 100644 index 0000000..ee04904 --- /dev/null +++ b/test/fixtures/input/Svelte.svelte @@ -0,0 +1,56 @@ + + +
+ +
{@html content}
+
+ + diff --git a/test/fixtures/input/css.css b/test/fixtures/input/css.css new file mode 100644 index 0000000..a77a611 --- /dev/null +++ b/test/fixtures/input/css.css @@ -0,0 +1,11 @@ +@media (max-width: 480px) { + .bd-examples { + margin-right: -0.75rem; + margin-left: -0.75rem; + } + + .bd-examples > [class^='col-'] { + padding-left: 0.75rem; + padding-right: 0.75rem; + } +} diff --git a/test/fixtures/input/html.html b/test/fixtures/input/html.html new file mode 100644 index 0000000..d14b767 --- /dev/null +++ b/test/fixtures/input/html.html @@ -0,0 +1,28 @@ + + + + + My tITlE + + + + +

+ Hello world!
+ This is HTML5 Boilerplate. +

+ + diff --git a/test/fixtures/input/javascript.js b/test/fixtures/input/javascript.js new file mode 100644 index 0000000..4b4b2f3 --- /dev/null +++ b/test/fixtures/input/javascript.js @@ -0,0 +1,66 @@ +// This file is generated by ChatGPT + +// eslint-disable-next-line no-console +var log = console.log; + +// Define a class using ES6 class syntax +class Person { + constructor(name, age) { + this.name = name; + this.age = age; + } + + // Define a method within the class + sayHello() { + log(`Hello, my name is ${this.name} and I am ${this.age} years old.`); + } +} + +// Create an array of objects +const people = [new Person('Alice', 30), new Person('Bob', 25), new Person('Charlie', 35)]; + +// Use the forEach method to iterate over the array +people.forEach((person) => { + person.sayHello(); +}); + +// Use a template literal to create a multiline string +const multilineString = ` + This is a multiline string + that spans multiple lines. +`; + +// Use destructuring assignment to extract values from an object +const { name, age } = people[0]; +log(`First person in the array is ${name} and they are ${age} years old.`, multilineString); + +// Use the spread operator to create a new array +const numbers = [1, 2, 3]; +const newNumbers = [...numbers, 4, 5]; +log(newNumbers); + +// Use a try-catch block for error handling +try { + // Attempt to parse an invalid JSON string + JSON.parse('invalid JSON'); +} catch (error) { + console.error('Error parsing JSON:', error.message); +} + +// Use a ternary conditional operator +const isEven = (num) => num % 2 === 0; +const number = 7; +log(`${number} is ${isEven(number) ? 'even' : 'odd'}.`); + +// Use a callback function with setTimeout for asynchronous code +setTimeout(() => { + log('This code runs after a delay of 2 seconds.'); +}, 2000); + +let a, b, c, d, foo; + +if (a || b || c || d || (d && b)) { + foo(); +} + +export {}; diff --git a/test/fixtures/input/markdown.md b/test/fixtures/input/markdown.md new file mode 100644 index 0000000..d46a742 --- /dev/null +++ b/test/fixtures/input/markdown.md @@ -0,0 +1,35 @@ +# Header + +_Look,_ code blocks are formatted _too!_ + +```js +// This should be handled by ESLint instead of Prettier +function identity(x) { + if (foo) { + console.log('bar'); + } +} +``` + +```css +/* This should be handled by Prettier */ +.foo { + color: red; +} +``` + +| Pilot | Airport | Hours | +| -------- | :-----: | ----: | +| John Doe | SKG | 1338 | +| Jane Roe | JFK | 314 | + +--- + +- List +- with a [link] (/to/somewhere) +- and [another one] + + [another one]: http://example.com 'Example title' + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. +Curabitur consectetur maximus risus, sed maximus tellus tincidunt et. diff --git a/test/fixtures/input/svg.svg b/test/fixtures/input/svg.svg new file mode 100644 index 0000000..fdfc3bd --- /dev/null +++ b/test/fixtures/input/svg.svg @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/test/fixtures/input/tsconfig.testonly.json b/test/fixtures/input/tsconfig.testonly.json new file mode 100644 index 0000000..d21d7db --- /dev/null +++ b/test/fixtures/input/tsconfig.testonly.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "target": "ESNext", + "skipLibCheck": true, + "strict": true, + "skipDefaultLibCheck": true, + "module": "ESNext", + "moduleResolution": "Bundler" + } +} diff --git a/test/fixtures/input/typescript.ts b/test/fixtures/input/typescript.ts new file mode 100644 index 0000000..1cc0463 --- /dev/null +++ b/test/fixtures/input/typescript.ts @@ -0,0 +1,82 @@ +// Define a TypeScript interface +interface Person { + name: string; + age: number; +} + +// Create an array of objects with the defined interface +const people: Person[] = [ + { name: 'Alice', age: 30 }, + { name: 'Bob', age: 25 }, + { name: 'Charlie', age: 35 }, +]; + +// eslint-disable-next-line no-console +var log = console.log; + +// Use a for...of loop to iterate over the array +for (const person of people) { + log(`Hello, my name is ${person.name} and I am ${person.age} years old.`); +} + +// Define a generic function +function identity(arg: T): T { + return arg; +} + +// Use the generic function with type inference +const result = identity('TypeScript is awesome'); +log(result); + +// Use optional properties in an interface +interface Car { + make: string; + model?: string; +} + +// Create objects using the interface +const car1: Car = { make: 'Toyota' }; +const car2: Car = { + make: 'Ford', + model: 'Focus', +}; + +// Use union types +type Fruit = 'apple' | 'banana' | 'orange'; +const favoriteFruit: Fruit = 'apple'; + +// Use a type assertion to tell TypeScript about the type +const inputValue: any = '42'; +const numericValue = inputValue as number; + +// Define a class with access modifiers +class Animal { + private name: string; + constructor(name: string) { + this.name = name; + } + protected makeSound(sound: string) { + log(`${this.name} says ${sound}`); + } +} + +// Extend a class +class Dog extends Animal { + constructor(private alias: string) { + super(alias); + } + bark() { + this.makeSound('Woof!'); + } +} + +const dog = new Dog('Buddy'); +dog.bark(); + +var fn = (): string => { + return 'hello' + 1; +}; + +log(car1, car2, favoriteFruit, numericValue, fn()); + +export {}; diff --git a/test/fixtures/input/xml.xml b/test/fixtures/input/xml.xml new file mode 100644 index 0000000..43f437e --- /dev/null +++ b/test/fixtures/input/xml.xml @@ -0,0 +1,13 @@ + +Effective Java45.00 + Bluetooth Speaker120.00 + Clean Code + 33.50 + + + + diff --git a/test/fixtures/output-fixed-auto/Svelte.svelte b/test/fixtures/output-fixed-auto/Svelte.svelte new file mode 100644 index 0000000..ee44897 --- /dev/null +++ b/test/fixtures/output-fixed-auto/Svelte.svelte @@ -0,0 +1,56 @@ + + +
+ +
{@html content}
+
+ + diff --git a/test/fixtures/output-fixed-auto/css.css b/test/fixtures/output-fixed-auto/css.css new file mode 100644 index 0000000..4bf7637 --- /dev/null +++ b/test/fixtures/output-fixed-auto/css.css @@ -0,0 +1,11 @@ +@media (width <= 480px) { + .bd-examples { + margin-right: -0.75rem; + margin-left: -0.75rem; + } + + .bd-examples > [class^='col-'] { + padding-right: 0.75rem; + padding-left: 0.75rem; + } +} diff --git a/test/fixtures/output-fixed-auto/html.html b/test/fixtures/output-fixed-auto/html.html new file mode 100644 index 0000000..19a2408 --- /dev/null +++ b/test/fixtures/output-fixed-auto/html.html @@ -0,0 +1,28 @@ + + + + + My tITlE + + + + +

+ Hello world!
+ This is HTML5 Boilerplate. +

+ + diff --git a/test/fixtures/output-fixed-auto/javascript.js b/test/fixtures/output-fixed-auto/javascript.js new file mode 100644 index 0000000..a3c590e --- /dev/null +++ b/test/fixtures/output-fixed-auto/javascript.js @@ -0,0 +1,69 @@ +// This file is generated by ChatGPT + +const { log } = console; + +// Define a class using ES6 class syntax +class Person { + constructor(name, age) { + this.name = name; + this.age = age; + } + + // Define a method within the class + sayHello() { + log(`Hello, my name is ${this.name} and I am ${this.age} years old.`); + } +} + +// Create an array of objects +const people = [new Person('Alice', 30), new Person('Bob', 25), new Person('Charlie', 35)]; + +// Use the forEach method to iterate over the array +for (const person of people) { + person.sayHello(); +} + +// Use a template literal to create a multiline string +const multilineString = ` + This is a multiline string + that spans multiple lines. +`; + +// Use destructuring assignment to extract values from an object +const { age, name } = people[0]; +log(`First person in the array is ${name} and they are ${age} years old.`, multilineString); + +// Use the spread operator to create a new array +const numbers = [1, 2, 3]; +const newNumbers = [...numbers, 4, 5]; +log(newNumbers); + +// Use a try-catch block for error handling +try { + // Attempt to parse an invalid JSON string + JSON.parse('invalid JSON'); +} catch (error) { + console.error('Error parsing JSON:', error.message); +} + +// Use a ternary conditional operator +const isEven = (number_) => number_ % 2 === 0; +const number = 7; +log(`${number} is ${isEven(number) ? 'even' : 'odd'}.`); + +// Use a callback function with setTimeout for asynchronous code +setTimeout(() => { + log('This code runs after a delay of 2 seconds.'); +}, 2000); + +let a; +let b; +let c; +let d; +let foo; + +if (a || b || c || d || (d && b)) { + foo(); +} + +export {}; diff --git a/test/fixtures/output-fixed-auto/markdown.md b/test/fixtures/output-fixed-auto/markdown.md new file mode 100644 index 0000000..5f34c38 --- /dev/null +++ b/test/fixtures/output-fixed-auto/markdown.md @@ -0,0 +1,35 @@ +# Header + +_Look,_ code blocks are formatted _too!_ + +```js +// This should be handled by ESLint instead of Prettier +function identity(x) { + if (foo) { + console.log('bar'); + } +} +``` + +```css +/* This should be handled by Prettier */ +.foo { + color: red; +} +``` + +| Pilot | Airport | Hours | +| -------- | :-----: | ----: | +| John Doe | SKG | 1338 | +| Jane Roe | JFK | 314 | + +--- + +- List +- with a \[link] (/to/somewhere) +- and [another one] + + [another one]: http://example.com 'Example title' + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. +Curabitur consectetur maximus risus, sed maximus tellus tincidunt et. diff --git a/test/fixtures/output-fixed-auto/svg.svg b/test/fixtures/output-fixed-auto/svg.svg new file mode 100644 index 0000000..fdfc3bd --- /dev/null +++ b/test/fixtures/output-fixed-auto/svg.svg @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/test/fixtures/output-fixed-auto/tsconfig.testonly.json b/test/fixtures/output-fixed-auto/tsconfig.testonly.json new file mode 100644 index 0000000..66372fb --- /dev/null +++ b/test/fixtures/output-fixed-auto/tsconfig.testonly.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "target": "ESNext", + "module": "ESNext", + "moduleResolution": "Bundler", + "strict": true, + "skipDefaultLibCheck": true, + "skipLibCheck": true + } +} diff --git a/test/fixtures/output-fixed-auto/typescript.ts b/test/fixtures/output-fixed-auto/typescript.ts new file mode 100644 index 0000000..5d30e86 --- /dev/null +++ b/test/fixtures/output-fixed-auto/typescript.ts @@ -0,0 +1,79 @@ +// Define a TypeScript interface +type Person = { + age: number; + name: string; +}; + +// Create an array of objects with the defined interface +const people: Person[] = [ + { age: 30, name: 'Alice' }, + { age: 25, name: 'Bob' }, + { age: 35, name: 'Charlie' }, +]; + +const { log } = console; + +// Use a for...of loop to iterate over the array +for (const person of people) { + log(`Hello, my name is ${person.name} and I am ${person.age} years old.`); +} + +// Define a generic function +function identity(arg: T): T { + return arg; +} + +// Use the generic function with type inference +const result = identity('TypeScript is awesome'); +log(result); + +// Use optional properties in an interface +type Car = { + make: string; + model?: string; +}; + +// Create objects using the interface +const car1: Car = { make: 'Toyota' }; +const car2: Car = { + make: 'Ford', + model: 'Focus', +}; + +// Use union types +type Fruit = 'apple' | 'banana' | 'orange'; +const favoriteFruit: Fruit = 'apple'; + +// Use a type assertion to tell TypeScript about the type +const inputValue: any = '42'; +const numericValue = inputValue as number; + +// Define a class with access modifiers +class Animal { + private readonly name: string; + constructor(name: string) { + this.name = name; + } + protected makeSound(sound: string) { + log(`${this.name} says ${sound}`); + } +} + +// Extend a class +class Dog extends Animal { + constructor(private readonly alias: string) { + super(alias); + } + bark() { + this.makeSound('Woof!'); + } +} + +const dog = new Dog('Buddy'); +dog.bark(); + +const fn = (): string => 'hello' + 1; + +log(car1, car2, favoriteFruit, numericValue, fn()); + +export {}; diff --git a/test/fixtures/output-fixed-auto/xml.xml b/test/fixtures/output-fixed-auto/xml.xml new file mode 100644 index 0000000..43f437e --- /dev/null +++ b/test/fixtures/output-fixed-auto/xml.xml @@ -0,0 +1,13 @@ + +Effective Java45.00 + Bluetooth Speaker120.00 + Clean Code + 33.50 + + + + diff --git a/test/fixtures/output-fixed-manual/Svelte.svelte b/test/fixtures/output-fixed-manual/Svelte.svelte new file mode 100644 index 0000000..ee44897 --- /dev/null +++ b/test/fixtures/output-fixed-manual/Svelte.svelte @@ -0,0 +1,56 @@ + + +
+ +
{@html content}
+
+ + diff --git a/test/fixtures/output-fixed-manual/css.css b/test/fixtures/output-fixed-manual/css.css new file mode 100644 index 0000000..4bf7637 --- /dev/null +++ b/test/fixtures/output-fixed-manual/css.css @@ -0,0 +1,11 @@ +@media (width <= 480px) { + .bd-examples { + margin-right: -0.75rem; + margin-left: -0.75rem; + } + + .bd-examples > [class^='col-'] { + padding-right: 0.75rem; + padding-left: 0.75rem; + } +} diff --git a/test/fixtures/output-fixed-manual/html.html b/test/fixtures/output-fixed-manual/html.html new file mode 100644 index 0000000..bc5d817 --- /dev/null +++ b/test/fixtures/output-fixed-manual/html.html @@ -0,0 +1,29 @@ + + + + + My tITlE + + + + + +

+ Hello world!
+ This is HTML5 Boilerplate. +

+ + diff --git a/test/fixtures/output-fixed-manual/javascript.js b/test/fixtures/output-fixed-manual/javascript.js new file mode 100644 index 0000000..f03b826 --- /dev/null +++ b/test/fixtures/output-fixed-manual/javascript.js @@ -0,0 +1,64 @@ +// This file is generated by ChatGPT + +const { log } = console; + +// Define a class using ES6 class syntax +class Person { + /** + * Creates an instance of Person. + * @param {string} name Name + * @param {number} age Age + */ + constructor(name, age) { + this.name = name; + this.age = age; + } + + // Define a method within the class + sayHello() { + log(`Hello, my name is ${this.name} and I am ${this.age} years old.`); + } +} + +// Create an array of objects +const people = [new Person('Alice', 30), new Person('Bob', 25), new Person('Charlie', 35)]; + +// Use the forEach method to iterate over the array +for (const person of people) { + person.sayHello(); +} + +// Use a template literal to create a multiline string +const multilineString = ` + This is a multiline string + that spans multiple lines. +`; + +// Use destructuring assignment to extract values from an object +const { age, name } = people[0]; +log(`First person in the array is ${name} and they are ${age} years old.`, multilineString); + +// Use the spread operator to create a new array +const numbers = [1, 2, 3]; +const newNumbers = [...numbers, 4, 5]; +log(newNumbers); + +// Use a try-catch block for error handling +try { + // Attempt to parse an invalid JSON string + JSON.parse('invalid JSON'); +} catch (error) { + console.error('Error parsing JSON:', error); +} + +// Use a ternary conditional operator +const isEven = (/** @type {number} */ number_) => number_ % 2 === 0; +const number = 7; +log(`${number} is ${isEven(number) ? 'even' : 'odd'}.`); + +// Use a callback function with setTimeout for asynchronous code +setTimeout(() => { + log('This code runs after a delay of 2 seconds.'); +}, 2000); + +export {}; diff --git a/test/fixtures/output-fixed-manual/markdown.md b/test/fixtures/output-fixed-manual/markdown.md new file mode 100644 index 0000000..3bb7d2c --- /dev/null +++ b/test/fixtures/output-fixed-manual/markdown.md @@ -0,0 +1,35 @@ +# Header + +_Look,_ code blocks are formatted _too!_ + +```js +// This should be handled by ESLint instead of Prettier +function identity(x) { + if (foo) { + console.log('bar'); + } +} +``` + +```css +/* This should be handled by Prettier */ +.foo { + color: red; +} +``` + +| Pilot | Airport | Hours | +| -------- | :-----: | ----: | +| John Doe | SKG | 1338 | +| Jane Roe | JFK | 314 | + +--- + +- List +- with a \[link] (/to/somewhere) +- and [another one][] + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. +Curabitur consectetur maximus risus, sed maximus tellus tincidunt et. + +[another one]: http://example.com 'Example title' diff --git a/test/fixtures/output-fixed-manual/svg.svg b/test/fixtures/output-fixed-manual/svg.svg new file mode 100644 index 0000000..fdfc3bd --- /dev/null +++ b/test/fixtures/output-fixed-manual/svg.svg @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/test/fixtures/output-fixed-manual/tsconfig.testonly.json b/test/fixtures/output-fixed-manual/tsconfig.testonly.json new file mode 100644 index 0000000..66372fb --- /dev/null +++ b/test/fixtures/output-fixed-manual/tsconfig.testonly.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "target": "ESNext", + "module": "ESNext", + "moduleResolution": "Bundler", + "strict": true, + "skipDefaultLibCheck": true, + "skipLibCheck": true + } +} diff --git a/test/fixtures/output-fixed-manual/typescript.ts b/test/fixtures/output-fixed-manual/typescript.ts new file mode 100644 index 0000000..e4428fb --- /dev/null +++ b/test/fixtures/output-fixed-manual/typescript.ts @@ -0,0 +1,71 @@ +// Define a TypeScript interface +type Person = { + age: number; + name: string; +}; + +// Create an array of objects with the defined interface +const people: Person[] = [ + { age: 30, name: 'Alice' }, + { age: 25, name: 'Bob' }, + { age: 35, name: 'Charlie' }, +]; + +const { log } = console; + +// Use a for...of loop to iterate over the array +for (const person of people) { + log(`Hello, my name is ${person.name} and I am ${person.age} years old.`); +} + +// Define a generic function +function identity(arg: T): T { + return arg; +} + +// Use the generic function with type inference +const result = identity('TypeScript is awesome'); +log(result); + +// Use optional properties in an interface +type Car = { + make: string; + model?: string; +}; + +// Create objects using the interface +const car1: Car = { make: 'Toyota' }; +const car2: Car = { + make: 'Ford', + model: 'Focus', +}; + +// Use union types +type Fruit = 'apple' | 'banana' | 'orange'; +const favoriteFruit: Fruit = 'apple'; + +// Define a class with access modifiers +class Animal { + constructor(private readonly name: string) {} + protected makeSound(sound: string) { + log(`${this.name} says ${sound}`); + } +} + +// Extend a class +class Dog extends Animal { + bark() { + this.makeSound('Woof!'); + } +} + +const dog = new Dog('Buddy'); +dog.bark(); + +const fn = (): string => 'hello' + 1; + +const numericValue = 1; + +log(car1, car2, favoriteFruit, numericValue, fn()); + +export {}; diff --git a/test/fixtures/output-fixed-manual/xml.xml b/test/fixtures/output-fixed-manual/xml.xml new file mode 100644 index 0000000..43f437e --- /dev/null +++ b/test/fixtures/output-fixed-manual/xml.xml @@ -0,0 +1,13 @@ + +Effective Java45.00 + Bluetooth Speaker120.00 + Clean Code + 33.50 + + + + diff --git a/tsconfig.json b/tsconfig.json index d377869..8006199 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,5 +3,10 @@ // Includes project dit-files files for typescript-eslint integration "include": ["**/*", "**/**.*"], - "exclude": ["**/dist/", "**/bin/"] + "exclude": [ + "**/dist/", + "**/bin/", + "test/fixtures/input/*.*", + "test/fixtures/output-fixed-auto/*.*" + ] }