This project is deprecated in favour of stylelint-config-visionapps.
##CSS Standard Style
###Rules
- Use 4 spaces for indentation.
h1 {
color: lime;
}
- Use single quotes.
h1:after {
content: ' ';
}
- Write urls without quotes.
div {
background-image: url(background.jpg);
}
- In attribute selectors, enclose attribute value in quotes.
a[target='_blank'] {
color: lime;
}
- Don’t select via IDs.
// ✓ ok
.element {
color: lime;
}
// ✗ avoid
#element {
color: lime;
}
- Add a space after selector.
// ✓ ok
h1 {
color: lime;
}
// ✗ avoid
h1{
color: lime;
}
- Add a space after property name.
// ✓ ok
h1 {
color: lime;
}
// ✗ avoid
h1 {
color:lime;
}
- Commas should have a space after them.
p {
font-family: 'Times New Roman', Times, serif;
}
- Add a semicolon after every declaration.
h1 {
color: lime;
text-align: center // ✗ avoid
}
- Put each declaration on a line.
h1 {
color: lime;text-align: center; // ✗ avoid
}
- Put multiple values on one line each.
h1,
h2,
h3 {
color: lime;
}
- Always put a blank line between rules.
// ✓ ok
h1 {
color: lime;
}
p {
font-family: 'Times New Roman', Times, serif;
}
// ✗ avoid
h1 {
color: lime;
}
p {
font-family: 'Times New Roman', Times, serif;
}
- Multiple blank lines are not allowed.
// ✓ ok
h1 {
color: lime;
}
p {
font-family: 'Times New Roman', Times, serif;
}
// ✗ avoid
h1 {
color: lime;
}
p {
font-family: 'Times New Roman', Times, serif;
}
We are using stylelint for easiest implementation of standardcss rules. This linter is powered by PostCSS. In this example we are going to use Grunt, however you can choose any task runner that supports PostCSS.
You need these npm packages: stylelint, grunt, grunt-postcss and if you are using any CSS preprocessor, you might need supporting PostCSS package. In our example postcss-less.
Best practice is to check your CSS before any other tasks process it.
####Installation
- Install npm packages
- Include
.stylelintrc
in the root of your directory - Prepare Grunt PostCSS task
- If you are using preprocessor include it in PostCSS task
- Add stylelint and postcss-reporter (at least with clearMessages option, but we recommend throwError also)
- Add other Grunt tasks to process your CSS
- Lint your CSS!
- (Optional) Cry over errors and inconsistencies in your stylesheet
lint: {
options: {
syntax: require('postcss-less'),
processors: [
require('stylelint'),
require('postcss-reporter')({
clearMessages: true,
throwError: true,
}),
],
},
src: 'resources/less/**/*.less',
dest: '.tmp/main.less',
},