Skip to content

Commit

Permalink
fix more issues
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Jan 10, 2023
1 parent 2079dd4 commit 3f22656
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 23 deletions.
26 changes: 10 additions & 16 deletions lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,9 @@ export type RuleModule = TSESLint.RuleModule<'', []> & {
meta: { hasSuggestions?: boolean; docs: { recommendedConfig?: 'error' | 'warn' } }
}

type RecommendedConfig<TOptions extends readonly unknown[]> =
| TSESLint.RuleMetaDataDocs['recommended']
| [TSESLint.RuleMetaDataDocs['recommended'], ...TOptions]

// These 2 types are copied from @typescript-eslint/experimental-utils' CreateRuleMeta
// and modified to our needs
export type StorybookRuleMetaDocs<TOptions extends readonly unknown[]> = Omit<
TSESLint.RuleMetaDataDocs,
'url'
> & {
export type StorybookRuleMetaDocs = Omit<TSESLint.RuleMetaDataDocs, 'url'> & {
/**
* Whether or not this rule should be excluded from linter config
*/
Expand All @@ -24,20 +17,21 @@ export type StorybookRuleMetaDocs<TOptions extends readonly unknown[]> = Omit<
*/
categories?: CategoryId[]
}
export type StorybookRuleMeta<
TMessageIds extends string,
TOptions extends readonly unknown[]
> = Omit<TSESLint.RuleMetaData<TMessageIds>, 'docs'> & {
docs: StorybookRuleMetaDocs<TOptions>

export type StorybookRuleMeta<TMessageIds extends string> = Omit<
TSESLint.RuleMetaData<TMessageIds>,
'docs'
> & {
docs: StorybookRuleMetaDocs
}

// const docs: StorybookRuleMetaDocs<any> = {
// recommended: true,
// Comment out for testing purposes:
// const docs: StorybookRuleMetaDocs = {
// description: 'bla',
// recommended: 'error',
// }

// const meta: StorybookRuleMeta<'someId', any> = {
// const meta: StorybookRuleMeta<'someId'> = {
// messages: {
// someId: 'yea',
// },
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/create-storybook-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function createStorybookRule<
...remainingConfig
}: Readonly<{
name: string
meta: StorybookRuleMeta<TMessageIds, TOptions>
meta: StorybookRuleMeta<TMessageIds>
defaultOptions: Readonly<TOptions>
create: (
context: Readonly<TSESLint.RuleContext<TMessageIds, TOptions>>,
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ export const getDescriptor = (
if (!['StringLiteral', 'Literal'].includes(t.type)) {
throw new Error(`Unexpected descriptor element: ${t.type}`)
}
// @ts-expect-error TODO: t should be only StringLiteral or Literal, and the type is not resolving correctly
return t.value
})
case 'Literal':
// TODO: Investigation needed. Type systems says, that "RegExpLiteral" does not exist
// @ts-ignore
// @ts-expect-error TODO: Investigation needed. Type systems says, that "RegExpLiteral" does not exist
case 'RegExpLiteral':
// @ts-ignore
return property.value.value
Expand Down
6 changes: 3 additions & 3 deletions tools/update-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ const externalRuleOverrides = {
}

function formatRules(rules: TCategory['rules'], exclude?: string[]) {
const obj = rules?.reduce(
const obj = rules.reduce(
(setting, rule) => {
if (!exclude?.includes(rule.ruleId)) {
setting[rule.ruleId] = rule.meta.docs.recommended || 'error'
}
return setting
},
{ ...externalRuleOverrides }
) ?? { ...externalRuleOverrides }
)

return JSON.stringify(obj, null, 2)
}

function formatSingleRule(rules: TCategory['rules'], ruleId: string) {
const ruleOpt = rules?.find((rule) => rule.ruleId === ruleId)?.meta.docs.recommended || 'error'
const ruleOpt = rules.find((rule) => rule.ruleId === ruleId)?.meta.docs.recommended || 'error'

return JSON.stringify({ [ruleId]: ruleOpt }, null, 2)
}
Expand Down
2 changes: 1 addition & 1 deletion tools/utils/categories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const categoriesConfig: TCategoriesConfig = {
},
}

export const categoryIds = Object.keys(categoriesConfig)
export const categoryIds = Object.keys(categoriesConfig) as CategoryId[]

for (const categoryId of categoryIds) {
categoriesConfig[categoryId].rules = []
Expand Down

0 comments on commit 3f22656

Please sign in to comment.