Skip to content

Commit

Permalink
refactor: some dedupe of plugin names
Browse files Browse the repository at this point in the history
  • Loading branch information
mightyiam committed Nov 9, 2024
1 parent d1ca57c commit 0c29575
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 27 deletions.
16 changes: 3 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { TSESLint } from '@typescript-eslint/utils'
import { parser, plugin as tseslintPlugin } from 'typescript-eslint'
import eslintCommentsPlugin from 'eslint-plugin-eslint-comments'
import importPlugin from 'eslint-plugin-import'
import nPlugin from 'eslint-plugin-n'
import promisePlugin from 'eslint-plugin-promise'
import { rules } from './rules.js'
import { parser } from 'typescript-eslint'
import { rules, plugins } from './rules.js'

const eslintRuleNames = [
...new TSESLint.Linter({ configType: 'eslintrc' }).getRules().keys(),
Expand All @@ -25,13 +21,7 @@ const config: TSESLint.FlatConfig.Config = {
projectService: true,
},
},
plugins: {
'@typescript-eslint': tseslintPlugin,
'eslint-comments': eslintCommentsPlugin,
import: importPlugin,
n: nPlugin,
promise: promisePlugin,
},
plugins,
rules: {
...Object.fromEntries(
namesOfEslintRulesForWhichWeAreUsingTsEquivalents.map((name) => [
Expand Down
15 changes: 13 additions & 2 deletions src/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import promiseRules from './rules/promise.js'
import typescriptEslint from './rules/typescript-eslint.js'
import importRules from './rules/import.js'

export interface PluginRuleEntries {
export interface PluginUsage {
pluginName: string
plugin: TSESLint.FlatConfig.Plugin | 'eslint'
rules: Record<string, TSESLint.SharedConfig.RuleEntry>
}

const imports: PluginRuleEntries[] = [
const imports: PluginUsage[] = [
typescriptEslint,
eslintCommentsRules,
eslintRules,
Expand All @@ -38,3 +39,13 @@ const ruleEntries: Array<[string, TSESLint.SharedConfig.RuleEntry]> =

export const rules: Record<string, TSESLint.SharedConfig.RuleEntry> =
Object.fromEntries(ruleEntries)

export const plugins: Record<string, TSESLint.FlatConfig.Plugin> =
Object.fromEntries(
imports
.filter(({ plugin }) => plugin !== 'eslint')
.map(({ pluginName, plugin }) => [
pluginName,
plugin as TSESLint.FlatConfig.Plugin,
]),
)
6 changes: 4 additions & 2 deletions src/rules/eslint-comments.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { PluginRuleEntries } from '../rules.js'
import plugin from 'eslint-plugin-eslint-comments'
import type { PluginUsage } from '../rules.js'

const rules: PluginRuleEntries = {
const rules: PluginUsage = {
pluginName: 'eslint-comments',
plugin,
rules: {
'require-description': [
'error',
Expand Down
5 changes: 3 additions & 2 deletions src/rules/eslint.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { PluginRuleEntries } from '../rules.js'
import type { PluginUsage } from '../rules.js'

const rules: PluginRuleEntries = {
const rules: PluginUsage = {
pluginName: '',
plugin: 'eslint',
rules: {
'accessor-pairs': [
'error',
Expand Down
6 changes: 4 additions & 2 deletions src/rules/import.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { PluginRuleEntries } from '../rules.js'
import plugin from 'eslint-plugin-import'
import type { PluginUsage } from '../rules.js'

const rules: PluginRuleEntries = {
const rules: PluginUsage = {
pluginName: 'import',
plugin,
rules: {
export: ['error'],
first: ['error'],
Expand Down
6 changes: 4 additions & 2 deletions src/rules/n.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { PluginRuleEntries } from '../rules.js'
import plugin from 'eslint-plugin-n'
import type { PluginUsage } from '../rules.js'

const rules: PluginRuleEntries = {
const rules: PluginUsage = {
pluginName: 'n',
plugin,
rules: {
'handle-callback-err': ['error', '^(err|error)$'],
'no-callback-literal': ['error'],
Expand Down
6 changes: 4 additions & 2 deletions src/rules/promise.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { PluginRuleEntries } from '../rules.js'
import plugin from 'eslint-plugin-promise'
import type { PluginUsage } from '../rules.js'

const rules: PluginRuleEntries = {
const rules: PluginUsage = {
pluginName: 'promise',
plugin,
rules: {
'param-names': ['error'],
},
Expand Down
6 changes: 4 additions & 2 deletions src/rules/typescript-eslint.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { PluginRuleEntries } from '../rules.js'
import type { PluginUsage } from '../rules.js'
import { plugin } from 'typescript-eslint'

const rules: PluginRuleEntries = {
const rules: PluginUsage = {
pluginName: '@typescript-eslint',
plugin,
rules: {
'adjacent-overload-signatures': ['error'],
'array-type': ['error', { default: 'array-simple' }],
Expand Down

0 comments on commit 0c29575

Please sign in to comment.