Skip to content

Update to ESLint 9 flat config #258

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

Merged
merged 1 commit into from
Jun 22, 2025
Merged
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
40 changes: 0 additions & 40 deletions .eslintrc.cjs

This file was deleted.

3 changes: 1 addition & 2 deletions __tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import path from 'node:path'

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

import capsizePlugin from '../src/index.js'
import { css, html, run } from './run.js'
import { css, run } from './run.js'

// eslint-disable-next-line unicorn/prefer-module
const CONFIG_PATH = path.resolve(__dirname, './tailwind.config.js')
Expand Down
8 changes: 3 additions & 5 deletions __tests__/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,23 @@ import path from 'node:path'

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

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

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

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

return postcss(tailwind).process(input, {
// eslint-disable-next-line unicorn/prefer-module
from: `${path.resolve(__filename)}?test=${currentTestName}`,
// @ts-expect-error -- TS thinks this file is built to CJS.
from: `${path.resolve(import.meta.filename)}?test=${currentTestName!}`,
})
}
29 changes: 14 additions & 15 deletions __tests__/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,25 @@
*/

import { diff } from 'jest-diff'
// eslint-disable-next-line import/default
import prettier from 'prettier'
import { expect } from 'vitest'

expect.extend({
async toMatchFormattedCss(received: string, argument: string) {
async function format(input: string) {
return prettier.format(input.replaceAll('\n', ''), {
parser: 'css',
printWidth: 100,
})
}
async function format(input: string) {
return prettier.format(input.replaceAll('\n', ''), {
parser: 'css',
printWidth: 120,
})
}

function stripped(value: string) {
return value
.replace(/\/\* ! tailwindcss .* \*\//, '')
.replaceAll(/\s/g, '')
.replaceAll(';', '')
}
function stripped(value: string) {
return value
.replace(/\/\*! tailwindcss .* \*\//, '')
.replaceAll(/\s/g, '')
.replaceAll(';', '')
}

expect.extend({
async toMatchFormattedCss(received: string, argument: string) {
let options = {
comment: 'stripped(received) === stripped(argument)',
isNot: this.isNot,
Expand Down
38 changes: 38 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import zazen from '@zazen/eslint-config'
import zazenNode from '@zazen/eslint-config/node'
import zazenStylistic from '@zazen/eslint-config/stylistic'
import zazenTypeScript from '@zazen/eslint-config/typescript'
import { defineConfig } from 'eslint/config'

const config = defineConfig([
...zazen,
...zazenNode,
...zazenTypeScript,

{
name: 'project:rules',
settings: {
'import-x/ignore': ['node_modules'],
node: {
version: '20',
},
},
rules: {
'import-x/no-anonymous-default-export': ['error', { allowObject: true }],
},
},
{
name: 'project:rules:configs',
files: ['**/*.config.{js,mjs}'],
rules: {
'import-x/no-extraneous-dependencies': [
'error',
{ devDependencies: true },
],
},
},

zazenStylistic,
])

export default config
Loading