8000 cannot resolve generated rule type of `eslint-plugin-jsx-a11y` · Issue #7 · antfu/eslint-typegen · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
cannot resolve generated rule type of eslint-plugin-jsx-a11y #7
Closed
@kazupon

Description

@kazupon

Describe the bug

summary

when we generate eslint-plugin-jsx-a11y rules with using pluginsToRulesDTS, the type of these rules cannot resolve.

details

As an example of jsx-a11y/accessible-emoji,
in eslint-typegen.d.ts generated by reproduction, the output is as follows:

RuleOptions

  /**
   * Enforce emojis are wrapped in `<span>` and provide screenreader access.
   * @see https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/accessible-emoji.md
   * @deprecated
   */
  'jsx-a11y/accessible-emoji'?: Linter.RuleEntry<JsxA11yAccessibleEmoji>

Type Declarations:

// ----- jsx-a11y/accessible-emoji -----
type _JsxA11YAccessibleEmoji_JsxA11YAccessibleEmoji = []|[{
  [k: string]: unknown | undefined
}]

In RuleOptions, it's output as JsxA11yAccessibleEmoji, but in Declarations it is output as _JsxA11yAccessibleEmoji_JsxA11yAccessibleEmoji and the type. The type is not correctly linked.

Debugging tips

I’ve found out the code to see where the problem was and found that the issue was around compile from JSON schema.

eslint-typegen/src/core.ts

Lines 214 to 223 in 55af100

customName(schema, keyName) {
const resolved = schema.title || schema.$id || keyName
if (resolved === name)
return name
if (!resolved)
return undefined!
return `_${name}_${resolved}`
},
...compileOptions,
})

In the eslint-plugin-jsx-a11y case, schema.$id and name do not match, so _${name}_${resolved} is resolved.

In jsx-a11y/accessible-emoji case, these values are the following values:

  • name: 'JsxA11yAccessibleEmoji'
  • schema.$id: 'JsxA11YAccessibleEmoji'

Why it's normalized though, I have debugged deeply, and that’s normalized at toSafeString in json-schema-to-typescript-lite.

https://github.com/antfu/json-schema-to-typescript-lite/blob/b9f90414c1d74259d6674305ee3feb3fd3793f50/src/utils.ts#L160-L181

I hope my debugging info will help you debug. :)

Reproduction

https://github.com/kazupon/eslint-typegen-repro1

System Info

System:
    OS: macOS 13.6.7
    CPU: (10) arm64 Apple M1 Max
    Memory: 251.56 MB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.19.1 - ~/.nvm/versions/node/v18.19.1/bin/node
  Browsers:
    Chrome: 127.0.6533.119
    Edge: 127.0.2651.98
    Firefox: 118.0.1
    Safari: 16.6

Used Package Manager

pnpm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.

Contributions

  • I am willing to submit a PR to fix this issue
  • I am willing to submit a PR with failing tests (actually just go ahead and do it, thanks!)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0