Skip to content

Commit

Permalink
fix: fix plugin configs creation
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed May 23, 2023
1 parent f26aa7f commit 559a2ce
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ type RuleSeverity = 'off' | 'warn' | 'error'

type RuleDeclaration = [RuleSeverity, { [key: string]: unknown }?]

let getRulesWithOptions = (options: {
let createConfigWithOptions = (options: {
type: SortType
order: SortOrder
}): {
[key: string]: RuleDeclaration
plugins: ['perfectionist']
rules: {
[key: string]: RuleDeclaration
}
} => {
let recommendedRules: {
[key: string]: RuleDeclaration
Expand All @@ -31,12 +34,15 @@ let getRulesWithOptions = (options: {
[sortObjectKeysName]: ['error'],
[sortUnionTypesName]: ['error'],
}
return Object.fromEntries(
Object.entries(recommendedRules).map(([key, [message, baseOptions = {}]]) => [
key,
[message, Object.assign(baseOptions, options)],
]),
)
return {
plugins: ['perfectionist'],
rules: Object.fromEntries(
Object.entries(recommendedRules).map(([key, [message, baseOptions = {}]]) => [
key,
[message, Object.assign(baseOptions, options)],
]),
),
}
}

export default {
Expand All @@ -52,15 +58,15 @@ export default {
[sortUnionTypesName]: sortUnionTypes,
},
configs: {
'recommended-alphabetical': getRulesWithOptions({
'recommended-alphabetical': createConfigWithOptions({
type: SortType.alphabetical,
order: SortOrder.asc,
}),
'recommended-natural': getRulesWithOptions({
'recommended-natural': createConfigWithOptions({
type: SortType.natural,
order: SortOrder.asc,
}),
'recommended-line-length': getRulesWithOptions({
'recommended-line-length': createConfigWithOptions({
type: SortType['line-length'],
order: SortOrder.desc,
}),
Expand Down

0 comments on commit 559a2ce

Please sign in to comment.