All Projects → straker → Css Style Guide Audit

straker / Css Style Guide Audit

Licence: mit
Audit the CSS on a page to see what elements are using styles from the style guide and which styles are overriding them

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Css Style Guide Audit

Ios Handbook
Guidelines and best practices for excellent iOS apps
Stars: ✭ 337 (-4.53%)
Mutual labels:  styleguide, style-guide
house style
A shared house style for Ruby projects
Stars: ✭ 19 (-94.62%)
Mutual labels:  styleguide, style-guide
kotlin-style-guide
red_mad_robot Kotlin Style Guide
Stars: ✭ 85 (-75.92%)
Mutual labels:  styleguide, style-guide
Livingcss
Parse comments in your CSS to generate a living style guide using Markdown, Handlebars, Polymer, and Prism syntax highlighter.
Stars: ✭ 237 (-32.86%)
Mutual labels:  styleguide, style-guide
python
Python Style Guide
Stars: ✭ 49 (-86.12%)
Mutual labels:  styleguide, style-guide
Nodebestpractices
✅ The Node.js best practices list (December 2021)
Stars: ✭ 72,734 (+20504.53%)
Mutual labels:  styleguide, style-guide
eslint-config-mingelz
A shared ESLint configuration with Chinese comments. 一份带有完整中文注释的 ESLint 规则。
Stars: ✭ 15 (-95.75%)
Mutual labels:  styleguide, style-guide
Vue Styleguidist
Created from react styleguidist for Vue Components with a living style guide
Stars: ✭ 2,133 (+504.25%)
Mutual labels:  styleguide, style-guide
SFMC-Cookbook
How to survive as a developer for Salesforce Marketing Cloud
Stars: ✭ 70 (-80.17%)
Mutual labels:  styleguide, style-guide
styleguide-todo-grammar
/sBin/StyleGuide/ToDo
Stars: ✭ 19 (-94.62%)
Mutual labels:  styleguide, style-guide
Stylemark
Generate interactive style guides from Markdown.
Stars: ✭ 217 (-38.53%)
Mutual labels:  styleguide, style-guide
Vuejs Component Style Guide
Vue.js Component Style Guide
Stars: ✭ 2,796 (+692.07%)
Mutual labels:  styleguide, style-guide
Frontend Nanodegree Styleguide Zh
优达学城(Udacity)前端样式指南
Stars: ✭ 188 (-46.74%)
Mutual labels:  styleguide, style-guide
Javascript
JavaScript Style Guide
Stars: ✭ 117,286 (+33125.5%)
Mutual labels:  styleguide, style-guide
Ue4 Style Guide
An attempt to make Unreal Engine 4 projects more consistent
Stars: ✭ 2,656 (+652.41%)
Mutual labels:  styleguide, style-guide
styleguide
Official code style guide of Banksalad
Stars: ✭ 91 (-74.22%)
Mutual labels:  styleguide, style-guide
Javascript Style Guide
Airbnb JavaScript 스타일 가이드
Stars: ✭ 132 (-62.61%)
Mutual labels:  styleguide, style-guide
Styleguide Generators
An overview of automatic living styleguide generators
Stars: ✭ 1,902 (+438.81%)
Mutual labels:  styleguide, style-guide
git-style-guide
Руководство по использованию Git на русском языке
Stars: ✭ 30 (-91.5%)
Mutual labels:  styleguide, style-guide
ue5-style-guide
An attempt to make Unreal Engine 4 projects more consistent
Stars: ✭ 2,892 (+719.26%)
Mutual labels:  styleguide, style-guide

Style Guide Auditing Tool

Audit the CSS on a page to see what elements are using styles from the style guide and which styles are overriding them.

IMPORTANT: Dropbox changed how their Public folder worked and removed all previous links to files hosted in it (which is where the Bookmarklet script is kept). All previous versions (1.0.1 and below) of the bookmarklet will no longer work until you've updated to the latest code.

How it works

The code parses all the style sheets on the page and keeps track of every rule and how it affects all elements. When you run the audit, it takes this information and looks at which rules from other style sheets are overriding the rules from the style guide. Any elements that have an override are highlighted.

If you click on any highlighted element, the tool will show you which rules from which style sheets are providing the overrides.

The tool will also outline each element that is using a rule from the style guide. This helps to highlight any elements that should be using the style guide but aren't. Rules that purely use element selectors (no class selector in the rule) will be ignored since those are always applied so long as the style guide is being used on the page.

How to use

Out of the box, the tool provides two global functions: parseStyleSheets() and auditStyleGuide(). Running parseStyleSheets() will parse the style sheets on the page. After the function completes, you can run auditStyleGuide() to run the audit.

auditStyleGuide() takes two parameters, the first is a string that is the name of the style guide to audit. It uses fuzzy matching to find the name for cases when your compiled style sheet uses hashes, or if you use a minified version on production and a non-minified version on localhost.

// matches any styleSheet that contains the text 'pattern-lib':
// localhost/css/pattern-lib.css
// http://myDomain/styles/pattern-lib.min.css
// http://myDomain/styles/pattern-lib-17D8401NDL.css,
auditStyleGuide('pattern-lib');

The second parameter is an array of style sheets to ignore from the audit. This is useful if you are using a global style sheet like Bootstrap and don't care to know if it overrides any of your style guide's rules. Again, it uses fuzzy matching for the name.

// ignores any styleSheet that contains the text 'bootstrap' or 'normalize'
auditStyleGuide('pattern-lib', ['bootstrap','normalize']);

Customizing the audit

The tool also allows you to customize the audit. You can pass an array of custom rules to auditStyleGuide() as the third parameter that will highlight any element that fails the rule.

For example, let's say you wanted to validate the accessibility of your page by ensuring that all anchor tags navigate and are not just there for JavaScript events. You could write a rule that checks that all anchor tags have a valid href property and run the rule with the audit. Any anchor tags that do not have a valid href will be highlighted.

var customRules = [{
  type: 'my-custom-rule',
  selector: 'a[href^="javascript"], a[], a:not([href])',
  description: 'Anchor tags that do not navigate should be buttons.'
}];

auditStyleGuide('pattern-lib', ['bootstrap'], customRules);

A rule consists of three properties:

  • type: a slug that identifies the rule. This slug will be added to the data-style-audit attribute of any element that fails the rule. This is useful if you want to give those elements your own styling.
  • selector: how to identify any elements that do not pass the rule (using document.querySelectorAll)
  • description: the text to display in the audit results for any element that fails the rule.

Using the bookmarklet

You can also create a bookmarklet that will run the entire audit for you on any page. Just edit src/run.js to include any custom rules and the style sheet to audit, and then run gulp scripts. This will create bookmarklet.js that you can then copy into your favorites bar.

This is an excellent tool to give to designers who can then help run the audits of the site on their own.

IMPORTANT - If you are going to create your own custom bookmarklet, please create a branch on your fork where you will push the changes. I will not accept any pull requests that change src/run.js or bookmarklet.js, so if you need to submit a fix, you must do so on a clean branch without custom bookmarklet changes. More info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].