Skip to content

fix(linter): correct capitalized-comments rule config schema to tuple format#17208

Closed
Copilot wants to merge 10 commits intomainfrom
copilot/fix-capitalized-comments-docs
Closed

fix(linter): correct capitalized-comments rule config schema to tuple format#17208
Copilot wants to merge 10 commits intomainfrom
copilot/fix-capitalized-comments-docs

Conversation

Copy link
Contributor

Copilot AI commented Dec 21, 2025

Fix capitalized-comments rule configuration documentation

Resolves the issue where the capitalized-comments rule had incorrect configuration option docs that didn't match ESLint's format.

Changes Made

  1. Created proper tuple schema (CapitalizedCommentsSchema)

    • Represents the configuration as a tuple: [capitalize_option, options]
    • First element: "always" | "never" enum
    • Second element: Optional configuration object
  2. Added comprehensive field descriptions for all configuration options using doc comments:

    • ignorePattern: Pattern for comments to ignore
    • ignoreInlineComments: Whether to ignore inline comments
    • ignoreConsecutiveComments: Whether to ignore consecutive comments
    • line: Configuration specific to line comments
    • block: Configuration specific to block comments
  3. Updated schema generation

    • Changed config = OptionsJson to config = CapitalizedCommentsSchema in declare_oxc_lint!
    • Documentation now properly shows tuple array format matching ESLint
    • Uses /// doc comments instead of #[schemars(description)] attributes per codebase convention

Verification

  • ✅ All 886 linter tests pass
  • ✅ Configuration parsing works correctly
  • ✅ Rule execution verified with test configurations
  • ✅ Documentation generation produces correct tuple format
  • ✅ No clippy warnings
  • ✅ Tested with real configuration file and JavaScript code

Example Generated Documentation

## Configuration

Configuration schema for the rule.
The rule accepts a tuple array configuration: `[capitalize_option, options]`

- First element: `"always"` (default) or `"never"` - controls whether comments should be capitalized
- Second element: Optional object with additional configuration properties

### The 1st option
type: `"always" | "never"`

### The 2nd option
type: `object | null`

Example Configuration

{
  "rules": {
    "capitalized-comments": ["warn", "always", {
      "ignorePattern": "pragma|ignored",
      "ignoreInlineComments": true,
      "ignoreConsecutiveComments": true,
      "line": {
        "ignorePattern": "pragma|ignored"
      },
      "block": {
        "ignorePattern": "ignored"
      }
    }]
  }
}
Original prompt

This section details on the original issue you should resolve

<issue_title>linter: capitalized-comments rule has incorrect config option docs</issue_title>
<issue_description>### What version of Oxlint are you using?

0.34.0

What command did you run?

N/A

What does your .oxlintrc.json config file look like?

N/A

What happened?

See the original ESLint rule for comparison: https://eslint.org/docs/latest/rules/capitalized-comments#rule-details

And the format of the options passed in for the rule's tests:

