Skip to content

Conversation

azu
Copy link
Member

@azu azu commented Jun 29, 2025

Summary

This PR implements proper support for the info severity level across all formatters and adds comprehensive test coverage, resolving the confusion between none and info severity levels.

Fixes #1608

Changes Made

1. Updated Severity Level Definitions

  • Updated TextlintRuleSeverityLevelKeys.ts: Changed info from value 0 to 3 to make it distinct from none
  • Updated TextlintRuleSeverityLevel.ts: Added proper type support for info level
  • Updated SeverityLevel.ts: Aligned CLI severity definitions

2. Enhanced All Formatters

Updated all formatters to properly handle the three distinct severity levels:

Linter Formatters:

  • stylish.ts: Added green "info" display with proper counting
  • compact.ts: Added "Info" prefix for info messages
  • unix.ts: Added "[Info/rule_id]" format
  • table.ts: Added "info" type in table format
  • checkstyle.ts: Added severity="info" in XML output
  • junit.ts: Added "Info" severity in test output
  • tap.ts: Added severity: info in YAML output
  • pretty-error.ts: Added info level handling with proper counting

Fixer Formatter:

  • stylish.ts: Added info level support for fix output

3. Updated Core Logic

  • rule-severity.ts: Updated error message to include "info" in severity options
  • filter-severity-process.ts: Maintained --quiet behavior to show only errors

4. Comprehensive Test Coverage

Added test cases for info severity level across all formatters:

  • Added info level tests for all 10 formatter test files
  • Added CLI snapshot tests for info severity with different formatters
  • Ensured proper output formatting for info messages

Behavior Changes

Before

// Confusing: info had same value as none
TextlintRuleSeverityLevelKeys.info === 0  // Same as none
// Info messages displayed as warnings in all formatters

After

// Clear distinction
TextlintRuleSeverityLevelKeys.none === 0     // Disabled
TextlintRuleSeverityLevelKeys.warning === 1  // Warning (yellow)
TextlintRuleSeverityLevelKeys.error === 2    // Error (red)  
TextlintRuleSeverityLevelKeys.info === 3     // Info (green)

Formatter Output Examples

Stylish:

  5:10  info  Unexpected foo  foo
✖ 1 problem (0 Errors, 0 Warning, 1 info)

Compact:

foo.js: line 5, col 10, Info - Unexpected foo. (foo)

Table:

║ 5        │ 10       │ info     │ Unexpected foo. │ foo ║

Backward Compatibility

  • No breaking changes: Existing configurations continue to work
  • --quiet flag: Still shows only errors (severity 2) as before
  • Rule configurations: Existing severity: "info" now works as expected

Testing

  • ✅ All existing tests pass
  • ✅ Added comprehensive test coverage for info severity
  • ✅ Added CLI snapshot tests for different formatters
  • ✅ Verified --quiet flag behavior is preserved

Benefits

  1. Clear semantic meaning: Info messages are visually distinct from warnings
  2. Better user experience: Users can use info level for non-critical suggestions
  3. Consistent behavior: All formatters handle severity levels uniformly
  4. Improved maintainability: Using constants instead of magic numbers

@Copilot Copilot AI review requested due to automatic review settings June 29, 2025 13:39
Copy link
Contributor

@Copilot Copilot AI left a 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 adds support for a new "info" severity level across the codebase, ensuring that all formatters and tests correctly handle this additional level. Key changes include updating severity level definitions, enhancing formatter outputs to differentiate "info" from other severities, and adding comprehensive test coverage to validate the new behavior.

Reviewed Changes

Copilot reviewed 32 out of 32 changed files in this pull request and generated 1 comment.

File Description
packages/textlint/src/shared/type/SeverityLevel.ts Updates the severity level mapping to distinguish info from none, warning, and error
packages/@textlint/types/src/Rule/TextlintRuleSeverityLevel.ts Revises type definitions to support info as a distinct severity
Various formatter source and test files Modify message type calculations and summary constructions to handle "info" severity consistently
packages/@textlint/kernel/src/shared/rule-severity.ts and related Updates error messages and doc details to include the new "info" severity
Comments suppressed due to low confidence (1)

packages/@textlint/kernel/src/messages/filter-severity-process.ts:8

  • Consider adding tests to verify that info severity messages are correctly filtered out when the --quiet flag is enabled, ensuring that only error messages (severity 2) are displayed in quiet mode.
 * Filter messages by their severity.

@@ -101,19 +111,19 @@ function formatter(results: TextlintResult[], options: FormatterOptions) {
});

if (total > 0) {
const problemParts = [];
Copy link
Preview

Copilot AI Jun 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for building the summary string for problem counts is duplicated across multiple formatter files. Consider extracting this common logic into a shared utility function to improve maintainability.

Copilot uses AI. Check for mistakes.

azu added 3 commits June 29, 2025 22:50
The test was expecting '1 warning' but should expect '1 info' when severity is 3.
This aligns with the actual formatter output that correctly displays info messages.
- Replace TextlintRuleSeverityLevelKeys with numeric values (1: warning, 2: error, 3: info)
- Remove dependency on @textlint/kernel from formatter packages to maintain clean architecture
- Update all 10 formatters: stylish, compact, unix, table, checkstyle, junit, tap, pretty-error, fixer-formatter
- All tests continue to pass with numeric severity level checks
- Add detailed explanation of severity levels (1: warning, 2: error, 3: info)
- Update examples to include severity property
- Remove outdated reference to SeverityLevel.js file
- Add practical examples showing info level usage
Copy link
Contributor

github-actions bot commented Jun 29, 2025

PR Preview Action v1.6.1

🚀 View preview at
https://textlint.github.io/textlint/pr-preview/pr-1610/

Built to branch gh-pages at 2025-06-29 14:56 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

- Add tests for filterWarningMessages function to ensure it filters out info messages (severity 3) and warning messages (severity 1)
- Add tests for through function to verify it passes all messages unchanged
- Add tests for createSeverityFilter to verify --quiet flag behavior
- Ensure info messages are properly filtered when using --quiet mode
- Tests validate that only error messages (severity 2) are shown in quiet mode
@azu azu added the Type: Feature New Feature label Jun 29, 2025
@azu azu self-assigned this Jun 29, 2025
@azu azu changed the title feat: implement 'info' severity level support across formatters and tests feat: implement info severity level Jun 29, 2025
azu added 7 commits June 29, 2025 23:08
- Fix test case to expect '1 Info' instead of '1 Warning' for info severity (3)
- Update warningCount from 1 to 0 in test data to match actual behavior
- Info messages should be counted separately from warnings and errors
- Table formatter correctly displays info messages with their own category
- Implement tests for the pretty-error formatter to validate error output formatting.
- Add tests for the stylish formatter to ensure correct handling of messages and severity levels.
- Create tests for the table formatter to verify the output structure for different message scenarios.
- Introduce tests for the tap formatter to check the output format for single and multiple messages.
- Develop tests for the unix formatter to confirm the correct formatting of error messages across multiple files.
Comment on lines 5 to +9
type none = 0;
type info = 0;
type warning = 1;
type error = 2;
export type TextlintRuleSeverityLevel = none | info | warning | error;
type info = 3;
export type TextlintRuleSeverityLevel = none | warning | error | info;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

main change

@azu azu merged commit 7d56491 into master Jun 29, 2025
18 checks passed
@azu azu deleted the severity-info branch June 29, 2025 14:58
@github-actions github-actions bot mentioned this pull request Jun 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature New Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support severity: "info" level for rules and formatters
1 participant