Linting & Code Formatting¶
Table of Contents¶
- Overview
- Coding Standards
- Editor Setup
- Project Setup
- ERB/HTML Formatting
- Tips & Tricks
- Known Issues
- See Also
Overview¶
At Lemone, we use three main tools for front-end linting and formatting: ESLint, Stylelint, and Prettier.
Philosophy¶
Linting vs Formatting: - Linting: Prevent errors and catch bugs (ESLint, Stylelint) - Formatting: Enforce style conventions and consistency (Prettier)
Tools¶
ESLint: JavaScript/TypeScript linting Stylelint: CSS/SCSS linting Prettier: Code formatting (optional, project-dependent)
Coding Standards¶
JavaScript¶
Rules based on: Airbnb JavaScript Style Guide
Key conventions:
- Use double quotes (")
- Follow Airbnb ES6+ best practices
Example:
CSS/SCSS¶
Rules based on: Sass Guidelines
Key conventions:
1. Use double quotes (")
2. Order properties alphabetically
3. Use BEM naming convention (.block__element--modifier)
4. Maximum nesting depth: 4 levels
Example:
.card {
background-color: white;
border-radius: 8px;
padding: 1rem;
&__title {
font-size: 1.5rem;
font-weight: bold;
&--highlighted {
color: blue;
}
}
}
Editor Setup¶
VS Code¶
Required Extensions¶
Install these extensions:
- ESLint - JavaScript/TypeScript linting
- Stylelint - CSS/SCSS linting
- Tailwind CSS IntelliSense - Tailwind autocomplete
- Prettier - Code formatting (optional)
Configuration¶
Open settings.json: Press Cmd + Shift + P, search for "settings", and select "Preferences: Open User Settings (JSON)".
Basic Linting Setup¶
Add to your settings.json:
{
// Disable built-in validators (let linters handle validation)
"css.validate": false,
"less.validate": false,
"scss.validate": false,
"typescript.validate.enable": false,
"javascript.validate.enable": false,
// Tailwind CSS
"tailwindCSS.emmetCompletions": true,
// Stylelint
"stylelint.packageManager": "yarn",
"stylelint.validate": [
"css",
"less",
"postcss",
"scss"
],
"stylelint.snippet": [
"css",
"less",
"postcss",
"scss"
],
// Set default formatter for SCSS
"[scss]": {
"editor.defaultFormatter": "stylelint.vscode-stylelint"
},
// Format on save
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.stylelint": true
},
// Always use workspace indentation settings
"editor.detectIndentation": false,
// ESLint
"eslint.packageManager": "yarn",
"eslint.format.enable": true,
// Set default formatter for JavaScript
"[javascript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
}
}
Prettier Configuration (Optional)¶
If using Prettier, add:
This ensures Prettier only runs when a .prettierrc file is present in the project.
Project Setup¶
WordPress (Sage 10)¶
Install required packages:
yarn add -D @roots/bud-eslint @roots/bud-stylelint eslint-config-airbnb-base stylelint-config-sass-guidelines
Example project: EPC Website
Configuration Files¶
File: .eslintrc.json
File: .stylelintrc.json
{
"extends": "stylelint-config-sass-guidelines",
"rules": {
"string-quotes": "double",
"order/properties-alphabetical-order": true,
"max-nesting-depth": 4
}
}
Static Sites (ParcelJS)¶
Install required packages:
yarn add -D @parcel/validator-eslint parcel-validator-stylelint eslint stylelint eslint-config-airbnb-base stylelint-config-sass-guidelines
Example project: Lowlands Community
Shopify¶
Warning
Setup documentation for Shopify projects is pending.
Ruby on Rails¶
Warning
Setup documentation for Rails projects is pending.
See ERB/HTML Formatting for Rails template formatting.
ERB/HTML Formatting¶
For Ruby on Rails projects using ERB templates.
Setup¶
Step 1: Install the gem
Step 2: Install VS Code Extension
Install: ERB Formatter/Beautify
Extension ID: aliariff.vscode-erb-beautify
Step 3: Configure VS Code
Add to settings.json:
{
"[erb]": {
"editor.defaultFormatter": "aliariff.vscode-erb-beautify",
"editor.formatOnSave": true
},
"files.associations": {
"*.html.erb": "erb"
}
}
Step 4: Test
Open any .html.erb file and save. The file should automatically format.
Resources¶
- htmlbeautifier GitHub - The Ruby gem powering ERB formatting
Tips & Tricks¶
Disabling Stylelint Rules¶
Sometimes you need to ignore specific rules. Use inline comments to disable linting:
Disable all rules for one line:
.bg-gradient-transparent-to-purple-200 {
--to-color: theme(colors.purple.200); /* stylelint-disable-line */
}
Disable specific rules:
.bg-gradient-transparent-to-purple-200 {
--to-color: theme(
colors.purple.200
); /* stylelint-disable-line number-leading-zero number-no-trailing-zeros */
}
Disable for entire block:
Warning
Use exceptions sparingly! If you find yourself disabling a rule frequently, propose changing the rule instead of disabling it everywhere.
Resources: Stylelint: Ignore Code
Disabling ESLint Rules¶
Disable all rules for one line:
Disable specific rule:
Disable for entire file:
Disable for next line:
Warning
Use exceptions sparingly! If you find yourself disabling a rule frequently, propose changing the rule instead.
Resources: ESLint: Disabling Rules
Known Issues¶
Stylelint Stylistic Rules¶
Issue: Stylelint has frozen stylistic rules and now recommends using Prettier alongside Stylelint for formatting.
Impact:
- number-leading-zero - Bug won't be fixed
- number-no-trailing-zeros - Bug won't be fixed
Future Plans:
We're evaluating integrating Prettier for formatting. This requires:
- Making Prettier work alongside ESLint/Stylelint
- Only enabling Prettier when .prettierrc is present
- Integrating Tailwind class sorting
Tailwind Class Sorting¶
Status: Pending implementation
We want to integrate automatic Tailwind class sorting with Prettier, but this needs to be configured properly to work with our existing linting setup.
Reference Projects¶
Examples of properly configured linting setups:
Frontend Boilerplate: codepot.nl/developers/frontend/boilerplate WordPress (Sage 10): EPC Website Static Site (ParcelJS): Lowlands Community
See Also¶
- CSS & SCSS Development - BEM methodology, file structure
- Code Editors - VS Code and NeoVim configuration
- Git Development Guide - Commit conventions (similar style enforcement)
- WordPress Development - WordPress-specific development practices