docs/checks_valid.js.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: checks/valid.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: checks/valid.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>'use strict'
// 1 grab attribute selectors OR mixins that are by themselves
// 2 strip attr selectors or classes/ids from elements
// 3 ignore syntax
// 4 ignore numbers
// 5 ( from || to ) are only valid inside @keyframe
// 6 the actual JSON property whitelist we will test against
// 7 if interpolated value just give it a pass
var attrOrMixinRe = /^\[\S+\]|({[\S]+})|(\([\S ]+\))|(\(\))/ // 1
var stripRe = /(?=\S)\[\S+\]|(\.|#)(\w|-)+/ // /(?=\S)\[\S+\]/ // 2
var ignoreRe = /^[$.#]|[&=>+~]|if|for|else|return|@block|calc|@extend|@media/ // 3
var numRe = /\d+?(?=px|%|em|rem|v(h|w)|v(min|max)|ex|ch|mm|cm|in|pt|pc|mozmm)/ // 4
var keyRe = /((from)|(to))+(?= $| {| \d|\n|{)/ // 5
var validJSON = require( '../data/valid.json' ) // 6
var interpolatedRe = /( *{\S+} *)/ // 7
/**
* @description check against a JSON of all valid css properties and values
* @param {string} [line] current line being linted
* @returns {boolean | undefined} true if problem, false if no prob, undefined if we skipped
*/
module.exports = function valid( line ) {
// from and to are valid keyframes properties, but not outside that context
if ( !this.state.keyframes && line.match( keyRe ) ) { return }
// 1 split by tabs and spaces, tabs mess with pattern matching
var isValid = false
var arr = this.splitAndStrip( new RegExp( /[\s\t,:]/ ), line ) // 1
// if not splittable for some reason
if ( typeof arr[0] === 'undefined' ) return
// in order, let line be considered valid if:
// 1 we are in a hash or css block or root block
// 2 classname, varname, id, or syntax.
// 3 if the selector only consists of an attr or mixin (which can be custom)
// 4 if it's a number
if ( this.state.hashOrCSS || // 1
this.state.root || // 1
interpolatedRe.test( this.cache.origLine ) ||
ignoreRe.test( line.trim() ) || // 2
attrOrMixinRe.test( line ) || // 3
numRe.test( arr[0] ) ) { // 3
isValid = true
}
// if using an attr selector ( div[madeUpAttribute] ), strip it out ( div )
if ( !isValid ) {
arr[0] = arr[0].replace( stripRe, '' ).trim()
}
// if no match yet, check for css && prefix + css, will return true at first match
if ( !isValid ) {
isValid = validJSON.css.some( function( css ) {
return arr[0] === css || this.checkPrefix( arr[0], css, validJSON )
}.bind( this ) )
}
// if no match yet, try html && html + pseudo
if ( !isValid ) {
isValid = validJSON.html.some( function( html ) {
return arr[0] === html || this.checkPseudo( arr[0], html, validJSON )
}.bind( this ) )
}
// if no match yet, try pseudo as standalone
if ( !isValid ) {
isValid = validJSON.pseudo.some( function( pseudo ) {
// psuedo selectors could have one of two colons
return ':' + arr[0] === pseudo || '::' + arr[0] === pseudo
} )
}
// if no match yet, try declared mixins and custom properties
if ( !isValid ) {
isValid = this.cache.customProperties.some( function( mixin ) {
return arr[0] === mixin
} )
}
if ( isValid === false ) {
this.msg( 'property is not valid', line.indexOf( arr[0] ) )
}
return isValid
}
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#blocks">blocks</a></li><li><a href="global.html#brackets">brackets</a></li><li><a href="global.html#checkPrefix">checkPrefix</a></li><li><a href="global.html#checkPseudo">checkPseudo</a></li><li><a href="global.html#colons">colons</a></li><li><a href="global.html#colors">colors</a></li><li><a href="global.html#commaSpace">commaSpace</a></li><li><a href="global.html#commentSpace">commentSpace</a></li><li><a href="global.html#config">config</a></li><li><a href="global.html#cssLiteral">cssLiteral</a></li><li><a href="global.html#depthLimit">depthLimit</a></li><li><a href="global.html#done">done</a></li><li><a href="global.html#duplicates">duplicates</a></li><li><a href="global.html#efficient">efficient</a></li><li><a href="global.html#extendPref">extendPref</a></li><li><a href="global.html#getFiles">getFiles</a></li><li><a href="global.html#hashEnd">hashEnd</a></li><li><a href="global.html#hashStart">hashStart</a></li><li><a href="global.html#indentPref">indentPref</a></li><li><a href="global.html#init">init</a></li><li><a href="global.html#keyframesEnd">keyframesEnd</a></li><li><a href="global.html#keyframesStart">keyframesStart</a></li><li><a href="global.html#leadingZero">leadingZero</a></li><li><a href="global.html#lint">lint</a></li><li><a href="global.html#mixed">mixed</a></li><li><a href="global.html#msg">msg</a></li><li><a href="global.html#namingConvention">namingConvention</a></li><li><a href="global.html#noImportant">noImportant</a></li><li><a href="global.html#none">none</a></li><li><a href="global.html#parenSpace">parenSpace</a></li><li><a href="global.html#parse">parse</a></li><li><a href="global.html#placeholders">placeholders</a></li><li><a href="global.html#prefixVarsWithDollar">prefixVarsWithDollar</a></li><li><a href="global.html#quotePref">quotePref</a></li><li><a href="global.html#read">read</a></li><li><a href="global.html#reporter">reporter</a></li><li><a href="global.html#resetOnChange">resetOnChange</a></li><li><a href="global.html#rootEnd">rootEnd</a></li><li><a href="global.html#rootStart">rootStart</a></li><li><a href="global.html#semicolons">semicolons</a></li><li><a href="global.html#setConfig">setConfig</a></li><li><a href="global.html#setContext">setContext</a></li><li><a href="global.html#setState">setState</a></li><li><a href="global.html#sortOrder">sortOrder</a></li><li><a href="global.html#splitAndStrip">splitAndStrip</a></li><li><a href="global.html#stackedProperties">stackedProperties</a></li><li><a href="global.html#startsWithComment">startsWithComment</a></li><li><a href="global.html#state">state</a></li><li><a href="global.html#stylintOff">stylintOff</a></li><li><a href="global.html#stylintOn">stylintOn</a></li><li><a href="global.html#trailingWhitespace">trailingWhitespace</a></li><li><a href="global.html#trimLine">trimLine</a></li><li><a href="global.html#universal">universal</a></li><li><a href="global.html#watch">watch</a></li><li><a href="global.html#zeroUnits">zeroUnits</a></li><li><a href="global.html#zIndexNormalize">zIndexNormalize</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.2</a> on Sun Oct 09 2016 22:18:45 GMT+0200 (CEST)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>