Skip to content

Commit

Permalink
feat: update to eslint v9
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpnielsen committed Jun 24, 2024
1 parent 4e8b6c9 commit 7343205
Show file tree
Hide file tree
Showing 32 changed files with 3,208 additions and 2,085 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
// Enable the ESlint flat config support
"eslint.experimental.useFlatConfig": true,
"eslint.useFlatConfig": true,

// Disable the default formatter, use eslint instead
"prettier.enable": false,
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ This config also provides some optional plugins/rules for extended usages.

This plugin [`eslint-plugin-perfectionist`](https://github.com/azat-io/eslint-plugin-perfectionist) allows you to sorted object keys, imports, etc, with auto-fix.

The plugin is installed but no rules are enabled by default.
The plugin is installed but no rules are enabled by default.

It's recommended to opt-in on each file individually using [configuration comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1).

Expand All @@ -263,7 +263,6 @@ const objectWantedToSort = {
b: 1,
c: 3,
};
/* eslint perfectionist/sort-objects: "off" */
```

### Type Aware Rules
Expand Down
9 changes: 7 additions & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// @ts-check
import styleMigrate from '@stylistic/eslint-plugin-migrate';
import JITI from 'jiti';

import configure from './dist/index.js';
const jiti = JITI(import.meta.url);

/**
* @type {import('./src').default}
*/
const configure = jiti('./src').default;

export default configure(
{
Expand Down
10 changes: 10 additions & 0 deletions fixtures/input/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,13 @@ log(`${number} is ${isEven(number) ? 'even' : 'odd'}.`);
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()
}
10 changes: 10 additions & 0 deletions fixtures/output/all/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,13 @@ log(`${number} is ${isEven(number) ? 'even' : 'odd'}.`);
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();
}
32 changes: 31 additions & 1 deletion fixtures/output/all/tsx.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
// unchanged
import type { Person } from './typescript';

export function Component1({ children }: { children: React.ReactNode }) {
return <div>{children}</div>;
}

export function jsx2({ name, age }: Person) {
const props = { a: name, b: age };
return (
<a aria-label="bar" title={`foo`}>
<div
{...props}
className="2"
>
Inline Text
</div>
<Component1>
Block Text
</Component1>
<div>
Mixed
<div>Foo</div>
Text
<b> Bar</b>
</div>
<p>
foo<i>bar</i><b>baz</b>
</p>
</a>
);
}
85 changes: 84 additions & 1 deletion fixtures/output/all/typescript.ts
Original file line number Diff line number Diff line change
@@ -1 +1,84 @@
// unchanged
// Define a TypeScript interface
export 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
const 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< T >(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();

function fn(): string {
return `hello${1}`;
}

log(car1, car2, favoriteFruit, numericValue, fn());
24 changes: 17 additions & 7 deletions fixtures/output/double-quotes/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class Person {

// Create an array of objects
const people = [
new Person("Alice", 30),
new Person("Bob", 25),
new Person("Charlie", 35),
new Person('Alice', 30),
new Person('Bob', 25),
new Person('Charlie', 35),
];

// Use the forEach method to iterate over the array
Expand All @@ -46,17 +46,27 @@ log(newNumbers);
// Use a try-catch block for error handling
try {
// Attempt to parse an invalid JSON string
JSON.parse("invalid JSON");
JSON.parse('invalid JSON');
} catch (error) {
console.error("Error parsing JSON:", error.message);
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"}.`);
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.");
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();
}
11 changes: 6 additions & 5 deletions fixtures/output/double-quotes/tsx.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import type { Person } from "./typescript";
import type { Person } from './typescript';

export function Component1({ children }: { children: React.ReactNode }) {
return <div>{children}</div>;
}

export function jsx2({ name, age }: Person) {
const props = { a: name,
b: age };
const props = { a: name, b: age };
return (
<a aria-label="bar" title={`foo`}>
<div
{...props}
className="2"
>Inline Text
>
Inline Text
</div>
<Component1>
Block Text
</Component1>
<div>
Mixed
<div>Foo</div>
Text<b> Bar</b>
Text
<b> Bar</b>
</div>
<p>
foo<i>bar</i><b>baz</b>
Expand Down
29 changes: 16 additions & 13 deletions fixtures/output/double-quotes/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Define a TypeScript interface
export interface Person {
name: string; age: number;
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 },
{ name: 'Alice', age: 30 },
{ name: 'Bob', age: 25 },
{ name: 'Charlie', age: 35 },
];

// eslint-disable-next-line no-console
Expand All @@ -26,7 +26,8 @@ function identity< T >(arg: T): T {

// Use the generic function with type inference
const result = identity(
"TypeScript is awesome");
'TypeScript is awesome',
);
log(result);

// Use optional properties in an interface
Expand All @@ -36,16 +37,18 @@ interface Car {
}

// Create objects using the interface
const car1: Car = { make: "Toyota" };
const car1: Car = { make: 'Toyota' };
const car2: Car = {
make: "Ford", model: "Focus" };
make: 'Ford',
model: 'Focus',
};

// Use union types
type Fruit = "apple" | "banana" | "orange";
const favoriteFruit: Fruit = "apple";
type Fruit = 'apple' | 'banana' | 'orange';
const favoriteFruit: Fruit = 'apple';

// Use a type assertion to tell TypeScript about the type
const inputValue: any = "42";
const inputValue: any = '42';
const numericValue = inputValue as number;

// Define a class with access modifiers
Expand All @@ -67,11 +70,11 @@ class Dog extends Animal {
}

bark() {
this.makeSound("Woof!");
this.makeSound('Woof!');
}
}

const dog = new Dog("Buddy");
const dog = new Dog('Buddy');
dog.bark();

function fn(): string {
Expand Down
10 changes: 10 additions & 0 deletions fixtures/output/js/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,13 @@ log(`${number} is ${isEven(number) ? 'even' : 'odd'}.`);
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();
}
1 change: 0 additions & 1 deletion fixtures/output/js/tsx.tsx

This file was deleted.

1 change: 0 additions & 1 deletion fixtures/output/js/typescript.ts

This file was deleted.

12 changes: 11 additions & 1 deletion fixtures/output/no-style/javascript.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This file is generated by ChatGPT

// eslint-disable-next-line no-console
const log = console.log;
const log = console.log

// Define a class using ES6 class syntax
class Person {
Expand Down Expand Up @@ -60,3 +60,13 @@ log(`${number} is ${isEven(number) ? 'even' : 'odd'}.`);
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()
}
1 change: 0 additions & 1 deletion fixtures/output/no-style/tsx.tsx

This file was deleted.

1 change: 0 additions & 1 deletion fixtures/output/no-style/typescript.ts

This file was deleted.

Loading

0 comments on commit 7343205

Please sign in to comment.