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

feat(ts): can change tsconfig by env #136

Merged
merged 3 commits into from Dec 12, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Expand Up @@ -57,7 +57,16 @@ Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?it

### TypeScript Aware Rules

Type aware rules are enabled when a `tsconfig.eslint.json` is found in the project root. Refer to [this file](https://github.com/antfu/eslint-config/blob/main/packages/typescript/index.js#L17).
Type aware rules are enabled when a `tsconfig.eslint.json` is found in the project root. If you want to enable it while have no `tsconfig.eslint.json` in the project root, you can change tsconfig name by modifying `ESLINT_TSCONFIG` env.

```js
// .eslintrc.js
process.env.ESLINT_TSCONFIG = 'tsconfig.json'

module.exports = {
extends: '@antfu'
}
```

## Extended Reading

Expand Down
6 changes: 4 additions & 2 deletions packages/typescript/index.js
Expand Up @@ -2,6 +2,8 @@ const fs = require('fs')
const { join } = require('path')
const basic = require('@antfu/eslint-config-basic')

const tsconfig = process.env.ESLINT_TSCONFIG || 'tsconfig.eslint.json'

module.exports = {
extends: [
'@antfu/eslint-config-basic',
Expand All @@ -14,12 +16,12 @@ module.exports = {
},
},
overrides: basic.overrides.concat(
!fs.existsSync(join(process.cwd(), 'tsconfig.eslint.json'))
!fs.existsSync(join(process.cwd(), tsconfig))
? []
: [{
parserOptions: {
tsconfigRootDir: process.cwd(),
project: ['tsconfig.eslint.json'],
project: [tsconfig],
},
parser: '@typescript-eslint/parser',
excludedFiles: ['**/*.md/*.*'],
Expand Down