Skip to content

Commit

Permalink
docs(changeset): feat: add nailyProxy() function to proxy eslint conf…
Browse files Browse the repository at this point in the history
…ig to naily.config.ts
  • Loading branch information
nailiable committed Nov 5, 2024
1 parent f5353a7 commit 4e8a0a3
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/forty-parents-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nailyjs/eslint": patch
---

feat: add nailyProxy() function to proxy eslint config to naily.config.ts
15 changes: 2 additions & 13 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
// @ts-check
import naily from '@nailyjs/eslint'
import { nailyProxy } from '@nailyjs/eslint'

export default naily({
type: 'lib',
rules: {
'antfu/curly': 'off',
'antfu/if-newline': 'off',
'ts/method-signature-style': 'off',
'ts/no-wrapper-object-types': 'off',
'no-console': 'off',
'unicorn/throw-new-error': 'off',
},
})
export default await nailyProxy()
12 changes: 12 additions & 0 deletions naily.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ export default defineConfig({
naily: {
cli: {},

eslint: {
type: 'lib',
rules: {
'antfu/curly': 'off',
'antfu/if-newline': 'off',
'ts/method-signature-style': 'off',
'ts/no-wrapper-object-types': 'off',
'no-console': 'off',
'unicorn/throw-new-error': 'off',
},
},

typeorm: {
type: 'sqlite',
database: path.join(cwd(), './node_modules/.cache/naily/typeorm.db'),
Expand Down
4 changes: 3 additions & 1 deletion packages/eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"prepublishOnly": "tsup"
},
"dependencies": {
"@antfu/eslint-config": "^3.8.0"
"@antfu/eslint-config": "^3.8.0",
"@nailyjs/config": "workspace:*",
"@nailyjs/ioc": "workspace:*"
},
"devDependencies": {
"tsup": "^8.3.0"
Expand Down
42 changes: 42 additions & 0 deletions packages/eslint/src/eslint-bootstrap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import antfu from '@antfu/eslint-config'
import { Value } from '@nailyjs/config'
import { AbstractBootstrap, ClassWrapper, Container, Injectable } from '@nailyjs/ioc'

@Injectable()
export class EslintService {
constructor(
@Value('naily.eslint')
private readonly value: Naily.Configuration.NailyUserConfig['eslint'],
) {}

getEslintConfig(): Parameters<typeof antfu> {
return [
(this.value || {}),
...((this.value || {}).extraOptions || []),
]
}

static getInstance(container: Container): EslintService {
const wrapper = container.getContainer().get(EslintService) as ClassWrapper<EslintService>
if (!wrapper) return container.createClassWrapper(EslintService).getClassFactory().getOrCreateInstance()
return wrapper.getClassFactory().getOrCreateInstance()
}
}

export class ESLintBootstrap extends AbstractBootstrap {
async run(): Promise<ReturnType<typeof antfu>> {
await this.getPluginRunner().runBeforeRun()
const args = EslintService.getInstance(this).getEslintConfig()

return antfu({
...args[0],
rules: {
'ts/method-signature-style': 'off',
'ts/consistent-type-imports': 'off',
'ts/no-redeclare': 'off',
'ts/no-namespace': 'off',
...(args[0] || {}).rules,
},
}, ...args.slice(1))
}
}
8 changes: 8 additions & 0 deletions packages/eslint/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import antfu from '@antfu/eslint-config'
import { ConfigPlugin } from '@nailyjs/config'
import { ESLintBootstrap } from './eslint-bootstrap'

export function naily(...args: Parameters<typeof antfu>): ReturnType<typeof antfu> {
return antfu({
Expand All @@ -13,4 +15,10 @@ export function naily(...args: Parameters<typeof antfu>): ReturnType<typeof antf
}, ...args.slice(1))
}

export async function nailyProxy(): Promise<ReturnType<typeof antfu>> {
return await new ESLintBootstrap()
.use(ConfigPlugin())
.run()
}

export default naily
13 changes: 13 additions & 0 deletions packages/eslint/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import antfu from '@antfu/eslint-config'

declare global {
namespace Naily {
namespace Configuration {
interface NailyUserConfig {
eslint?: Parameters<typeof antfu>[0] & {
extraOptions?: Array<Parameters<typeof antfu>[1]>
}
}
}
}
}
2 changes: 2 additions & 0 deletions packages/eslint/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"compilerOptions": {
"target": "ES2022",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"module": "ES2022",
"moduleResolution": "Bundler"
},
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4e8a0a3

Please sign in to comment.