Skip to content

Enhancement(eslint-plugin): Export types of rules option for flat config #8571

Open
@linlinyang

Description

@linlinyang

Before You File a Proposal Please Confirm You Have Done The Following...

Description

I hope I can define ts lint rules in my flat eslint.config.ts which will be compared to eslint.config.js like this:

import type { Linter } from 'eslint';
import type {ruleOptions} from '@typescript-eslint/eslint-plugin';

type TSRules = {
  [K in keyof ruleOptions]?: Linter.RuleEntry<ruleOptions[K]>;
};
// Than those rules has hints
const rules: TSRules = {
  'accessor-pairs': 'error',
  'array-type': ['error', {
     readonly: 'array'
   }]
};

And It helpful for define rule with prefix:

import type { Linter } from 'eslint';
import type {ruleOptions} from '@typescript-eslint/eslint-plugin';

type TSRules = {
  [K in keyof ruleOptions as `ts/${K}`]?: Linter.RuleEntry<ruleOptions[K]>;
};
// Than those rules has hints
const rules: TSRules = {
  'ts/accessor-pairs': 'error',
  'ts/array-type': ['error', {
     readonly: 'array'
   }]
};

In use of:

import type { Linter } from 'eslint';
import parseTs from '@typescript-eslint/parser';
import pluginTs from '@typescript-eslint/eslint-plugin';

const flatconfig: Linter.FlatConfig[] = [{
  plugins: {
    ts: pluginTs as any
  },
  files: ['**/*.?([cm])ts'],
  languageOptions: {
    parser: parseTs as any,
    parserOptions: {
      project: true,
      sourceType: 'module',
      // extraFileExtensions: ['.vue']
    }
  },
  
  rules: {
    ...rules
  }
}]

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginteam assignedA member of the typescript-eslint team should work on this.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions