Skip to content

Commit

Permalink
Merge pull request #374 from alphagov/sass-warn
Browse files Browse the repository at this point in the history
Add colour contrast test
  • Loading branch information
NickColley committed Jan 19, 2017
2 parents 175c9d2 + bf34b09 commit d15e738
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules/
.sass-cache
npm-debug.log
spec/stylesheets
spec/stylesheets/test*
_SpecRunner.html
6 changes: 5 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ module.exports = function (grunt) {
}
)

allSassFiles.push("@import '_colour_contrast_spec.scss';")

grunt.file.write(
'./spec/stylesheets/test.scss',
allSassFiles.join('\n')
Expand Down Expand Up @@ -46,7 +48,9 @@ module.exports = function (grunt) {
},
options: {
loadPath: [
'./stylesheets'
'./node_modules',
'./stylesheets',
'./spec/stylesheets'
],
style: 'nested'
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"grunt-contrib-jasmine": "^1.0.0",
"grunt-contrib-sass": "0.7.4",
"jquery": "~1.12.4",
"standard": "^8.2.0"
"standard": "^8.2.0",
"sass-color-helpers": "^2.0.3"
},
"scripts": {
"test": "grunt test && npm run lint --silent",
Expand Down
12 changes: 12 additions & 0 deletions spec/stylesheets/_colour_contrast_spec.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@import "colours/organisation";
@import "sass-color-helpers/stylesheets/color-helpers/math";
@import "sass-color-helpers/stylesheets/color-helpers/contrast";

@each $organisation in $all-organisation-brand-colours {
$minimum-contrast: 4.5;
$contrast: ch-color-contrast($white, nth($organisation, 3));

@if ($contrast < $minimum-contrast) {
@error "Contrast ratio for #{nth($organisation, 1)} too low. #{nth($organisation, 3)} on #{$white} has a contrast of: #{$contrast}. Must be higher than #{$minimum-contrast} for WCAG AA support";
}
}

0 comments on commit d15e738

Please sign in to comment.