Skip to content

Commit 9d8b80c

Browse files
authored
Update to ESLint 9 flat config (#258)
1 parent bbabd6a commit 9d8b80c

File tree

11 files changed

+2671
-1532
lines changed

11 files changed

+2671
-1532
lines changed

.eslintrc.cjs

Lines changed: 0 additions & 40 deletions
This file was deleted.

__tests__/plugin.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import path from 'node:path'
55

66
import { describe, expect, it } from 'vitest'
77

8-
import capsizePlugin from '../src/index.js'
9-
import { css, html, run } from './run.js'
8+
import { css, run } from './run.js'
109

1110
// eslint-disable-next-line unicorn/prefer-module
1211
const CONFIG_PATH = path.resolve(__dirname, './tailwind.config.js')

__tests__/run.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,23 @@ import path from 'node:path'
33

44
import tailwind from '@tailwindcss/postcss'
55
import postcss from 'postcss'
6-
// @ts-expect-error -- Trying to import a type in a CJS module I guess.
76
import type { Config } from 'tailwindcss'
87
import { expect } from 'vitest'
98

109
export const css = String.raw
11-
export const html = (strings: string[] | ArrayLike<string>) => String.raw({ raw: strings })
1210

1311
export async function run(input: string, config: Config, options?: Record<string, unknown>) {
1412
let { currentTestName } = expect.getState()
1513
let configFile = `
1614
const capsizePlugin = require('../src/index.js')
17-
const config = ${JSON.stringify(config, null, 4)}
15+
const config = ${JSON.stringify(config, undefined, 4)}
1816
module.exports = { ...config, plugins: [capsizePlugin${options ? `(${JSON.stringify(options)})` : ''}] }
1917
`
2018

2119
await fs.writeFile('__tests__/tailwind.config.js', configFile, 'utf8')
2220

2321
return postcss(tailwind).process(input, {
24-
// eslint-disable-next-line unicorn/prefer-module
25-
from: `${path.resolve(__filename)}?test=${currentTestName}`,
22+
// @ts-expect-error -- TS thinks this file is built to CJS.
23+
from: `${path.resolve(import.meta.filename)}?test=${currentTestName!}`,
2624
})
2725
}

__tests__/setup.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,25 @@
44
*/
55

66
import { diff } from 'jest-diff'
7-
// eslint-disable-next-line import/default
87
import prettier from 'prettier'
98
import { expect } from 'vitest'
109

11-
expect.extend({
12-
async toMatchFormattedCss(received: string, argument: string) {
13-
async function format(input: string) {
14-
return prettier.format(input.replaceAll('\n', ''), {
15-
parser: 'css',
16-
printWidth: 100,
17-
})
18-
}
10+
async function format(input: string) {
11+
return prettier.format(input.replaceAll('\n', ''), {
12+
parser: 'css',
13+
printWidth: 120,
14+
})
15+
}
1916

20-
function stripped(value: string) {
21-
return value
22-
.replace(/\/\* ! tailwindcss .* \*\//, '')
23-
.replaceAll(/\s/g, '')
24-
.replaceAll(';', '')
25-
}
17+
function stripped(value: string) {
18+
return value
19+
.replace(/\/\*! tailwindcss .* \*\//, '')
20+
.replaceAll(/\s/g, '')
21+
.replaceAll(';', '')
22+
}
2623

24+
expect.extend({
25+
async toMatchFormattedCss(received: string, argument: string) {
2726
let options = {
2827
comment: 'stripped(received) === stripped(argument)',
2928
isNot: this.isNot,

eslint.config.mjs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import zazen from '@zazen/eslint-config'
2+
import zazenNode from '@zazen/eslint-config/node'
3+
import zazenStylistic from '@zazen/eslint-config/stylistic'
4+
import zazenTypeScript from '@zazen/eslint-config/typescript'
5+
import { defineConfig } from 'eslint/config'
6+
7+
const config = defineConfig([
8+
...zazen,
9+
...zazenNode,
10+
...zazenTypeScript,
11+
12+
{
13+
name: 'project:rules',
14+
settings: {
15+
'import-x/ignore': ['node_modules'],
16+
node: {
17+
version: '20',
18+
},
19+
},
20+
rules: {
21+
'import-x/no-anonymous-default-export': ['error', { allowObject: true }],
22+
},
23+
},
24+
{
25+
name: 'project:rules:configs',
26+
files: ['**/*.config.{js,mjs}'],
27+
rules: {
28+
'import-x/no-extraneous-dependencies': [
29+
'error',
30+
{ devDependencies: true },
31+
],
32+
},
33+
},
34+
35+
zazenStylistic,
36+
])
37+
38+
export default config

0 commit comments

Comments
 (0)