Skip to content

JS-1803 Fix S6478 false positives for react-table headers#7126

Draft
francois-mora-sonarsource wants to merge 2 commits into
masterfrom
fix/s6478-react-table-header-renderers
Draft

JS-1803 Fix S6478 false positives for react-table headers#7126
francois-mora-sonarsource wants to merge 2 commits into
masterfrom
fix/s6478-react-table-header-renderers

Conversation

@francois-mora-sonarsource
Copy link
Copy Markdown
Contributor

Summary

Fixes a React false positive in S6478 by treating react-table column Header functions as render callbacks, not nested component definitions.

The exemption is scoped to column-like objects containing Header plus accessor, columns, or id, and a regression test keeps generic Header renderer objects noncompliant.

Validation

  • ./node_modules/.bin/tsx --tsconfig packages/tsconfig.test.json --test packages/analysis/src/jsts/rules/S6478/unit.test.ts
  • git diff --check

npm run bridge:compile was attempted, but this fresh worktree lacks the ignored generated rule metadata/index artifacts expected by the command, so it fails before branch-specific checking.

@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title Fix S6478 false positives for react-table headers JS-1803 Fix S6478 false positives for react-table headers May 29, 2026
@hashicorp-vault-sonar-prod
Copy link
Copy Markdown

hashicorp-vault-sonar-prod Bot commented May 29, 2026

JS-1803

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 29, 2026

Ruling Report

No changes to ruling expected issues in this PR

@gitar-bot
Copy link
Copy Markdown

gitar-bot Bot commented May 29, 2026

Code Review ✅ Approved

Excludes react-table column headers from S6478 by treating them as render callbacks rather than nested component definitions. No issues found.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@sonarqube-next
Copy link
Copy Markdown

@francois-mora-sonarsource
Copy link
Copy Markdown
Contributor Author

Rule Profile

Field Value
Rule S6478 - React components should not be nested
Severity / type Major CODE_SMELL
Sonar Way Yes
Scope Main
function Parent() {
  function Header() {
    return <div />;
  }

  return <Header />;
}

False Positive Pattern

The false positives happen in react-table v7 column definitions where the Header property is a render callback. S6478 normally treats functions returning JSX inside another component as nested component definitions, but react-table consumes Header as part of its column configuration API, not as a React component declared and rendered by the parent component.

function Parent() {
  const columns = [
    {
      Header: () => <CustomHeader />,
      accessor: 'name',
    },
  ];

  useTable({ columns });
  return <Table columns={columns} />;
}

False Negative Risk

The risk is bounded because the fix does not suppress all nested JSX-returning functions or all object properties named like components. It suppresses only static Header property values inside objects that look like react-table column definitions, identified by column-shape properties such as accessor, id, or nested columns. Computed properties and ordinary nested component definitions are still reported.

Fix Summary

The implementation recognizes react-table column header renderers before delegating to the underlying nested-component rule. When a function is used as a column Header renderer, S6478 skips the report because that callback is a library configuration hook rather than an unstable nested React component.

  • Detects static Header function values in column-like object expressions.
  • Requires a react-table column shape, such as accessor, id, or nested columns.
  • Keeps computed Header properties and non-column object shapes reportable.
  • Adds regression coverage for valid react-table headers and invalid computed-header cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant