Skip to content

Commit

Permalink
✨ improve(@roots/bud-eslint): eslint peer dependencies (#2229)
Browse files Browse the repository at this point in the history
## References

- #2224 
- #2222
- #2216

## Type of change

**PATCH: backwards compatible change**
  • Loading branch information
kellymears authored Apr 20, 2023
1 parent d69177c commit e0f0918
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 160 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
"@types/lodash": "4.14.192",
"@types/node": "18.15.10",
"@types/prettier": "2.7.2",
"@typescript-eslint/eslint-plugin": "5.57.0",
"@typescript-eslint/parser": "5.57.0",
"@typescript-eslint/eslint-plugin": "5.59.0",
"@typescript-eslint/parser": "5.59.0",
"@vitest/coverage-istanbul": "0.29.7",
"@vitest/ui": "0.29.7",
"eslint": "8.36.0",
"eslint": "8.38.0",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-n": "15.6.1",
"eslint-plugin-n": "15.7.0",
"eslint-plugin-react": "7.32.2",
"eslint-plugin-react-hooks": "4.6.0",
"eslint-plugin-simple-import-sort": "10.0.0",
Expand Down
18 changes: 3 additions & 15 deletions sources/@roots/bud-eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,19 @@
"types": "./lib/index.d.ts",
"module": "./lib/index.js",
"devDependencies": {
"@roots/bud": "workspace:sources/@roots/bud",
"@skypack/package-check": "0.2.2",
"@types/eslint": "8.21.3",
"@types/node": "18.15.10"
},
"dependencies": {
"@roots/bud": "workspace:sources/@roots/bud",
"@roots/bud-framework": "workspace:sources/@roots/bud-framework",
"@roots/bud-support": "workspace:sources/@roots/bud-support",
"eslint": "8.36.0",
"eslint-webpack-plugin": "4.0.0",
"eslint": "8.38.0",
"eslint-webpack-plugin": "4.0.1",
"tslib": "2.5.0",
"webpack": "5.76.3"
},
"peerDependencies": {
"@roots/bud": "*",
"eslint": "*"
},
"peerDependenciesMeta": {
"@roots/bud": {
"optional": true
},
"eslint": {
"optional": true
}
},
"volta": {
"extends": "../../../package.json"
}
Expand Down
80 changes: 41 additions & 39 deletions sources/@roots/bud-eslint/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export class BudEslint extends Extension<Options, EslintPlugin> {
*/
@bind
public override async register(bud: Bud) {
/**
* Resolve eslint
*/
this.set(`eslintPath`, await this.resolve(`eslint`, import.meta.url))

if (!bud.context.files) return
Expand All @@ -48,58 +51,57 @@ export class BudEslint extends Extension<Options, EslintPlugin> {
)

if (config) {
if (!config.module) {
switch (config.dynamic) {
case true:
config.module = await this.import(config.path, import.meta.url)
break
if (config.module) {
this.set(`overrideConfig`, config.module).set(`useEslintrc`, false)
return
}

default:
switch (config.extension) {
case `json`:
config.module = await bud.fs.json.read(config.path)
break
switch (config.dynamic) {
case true:
config.module = await this.import(config.path, import.meta.url)
break

case `yml`:
config.module = await bud.fs.yml.read(config.path)
break
default:
switch (config.extension) {
case `json`:
config.module = await bud.fs.json.read(config.path)
break

case `yaml`:
config.module = await bud.fs.yml.read(config.path)
break
case `yml`:
config.module = await bud.fs.yml.read(config.path)
break

default:
case `yaml`:
config.module = await bud.fs.yml.read(config.path)
break

default:
this.logger.warn(
`Unknown eslint config format.`,
`Please update \`${config.name}\` to use one of: js, cjs, mjs, json, yml, yaml`,
)

try {
config.module = await bud.fs.json.read(config.path)
this.logger.warn(
`Unknown eslint config format.`,
`Please update \`${config.name}\` to use one of: js, cjs, mjs, json, yml, yaml`,
`Parsed as json.`,
)

} catch (err) {
try {
config.module = await bud.fs.json.read(config.path)
config.module = await bud.fs.yml.read(config.path)
this.logger.warn(
`Unknown eslint config format.`,
`Parsed as json.`,
`Parsed as yml.`,
)
} catch (err) {
try {
config.module = await bud.fs.yml.read(config.path)
this.logger.warn(
`Unknown eslint config format.`,
`Parsed as yml.`,
)
} catch (err) {
this.logger.error(
`Unknown eslint config format.`,
`Could not parse ${config.name} as json or yml.`,
)
}
this.logger.error(
`Unknown eslint config format.`,
`Could not parse ${config.name} as json or yml.`,
)
}
}
}
}

if (config.module) {
this.set(`overrideConfig`, config.module).set(`useEslintrc`, false)
}
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions sources/@roots/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@
"@types/eslint-plugin-prettier": "^3.1.0",
"@types/node": "18.15.10",
"@types/prettier": "2.7.2",
"eslint": "8.36.0",
"eslint": "8.38.0",
"prettier": "2.8.7"
},
"dependencies": {
"@babel/eslint-parser": "7.21.3",
"@typescript-eslint/eslint-plugin": "5.57.0",
"@typescript-eslint/parser": "5.57.0",
"@typescript-eslint/eslint-plugin": "5.59.0",
"@typescript-eslint/parser": "5.59.0",
"eslint-config-prettier": "8.8.0",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-jsx-a11y": "^6.7.1",
Expand Down
Loading

0 comments on commit e0f0918

Please sign in to comment.