InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

CSS

    CSS selectors

    • CSS selectors

    CSS properties

    • CSS properties

    CSS cookbooks

    • !important annotation
    • Align div in center horizontally
    • Align div in center vertically
    • Align multiple divs horizontally
    • Align text in center horizontally
    • CSS - drop cap effect
    • CSS - enlarge image on hover
    • CSS - round toggle switch using checkbox and label
    • CSS automatic table row numbering
    • CSS circle and oval
    • CSS clearfix - clear float automatically using ::after
    • CSS counters
    • CSS nested counters
    • CSS3 gradients
    • Create CSS triangles
    • First letter capital and bigger
    • How to display text on image using css
    • Install sass on Mac or Linux using ruby gem
    • Place a div in bottom right corner of browser
    • Test site css, javascript, html in old IEs
    • csslint
    • inherit value
    • initial value
    • inline-block and baseline alignment
    • margin collapsing
    • node-sass quick start tutorial on Linux and Mac
    • unset value
    • web typography
     
    • Home
    • > Tutorials
    • > CSS

    Csslint – quick command-line tutorial and how to use it for pre-deployment sanity check

    By admin on Jan 17, 2016

    Csslint can be used to check the syntax of a css file. This can be used in release/deployment scripts to check the syntax of css before doing rsync/scp. Here are some useful csslint commands.

    csslint

    Files used in this tutorial

    .foo {
      background-color: red;
    }

    .foo {
      background-color red;
    }

    Check css syntaxt of a file

    Running csslint on a correct css file

    #!/bin/bash
    csslint correct.css
    echo "status code=$?"
    
    csslint: No errors in correct.css.
    status code=0
    
    Env: GNU bash, version 4.2.46

    Running csslint on an incorrect css file

    #!/bin/bash
    csslint incorrect.css
    echo "status code=$?"
    
    csslint: There are 2 problems in incorrect.css.
    
    incorrect.css
    1: warning at line 1, col 1
    Rule is empty.
    .foo {
    
    incorrect.css
    2: error at line 2, col 20
    Expected COLON at line 2, col 20.
      background-color red;
    status code=1
    
    Env: GNU bash, version 4.2.46

    Running csslint on files in a directory

    All files in dir

    $ csslint dir1
    

    To ignore some files

    $ csslint --exclude-list=./dir1/incorrect.css dir1
    

    Using csslint in deployment script

    csslint return shell status code 0 ($?) is everything is correct otherwise non 0 code. It can be used in deployment scripts to exit in case there is any css lint error.

    csslint file1.css
    if [ $? != 0 ] ; then
      echo "Csslint failed. existing..."
      exit
    fi
    ## do regular deployment
    ...
    

    You can sleo set -e flag in bash which causes the script to exit whenever there is an error.

    ## Will cause script to exit on any error
    set -e
    csslint file1.css
    ## do regular deployment
    ...
    

    Suggested posts:

    1. Embed youtube video with javascript on-click lazy loading approach
    2. Bash – how to redirect stderr to stdout or file
    3. Command line – top IP list from apache access log
    4. jQuery – find total number of DOM elements
    5. How to display auto fade out message using jQuery
    6. Can global variables be modified in bash function?
    7. Git show details of a commit hash
    8. How to recover svn lost password on Linux
    Share this article: share on facebook share on linkedin tweet this submit to reddit
    Posted in Tutorials | Tagged CSS, CSS cookbook, Linux
    • Browse content
    • Article Topics
    • Article archives
    • Contact Us
    Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

    Copyright © 2025 InfoHeap.

    Powered by WordPress