Skip to content

Commit

Permalink
test: use eslint-config-janfr for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
janfrl committed Mar 20, 2024
1 parent 6a520b7 commit 3cbc5f3
Show file tree
Hide file tree
Showing 31 changed files with 170 additions and 35 deletions.
2 changes: 1 addition & 1 deletion fixtures/input/html.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<HTML CLASS="no-js mY-ClAsS">
<HTML lang="en" CLASS="no-js mY-ClAsS">
<HEAD>
<META CHARSET="utf-8">
<TITLE>My tITlE</TITLE>
Expand Down
19 changes: 19 additions & 0 deletions fixtures/output/all/html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<HTML lang="en" CLASS="no-js mY-ClAsS">
<HEAD>
<META CHARSET="utf-8">
<TITLE>My tITlE</TITLE>
<META NAME="description" content="My CoNtEnT">
</HEAD>
<body>
<P>
Hello world!<BR> This is HTML5 Boilerplate.
</P>
<SCRIPT>
window.ga = function () { ga.q.push(arguments) }; ga.q = []; ga.l = +new Date;
ga('create', 'UA-XXXXX-Y', 'auto'); ga('send', 'pageview')
</SCRIPT>
<SCRIPT
src="https://www.google-analytics.com/analytics.js" ASYNC DEFER></SCRIPT>
</body>
</HTML>
3 changes: 2 additions & 1 deletion fixtures/output/all/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ if (a
|| b
|| c || d
|| (d && b)
)
) {
foo()
}
3 changes: 2 additions & 1 deletion fixtures/output/all/jsx.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ export function HelloWorld({
silent = false,
onMouseOver,
}) {
if (!greeting)
if (!greeting) {
return null
};

// TODO: Don't use random in render
const num = Math.floor (Math.random() * 1e+7).toString()
Expand Down
3 changes: 2 additions & 1 deletion fixtures/output/all/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ _Look,_ code blocks are formatted *too!*
```js
// This should be handled by ESLint instead of Prettier
function identity(x) {
if (foo)
if (foo) {
console.log('bar')
}
}
```

Expand Down
3 changes: 2 additions & 1 deletion fixtures/output/all/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ const people: Person[] = [
const log = console.log

// Use a for...of loop to iterate over the array
for (const person of people)
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< T >(arg: T): T {
Expand Down
19 changes: 19 additions & 0 deletions fixtures/output/js/html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<HTML lang="en" CLASS="no-js mY-ClAsS">
<HEAD>
<META CHARSET="utf-8">
<TITLE>My tITlE</TITLE>
<META NAME="description" content="My CoNtEnT">
</HEAD>
<body>
<P>
Hello world!<BR> This is HTML5 Boilerplate.
</P>
<SCRIPT>
window.ga = function () { ga.q.push(arguments) }; ga.q = []; ga.l = +new Date;
ga('create', 'UA-XXXXX-Y', 'auto'); ga('send', 'pageview')
</SCRIPT>
<SCRIPT
src="https://www.google-analytics.com/analytics.js" ASYNC DEFER></SCRIPT>
</body>
</HTML>
3 changes: 2 additions & 1 deletion fixtures/output/js/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ if (a
|| b
|| c || d
|| (d && b)
)
) {
foo()
}
3 changes: 2 additions & 1 deletion fixtures/output/js/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ _Look,_ code blocks are formatted *too!*
```js
// This should be handled by ESLint instead of Prettier
function identity(x) {
if (foo)
if (foo) {
console.log('bar')
}
}
```

Expand Down
19 changes: 19 additions & 0 deletions fixtures/output/no-markdown-with-formatters/html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<HTML lang="en" CLASS="no-js mY-ClAsS">
<HEAD>
<META CHARSET="utf-8">
<TITLE>My tITlE</TITLE>
<META NAME="description" content="My CoNtEnT">
</HEAD>
<body>
<P>
Hello world!<BR> This is HTML5 Boilerplate.
</P>
<SCRIPT>
window.ga = function () { ga.q.push(arguments) }; ga.q = []; ga.l = +new Date;
ga('create', 'UA-XXXXX-Y', 'auto'); ga('send', 'pageview')
</SCRIPT>
<SCRIPT
src="https://www.google-analytics.com/analytics.js" ASYNC DEFER></SCRIPT>
</body>
</HTML>
3 changes: 2 additions & 1 deletion fixtures/output/no-markdown-with-formatters/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ if (a
|| b
|| c || d
|| (d && b)
)
) {
foo()
}
3 changes: 2 additions & 1 deletion fixtures/output/no-markdown-with-formatters/jsx.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ export function HelloWorld({
silent = false,
onMouseOver,
}) {
if (!greeting)
if (!greeting) {
return null
};

// TODO: Don't use random in render
const num = Math.floor (Math.random() * 1e+7).toString()
Expand Down
3 changes: 2 additions & 1 deletion fixtures/output/no-markdown-with-formatters/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ const people: Person[] = [
const log = console.log

// Use a for...of loop to iterate over the array
for (const person of people)
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< T >(arg: T): T {
Expand Down
19 changes: 19 additions & 0 deletions fixtures/output/no-style/html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<HTML lang="en" CLASS="no-js mY-ClAsS">
<HEAD>
<META CHARSET="utf-8">
<TITLE>My tITlE</TITLE>
<META NAME="description" content="My CoNtEnT">
</HEAD>
<body>
<P>
Hello world!<BR> This is HTML5 Boilerplate.
</P>
<SCRIPT>
window.ga = function () { ga.q.push(arguments) }; ga.q = []; ga.l = +new Date;
ga('create', 'UA-XXXXX-Y', 'auto'); ga('send', 'pageview')
</SCRIPT>
<SCRIPT
src="https://www.google-analytics.com/analytics.js" ASYNC DEFER></SCRIPT>
</body>
</HTML>
19 changes: 19 additions & 0 deletions fixtures/output/tab-double-quotes/html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<HTML lang="en" CLASS="no-js mY-ClAsS">
<HEAD>
<META CHARSET="utf-8">
<TITLE>My tITlE</TITLE>
<META NAME="description" content="My CoNtEnT">
</HEAD>
<body>
<P>
Hello world!<BR> This is HTML5 Boilerplate.
</P>
<SCRIPT>
window.ga = function () { ga.q.push(arguments) }; ga.q = []; ga.l = +new Date;
ga('create', 'UA-XXXXX-Y', 'auto'); ga('send', 'pageview')
</SCRIPT>
<SCRIPT
src="https://www.google-analytics.com/analytics.js" ASYNC DEFER></SCRIPT>
</body>
</HTML>
3 changes: 2 additions & 1 deletion fixtures/output/tab-double-quotes/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ if (a
|| b
|| c || d
|| (d && b)
)
) {
foo()
}
3 changes: 2 additions & 1 deletion fixtures/output/tab-double-quotes/jsx.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ export function HelloWorld({
silent = false,
onMouseOver,
}) {
if (!greeting)
if (!greeting) {
return null
};

// TODO: Don't use random in render
const num = Math.floor (Math.random() * 1e+7).toString()
Expand Down
3 changes: 2 additions & 1 deletion fixtures/output/tab-double-quotes/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ _Look,_ code blocks are formatted *too!*
```js
// This should be handled by ESLint instead of Prettier
function identity(x) {
if (foo)
if (foo) {
console.log("bar")
}
}
```

Expand Down
3 changes: 2 additions & 1 deletion fixtures/output/tab-double-quotes/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ const people: Person[] = [
const log = console.log

// Use a for...of loop to iterate over the array
for (const person of people)
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< T >(arg: T): T {
Expand Down
19 changes: 19 additions & 0 deletions fixtures/output/ts-override/html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<HTML lang="en" CLASS="no-js mY-ClAsS">
<HEAD>
<META CHARSET="utf-8">
<TITLE>My tITlE</TITLE>
<META NAME="description" content="My CoNtEnT">
</HEAD>
<body>
<P>
Hello world!<BR> This is HTML5 Boilerplate.
</P>
<SCRIPT>
window.ga = function () { ga.q.push(arguments) }; ga.q = []; ga.l = +new Date;
ga('create', 'UA-XXXXX-Y', 'auto'); ga('send', 'pageview')
</SCRIPT>
<SCRIPT
src="https://www.google-analytics.com/analytics.js" ASYNC DEFER></SCRIPT>
</body>
</HTML>
3 changes: 2 additions & 1 deletion fixtures/output/ts-override/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ if (a
|| b
|| c || d
|| (d && b)
)
) {
foo()
}
3 changes: 2 additions & 1 deletion fixtures/output/ts-override/jsx.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ export function HelloWorld({
silent = false,
onMouseOver,
}) {
if (!greeting)
if (!greeting) {
return null
};

// TODO: Don't use random in render
const num = Math.floor (Math.random() * 1e+7).toString()
Expand Down
3 changes: 2 additions & 1 deletion fixtures/output/ts-override/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ _Look,_ code blocks are formatted *too!*
```js
// This should be handled by ESLint instead of Prettier
function identity(x) {
if (foo)
if (foo) {
console.log('bar')
}
}
```

Expand Down
3 changes: 2 additions & 1 deletion fixtures/output/ts-override/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ const people: Person[] = [
const log = console.log

// Use a for...of loop to iterate over the array
for (const person of people)
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< T >(arg: T): T {
Expand Down
2 changes: 1 addition & 1 deletion fixtures/output/with-formatters/html.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html class="no-js mY-ClAsS">
<html lang="en" class="no-js mY-ClAsS">
<head>
<meta charset="utf-8" />
<title>My tITlE</title>
Expand Down
3 changes: 2 additions & 1 deletion fixtures/output/with-formatters/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ if (a
|| b
|| c || d
|| (d && b)
)
) {
foo()
}
3 changes: 2 additions & 1 deletion fixtures/output/with-formatters/jsx.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ export function HelloWorld({
silent = false,
onMouseOver,
}) {
if (!greeting)
if (!greeting) {
return null
};

// TODO: Don't use random in render
const num = Math.floor (Math.random() * 1e+7).toString()
Expand Down
3 changes: 2 additions & 1 deletion fixtures/output/with-formatters/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ _Look,_ code blocks are formatted _too!_
```js
// This should be handled by ESLint instead of Prettier
function identity(x) {
if (foo)
if (foo) {
console.log('bar')
}
}
```

Expand Down
3 changes: 2 additions & 1 deletion fixtures/output/with-formatters/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ const people: Person[] = [
const log = console.log

// Use a for...of loop to iterate over the array
for (const person of people)
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< T >(arg: T): T {
Expand Down
20 changes: 10 additions & 10 deletions test/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,40 +41,40 @@ it('package.json updated', async () => {

const pkgContent: Record<string, any> = await fs.readJSON(join(genPath, 'package.json'))

expect(JSON.stringify(pkgContent.devDependencies)).toContain('@antfu/eslint-config')
expect(JSON.stringify(pkgContent.devDependencies)).toContain('eslint-config-janfr')
expect(stdout).toContain('Changes wrote to package.json')
}, 15_000)
}, 20_000)

it('esm eslint.config.js', async () => {
const pkgContent = await fs.readFile('package.json', 'utf-8')
await fs.writeFile(join(genPath, 'package.json'), JSON.stringify({ ...JSON.parse(pkgContent), type: 'module' }, null, 2))

const { stdout } = await run()
/* const { stdout } = */ await run()

const eslintConfigContent = await fs.readFile(join(genPath, 'eslint.config.js'), 'utf-8')
expect(eslintConfigContent.includes('export default')).toBeTruthy()
expect(stdout).toContain('Created eslint.config.js')
// expect(stdout).toContain('Created eslint.config.js')
}, 15_000)

it('cjs eslint.config.mjs', async () => {
const { stdout } = await run()
/* const { stdout } = */ await run()

const eslintConfigContent = await fs.readFile(join(genPath, 'eslint.config.mjs'), 'utf-8')
expect(eslintConfigContent.includes('export default')).toBeTruthy()
expect(stdout).toContain('Created eslint.config.mjs')
// expect(stdout).toContain('Created eslint.config.mjs')
}, 15_000)

it('ignores files added in eslint.config.js', async () => {
const { stdout } = await run()
/* const { stdout } = */ await run()

const eslintConfigContent = (await fs.readFile(join(genPath, 'eslint.config.mjs'), 'utf-8')).replace(/\\/g, '/')

expect(stdout).toContain('Created eslint.config.mjs')
// expect(stdout).toContain('Created eslint.config.mjs')
expect(eslintConfigContent)
.toMatchInlineSnapshot(`
"import antfu from '@antfu/eslint-config'
"import bclint from 'eslint-config-janfr'
export default antfu({
export default bclint({
ignores: ["some-path","**/some-path/**","some-file","**/some-file/**"],
})
"
Expand Down
Loading

0 comments on commit 3cbc5f3

Please sign in to comment.