("// Გ", "// გ", Some(serde_json::json!(["never"]))),
("// 𑢢", "// 𑣂", Some(serde_json::json!(["never"]))),
("//* jscs: enable", "//* Jscs: enable", Some(serde_json::json!(["always"]))),
("//* jscs:disable", "//* Jscs:disable", Some(serde_json::json!(["always"]))),
("//* eslint-disable-line", "//* Eslint-disable-line", Some(serde_json::json!(["always"]))),
(
"//* eslint-disable-next-line",
"//* Eslint-disable-next-line",
Some(serde_json::json!(["always"])),
),
(
"/*
* eslint semi:off */",
"/*
* Eslint semi:off */",
Some(serde_json::json!(["always"])),
),
(
"/*
* eslint-env node */",
"/*
* Eslint-env node */",
Some(serde_json::json!(["always"])),
),
(
"/*
* istanbul ignore next */",
"/*
* Istanbul ignore next */",
Some(serde_json::json!(["always"])),
),
(
"/*
* jshint asi:true */",
"/*
* Jshint asi:true */",
Some(serde_json::json!(["always"])),
),
(
"/*
* jscs: enable */",
"/*
* Jscs: enable */",
Some(serde_json::json!(["always"])),
),
(
"/*
* global var1, var2 */",
"/*
* Global var1, var2 */",
Some(serde_json::json!(["always"])),
),
(
"/*
* global var1:true, var2 */",
"/*
* Global var1:true, var2 */",
Some(serde_json::json!(["always"])),
),
(
"/*
* globals var1, var2 */",
"/*
* Globals var1, var2 */",
Some(serde_json::json!(["always"])),
),
(
"/*
* globals var1:true, var2 */",
"/*
* Globals var1:true, var2 */",
Some(serde_json::json!(["always"])),
),
(
"/*
* exported myVar */",
"/*
* Exported myVar */",
Some(serde_json::json!(["always"])),
),
("foo(/* invalid */a);", "foo(/* Invalid */a);", Some(serde_json::json!(["always"]))),
(
"foo(/* invalid */a);",
"foo(/* Invalid */a);",
Some(serde_json::json!(["always", { "ignoreInlineComments": false }])),
),
(
"foo(a, // not an inline comment
b);",
"foo(a, // Not an inline comment
b);",
Some(serde_json::json!(["always", { "ignoreInlineComments": true }])),
),
(
"foo(a, /* not an inline comment */
b);",
"foo(a, /* Not an inline comment */
b);",
Some(serde_json::json!(["always", { "ignoreInlineComments": true }])),
),
(
"foo(a,
/* not an inline comment */b);",
"foo(a,
/* Not an inline comment */b);",
Some(serde_json::json!(["always", { "ignoreInlineComments": true }])),
),
(
"foo(a,
/* not an inline comment */
b);",
"foo(a,
/* Not an inline comment */
b);",
Some(serde_json::json!(["always", { "ignoreInlineComments": true }])),
),
(
"foo(a, // Not an inline comment
b);",
"foo(a, // not an inline comment
b);",
Some(serde_json::json!(["never", { "ignoreInlineComments": true }])),
),
(
"foo(a, /* Not an inline comment */
b);",
"foo(a, /* not an inline comment */
b);",
Some(serde_json::json!(["never", { "ignoreInlineComments": true }])),
),
(
"foo(a,
/* Not an inline comment */b);",
"foo(a,
/* not an inline comment */b);",
Some(serde_json::json!(["never", { "ignoreInlineComments": true }])),
),
(
"foo(a,
/* Not an inline comment */
b);",
"foo(a,
/* not an inline comment */
b);",
Some(serde_json::json!(["never", { "ignoreInlineComments": true }])),
),
(
"// not matching",
"// Not matching",
Some(serde_json::json!(["always", { "ignorePattern": "ignored?" }])),
),
(
"// Not matching",
"// not matching",
Some(serde_json::json!(["never", { "ignorePattern": "ignored?" }])),
),
(
"// should fail. https://github.com",
"// Should fail. https://github.com",
Some(serde_json::json!(["always"])),
),
(
"// Should fail. https://github.com",
"// should fail. https://github.com",
Some(serde_json::json!(["never"])),
),
];

The docs are completely different and very confusing as a result: https://oxc.rs/docs/guide/usage/linter/rules/eslint/capitalized-comments.html#configuration

This rule will need to be updated to use a tuple config and document the options it takes correctly.

Implemented in #16896.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix linter config options for capitalized-comments rule fix(linter): correct capitalized-comments rule config schema to tuple format Dec 21, 2025
Copilot AI requested a review from camc314 December 21, 2025 13:56
@github-actions github-actions bot added A-linter Area - Linter C-bug Category - Bug labels Dec 21, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 21, 2025

CodSpeed Performance Report

Merging #17208 will not alter performance

Comparing copilot/fix-capitalized-comments-docs (c159008) with main (529901c)

Summary

✅ 4 untouched
⏩ 41 skipped1

Footnotes

  1. 41 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@connorshea connorshea force-pushed the copilot/fix-capitalized-comments-docs branch from 94a3aa3 to 7514288 Compare December 29, 2025 05:59
@connorshea connorshea marked this pull request as ready for review December 29, 2025 06:00
Copilot AI review requested due to automatic review settings December 29, 2025 06:00
Copy link
Contributor

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 fixes the incorrect configuration documentation for the capitalized-comments linter rule to match ESLint's tuple array format.

