Skip to content

Commit

Permalink
[#43] 👽️ Convert ts to flat config
Browse files Browse the repository at this point in the history
  • Loading branch information
yongholeeme committed Dec 20, 2024
1 parent 2173ea8 commit 1f6755d
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 158 deletions.
30 changes: 30 additions & 0 deletions packages/eslint-config/configs/typescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import globals from 'globals'

import recommends from '../recommends/index.js'
import recommendsReact from '../recommends/react.js'
import recommendsTypescript from '../recommends/typescript.js'
import rulesFront from '../rules/front/index.js'
import rulesTypescript from '../rules/typescript/index.js'

export default [
...recommends,
...recommendsReact,
...recommendsTypescript,
...rulesFront,
rulesTypescript,
{
languageOptions: {
globals: {
...globals.node,
...globals.browser,
...globals.jest,
},
},
},
{
files: ['*.js', '*.jsx'],
rules: {
'no-undef': 'error',
},
},
]
2 changes: 2 additions & 0 deletions packages/eslint-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'node:fs'

import node from './configs/node.js'
import front from './configs/front.js'
import typescript from './configs/typescript.js'

const pkg = JSON.parse(fs.readFileSync(new URL('./package.json', import.meta.url), 'utf8'))

Expand All @@ -13,5 +14,6 @@ export default {
configs: {
node,
front,
typescript,
},
}
4 changes: 2 additions & 2 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.15.0",
"@naverpay/eslint-plugin": "workspace:*",
"@typescript-eslint/eslint-plugin": ">=7",
"@typescript-eslint/parser": ">=7",
"@typescript-eslint/eslint-plugin": ">=8",
"@typescript-eslint/parser": ">=8",
"eslint": ">=9",
"eslint-config-eslint": "^7.0.0",
"eslint-config-prettier": "^9.1.0",
Expand Down
19 changes: 13 additions & 6 deletions packages/eslint-config/recommends/typescript.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
module.exports = {
extends: [
'plugin:@typescript-eslint/recommended', // https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/recommended.ts
'plugin:@typescript-eslint/stylistic', // https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/stylistic.ts
],
}
import {FlatCompat} from '@eslint/eslintrc'
import path from 'path'
import {fileURLToPath} from 'url'

// mimic CommonJS variables -- not needed if using CommonJS
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

const compat = new FlatCompat({
baseDirectory: __dirname,
})

export default [...compat.extends('plugin:@typescript-eslint/recommended', 'plugin:@typescript-eslint/stylistic')]
9 changes: 6 additions & 3 deletions packages/eslint-config/rules/typescript/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const {typescriptNamingConvention} = require('../../custom')
import typescriptPlugin from '@typescript-eslint/eslint-plugin'
import {typescriptNamingConvention} from '../../custom/index.js'

module.exports = {
plugins: ['@naverpay/eslint-plugin'],
export default {
plugins: {
'@typescript-eslint': typescriptPlugin,
},
rules: {
/** Require let or const instead of var
@see https://eslint.org/docs/latest/rules/no-var */
Expand Down
5 changes: 3 additions & 2 deletions packages/eslint-config/tests/typescript.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const config = require('../typescript')
const {checkErrorRule, createLinter} = require('./utils')
import {describe, test, expect} from 'vitest'
import config from '../configs/typescript.js'
import {checkErrorRule, createLinter} from './utils/index.js'

describe('typescript', () => {
describe('@typescript-eslint/naming-convention', function () {
Expand Down
23 changes: 0 additions & 23 deletions packages/eslint-config/typescript/index.js

This file was deleted.

Loading

0 comments on commit 1f6755d

Please sign in to comment.