Skip to content

feat(lint): add rule to limit excessive primary actions#191

Open
coryrylan wants to merge 1 commit into
mainfrom
topic-eslint-button
Open

feat(lint): add rule to limit excessive primary actions#191
coryrylan wants to merge 1 commit into
mainfrom
topic-eslint-button

Conversation

@coryrylan

@coryrylan coryrylan commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator
  • Introduced a new ESLint rule @nvidia-elements/lint/no-excessive-primary-actions to restrict the use of emphasis buttons to a maximum of two per page.
  • Updated ESLint configuration to include the new rule.
  • Added tests for the new rule to ensure correct functionality.
  • Updated documentation to reflect the new rule and its purpose.

Summary by CodeRabbit

  • New Features
    • Added an ESLint rule that reports a lint error when a page contains more than two primary action <nve-button interaction="emphasis"> elements.
    • Enabled the rule as an error in the HTML lint configuration.
  • Documentation
    • Added the new rule to the lint rules documentation and rules list (two-action limit).
  • Tests
    • Added unit tests covering valid/invalid counts, dynamic values, and separate template scopes.
    • Adjusted the existing visual button test setup to avoid the new rule for that specific case.

@coryrylan
coryrylan requested a review from johnyanarella July 24, 2026 15:22
@coryrylan coryrylan self-assigned this Jul 24, 2026
Copilot AI review requested due to automatic review settings July 24, 2026 15:22
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: ce332e13-7277-4104-8f3f-a04dfaf4b214

📥 Commits

Reviewing files that changed from the base of the PR and between 1ec8017 and b0254f0.

📒 Files selected for processing (7)
  • projects/core/eslint.config.js
  • projects/lint/README.md
  • projects/lint/src/eslint/configs/html.ts
  • projects/lint/src/eslint/internals/index.test.ts
  • projects/lint/src/eslint/rules/no-excessive-primary-actions.test.ts
  • projects/lint/src/eslint/rules/no-excessive-primary-actions.ts
  • projects/site/src/docs/lint/index.md

📝 Walkthrough

Walkthrough

Changes

Primary Action Linting

Layer / File(s) Summary
Rule implementation and coverage
projects/lint/src/eslint/rules/no-excessive-primary-actions.ts, projects/lint/src/eslint/rules/no-excessive-primary-actions.test.ts
Adds the rule, limiting matching emphasis buttons to two per document, with metadata and behavior tests.
Lint configuration and integration validation
projects/lint/src/eslint/configs/html.ts, projects/lint/src/eslint/internals/index.test.ts
Registers and enables the rule in the HTML configuration and validates strict-mode diagnostics.
Documentation and scoped configuration
projects/lint/README.md, projects/site/src/docs/lint/index.md, projects/core/eslint.config.js
Documents the rule and disables it for the specified visual test file.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant HTMLTemplate
  participant lintTemplate
  participant noExcessivePrimaryActions
  participant ESLintContext
  HTMLTemplate->>lintTemplate: parse HTML template
  lintTemplate->>noExcessivePrimaryActions: process Document and button attributes
  noExcessivePrimaryActions->>ESLintContext: report emphasis buttons beyond two
Loading

Suggested labels: scope(internals)

Suggested reviewers: copilot, johnyanarella

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding a lint rule to limit excessive primary actions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch topic-eslint-button

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

projects/core/eslint.config.js

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

projects/lint/src/eslint/internals/index.test.ts

Parsing error: error TS5012: Cannot read file '/tsconfig.json': ENOENT: no such file or directory, open '/tsconfig.json'.

projects/lint/src/eslint/rules/no-excessive-primary-actions.test.ts

Parsing error: error TS5012: Cannot read file '/tsconfig.json': ENOENT: no such file or directory, open '/tsconfig.json'.


Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

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 a new Elements ESLint rule to enforce a UX guideline: limit the number of “primary” (interaction="emphasis") <nve-button> actions to at most two within a page/template. It wires the rule into the recommended HTML config, updates downstream project ESLint overrides where needed, and documents the new rule.

Changes:

  • Added new rule @nvidia-elements/lint/no-excessive-primary-actions and enabled it as error in the recommended HTML config.
  • Added unit tests for the rule and an integration-style assertion via lintTemplate(...).
  • Updated lint documentation (docs site + package README) and disabled the rule for a specific Core visual test file.

Reviewed changes

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

Show a summary per file
File Description
projects/site/src/docs/lint/index.md Documents the new rule in the docs site lint rule list.
projects/lint/src/eslint/rules/no-excessive-primary-actions.ts Implements the new rule (counts interaction="emphasis" on <nve-button>).
projects/lint/src/eslint/rules/no-excessive-primary-actions.test.ts Adds rule-level tests for valid/invalid emphasis button counts.
projects/lint/src/eslint/internals/index.test.ts Adds coverage that lintTemplate(..., { strict: true }) surfaces the new message id.
projects/lint/src/eslint/configs/html.ts Registers and enables the new rule in the recommended HTML config/plugin.
projects/lint/README.md Documents the new rule in the lint package README rule table.
projects/core/eslint.config.js Disables the new rule for src/button/button.test.visual.ts.

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

Comment on lines +83 to +104
it('should count separate tagged templates independently', () => {
const javascriptTester = new RuleTester({
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
}
});

javascriptTester.run('separate tagged templates', rule, {
valid: [
`const first = html\`
<nve-button interaction="emphasis">One</nve-button>
<nve-button interaction="emphasis">Two</nve-button>
\`;
const second = html\`
<nve-button interaction="emphasis">Three</nve-button>
<nve-button interaction="emphasis">Four</nve-button>
\`;`
],
invalid: []
});
});
'@nvidia-elements/lint/no-deprecated-global-attribute-value': ['error'],
'@nvidia-elements/lint/no-deprecated-global-attributes': ['error'],
'@nvidia-elements/lint/no-deprecated-slots': ['error'],
'@nvidia-elements/lint/no-excessive-primary-actions': ['error'],

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

went with slightly more generic name so the rule has some flexibility to what it checks

- Introduced a new ESLint rule `@nvidia-elements/lint/no-excessive-primary-actions` to restrict the use of emphasis buttons to a maximum of two per page.
- Updated ESLint configuration to include the new rule.
- Added tests for the new rule to ensure correct functionality.
- Updated documentation to reflect the new rule and its purpose.

Signed-off-by: Cory Rylan <crylan@nvidia.com>
Copilot AI review requested due to automatic review settings July 24, 2026 19:55
@coryrylan
coryrylan force-pushed the topic-eslint-button branch from 1ec8017 to b0254f0 Compare July 24, 2026 19:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

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

Comment on lines +34 to +37
Tag(node: HtmlTagNode) {
if (node.name.toLowerCase() !== 'nve-button') {
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants