Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

How can I automate the validation checks on all the web pages that I’ve on production sites and get useful summaries of validation errors?

I use GitHub for front-end development.

How can I automate the validation of new code before it is rolled out into production?

share|improve this question
1  
related: stackoverflow.com/questions/11543319/… –  Simon Sep 18 at 14:26

closed as too broad by gnat, GlenH7, World Engineer Oct 22 at 1:13

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

You can use tools like Tidy to validate the output either before (if you want to hold sending an invalid document or correct it first) or while sending it to the client. For example, PHP has Tidy extension for that.

If you don't use any server-side programming, then unfortunately you won't be able to do the validation.

share|improve this answer

Many version control systems have some sort of hook that one can use to do things at a certain time. For example, when committing java code, one could put commit hooks in place such that before someone can commit, it runs the unit tests and they must pass. A similar approach can be used here.

git has several commit hooks, of the ones you'd most likely look at using:

  • Client side
    • pre-commit
    • post-commit
  • Server side
    • pre-receive
    • post-receive

These are run before or after the commit or push (on the server, receiving). There are several others that get into more particular spots of the git workflow.

The combination of tidy to validate the code and a commit hook on the source. Write a little script that would look something like (note, this code may not work - I haven't tested it, its more just a get an idea of what you would be doing):

#!/bin/bash

bad=0;

git diff --cached --name-status | while read st file; do
  # Skip deleted files.
  if [ "$st" == 'D' ]; then continue; fi
  if [[ $file =~ ".html ]] ; then
    tidy $file
    if [ $? != 0 ] ; then
      echo "$file failed validation"
      bad = 1
    fi
  fi
done

if [ $bad ] ; then
  echo "rejecting commit"
  exit 1
fi

Please write this in your preferred scripting language - hopefully its not bash.

This loops over the files being committed that are html files and then runs tidy against them. If tidy has a non-zero exit code, it says it failed validation. If any files fail to validate, it exits with a non-zero code which then would have the git hook fail the precommit.

Given the html nature of this, you may also find Deploying Websites With a Tiny Git Hook to be a useful read which works on a post receive hook on a server to copy the files committed into the webserver's htdocs.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.