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

Migrate to ESLint flat config #212

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
37 changes: 0 additions & 37 deletions .eslintrc.cjs

This file was deleted.

43 changes: 43 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import zazen from '@zazen/eslint-config'
import zazenNode from '@zazen/eslint-config/node'

/** @type {import('eslint').Linter.Config[]} */
const config = [
{ ignores: ['**/dist', '**/__tests__/*-errors.js'] },
...zazen,
...zazenNode,
{
name: 'project:base',
settings: {
'import-x/ignore': ['node_modules'],
node: {
version: '20',
},
},
rules: {
// Deprecated rule.
'no-return-await': 'off',
'import-x/no-anonymous-default-export': [
'error',
{ allowObject: true },
],
},
},
{
name: 'project:tests',
files: ['**/__tests__/**/*.?(m|c)js'],
ignores: ['**/__tests__/*-errors.js'],
rules: {
'import-x/no-extraneous-dependencies': 'off',
},
},
{
name: 'project:configs',
files: ['**/eslint.config.js'],
rules: {
'import-x/no-extraneous-dependencies': 'off',
},
},
]

export default config
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"devDependencies": {
"@changesets/cli": "2.27.1",
"@zazen/eslint-config": "workspace:*",
"eslint": "8.56.0",
"eslint": "9.0.0",
"husky": "8.0.3",
"lint-staged": "15.2.0",
"prettier": "3.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Install the conventions by running:

```shell
```sh
npm install --save-dev eslint @zazen/eslint-config
```

Expand Down
13 changes: 13 additions & 0 deletions packages/eslint-config/__tests__/base-errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { bar } from './node-errors'
import { dirname } from 'node:path'

function q() {
const foo = 'FOO'
if (foo !== 'FOO') {
return bar + dirname(import.meta.url)
} else {
return foo + bar + dirname(import.meta.url)
}
}

export const foo = 'foo'
51 changes: 51 additions & 0 deletions packages/eslint-config/__tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { readFile } from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

import configBase from '../configs/index.js'
import configNode from '../configs/node.js'
import { ESLint } from 'eslint'
import { describe, expect, it } from 'vitest'

const __dirname = path.dirname(fileURLToPath(import.meta.url))

const CONFIG_MAP = {
base: {
config: configBase,
errors: ['prefer-let/prefer-let', 'unicorn/prefer-ternary'],
},
node: {
config: configNode,
errors: ['n/no-deprecated-api', 'import-x/extensions'],
},
}

function hasRule(errors, ruleId) {
return errors.some((error) => error.ruleId === ruleId)
}

async function runEslint(string, config) {
let linter = new ESLint({
overrideConfig: config,
})

let [firstResult] = await linter.lintText(string, {
filePath: 'test-file.js',
})

return firstResult.messages
}

describe.each(['base', 'node'])('%s config', (config) => {
it('reports expected errors', async () => {
let code = await readFile(
path.resolve(__dirname, `./${config}-errors.js`),
'utf8',
)
let errors = await runEslint(code, CONFIG_MAP[config].config)

for (let rule of CONFIG_MAP[config].errors) {
expect(hasRule(errors, rule), JSON.stringify(errors)).toBeTruthy()
}
})
})
7 changes: 7 additions & 0 deletions packages/eslint-config/__tests__/node-errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import fs from 'fs'

import { foo } from './base-errors'

fs.exists('./foo.js')

export const bar = 'bar'
66 changes: 0 additions & 66 deletions packages/eslint-config/__tests__/test.mjs

This file was deleted.

Loading
Loading