Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eslint-types/eslint-define-config
Provide a defineConfig function for .eslintrc.js files
https://github.com/eslint-types/eslint-define-config
config configuration define-config eslint eslint-config eslintconfig typed typescript
Last synced: about 1 month ago
JSON representation
Provide a defineConfig function for .eslintrc.js files
- Host: GitHub
- URL: https://github.com/eslint-types/eslint-define-config
- Owner: eslint-types
- License: mit
- Created: 2021-03-24T12:33:11.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-12T05:12:59.000Z (7 months ago)
- Last Synced: 2024-04-13T14:41:03.583Z (7 months ago)
- Topics: config, configuration, define-config, eslint, eslint-config, eslintconfig, typed, typescript
- Language: TypeScript
- Homepage:
- Size: 3.4 MB
- Stars: 331
- Watchers: 4
- Forks: 25
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# eslint-define-config
Provide a `defineConfig` function for `.eslintrc.js`, and a `defineFlatConfig` function for `eslint.config.js` files.
# Installation
```bash
# add eslint and eslint-define-config to project’s dev dependencies
npm add --save-dev eslint eslint-define-config
# or
yarn add --dev eslint eslint-define-config
# or
pnpm add --save-dev eslint eslint-define-config
```# Usage
By default only `eslint`'s rules are supported. To activate auto-suggestions for Rules of specific plugins, you need to install the respective types for that plugin.
Plugins can either support their own types, or they could be supported by the community in the [`@eslint-types`](https://github.com/eslint-types/define-config-plugin-types) repository.A list of community supported plugins can be found [here](https://www.npmjs.com/org/eslint-types).
`.eslintrc.js`
```ts
// @ts-check
const { defineConfig } = require('eslint-define-config');///
module.exports = defineConfig({
root: true,
rules: {
// rules...
},
});
```## Flat Config
`eslint.config.js`
```ts
// @ts-check
const { defineFlatConfig } = require('eslint-define-config');
const js = require('@eslint/js');
const customConfig = require('./custom-config.js');///
module.exports = defineFlatConfig([
js.configs.recommended,
customConfig,
{
plugins: {
// plugins...
},
rules: {
// rules...
},
},
]);
```# Why?
Improve your eslint configuration experience with:
- auto-suggestions
- type checking (Use `// @ts-check` at the first line in your `.eslintrc.js` or `eslint.config.js`)
- documentation
- deprecation warnings## Video
_Click on the thumbnail to play the video_
## Want to support your own plugin?
:warning: **This feature is very new and requires the support of the respective plugin owners**
Add a `declare module` to your plugin package like this:
```ts
declare module 'eslint-define-config' {
export interface CustomRuleOptions {
/**
* Require consistently using either `T[]` or `Array` for arrays.
*
* @see [array-type](https://typescript-eslint.io/rules/array-type)
*/
'@typescript-eslint/array-type': [
{
default?: 'array' | 'generic' | 'array-simple';
readonly?: 'array' | 'generic' | 'array-simple';
},
];// ... more Rules
}
}
```There are other interfaces that can be extended.
- `CustomExtends`
- `CustomParserOptions`
- `CustomParsers`
- `CustomPlugins`
- `CustomSettings`# Credits
- [Proposal Idea](https://github.com/eslint/eslint/issues/14249)
- [Vite](https://github.com/vitejs/vite) and [Evan You](https://github.com/yyx990803) for the idea
- [@antfu](https://github.com/antfu) and his [tweet](https://twitter.com/antfu7/status/1365907188338753536)