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

✨ improve(@roots/bud-eslint): deprecate bud.eslint.fix #2099

Merged
merged 5 commits into from
Feb 12, 2023
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
7 changes: 6 additions & 1 deletion examples/eslint/bud.config.cjs
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
module.exports = async bud => bud.template().entry('app', 'app.js')
module.exports = async bud => {
bud
.html()
.entry('app', 'app.js')
.eslint.set(`fix`, true)
}
2 changes: 1 addition & 1 deletion examples/eslint/src/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const target = document.querySelector('body')
target.innerHTML = `
<div>
<h1>Hello from esbuild!</h1>
<h1>Hello</h1>
</div>
`
21 changes: 15 additions & 6 deletions sources/@roots/bud-eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
},
"keywords": [
"bud",
"bud-extension",
"eslint"
],
"engines": {
Expand All @@ -41,11 +40,15 @@
"src"
],
"type": "module",
"module": "./lib/index.js",
"types": "./lib/index.d.ts",
"exports": {
".": "./lib/index.js",
"./extension": "./lib/extension.js"
".": {
"types": "./lib/index.d.ts",
"default": "./lib/index.js"
},
"./extension": {
"types": "./lib/extension.d.ts",
"default": "./lib/extension.js"
}
},
"typesVersions": {
"*": {
Expand All @@ -57,6 +60,8 @@
]
}
},
"module": "./lib/index.js",
"types": "./lib/index.d.ts",
"devDependencies": {
"@roots/bud": "workspace:sources/@roots/bud",
"@skypack/package-check": "0.2.2",
Expand All @@ -72,14 +77,18 @@
},
"peerDependencies": {
"@roots/bud": "*",
"eslint": "*"
"eslint": "*",
"eslint-webpack-plugin": "*"
},
"peerDependenciesMeta": {
"@roots/bud": {
"optional": true
},
"eslint": {
"optional": true
},
"eslint-webpack-plugin": {
"optional": true
}
},
"volta": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class BudEslintCommand extends BudCommand {
)

if (!this.options?.length)
this.options = [this.bud.path(`@src`, `**/*.{ts,tsx,js,jsx}`)]
this.options = [this.bud.path(`@src`, `**`, `*.{ts,tsx,js,jsx}`)]

await this.$(this.bin, [eslint, ...this.options])
}
Expand Down
21 changes: 5 additions & 16 deletions sources/@roots/bud-eslint/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ import EslintPlugin from 'eslint-webpack-plugin'

/**
* Eslint webpack plugin adapter
*
* @public
* @decorator `@label`
* @decorator `@expose`
* @decorator `@plugin`
* @decorator `@options`
*/
@label(`@roots/bud-eslint`)
@expose(`eslint`)
Expand All @@ -29,36 +23,31 @@ import EslintPlugin from 'eslint-webpack-plugin'
resolvePluginsRelativeTo: app => app.context.basedir,
threads: false,
})
export default class BudEslint extends Extension<Options, EslintPlugin> {
export class BudEslint extends Extension<Options, EslintPlugin> {
/**
* `register` callback
*
* @public
* @decorator `@bind`
*/
@bind
public override async register(bud: Bud) {
const eslintPath = await this.resolve(`eslint`)
this.setOption(`eslintPath`, eslintPath)
this.set(`eslintPath`, await this.resolve(`eslint`))

const findFlatConfig = ({name}) => name.includes(`eslint.config`)

const userConfigs = Object.values(bud.context.config)
if (!userConfigs.some(findFlatConfig)) return

const flatConfig = userConfigs.find(findFlatConfig)
this.setOption(`baseConfig`, flatConfig.module)
this.set(`baseConfig`, flatConfig.module)
}

/**
* auto-fix rule violations
*
* @public
* @decorator `@bind`
* @deprecated - Use `bud.eslint.set('fix', true)` instead.
*/
@bind
public fix(fix: boolean = true): this {
this.setOption(`fix`, fix)
this.set(`fix`, fix)
return this
}
}
2 changes: 1 addition & 1 deletion sources/@roots/bud-eslint/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

import './types.js'

import BudEslint from './extension.js'
import {BudEslint} from './extension.js'
export default BudEslint
8 changes: 6 additions & 2 deletions sources/@roots/bud-eslint/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
/// <reference types="@roots/bud" />

import type BudEslint from './extension.js'
import type {BudEslint} from './extension.js'

declare module '@roots/bud-framework' {
interface Bud {
eslint: BudEslint
eslint: {
enable: BudEslint[`enable`]
get: BudEslint[`get`]
set: BudEslint[`set`]
}
}

interface Modules {
Expand Down
3 changes: 3 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7266,11 +7266,14 @@ __metadata:
peerDependencies:
"@roots/bud": "*"
eslint: "*"
eslint-webpack-plugin: "*"
peerDependenciesMeta:
"@roots/bud":
optional: true
eslint:
optional: true
eslint-webpack-plugin:
optional: true
languageName: unknown
linkType: soft

Expand Down