Skip to content

[Feature:Developer] Add CSS color linter rules#12475

Merged
williamjallen merged 4 commits intoSubmitty:mainfrom
Akarshkushwaha:feature-stylelint-colors
Mar 7, 2026
Merged

[Feature:Developer] Add CSS color linter rules#12475
williamjallen merged 4 commits intoSubmitty:mainfrom
Akarshkushwaha:feature-stylelint-colors

Conversation

@Akarshkushwaha
Copy link
Contributor

Why is this Change Important & Necessary?

Closes #11224

One of the most common review comments for CSS files is a reminder that colors from colors.css are preferred over hardcoded colors. This PR automates that check by adding Stylelint rules to prohibit hardcoded CSS colors.

What is the New Behavior?

Added color-named: "never" and color-no-hex: true rules to [site/.stylelintrc.json]. These rules will now flag any new CSS code that uses hardcoded color names (e.g., red, blue) or hex codes (e.g., #FF0000), enforcing usage of CSS variables from colors.css.

Legacy files that currently violate these rules are temporarily exempted via an overrides block in the config. These will be addressed in separate follow-up PRs.

What steps should a reviewer take to reproduce or test the bug or new feature?

  1. Run npm run css-stylelint in the site/ directory — it should pass.
  2. Try adding a hardcoded color like color: red; or color: #FF0000; to any non-exempted CSS file and run npm run css-stylelint again — it should fail with a color-named or color-no-hex error.

Automated Testing & Documentation

The Stylelint CI check will automatically enforce these rules on all future PRs. No additional automated tests are needed.

Other information

This is not a breaking change. No migrations are needed. The 20 legacy CSS files that currently use hardcoded colors are listed in the overrides block and will be cleaned up in subsequent PRs.

Added color-named: never and color-no-hex: true rules to enforce usage
of CSS variables from colors.css instead of hardcoded colors.

Legacy files that currently violate these rules are temporarily exempted
via an overrides block and will be addressed in separate PRs.
@codecov
Copy link

codecov bot commented Feb 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 21.66%. Comparing base (5cd01d6) to head (fe7b215).
⚠️ Report is 20 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main   #12475      +/-   ##
============================================
- Coverage     21.70%   21.66%   -0.05%     
- Complexity     9626     9638      +12     
============================================
  Files           268      268              
  Lines         36188    36233      +45     
  Branches        486      486              
============================================
- Hits           7856     7849       -7     
- Misses        27850    27902      +52     
  Partials        482      482              
Flag Coverage Δ
autograder 21.39% <ø> (ø)
js 2.04% <ø> (ø)
migrator 100.00% <ø> (ø)
php 20.68% <ø> (-0.07%) ⬇️
python_submitty_utils 80.08% <ø> (ø)
submitty_daemon_jobs 91.13% <ø> (+0.41%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Akarshkushwaha
Copy link
Contributor Author

@williamjallen I've opened a PR to address this: #12475

It adds the color-named and color-no-hex Stylelint rules. Existing files that violate these rules are temporarily exempted via an overrides block and will be cleaned up in follow-up PRs.

Copy link
Contributor

@JManion32 JManion32 left a comment

Choose a reason for hiding this comment

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

This change would be helpful for enforcing our CSS conventions, but I'm not a fan of overriding the rule in certain files (except for colors.css, that makes sense).

In the past, we've added inline ignores for existing violations. This allows us to enforce the new rule for all future PRs, and the inline ignores make it easier to complete the refactor in the future.

Would it be feasible to add inline ignores for each violation, or possibly find a way to get the count of existing violations then add a check to ensure new code doesn't increase this count?

@github-project-automation github-project-automation bot moved this from Seeking Reviewer to Work in Progress in Submitty Development Feb 26, 2026
Removed legacy CSS files from the Stylelint overrides array, replacing them with inline /* stylelint-disable-next-line */ comments above each violating line as requested by the reviewer.
@Akarshkushwaha
Copy link
Contributor Author

Akarshkushwaha commented Feb 28, 2026

@JManion32 Thanks for the feedback I completely agree — inline ignores are much safer and will prevent new violations from slipping into those files.

I've updated the PR to remove the global overrides block (except for colors.css as discussed) and instead added inline /* stylelint-disable-next-line */ comments for every existing violation across those legacy files.

@automateprojectmangement automateprojectmangement bot moved this from Work in Progress to In Review in Submitty Development Feb 28, 2026
Copy link
Member

@williamjallen williamjallen left a comment

Choose a reason for hiding this comment

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

@Akarshkushwaha Please see failing CI. It looks like you need to specify multiple rules in a few cases instead of listing multiple single-rule next-line ignores. See the docs here for more details/

@github-project-automation github-project-automation bot moved this from In Review to Work in Progress in Submitty Development Mar 1, 2026
Combined multiple adjacent '/* stylelint-disable-next-line */' comments into a single comma-separated list to resolve 'Unexpected !important declaration-no-important' errors thrown by the CI pipeline.
@automateprojectmangement automateprojectmangement bot moved this from Work in Progress to In Review in Submitty Development Mar 2, 2026
@github-project-automation github-project-automation bot moved this from In Review to Awaiting Maintainer Review in Submitty Development Mar 4, 2026
@williamjallen williamjallen merged commit 268d0b4 into Submitty:main Mar 7, 2026
26 checks passed
@github-project-automation github-project-automation bot moved this from Awaiting Maintainer Review to Done in Submitty Development Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Add linter rules to prohibit hardcoded CSS colors

3 participants