Skip to content

Commit

Permalink
feat: optionally detect tsconfig. close #12.
Browse files Browse the repository at this point in the history
  • Loading branch information
lvjiaxuan committed Feb 10, 2024
1 parent 67faf30 commit f009507
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 5 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All rules inherit from [@antfu/eslint-config](https://github.com/antfu/eslint-co

# Features
1. Add my [@lvjiaxuan/eslint-plugin](https://github.com/lvjiaxuan/eslint-config/blob/main/packages/eslint-plugin/src/index.ts).
2. Try to detect `tsconfig.json` if TypeScript is enabled, which means enabling type-aware rules.
2. Support auto-detect `tsconfig.json` by default if TypeScript is enabled, which means enabling type-aware rules.
3. Add my [eslint-plugin-oxlint](https://github.com/lvjiaxuan/eslint-config/tree/main/packages/eslint-plugin-oxlint/src/index.ts).

> [!NOTE]
Expand All @@ -15,6 +15,19 @@ All rules inherit from [@antfu/eslint-config](https://github.com/antfu/eslint-co

Follow [antfu's](https://github.com/antfu/eslint-config).

## Disable `tsconfig.json` auto-detected

```js
// eslint.config.js
import lv from '@lvjiaxuan/eslint-config'

export default lv({
typescript: {
notDetectTsconfig: true
}
})
```

## With [OXLint](https://github.com/oxc-project/oxc#-linter)

> Aim to improve lint performance.
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"pnpm": {
"patchedDependencies": {
"@antfu/eslint-config@2.6.4": "patches/@antfu__eslint-config@2.6.4.patch"
}
},
"simple-git-hooks": {
"pre-commit": [
"npx lint-staged"
Expand Down
15 changes: 15 additions & 0 deletions patches/@antfu__eslint-config@2.6.4.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/dist/index.d.ts b/dist/index.d.ts
index 089791f9291a88889e5238f9c229380eeb8fa5fa..3303a09743f7b6177abd52d41f84011aedc70403 100644
--- a/dist/index.d.ts
+++ b/dist/index.d.ts
@@ -216,6 +216,10 @@ interface OptionsTypeScriptWithTypes {
* @see https://typescript-eslint.io/linting/typed-linting/
*/
tsconfigPath?: string | string[];
+ /**
+ * Don't `tsconfigPath` anyway.
+ */
+ notDetectTsconfig?: boolean
}
interface OptionsHasTypeScript {
typescript?: boolean;
14 changes: 12 additions & 2 deletions pnpm-lock.yaml

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

9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ const lv: (...args: _Params) => ReturnType<Antfu> = async (...args) => {
let tsOptions = args[0]?.typescript

let isUseDetect = false
// Overwrite with detected `tsconfigPath` if no-set.
if (typeof tsOptions === 'object') {
if (!Object.hasOwn(tsOptions, 'tsconfigPath')) {
if ('notDetectTsconfig' in tsOptions && tsOptions.notDetectTsconfig === true) {
// Do nothing.
}
else if (!Object.hasOwn(tsOptions, 'tsconfigPath')) {
// Overwrite with detected `tsconfigPath` if no-set.
(tsOptions as OptionsTypeScriptWithTypes).tsconfigPath = await detectTsconfigPath()
isUseDetect = true
}

// Use settings.
}
else {
// @ts-expect-error typescript = true means {} .
Expand Down

0 comments on commit f009507

Please sign in to comment.