analyze-css
Advanced tools
Comparing version 0.4.1 to 0.5.0
@@ -9,2 +9,3 @@ /** | ||
fs = require('fs'), | ||
preprocessors = new (require('./preprocessors'))(), | ||
slickParse = require('slick').parse, | ||
@@ -22,2 +23,5 @@ VERSION = require('./../package').version; | ||
this.options = options; | ||
debug('opts: %j', this.options); | ||
if (typeof css !== 'string') { | ||
@@ -28,3 +32,18 @@ callback(new Error('css parameter passed is not a string!'), null); | ||
// preprocess the CSS (issue #3) | ||
if (typeof options.preprocessor === 'string') { | ||
debug('Using "%s" preprocessor', options.preprocessor); | ||
var preprocessor = preprocessors.get(options.preprocessor); | ||
try { | ||
css = preprocessor.process(css, options); | ||
} | ||
catch(ex) { | ||
throw new Error('Preprocessing failed: ' + ex); | ||
} | ||
debug('Preprocessing completed'); | ||
} | ||
res = this.analyze(css); | ||
@@ -219,2 +238,7 @@ | ||
break; | ||
// {"type":"import","import":"url('/css/styles.css')"} | ||
case 'import': | ||
this.emit('import', rule.import); | ||
break; | ||
} | ||
@@ -221,0 +245,0 @@ }, this); |
@@ -13,2 +13,3 @@ /** | ||
analyzer = require('./index'), | ||
preprocessors = new (require('./preprocessors'))(), | ||
url = require('url'); | ||
@@ -52,4 +53,8 @@ | ||
// call CommonJS module | ||
var analyzerOpts = { | ||
preprocessor: false | ||
}; | ||
function analyze(css) { | ||
new analyzer(css, callback); | ||
new analyzer(css, analyzerOpts, callback); | ||
} | ||
@@ -86,2 +91,10 @@ | ||
else { | ||
// find the matching preprocessor and use it | ||
if (analyzerOpts.preprocessor === false) { | ||
analyzerOpts.preprocessor = preprocessors.findMatchingByFileName(options.file); | ||
} | ||
// pass the name of the file being analyzed | ||
analyzerOpts.file = options.file; | ||
analyze(css); | ||
@@ -88,0 +101,0 @@ } |
{ | ||
"name": "analyze-css", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"author": "Maciej Brencz <maciej.brencz@gmail.com> (https://github.com/macbre)", | ||
@@ -26,2 +26,4 @@ "description": "CSS selectors complexity and performance analyzer", | ||
"fast-stats": "0.0.x", | ||
"glob": "^4.0.5", | ||
"node-sass": "^0.9.3", | ||
"optimist": "0.6.x", | ||
@@ -34,2 +36,3 @@ "slick": "~1.12.1", | ||
"glob": "~4.0.5", | ||
"istanbul": "^0.3.0", | ||
"jshint": "~2.5.2", | ||
@@ -42,3 +45,4 @@ "mocha": "~1.21.3" | ||
"test": "mocha -R spec", | ||
"lint": "jshint --verbose bin/ lib/ rules/ test/" | ||
"lint": "jshint --verbose bin/ lib/ rules/ test/", | ||
"coverage": "istanbul cover _mocha -- -R spec" | ||
}, | ||
@@ -45,0 +49,0 @@ "jshintConfig": { |
@@ -49,2 +49,12 @@ analyze-css | ||
### [grunt task](https://www.npmjs.org/package/grunt-contrib-analyze-css) | ||
> Created by @DeuxHuitHuit | ||
``` | ||
npm i grunt-contrib-analyze-css | ||
``` | ||
It uses configurable threshold and compares the analyze-css result with it. | ||
### Results | ||
@@ -54,3 +64,3 @@ | ||
{ | ||
"generator": "analyze-css v0.3.0", | ||
"generator": "analyze-css v0.4.1", | ||
"metrics": { | ||
@@ -67,2 +77,3 @@ "base64Length": 9308, | ||
"oldIEFixes": 51, | ||
"imports": 0, | ||
"importants": 3, | ||
@@ -109,2 +120,3 @@ "mediaQueries": 0, | ||
* **oldIEFixes**: number of fixes for old versions of Internet Explorer (e.g. ``* html .foo {}`` and ``.foo { *zoom: 1 }``, [read](http://blogs.msdn.com/b/ie/archive/2005/09/02/460115.aspx) [more](http://www.impressivewebs.com/ie7-ie8-css-hacks/)) | ||
* **imports** number of ``@import`` rules | ||
* **importants**: number of properties with value forced by ``!important`` | ||
@@ -111,0 +123,0 @@ * **mediaQueries**: number of media queries (e.g. ``@media screen and (min-width: 1370px)``) |
@@ -7,4 +7,6 @@ 'use strict'; | ||
analyzer.on('selector', function(rule, selector, expressions) { | ||
var noExpressions = expressions.length; | ||
// check more complex selectors only | ||
if (expressions.length < 2) { | ||
if (noExpressions < 2) { | ||
return; | ||
@@ -14,2 +16,3 @@ } | ||
var firstTag = expressions[0].tag, | ||
lastTag = expressions[noExpressions-1].tag, | ||
isDescendantCombinator = (expressions[1].combinator === '>'), | ||
@@ -22,2 +25,6 @@ isRedundant = false; | ||
} | ||
// matches html.modal-popup-mode body (issue #44) | ||
else if (firstTag === 'html' && lastTag === 'body' && noExpressions === 2) { | ||
isRedundant = false; | ||
} | ||
// matches "body .foo", but not "body > .bar' nor "body.foo .bar" | ||
@@ -24,0 +31,0 @@ else if (firstTag === 'body' && !isDescendantCombinator && !expressions[0].classList) { |
@@ -20,3 +20,3 @@ /*global describe, it */ | ||
it('should emit "' + metric + '" metric with a valid value - #' + (testId + 1), function() { | ||
assert.strictEqual(metricsActual[metric], metricsExpected[metric]); | ||
assert.strictEqual(metricsActual[metric], metricsExpected[metric], "Testing metric against: " + test.css); | ||
}); | ||
@@ -23,0 +23,0 @@ }); |
@@ -49,3 +49,9 @@ exports.tests = [ | ||
} | ||
}, | ||
{ | ||
css: 'html.modal-popup-mode body {}', | ||
metrics: { | ||
redundantBodySelectors: 0 | ||
} | ||
} | ||
]; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
144637
56
3246
162
9
5
8
+ Addedglob@^4.0.5
+ Addednode-sass@^0.9.3
+ Addedansi-regex@0.2.1(transitive)
+ Addedansi-styles@1.1.0(transitive)
+ Addedavailable-typed-arrays@1.0.7(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addedchalk@0.5.1(transitive)
+ Addedcommander@0.6.12.3.0(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addeddebug@2.0.0(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddiff@1.0.8(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedescape-string-regexp@1.0.21.0.5(transitive)
+ Addedfor-each@0.3.3(transitive)
+ Addedformatio@1.0.2(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedget-stdin@3.0.2(transitive)
+ Addedglob@3.2.34.5.3(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedgraceful-fs@2.0.3(transitive)
+ Addedgrowl@1.8.1(transitive)
+ Addedhas-ansi@0.1.0(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedis-arguments@1.1.1(transitive)
+ Addedis-callable@1.2.7(transitive)
+ Addedis-generator-function@1.0.10(transitive)
+ Addedis-typed-array@1.1.13(transitive)
+ Addedjade@0.26.3(transitive)
+ Addedminimatch@0.2.142.0.10(transitive)
+ Addedminimist@0.0.81.2.8(transitive)
+ Addedmkdirp@0.3.00.5.00.5.6(transitive)
+ Addedmocha@1.21.5(transitive)
+ Addedms@0.6.2(transitive)
+ Addednan@1.3.0(transitive)
+ Addednode-sass@0.9.6(transitive)
+ Addednode-sass-middleware@0.3.1(transitive)
+ Addednode-watch@0.3.5(transitive)
+ Addedobject-assign@1.0.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpossible-typed-array-names@1.0.0(transitive)
+ Addedsamsam@1.1.3(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedshelljs@0.3.0(transitive)
+ Addedsinon@1.10.3(transitive)
+ Addedstrip-ansi@0.3.0(transitive)
+ Addedsupports-color@0.2.0(transitive)
+ Addedutil@0.12.5(transitive)
+ Addedwhich-typed-array@1.1.15(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedyargs@1.3.3(transitive)