Comprehensive linting solution for JavaScript and TypeScript projects combining ESLint and Stylelint with unified interface
—
Pre-configured Stylelint setup with CSS modules, Prettier integration, and CSS-in-JS support. Provides comprehensive style linting for CSS, Less, Sass, SCSS, Stylus, and CSS-in-JS in TypeScript/JavaScript files.
Comprehensive Stylelint configuration with modern CSS support and CSS-in-JS capabilities.
// Stylelint configuration object (CommonJS module.exports)
// Location: src/config/stylelint/index.ts
const stylelintConfig: {
extends: string[];
plugins: string[];
rules: Record<string, any>;
customSyntax: string;
ignoreFiles: string[];
overrides: Array<{
files: string[];
customSyntax: string;
}>;
};Key Features:
Usage:
// stylelint.config.js
module.exports = require("@umijs/lint/dist/config/stylelint");const extends: [
"stylelint-config-standard",
"stylelint-config-prettier",
"stylelint-config-css-modules"
];Inherited Features:
const plugins: [
"stylelint-declaration-block-no-ignored-properties"
];Plugin Features:
const customSyntax: "postcss-less";
const overrides: [{
files: ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"];
customSyntax: "@stylelint/postcss-css-in-js";
}];Supported Syntaxes:
const rules: {
// Specificity and ordering
"no-descending-specificity": null;
// URL and attribute handling
"function-url-quotes": "always";
"selector-attribute-quotes": "always";
// Font family validation
"font-family-no-missing-generic-family-keyword": null;
// Plugin rules
"plugin/declaration-block-no-ignored-properties": true;
// Unit validation
"unit-no-unknown": [true, { ignoreUnits: ["rpx"] }];
// Web components
"selector-type-no-unknown": null;
// CSS modules
"value-keyword-case": ["lower", { ignoreProperties: ["composes"] }];
// Class naming patterns
"selector-class-pattern": [
"^([a-z][a-z0-9]*(-[a-z0-9]+)*|[a-z][a-zA-Z0-9]+)$",
{
message: "Expected class selector to be kebab-case or lowerCamelCase";
}
];
// Color functions
"color-function-notation": null;
// Font family restrictions
"declaration-property-value-disallowed-list": [
{
"font-family": "/^('|\")?PingFangSC(-(Regular|Medium|Semibold|Bold))?\\1$/"
},
{
message: "Unexpected value for property \"font-family\", which will cause some devices to render the wrong font, please delete this \"font-family\" css rule, see also: https://github.com/umijs/umi/pull/11001"
}
];
};const supportedFiles: [
"**/*.css", // CSS files
"**/*.less", // Less files
"**/*.scss", // SCSS files
"**/*.sass", // Sass files
"**/*.styl" // Stylus files
];const cssInJsFiles: [
"**/*.js", // JavaScript files with CSS-in-JS
"**/*.jsx", // JSX files with CSS-in-JS
"**/*.ts", // TypeScript files with CSS-in-JS
"**/*.tsx" // TSX files with CSS-in-JS
];CSS-in-JS Features:
# Lint CSS files
stylelint "src/**/*.{css,less,scss}"
# Lint with auto-fix
stylelint "src/**/*.{css,less,scss}" --fix# Lint CSS-in-JS in TypeScript files
stylelint "src/**/*.{ts,tsx}"
# Lint all style-related files
stylelint "src/**/*.{css,less,scss,ts,tsx}"// stylelint.config.js
const baseConfig = require("@umijs/lint/dist/config/stylelint");
module.exports = {
...baseConfig,
rules: {
...baseConfig.rules,
"color-hex-case": "upper",
"declaration-block-trailing-semicolon": "always"
}
};/* Valid class names */
.my-component { } /* kebab-case */
.myComponent { } /* lowerCamelCase */
.component-item { } /* kebab-case with hyphens */
/* Invalid class names */
.MyComponent { } /* PascalCase - not allowed */
.my_component { } /* snake_case - not allowed *//* CSS Modules composition */
.button {
composes: base-button from './base.css';
background: blue;
}Special Handling:
composes keyword is case-insensitive (exception to lowercase rule)// Less math operations are supported
.container {
width: calc(100% - 20px); // Standard CSS calc
height: 100px * 2; // Less multiplication
margin: 10px / 2; // Less division
}Configuration:
color-function-notation is disabled to prevent conflicts with Less mathMissing Dependencies:
# Ensure required packages are installed
npm install stylelint postcssSyntax Errors:
File Pattern Issues:
// stylelint.config.js
module.exports = {
...require("@umijs/lint/dist/config/stylelint"),
ignoreFiles: [
"node_modules/**/*",
"dist/**/*",
"build/**/*"
]
};/* Custom properties (CSS variables) */
:root {
--primary-color: #007bff;
--font-size-base: 16px;
}
.component {
color: var(--primary-color);
font-size: var(--font-size-base);
}/* Custom elements are allowed */
my-custom-element {
display: block;
padding: 1rem;
}
app-header,
app-footer {
position: relative;
}/* rpx units are supported (responsive pixels) */
.mobile-component {
width: 750rpx; /* Allowed */
height: 200rpx; /* Allowed */
font-size: 32rpx; /* Allowed */
}Install with Tessl CLI
npx tessl i tessl/npm-umijs--lint