-
-
Notifications
You must be signed in to change notification settings - Fork 154
refactor: fix all ESLint no-explicit-any warnings #1620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Replace any types with appropriate specific types (unknown, TxtNode, TextlintMessage, etc.) - Add ESLint disable comments for cases where any is necessary for functionality - Create test helper functions for better type safety in test files - Improve type safety across textlint packages while maintaining existing behavior Fixes 135 ESLint warnings without breaking changes. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR eliminates all ESLint @typescript-eslint/no-explicit-any
warnings by replacing any
with unknown
or more specific types and adds type‐safe test helpers where needed.
- Replaced generic
any
usages across code and tests withunknown
, domain types (e.g.,TextlintMessage
), or refined generics. - Introduced
test-helper.ts
in the linter‐formatter package to centralize creation of typed test messages and results. - Applied targeted
eslint-disable-next-line
only in legacy or otherwise very dynamic code paths where correct typing would break existing behavior.
Reviewed Changes
Copilot reviewed 56 out of 56 changed files in this pull request and generated no comments.
Show a summary per file
File or Package Path | Description |
---|---|
packages/textlint/test/pluguins/fixtures/example-plugin.ts | Updated plugin postProcess signature to use TextlintMessage . |
packages/textlint/src/util/logger.ts | Changed varargs from any[] to unknown[] in Logger methods. |
packages/textlint/src/engine/processor-map.ts | Refined PluginMap generic to unknown[] and return type. |
packages/textlint/src/config/config-initializer.ts | Tightened arrayToObject signature to Array<string> → unknown . |
packages/textlint-tester/test/…invalid-testcofig.test.ts | Recast invalid config from any to unknown when invoking tester. |
packages/@textlint/types/src/Rule/*.ts | Replaced index signatures any → unknown and refined handler return types. |
packages/@textlint/types/src/Plugin/TextlintPluginModule.ts | Typed plugin postProcess messages array with TextlintMessage . |
packages/@textlint/textlint-plugin-text/{src, test} | Updated postProcess signatures and tests to use TextlintMessage ; added disables for dynamic imports. |
packages/@textlint/textlint-plugin-markdown/{src, test} | Mirrored above plugin changes for Markdown processor. |
packages/@textlint/source-code-fixer/src/source-code-fixer.ts | Added disable for clone’s index signature and left it as-is. |
packages/@textlint/module-interop/src/index.ts | Introduced ESModule<T> type to remove any casts. |
packages/@textlint/markdown-to-ast/src/index.ts | Typed calculatePositionFromSiblings parameters as dynamic and disabled any . |
packages/@textlint/linter-formatter/test/formatters & test-helper.ts | Shifted all formatter tests to use TextlintResult[] and createTest* helpers. |
packages/@textlint/linter-formatter/src/{index.ts, formatters/*.ts} | Refined isFormatterFunction , formatter signatures, and YAML/TAP helper types. |
packages/@textlint/legacy-textlint-core/src/index.ts | Changed ignored constructor arg to unknown[] . |
packages/@textlint/kernel/src & test | Numerous casts from any → unknown or specific types; refined logger, invariant, padding locators, etc. |
packages/@textlint/ast-traverse/test/txt-traverse.test.ts | Updated test variables from any[] to TxtNode[] . |
Comments suppressed due to low confidence (1)
packages/textlint/src/util/logger.ts:12
- [nitpick] The rest parameter is named
message
but represents multiple values; consider renaming it tomessages
for clarity.
static log(...message: unknown[]) {
- Revert any -> unknown changes that cause type compatibility issues - Add eslint-disable-next-line comments instead to suppress warnings - Keep existing behavior while maintaining ESLint compliance
- Remove unused AnyTxtNode imports - Keep ESLint compliance while reducing build errors
- Fix stylish formatter test by creating proper TextlintMessage objects - Update CLI test mocks to match Logger interface with spread parameters - Add proper type assertions for complex test objects - Remove unused imports to eliminate TypeScript warnings - Maintain all existing functionality while improving type safety
- Fix severity type mismatch in fixer and linter processors - Fix config loader plugin options type - Fix example TypeScript code to return Promise<void> - Clean up unused ESLint disable comments and improve type assertions All ESLint warnings resolved and TypeScript builds successfully!
line: "<", | ||
column: ">", | ||
line: "<" as unknown as number, | ||
column: ">" as unknown as number, | ||
ruleId: "foo>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be ts-expecte-error
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
[index: string]: (node: any) => void | Promise<void>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This node: any
is expected.
This node
is external node, textlint could not know the type.
Summary
This PR fixes all 135 ESLint
@typescript-eslint/no-explicit-any
warnings across the textlint codebase without breaking existing functionality.Key Changes
Type Safety Improvements: Replaced
any
types with appropriate specific types:any
→unknown
for generic type guards and utility functionsany
→TxtNode
for AST node handlingany
→TextlintMessage
for message processingany
→TextlintResult
for formatter functionsTest Helper Creation: Added
test-helper.ts
for linter-formatter tests to provide type-safe test data generationStrategic ESLint Disables: Used
eslint-disable-next-line
comments only where changing the type would break existing functionality (e.g., legacy AST processing, dynamic module loading)Files Modified
@textlint/kernel
,@textlint/types
,@textlint/linter-formatter
@textlint/textlint-plugin-markdown
,@textlint/textlint-plugin-text
@textlint/source-code-fixer
,@textlint/markdown-to-ast
Before/After
Testing
pnpm run eslint
Test plan
pnpm run eslint
- should show 0 warnings🤖 Generated with Claude Code