Skip to content

Commit e1a9dbe

Browse files
authoredJul 15, 2024··
fix: tsconifgPath configuration (#541)
1 parent 94fd0f5 commit e1a9dbe

File tree

10 files changed

+352
-2
lines changed

10 files changed

+352
-2
lines changed
 

Diff for: ‎fixtures/output/ts-strict/javascript.js

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// This file is generated by ChatGPT
2+
3+
// eslint-disable-next-line no-console
4+
const log = console.log
5+
6+
// Define a class using ES6 class syntax
7+
class Person {
8+
constructor(name, age) {
9+
this.name = name
10+
this.age = age
11+
}
12+
13+
// Define a method within the class
14+
sayHello() {
15+
log(`Hello, my name is ${this.name} and I am ${this.age} years old.`)
16+
}
17+
}
18+
19+
// Create an array of objects
20+
const people = [
21+
new Person('Alice', 30),
22+
new Person('Bob', 25),
23+
new Person('Charlie', 35),
24+
]
25+
26+
// Use the forEach method to iterate over the array
27+
people.forEach((person) => {
28+
person.sayHello()
29+
})
30+
31+
// Use a template literal to create a multiline string
32+
const multilineString = `
33+
This is a multiline string
34+
that spans multiple lines.
35+
`
36+
37+
// Use destructuring assignment to extract values from an object
38+
const { name, age } = people[0]
39+
log(`First person in the array is ${name} and they are ${age} years old.`, multilineString)
40+
41+
// Use the spread operator to create a new array
42+
const numbers = [1, 2, 3]
43+
const newNumbers = [...numbers, 4, 5]
44+
log(newNumbers)
45+
46+
// Use a try-catch block for error handling
47+
try {
48+
// Attempt to parse an invalid JSON string
49+
JSON.parse('invalid JSON')
50+
}
51+
catch (error) {
52+
console.error('Error parsing JSON:', error.message)
53+
}
54+
55+
// Use a ternary conditional operator
56+
const isEven = num => num % 2 === 0
57+
const number = 7
58+
log(`${number} is ${isEven(number) ? 'even' : 'odd'}.`)
59+
60+
// Use a callback function with setTimeout for asynchronous code
61+
setTimeout(() => {
62+
log('This code runs after a delay of 2 seconds.')
63+
}, 2000)
64+
65+
let a, b, c, d, foo
66+
67+
if (a
68+
|| b
69+
|| c || d
70+
|| (d && b)
71+
) {
72+
foo()
73+
}

Diff for: ‎fixtures/output/ts-strict/jsx.jsx

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export function HelloWorld({
2+
greeting = 'hello',
3+
greeted = '"World"',
4+
silent = false,
5+
onMouseOver,
6+
}) {
7+
if (!greeting) {
8+
return null
9+
};
10+
11+
// TODO: Don't use random in render
12+
const num = Math.floor (Math.random() * 1e+7).toString()
13+
.replace(/\.\d+/g, '')
14+
15+
return (
16+
<div className="HelloWorld" title={`You are visitor number ${num}`} onMouseOver={onMouseOver}>
17+
<strong>{ greeting.slice(0, 1).toUpperCase() + greeting.slice(1).toLowerCase() }</strong>
18+
{greeting.endsWith(',')
19+
? ' '
20+
: <span style={{ color: '\grey' }}>", "</span> }
21+
<em>
22+
{ greeted }
23+
</em>
24+
{ (silent) ? '.' : '!'}
25+
</div>
26+
)
27+
}

Diff for: ‎fixtures/output/ts-strict/markdown.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Header
2+
======
3+
4+
_Look,_ code blocks are formatted *too!*
5+
6+
```js
7+
// This should be handled by ESLint instead of Prettier
8+
function identity(x) {
9+
if (foo) {
10+
console.log('bar')
11+
}
12+
}
13+
```
14+
15+
```css
16+
/* This should be handled by Prettier */
17+
.foo { color:red;}
18+
```
19+
20+
Pilot|Airport|Hours
21+
--|:--:|--:
22+
John Doe|SKG|1338
23+
Jane Roe|JFK|314
24+
25+
- - - - - - - - - - - - - - -
26+
27+
+ List
28+
+ with a [link] (/to/somewhere)
29+
+ and [another one]
30+
31+
[another one]: http://example.com 'Example title'
32+
33+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
34+
Curabitur consectetur maximus risus, sed maximus tellus tincidunt et.

Diff for: ‎fixtures/output/ts-strict/toml.toml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
comma = [
2+
1,
3+
2,
4+
3,
5+
]
6+
7+
[foo]
8+
b = 1
9+
c = "hello"
10+
a = { answer = 42 }
11+
indent = [
12+
1,
13+
2
14+
]
15+
16+
[a-table]
17+
apple.type = "fruit"
18+
apple.skin = "thin"
19+
apple.color = "red"
20+
21+
orange.type = "fruit"
22+
orange.skin = "thick"
23+
orange.color = "orange"

Diff for: ‎fixtures/output/ts-strict/tsx.tsx

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
export function Component1() {
2+
return <div />
3+
}
4+
5+
export function jsx2() {
6+
const props = { a: 1, b: 2 }
7+
return (
8+
<a foo="bar" bar="foo">
9+
<div
10+
{...props}
11+
a={1}
12+
b="2"
13+
>
14+
Inline Text
15+
</div>
16+
<Component1>
17+
Block Text
18+
</Component1>
19+
<div>
20+
Mixed
21+
<div>Foo</div>
22+
Text
23+
<b> Bar</b>
24+
</div>
25+
<p>
26+
foo
27+
<i>bar</i>
28+
<b>baz</b>
29+
</p>
30+
</a>
31+
)
32+
}

Diff for: ‎fixtures/output/ts-strict/typescript.ts

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Define a TypeScript interface
2+
interface Person {
3+
name: string
4+
age: number
5+
}
6+
7+
// Create an array of objects with the defined interface
8+
const people: Person[] = [
9+
{ name: 'Alice', age: 30 },
10+
{ name: 'Bob', age: 25 },
11+
{ name: 'Charlie', age: 35 },
12+
]
13+
14+
// eslint-disable-next-line no-console
15+
const log = console.log
16+
17+
// Use a for...of loop to iterate over the array
18+
for (const person of people) {
19+
log(`Hello, my name is ${person.name} and I am ${person.age} years old.`)
20+
}
21+
22+
// Define a generic function
23+
function identity< T >(arg: T): T {
24+
return arg
25+
}
26+
27+
// Use the generic function with type inference
28+
const result = identity(
29+
'TypeScript is awesome',
30+
)
31+
log(result)
32+
33+
// Use optional properties in an interface
34+
interface Car {
35+
make: string
36+
model?: string
37+
}
38+
39+
// Create objects using the interface
40+
const car1: Car = { make: 'Toyota' }
41+
const car2: Car = {
42+
make: 'Ford',
43+
model: 'Focus',
44+
}
45+
46+
// Use union types
47+
type Fruit = 'apple' | 'banana' | 'orange'
48+
const favoriteFruit: Fruit = 'apple'
49+
50+
// Use a type assertion to tell TypeScript about the type
51+
const inputValue: any = '42'
52+
const numericValue = inputValue as number
53+
54+
// Define a class with access modifiers
55+
class Animal {
56+
private name: string
57+
constructor(name: string) {
58+
this.name = name
59+
}
60+
61+
protected makeSound(sound: string) {
62+
log(`${this.name} says ${sound}`)
63+
}
64+
}
65+
66+
// Extend a class
67+
class Dog extends Animal {
68+
constructor(private alias: string) {
69+
super(alias)
70+
}
71+
72+
bark() {
73+
this.makeSound('Woof!')
74+
}
75+
}
76+
77+
const dog = new Dog('Buddy')
78+
dog.bark()
79+
80+
function fn(): string {
81+
return `hello${1}`
82+
}
83+
84+
log(car1, car2, favoriteFruit, numericValue, fn())

Diff for: ‎fixtures/output/ts-strict/vue-ts.vue

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<script setup lang="ts">
2+
// Define reactive data and props
3+
import { ref } from 'vue'
4+
5+
const greeting = ref('Hello, Vue 3!')
6+
const counter = ref<number | 1>(0)
7+
8+
// Define a function
9+
function incrementCounter() {
10+
counter.value++
11+
}
12+
</script>
13+
14+
<template>
15+
<div>
16+
<h1>{{ greeting }}</h1>
17+
<button @click="incrementCounter">
18+
Click me!
19+
</button>
20+
<p>Counter: {{ counter }}</p>
21+
</div>
22+
</template>
23+
24+
<style>
25+
.a { color: red }
26+
</style>
27+
28+
<style lang="scss">
29+
$font-stack: Helvetica, sans-serif;
30+
$primary-color: #333;
31+
32+
body { font: 100% $font-stack;
33+
color: $primary-color;
34+
}
35+
</style>

Diff for: ‎fixtures/output/ts-strict/vue.vue

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<script setup>
2+
// Define reactive data and props
3+
import { ref } from 'vue'
4+
5+
const greeting = ref(`Hello, Vue 3!${1}`)
6+
const counter = ref(0)
7+
const doubled = computed(() => counter.value * 2)
8+
9+
// Define a function
10+
function incrementCounter() {
11+
counter.value++
12+
}
13+
14+
const _zero = doubled.value + counter.value
15+
</script>
16+
17+
<template>
18+
<div>
19+
<h1>
20+
{{ greeting }}
21+
</h1>
22+
<button @click="incrementCounter">
23+
Click me!
24+
</button>
25+
<p>Counter: {{ counter }}</p>
26+
</div>
27+
</template>

Diff for: ‎src/configs/typescript.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import process from 'node:process'
22
import { GLOB_ASTRO_TS, GLOB_MARKDOWN, GLOB_TS, GLOB_TSX } from '../globs'
33
import type { OptionsComponentExts, OptionsFiles, OptionsOverrides, OptionsTypeScriptParserOptions, OptionsTypeScriptWithTypes, TypedFlatConfigItem } from '../types'
44
import { pluginAntfu } from '../plugins'
5-
import { interopDefault, renameRules, toArray } from '../utils'
5+
import { interopDefault, renameRules } from '../utils'
66

77
export async function typescript(
88
options: OptionsFiles & OptionsComponentExts & OptionsOverrides & OptionsTypeScriptWithTypes & OptionsTypeScriptParserOptions = {},
@@ -25,7 +25,7 @@ export async function typescript(
2525
GLOB_ASTRO_TS,
2626
]
2727
const tsconfigPath = options?.tsconfigPath
28-
? toArray(options.tsconfigPath)
28+
? options.tsconfigPath
2929
: undefined
3030
const isTypeAware = !!tsconfigPath
3131

Diff for: ‎test/fixtures.test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ runWithConfig(
5757
},
5858
)
5959

60+
// https://github.com/antfu/eslint-config/issues/255
61+
runWithConfig(
62+
'ts-strict',
63+
{
64+
typescript: {
65+
tsconfigPath: '../../tsconfig.json',
66+
},
67+
},
68+
{
69+
rules: {
70+
'ts/no-unsafe-return': ['off'],
71+
},
72+
},
73+
)
74+
6075
runWithConfig(
6176
'with-formatters',
6277
{

0 commit comments

Comments
 (0)
Please sign in to comment.