CSSHint
raw JSON → 0.3.4 verified Fri May 01 auth: no javascript maintenance
CSSHint is a Node.js-based CSS code review tool that lints CSS files for style consistency and errors. Current stable version 0.3.4, with an unknown release cadence (last update appears sporadic). It is built on PostCSS and supports rules from the ecomfe CSS style spec as well as CSSLint rules. Key differentiators: integration with global counters for project-wide consistency checks (hex color case, font-family case), and a promise-based API for file content checking.
Common errors
error TypeError: csshint is not a function ↓
cause Importing default export incorrectly, as the package only exports named functions.
fix
Use import { checkString } from 'csshint' instead of import csshint from 'csshint'.
error Cannot find module 'postcss' ↓
cause PostCSS is a peer dependency of csshint and must be installed manually if not auto-installed.
fix
Run npm install postcss as a dependency of your project.
Warnings
gotcha The package modifies global objects (CSSHINT_INVALID_ALL_COUNT, CSSHINT_HEXCOLOR_CASE_FLAG, CSSHINT_FONTFAMILY_CASE_FLAG) which can cause side effects across multiple lint runs. ↓
fix Avoid concurrent lint operations; reset globals between runs if needed.
deprecated The CLI interface may be unstable; documentation lacks clear CLI command support beyond basic usage. ↓
fix Use the Node.js API instead of CLI for consistent behavior.
Install
npm install csshint yarn add csshint pnpm add csshint Imports
- default wrong
const csshint = require('csshint')correctimport csshint from 'csshint' - checkString wrong
import checkString from 'csshint'correctimport { checkString } from 'csshint' - check wrong
const { check } = require('csshint')correctimport { check } from 'csshint'
Quickstart
import { checkString } from 'csshint';
const cssCode = `div { color: #fff; }`;
const config = {}; // optional custom config object
checkString(cssCode, config)
.then(result => {
console.log('Path:', result.path);
result.messages.forEach(msg => {
console.log(`${msg.ruleName}: ${msg.message} (line ${msg.line}, col ${msg.col})`);
});
})
.catch(err => {
console.error('Error reading file:', err);
});