Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update to eslint v9 #3

Open
wants to merge 2 commits into
base: eslint-9
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @jdpnielsen/eslint-flat-config
# @noaignite-dk/eslint-flat-config

- Single quotes, semi & tab indentation
- Auto fix for formatting (aimed to be used standalone **without** Prettier)
Expand All @@ -16,7 +16,7 @@
### Install

```bash
pnpm i -D eslint @jdpnielsen/eslint-flat-config
pnpm i -D eslint @noaignite-dk/eslint-flat-config
```

### Create config file
Expand All @@ -25,7 +25,7 @@ With [`"type": "module"`](https://nodejs.org/api/packages.html#type) in `package

```js
// eslint.config.js
import setupConfig from '@jdpnielsen/eslint-flat-config';
import setupConfig from '@noaignite-dk/eslint-flat-config';

export default setupConfig();
```
Expand All @@ -34,7 +34,7 @@ With CJS:

```js
// eslint.config.js
const setupConfig = require('@jdpnielsen/eslint-flat-config').default;
const setupConfig = require('@noaignite-dk/eslint-flat-config').default;

module.exports = setupConfig();
```
Expand Down Expand Up @@ -112,7 +112,7 @@ Normally you only need to import the preset:

```js
// eslint.config.js
import setupConfig from '@jdpnielsen/eslint-flat-config';
import setupConfig from '@noaignite-dk/eslint-flat-config';

export default setupConfig();
```
Expand All @@ -121,7 +121,7 @@ And that's it! Or you can configure each integration individually, for example:

```js
// eslint.config.js
import setupConfig from '@jdpnielsen/eslint-flat-config';
import setupConfig from '@noaignite-dk/eslint-flat-config';

export default setupConfig({
// Enable stylistic formatting rules
Expand Down Expand Up @@ -155,7 +155,7 @@ The `setupConfig` factory function also accepts any number of arbitrary custom c

```js
// eslint.config.js
import setupConfig from '@jdpnielsen/eslint-flat-config';
import setupConfig from '@noaignite-dk/eslint-flat-config';

export default setupConfig(
{
Expand Down Expand Up @@ -204,7 +204,7 @@ Certain rules would only be enabled in specific files, for example, `ts/*` rules

```js
// eslint.config.js
import setupConfig from '@jdpnielsen/eslint-flat-config';
import setupConfig from '@noaignite-dk/eslint-flat-config';

export default setupConfig(
{ vue: true, typescript: true },
Expand All @@ -228,7 +228,7 @@ We also provided an `overrides` options to make it easier:

```js
// eslint.config.js
import setupConfig from '@jdpnielsen/eslint-flat-config';
import setupConfig from '@noaignite-dk/eslint-flat-config';

export default setupConfig({
overrides: {
Expand All @@ -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 All @@ -272,7 +271,7 @@ You can optionally enable the [type aware rules](https://typescript-eslint.io/li

```js
// eslint.config.js
import setupConfig from '@jdpnielsen/eslint-flat-config';
import setupConfig from '@noaignite-dk/eslint-flat-config';

export default setupConfig({
typescript: {
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
Loading