Key changes:

  • Created a dedicated CapitalizedCommentsSchema tuple struct to represent the configuration as [capitalize_option, options]
  • Added comprehensive documentation comments to all configuration fields
  • Updated the rule declaration to use the new schema for proper documentation generation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

/// - First element: `"always"` (default) or `"never"` - controls whether comments should be capitalized
/// - Second element: Optional object with additional configuration properties
#[derive(Debug, Clone, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

The deny_unknown_fields attribute is not semantically meaningful for tuple structs. Tuple structs are serialized as arrays with positional elements, not as objects with named fields. This attribute is typically used with named structs to reject JSON objects with unexpected properties. Since this struct is only used for schema generation and not runtime deserialization, consider removing this attribute as it may cause confusion or unexpected schema generation behavior.

Suggested change
#[serde(deny_unknown_fields)]

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

I think this is probably true? But my suggestion being applied broke this suggestion so

@connorshea connorshea force-pushed the copilot/fix-capitalized-comments-docs branch from b549884 to c66acd9 Compare December 29, 2025 20:57
Copilot AI and others added 6 commits December 31, 2025 16:53
- Changed config schema from OptionsJson to CapitalizedCommentsSchema
- CapitalizedCommentsSchema properly represents tuple: [capitalize_option, options]
- Added descriptions to all configuration fields for better documentation
- First element: "always" | "never" (controls capitalization requirement)
- Second element: optional object with ignorePattern, ignoreInlineComments, etc.
- Documentation now matches ESLint format with proper tuple structure

Co-authored-by: camc314 <18101008+camc314@users.noreply.github.com>
Follow clippy recommendation to use #[expect(dead_code)] instead of #[allow(dead_code)]

Co-authored-by: camc314 <18101008+camc314@users.noreply.github.com>
Replace #[schemars(description)] attributes with /// doc comments
as per review feedback. This aligns with the codebase convention
and lets the doc generation system pick them up automatically.

Co-authored-by: connorshea <2977353+connorshea@users.noreply.github.com>
Signed-off-by: Connor Shea <connor.james.shea@gmail.com>
Signed-off-by: Connor Shea <connor.james.shea@gmail.com>
Signed-off-by: Connor Shea <connor.james.shea@gmail.com>
@connorshea
Copy link
Member

Closing in favor of #18748

@connorshea connorshea closed this Jan 31, 2026
graphite-app bot pushed a commit that referenced this pull request Jan 31, 2026
)

Fixes #17191. Previously, the docs were incorrect and a bit confusing for the user to understand. Now it's possible to actually configure the linter rule based on the docs.

AI Disclosure: Change was made with help from Claude Code and also based on the changes originally made with #17208.

Generated docs:

```md

## Configuration

Configuration for the capitalized-comments rule.

The first element specifies whether comments should `"always"` or `"never"`
begin with a capital letter. The second element is an optional object
containing additional options.

### The 1st option

type: `"always" | "never"`

### The 2nd option

This option is an object with the following properties:

#### block

type: `object`

Configuration options specific to block comments.

##### block.ignoreConsecutiveComments

type: `boolean`

If true, consecutive comments will be ignored after the first comment.

##### block.ignoreInlineComments

type: `boolean`

If true, inline comments (comments in the middle of code) will be ignored.

##### block.ignorePattern

type: `string`

A regex pattern. Comments that match the pattern will not cause violations.

#### ignoreConsecutiveComments

type: `boolean`

If true, consecutive comments will be ignored after the first comment.

#### ignoreInlineComments

type: `boolean`

If true, inline comments (comments in the middle of code) will be ignored.

#### ignorePattern

type: `string`

A regex pattern. Comments that match the pattern will not cause violations.

#### line

type: `object`

Configuration options specific to line comments.

##### line.ignoreConsecutiveComments

type: `boolean`

If true, consecutive comments will be ignored after the first comment.

##### line.ignoreInlineComments

type: `boolean`

If true, inline comments (comments in the middle of code) will be ignored.

##### line.ignorePattern

type: `string`

A regex pattern. Comments that match the pattern will not cause violations.
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

linter: capitalized-comments rule has incorrect config option docs

4 participants