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: support Flat ESLint config #1147

Merged
merged 1 commit into from
Aug 20, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .README/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,31 @@ npm install --save-dev eslint-plugin-jsdoc

## Configuration

### Flat config

```js
import jsdoc from 'eslint-plugin-jsdoc';

const config = [
// configuration included in plugin
jsdoc.configs['flat/recommended'],
// other configuration objects...
{
files: ['**/*.js'],
plugins: {
jsdoc,
},
rules: {
'jsdoc/require-description': 'warn'
}
}
];

export default config;
```

### `eslintrc`

Add `plugins` section to [.eslintrc.*](https://eslint.org/docs/user-guide/configuring#configuration-file-formats)
and specify `eslint-plugin-jsdoc` as a plugin.

Expand Down
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ JSDoc linting rules for ESLint.
* [eslint-plugin-jsdoc](#user-content-eslint-plugin-jsdoc)
* [Installation](#user-content-eslint-plugin-jsdoc-installation)
* [Configuration](#user-content-eslint-plugin-jsdoc-configuration)
* [Flat config](#user-content-eslint-plugin-jsdoc-configuration-flat-config)
* [`eslintrc`](#user-content-eslint-plugin-jsdoc-configuration-eslintrc)
* [Options](#user-content-eslint-plugin-jsdoc-options)
* [Settings](#user-content-eslint-plugin-jsdoc-settings)
* [Advanced](#user-content-eslint-plugin-jsdoc-advanced)
Expand Down Expand Up @@ -40,6 +42,35 @@ npm install --save-dev eslint-plugin-jsdoc
<a name="eslint-plugin-jsdoc-configuration"></a>
## Configuration

<a name="user-content-eslint-plugin-jsdoc-configuration-flat-config"></a>
<a name="eslint-plugin-jsdoc-configuration-flat-config"></a>
### Flat config

```js
import jsdoc from 'eslint-plugin-jsdoc';

const config = [
// configuration included in plugin
jsdoc.configs['flat/recommended'],
// other configuration objects...
{
files: ['**/*.js'],
plugins: {
jsdoc,
},
rules: {
'jsdoc/require-description': 'warn'
}
}
];

export default config;
```

<a name="user-content-eslint-plugin-jsdoc-configuration-eslintrc"></a>
<a name="eslint-plugin-jsdoc-configuration-eslintrc"></a>
### <code>eslintrc</code>

Add `plugins` section to [.eslintrc.*](https://eslint.org/docs/user-guide/configuring#configuration-file-formats)
and specify `eslint-plugin-jsdoc` as a plugin.

Expand Down
32 changes: 22 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import validTypes from './rules/validTypes.js';

/**
* @type {import('eslint').ESLint.Plugin & {
* configs: Record<string, import('eslint').ESLint.ConfigData>
* configs: Record<string, import('eslint').ESLint.ConfigData|{}>
* }}
*/
const index = {
Expand Down Expand Up @@ -118,11 +118,14 @@ const index = {

/**
* @param {"warn"|"error"} warnOrError
* @returns {import('eslint').ESLint.ConfigData}
* @param {boolean} [flat]
* @returns {import('eslint').ESLint.ConfigData | {plugins: {}, rules: {}}}
*/
const createRecommendedRuleset = (warnOrError) => {
const createRecommendedRuleset = (warnOrError, flat) => {
return {
plugins: [
plugins: flat ? {
jsdoc: index,
} : [
'jsdoc',
],
rules: {
Expand Down Expand Up @@ -185,10 +188,11 @@ const createRecommendedRuleset = (warnOrError) => {

/**
* @param {"warn"|"error"} warnOrError
* @returns {import('eslint').ESLint.ConfigData}
* @param {boolean} [flat]
* @returns {import('eslint').ESLint.ConfigData|{}}
*/
const createRecommendedTypeScriptRuleset = (warnOrError) => {
const ruleset = createRecommendedRuleset(warnOrError);
const createRecommendedTypeScriptRuleset = (warnOrError, flat) => {
const ruleset = createRecommendedRuleset(warnOrError, flat);

return {
...ruleset,
Expand All @@ -212,10 +216,11 @@ const createRecommendedTypeScriptRuleset = (warnOrError) => {

/**
* @param {"warn"|"error"} warnOrError
* @returns {import('eslint').ESLint.ConfigData}
* @param {boolean} [flat]
* @returns {import('eslint').ESLint.ConfigData|{}}
*/
const createRecommendedTypeScriptFlavorRuleset = (warnOrError) => {
const ruleset = createRecommendedRuleset(warnOrError);
const createRecommendedTypeScriptFlavorRuleset = (warnOrError, flat) => {
const ruleset = createRecommendedRuleset(warnOrError, flat);

return {
...ruleset,
Expand All @@ -240,4 +245,11 @@ index.configs['recommended-typescript-error'] = createRecommendedTypeScriptRules
index.configs['recommended-typescript-flavor'] = createRecommendedTypeScriptFlavorRuleset('warn');
index.configs['recommended-typescript-flavor-error'] = createRecommendedTypeScriptFlavorRuleset('error');

index.configs['flat/recommended'] = createRecommendedRuleset('warn', true);
index.configs['flat/recommended-error'] = createRecommendedRuleset('error', true);
index.configs['flat/recommended-typescript'] = createRecommendedTypeScriptRuleset('warn', true);
index.configs['flat/recommended-typescript-error'] = createRecommendedTypeScriptRuleset('error', true);
index.configs['flat/recommended-typescript-flavor'] = createRecommendedTypeScriptFlavorRuleset('warn', true);
index.configs['flat/recommended-typescript-flavor-error'] = createRecommendedTypeScriptFlavorRuleset('error', true);

export default index;
Loading