Skip to content

Commit

Permalink
✨ improve(@roots/bud-eslint): deprecate bud.eslint.fix (#2099)
Browse files Browse the repository at this point in the history
- deprecate `bud.eslint.fix`
- improve packaging
- update `examples/eslint`
- improve typings/intellisense: only expose to the public interface:
  - `bud.eslint.set`
  - `bud.eslint.get`
  - `bud.eslint.enable`

refers:

- #2079 

## Type of change

**PATCH: backwards compatible change**



This PR includes breaking changes to the following core packages:

- none

This PR includes breaking changes to the follow extensions:

- none

## Dependencies

### Adds

- none

### Removes

- none
  • Loading branch information
kellymears authored Feb 12, 2023
1 parent f31bad2 commit a17a32c
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 28 deletions.
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

0 comments on commit a17a32c

Please sign in to comment.